index.vue 10 KB

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