index.vue 8.6 KB

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