index.vue 11 KB

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