index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <!--
  2. 锦标赛 - 卡片页
  3. http://localhost:5173/card/#/pages/jbs/index
  4. https://oss-mbh5.colormaprun.com/card/#/pages/jbs/index
  5. -->
  6. <template>
  7. <view class="body body-radius">
  8. <view v-if="pageReady" class="content" :class="cssContentBg" @click="btnClick">
  9. <view class="top uni-row">
  10. <view class="top-right uni-row">
  11. <image mode="aspectFit" class="clock" src="/static/default/clock.png"></image>
  12. <view class="countdown">{{countdown}}</view>
  13. </view>
  14. </view>
  15. <view class="main uni-column">
  16. <view :class="cssLogo"></view>
  17. <view class="uni-row" style="position: relative;">
  18. <image v-if="notice" mode="aspectFit" src="/static/common/notice.png" class="notice"></image>
  19. <text class="type mod-text">{{type}}</text>
  20. </view>
  21. <text class="name mod-text">{{ecName}}</text>
  22. <button class="button mod-button">{{btnText}}</button>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import tools from '../../common/tools';
  29. import {
  30. token,
  31. ossUrl,
  32. apiCardBaseQuery,
  33. apiCardConfigQuery,
  34. apiUserCurrentRankNumQuery
  35. } from '../../common/api';
  36. export default {
  37. data() {
  38. return {
  39. pageReady: false,
  40. pageName: "index",
  41. rankKey: "rank-jbs",
  42. queryObj: {},
  43. queryString: "",
  44. token: "",
  45. ecId: 0, // 卡片id
  46. ecName: '', // 卡片名称
  47. ecDesc: '', // 卡片简介
  48. beginSecond: null, // 卡片开始时间戳,单位秒
  49. endSecond: null, // 卡片结束时间戳,单位秒
  50. countdown: "", // 倒计时
  51. interval: null,
  52. cssContentBg: "",
  53. cssLogo: "",
  54. type: "",
  55. btnText: "",
  56. notice: false, // 是否显示(小红点)通知图标
  57. }
  58. },
  59. computed: {},
  60. onLoad(query) { // 类型非必填,可自动推导
  61. // console.log(query);
  62. this.queryObj = query;
  63. this.queryString = tools.objectToQueryString(this.queryObj);
  64. // console.log(queryString);
  65. this.token = query["token"] ?? token;
  66. this.ecId = query["id"] ?? 0;
  67. this.type = query["type"] ?? "锦标赛";
  68. this.btnText = query["btnText"] ?? "开始比赛";
  69. this.rankKey += "-" + this.ecId;
  70. console.log("rankKey:", this.rankKey);
  71. tools.removeCssCode();
  72. this.getCardBaseQuery();
  73. this.getCardConfigQuery();
  74. this.getUserCurrentRankNumQuery();
  75. },
  76. onUnload() {
  77. this.clear();
  78. },
  79. methods: {
  80. dealNotice(rank) {
  81. // console.log('[dealFirstEnter]');
  82. let that = this;
  83. uni.getStorage({
  84. key: that.rankKey,
  85. success: (res) => {
  86. console.log('[getStorage]', that.rankKey, res.data);
  87. const oldRank = res.data;
  88. if (oldRank != rank) {
  89. that.notice = true;
  90. // that.setRankValue(rank);
  91. }
  92. },
  93. fail: (e) => {
  94. console.log('[getStorage] fail', that.rankKey, e);
  95. that.notice = true;
  96. // that.setRankValue(rank);
  97. },
  98. })
  99. },
  100. setRankValue(data) {
  101. let that = this;
  102. uni.setStorage({
  103. key: that.rankKey,
  104. data: data,
  105. success: () => {
  106. console.log('[setStorage] success', that.rankKey, data);
  107. },
  108. fail: (e) => {
  109. console.log('[setStorage] fail', that.rankKey, e);
  110. },
  111. })
  112. },
  113. clear() {
  114. if (this.interval != null) {
  115. clearInterval(this.interval);
  116. this.interval = null;
  117. }
  118. },
  119. loadConfig(config) {
  120. // console.log("config", config);
  121. const css = config.css;
  122. if (css != undefined && css.length > 0) {
  123. tools.loadCssCode(css);
  124. if (css.indexOf(".content-bg{") >= 0) {
  125. this.cssContentBg = "content-bg";
  126. }
  127. if (css.indexOf(".logo{") >= 0) {
  128. this.cssLogo = "logo";
  129. }
  130. }
  131. if (this.cssContentBg == "") {
  132. this.cssContentBg = "content-bg-default";
  133. }
  134. if (this.cssLogo == "") {
  135. this.cssLogo = "logo-default";
  136. }
  137. console.log("[loadConfig] cssContentBg:", this.cssContentBg);
  138. console.log("[loadConfig] cssLogo:", this.cssLogo);
  139. this.pageReady = true;
  140. },
  141. // 获取倒计时
  142. getCountdown() {
  143. // console.log(this.endSecond)
  144. if (this.endSecond > 0) {
  145. const now = Date.now() / 1000;
  146. const dif = this.endSecond - now;
  147. // const dif = 3600*24 - 60;
  148. if (dif > 0) {
  149. this.countdown = "距结束 " + tools.convertSecondsToDHM(dif);
  150. } else {
  151. this.countdown = "已结束";
  152. }
  153. // this.countdown = tools.convertSecondsToHMS(dif);
  154. } else {
  155. this.countdown = "距结束 --天--小时";
  156. }
  157. },
  158. // 卡片基本信息查询
  159. getCardBaseQuery() {
  160. uni.request({
  161. url: apiCardBaseQuery,
  162. header: {
  163. "Content-Type": "application/x-www-form-urlencoded",
  164. "token": this.token,
  165. },
  166. method: "POST",
  167. data: {
  168. ecId: this.ecId
  169. },
  170. success: (res) => {
  171. // console.log("getCardBaseQuery", res)
  172. const data = res.data.data;
  173. this.ecName = data.ecName;
  174. this.ecDesc = data.ecDesc;
  175. this.beginSecond = data.beginSecond;
  176. this.endSecond = data.endSecond;
  177. this.getCountdown();
  178. this.clear();
  179. this.interval = setInterval(this.getCountdown, 60000);
  180. },
  181. fail: (err) => {
  182. console.log("getCardBaseQuery err", err)
  183. },
  184. });
  185. },
  186. // 卡片配置信息查询
  187. getCardConfigQuery() {
  188. uni.request({
  189. url: apiCardConfigQuery,
  190. header: {
  191. "Content-Type": "application/x-www-form-urlencoded",
  192. "token": this.token,
  193. },
  194. method: "POST",
  195. data: {
  196. ecId: this.ecId,
  197. pageName: this.pageName
  198. },
  199. success: (res) => {
  200. // console.log("getCardConfigQuery", res)
  201. const data = res.data.data;
  202. const config = data.configJson != "" ? JSON.parse(data.configJson) : "";
  203. // console.log("configJson", config);
  204. /* const config = {
  205. "css": `
  206. .content-bg{
  207. background: url('static/cardbg/xfl.png') no-repeat;
  208. background-size: cover;
  209. }
  210. .logo{
  211. width: 50vw;
  212. height: 50vw;
  213. background: url('static/logo/xfl.png') no-repeat;
  214. background-size: contain;
  215. }
  216. `
  217. }; */
  218. this.loadConfig(config);
  219. },
  220. fail: (err) => {
  221. console.log("getCardConfigQuery err", err)
  222. },
  223. });
  224. },
  225. // 卡片用户当前排名查询
  226. getUserCurrentRankNumQuery() {
  227. uni.request({
  228. url: apiUserCurrentRankNumQuery,
  229. header: {
  230. "Content-Type": "application/x-www-form-urlencoded",
  231. "token": this.token,
  232. },
  233. method: "POST",
  234. data: {
  235. ecId: this.ecId
  236. },
  237. success: (res) => {
  238. // console.log("getUserCurrentRankNumQuery", res)
  239. if (res.data.code == 0) {
  240. const data = res.data.data;
  241. const rankNum = data.rankNum;
  242. this.dealNotice(rankNum);
  243. }
  244. },
  245. fail: (err) => {
  246. console.log("getUserCurrentRankNumQuery err", err)
  247. },
  248. });
  249. },
  250. btnClick() {
  251. // uni.reLaunch({
  252. // url: '/pages/jbs/rankList?full=true&' + this.queryString
  253. // });
  254. const url = `${ossUrl}#/pages/jbs/rankList?${this.queryString}&full=true`;
  255. tools.appAction(url);
  256. }
  257. }
  258. }
  259. </script>
  260. <style scoped>
  261. .content {
  262. width: 100vw;
  263. height: 100vh;
  264. }
  265. .content-bg-default {
  266. background: linear-gradient(180deg, #7aedff 0%, #047200 100%);
  267. /* background: linear-gradient(180deg, #178bff 0%, #004d9b 100%); */
  268. /* background: linear-gradient(180deg, #7aedff 0%, #8d2219 100%); */
  269. }
  270. .top {
  271. width: 100%;
  272. justify-content: flex-end;
  273. }
  274. .top-right {
  275. min-width: 180rpx;
  276. height: 80rpx;
  277. margin-top: 30rpx;
  278. margin-right: 30rpx;
  279. padding-left: 16rpx;
  280. padding-right: 16rpx;
  281. background-color: rgba(0, 0, 0, 0.3);
  282. border-radius: 12px;
  283. }
  284. .clock {
  285. width: 50rpx;
  286. height: 50rpx;
  287. margin-right: 12rpx;
  288. }
  289. .countdown {
  290. min-width: 120rpx;
  291. text-align: center;
  292. font-family: Roboto;
  293. color: #ffffff;
  294. font-size: 46rpx;
  295. /* letter-spacing: 2rpx; */
  296. }
  297. .main {
  298. width: 100%;
  299. height: 700rpx;
  300. margin-top: 20rpx;
  301. justify-content: space-evenly;
  302. }
  303. .logo-default {
  304. width: 50vw;
  305. height: 50vw;
  306. background-image: url('/static/logo/jbs.png');
  307. background-repeat: no-repeat;
  308. background-position-x: center;
  309. background-position-y: center;
  310. background-size: contain;
  311. }
  312. .notice {
  313. width: 30rpx;
  314. height: 30rpx;
  315. /* margin-right: 30rpx; */
  316. position: absolute;
  317. left: -60rpx;
  318. }
  319. .type {
  320. opacity: 60%;
  321. /* line-height: 25px; */
  322. font-family: Roboto;
  323. color: #ffffff;
  324. font-size: 40rpx;
  325. text-align: center;
  326. }
  327. .name {
  328. font-family: Roboto;
  329. color: #ffffff;
  330. font-size: 50rpx;
  331. text-align: center;
  332. }
  333. .button {
  334. width: 320rpx;
  335. height: 86rpx;
  336. margin-top: 30rpx;
  337. color: #000000;
  338. background: #ffffff;
  339. border-radius: 56rpx;
  340. font-size: 46rpx;
  341. line-height: 80rpx;
  342. }
  343. /* .mod-text {
  344. color: #FF6203 !important;
  345. }
  346. .mod-button {
  347. color: #ffffff !important;
  348. background-color: #FF6203 !important;
  349. } */
  350. </style>