index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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 != '') {
  180. css = `.logo{
  181. width: 80vw !important;
  182. height: 40vw !important;
  183. background: url('${tplInfo.matchLogo}') no-repeat center !important;
  184. background-size: contain !important;
  185. }`;
  186. }
  187. if (css.length > 0) {
  188. tools.loadCssCode(css, "css-user");
  189. }
  190. },
  191. // 获取倒计时
  192. getCountdown() {
  193. // console.log(this.endSecond)
  194. if (this.endSecond > 0) {
  195. const now = Date.now() / 1000;
  196. const dif = this.endSecond - now;
  197. // const dif = 3600*24 - 60;
  198. if (dif > 0) {
  199. this.countdown = "距结束 " + tools.convertSecondsToDHM(dif);
  200. } else {
  201. this.countdown = "已结束";
  202. this.isFinished = true;
  203. }
  204. // this.countdown = tools.convertSecondsToHMS(dif);
  205. } else {
  206. this.countdown = "距结束 --天--小时";
  207. }
  208. },
  209. // 卡片基本信息查询
  210. getCardBaseQuery() {
  211. uni.request({
  212. url: apiCardBaseQuery,
  213. header: {
  214. "Content-Type": "application/x-www-form-urlencoded",
  215. "token": this.token,
  216. },
  217. method: "POST",
  218. data: {
  219. ecId: this.ecId,
  220. pageName: this.pageName
  221. },
  222. success: (res) => {
  223. // console.log("getCardBaseQuery", res)
  224. const data = res.data.data;
  225. this.ecName = data.ecName;
  226. this.ecDesc = data.ecDesc;
  227. this.beginSecond = data.beginSecond;
  228. this.endSecond = data.endSecond;
  229. this.secondCardName = data.secondCardName;
  230. this.getCountdown();
  231. this.clear();
  232. this.interval = setInterval(this.getCountdown, 60000);
  233. },
  234. fail: (err) => {
  235. console.log("getCardBaseQuery err", err)
  236. },
  237. });
  238. },
  239. // 用户是否已经报名卡片对应赛事查询
  240. getUserJoinCardQuery() {
  241. uni.request({
  242. url: apiUserJoinCardQuery,
  243. header: {
  244. "Content-Type": "application/x-www-form-urlencoded",
  245. "token": this.token
  246. },
  247. method: "POST",
  248. data: {
  249. ecId: this.ecId
  250. },
  251. success: (res) => {
  252. // console.log("getUserJoinCardQuery", res)
  253. const code = res.data.code;
  254. const data = res.data.data;
  255. if (code == 0) {
  256. this.isJoin = data.isJoin;
  257. /*if (this.isJoin) {
  258. this.btnText = "已报名";
  259. } else {
  260. this.btnText = "未报名";
  261. } */
  262. }
  263. },
  264. fail: (err) => {
  265. console.log("getUserJoinCardQuery err", err)
  266. },
  267. });
  268. },
  269. // 卡片对应线上赛多个活动查询
  270. matchRsDetailQuery() {
  271. uni.request({
  272. url: apiMatchRsDetailQuery,
  273. header: {
  274. "Content-Type": "application/x-www-form-urlencoded",
  275. "token": this.token,
  276. },
  277. method: "POST",
  278. data: {
  279. ecId: this.ecId
  280. },
  281. success: (res) => {
  282. // console.log("matchRsDetailQuery", res);
  283. if (res.data.code == 0) {
  284. const data = res.data.data;
  285. const rank = JSON.stringify(data);
  286. this.dealNotice(rank);
  287. }
  288. },
  289. fail: (err) => {
  290. console.log("matchRsDetailQuery err", err)
  291. },
  292. });
  293. },
  294. btnClick() {
  295. if (this.isJoin) { // 已报名
  296. const url = `${ossUrl}#/pages/tpl/style1/rankList?${this.queryString}&full=true`;
  297. tools.appAction(url);
  298. } else { // 未报名
  299. if (!this.isFinished) { // 赛事未结束
  300. if (this.secondCardName == 'rankList') {
  301. const url = `${ossUrl}#/pages/tpl/style1/rankList?${this.queryString}&full=true`;
  302. tools.appAction(url);
  303. } else {
  304. const url = `${ossUrl}#/pages/tpl/style1/signup?${this.queryString}&full=true`;
  305. tools.appAction(url);
  306. }
  307. } else { // 赛事已结束
  308. const url = `${ossUrl}#/pages/tpl/style1/rankList?${this.queryString}&full=true`;
  309. tools.appAction(url);
  310. }
  311. }
  312. }
  313. }
  314. }
  315. </script>
  316. <style scoped>
  317. .content {
  318. width: 100vw;
  319. height: 100vh;
  320. }
  321. .content-bg {
  322. background: linear-gradient(180deg, #7aedff 0%, #047200 100%);
  323. /* background: linear-gradient(180deg, #178bff 0%, #004d9b 100%); */
  324. /* background: linear-gradient(180deg, #7aedff 0%, #8d2219 100%); */
  325. }
  326. .card-top {
  327. width: 100%;
  328. justify-content: flex-end;
  329. }
  330. .top-right {
  331. min-width: 180rpx;
  332. height: 80rpx;
  333. margin-top: 30rpx;
  334. margin-right: 30rpx;
  335. padding-left: 16rpx;
  336. padding-right: 16rpx;
  337. background-color: rgba(0, 0, 0, 0.3);
  338. border-radius: 12px;
  339. }
  340. .clock {
  341. width: 50rpx;
  342. height: 50rpx;
  343. margin-right: 12rpx;
  344. }
  345. .countdown {
  346. min-width: 120rpx;
  347. text-align: center;
  348. font-family: Roboto;
  349. color: #ffffff;
  350. font-size: 46rpx;
  351. /* letter-spacing: 2rpx; */
  352. }
  353. .card-main {
  354. width: 100%;
  355. /* height: 700rpx; */
  356. height: 660rpx;
  357. margin-top: 20rpx;
  358. justify-content: space-evenly;
  359. }
  360. .logo {
  361. width: 50vw;
  362. height: 50vw;
  363. background-image: url('https://oss-mbh5.colormaprun.com/static/logo/default.png');
  364. background-repeat: no-repeat;
  365. background-position-x: center;
  366. background-position-y: center;
  367. background-size: contain;
  368. }
  369. .notice {
  370. width: 30rpx;
  371. height: 30rpx;
  372. /* margin-right: 30rpx; */
  373. position: absolute;
  374. left: -60rpx;
  375. }
  376. .type {
  377. opacity: 60%;
  378. /* line-height: 25px; */
  379. font-family: Roboto;
  380. color: #ffffff;
  381. font-size: 40rpx;
  382. text-align: center;
  383. }
  384. .name {
  385. font-family: Roboto;
  386. color: #ffffff;
  387. font-size: 50rpx;
  388. text-align: center;
  389. }
  390. .button {
  391. width: 320rpx;
  392. height: 86rpx;
  393. margin-top: 30rpx;
  394. color: #000000;
  395. background: #ffffff;
  396. border-radius: 56rpx;
  397. font-size: 46rpx;
  398. line-height: 80rpx;
  399. }
  400. </style>