index.vue 9.5 KB

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