index.vue 8.4 KB

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