index.vue 10 KB

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