index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <!--
  2. [报名] 样式2 - 卡片页
  3. http://localhost:5173/card/#/pages/bm/style2/index
  4. https://oss-mbh5.colormaprun.com/card/#/pages/bm/style2/index
  5. -->
  6. <template>
  7. <view class="body body-radius">
  8. <view class="content" :class="cssContentBg" @click="btnClick">
  9. <view class="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="main uni-column">
  16. <!-- <image mode="aspectFit" :class="cssLogo" :src="logoSrc"></image> -->
  17. <view :class="cssLogo"></view>
  18. <view class="uni-row" style="position: relative;">
  19. <image v-if="notice" mode="aspectFit" src="/static/common/notice.png" class="notice"></image>
  20. <text class="type mod-text">{{type}}</text>
  21. </view>
  22. <text class="name mod-text">{{ecName}}</text>
  23. <button class="button mod-button">{{btnText}}</button>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import tools from '../../../common/tools';
  30. import {
  31. token,
  32. ossUrl,
  33. apiCardBaseQuery,
  34. apiUserJoinCardQuery,
  35. apiCardConfigQuery,
  36. apiMatchRsDetailQuery
  37. } from '../../../common/api';
  38. export default {
  39. data() {
  40. return {
  41. // audioSrc: "/static/audio/2.mp3",
  42. // audioSrc: "https://oss-mbh5.colormaprun.com/card/static/audio/2.mp3",
  43. // audioSrc: "http://t-oss-mbh5.colormaprun.com/card/static/audio/2.mp3",
  44. pageName: "index",
  45. rankKey: "rank-bm-style2",
  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. cssContentBg: "",
  63. cssLogo: "",
  64. // logoSrc: "",
  65. type: "",
  66. btnText: "",
  67. notice: false, // 是否显示(小红点)通知图标
  68. }
  69. },
  70. computed: {},
  71. onLoad(query) { // 类型非必填,可自动推导
  72. // console.log(query);
  73. this.queryObj = query;
  74. this.queryString = tools.objectToQueryString(this.queryObj);
  75. // console.log(queryString);
  76. this.token = query["token"] ?? token;
  77. this.ecId = query["id"] ?? 0;
  78. // this.contentBg = "content-bg-" + (query["bg"] ?? "green");
  79. // this.logoSrc = "/static/logo/" + (query["logo"] ?? "jbs") + '.png';
  80. this.type = query["type"] ?? "锦标赛";
  81. this.btnText = query["btnText"] ?? "开始比赛";
  82. this.rankKey += "-" + this.ecId;
  83. console.log("rankKey:", this.rankKey);
  84. tools.removeCssCode();
  85. this.getCardBaseQuery();
  86. this.getCardConfigQuery();
  87. this.matchRsDetailQuery();
  88. },
  89. onShow() {
  90. this.getUserJoinCardQuery();
  91. },
  92. onUnload() {
  93. this.clear();
  94. },
  95. methods: {
  96. playMusic() {
  97. // if (this.$audio.audioStatus == 0 || this.$audio.audioSrc != this.audioSrc) {
  98. // this.$audio.playAudio(this.audioSrc);
  99. // }
  100. },
  101. dealNotice(rank) {
  102. // console.log('[dealNotice]');
  103. let that = this;
  104. uni.getStorage({
  105. key: that.rankKey,
  106. success: (res) => {
  107. console.log('[getStorage]', that.rankKey, res.data);
  108. const oldRank = res.data;
  109. if (oldRank != rank) {
  110. that.notice = true;
  111. // that.setRankValue(rank);
  112. }
  113. },
  114. fail: (e) => {
  115. console.log('[getStorage] fail', that.rankKey, e);
  116. that.notice = true;
  117. // that.setRankValue(rank);
  118. },
  119. })
  120. },
  121. setRankValue(data) {
  122. let that = this;
  123. uni.setStorage({
  124. key: that.rankKey,
  125. data: data,
  126. success: () => {
  127. console.log('[setStorage] success', that.rankKey, data);
  128. },
  129. fail: (e) => {
  130. console.log('[setStorage] fail', that.rankKey, e);
  131. },
  132. })
  133. },
  134. clear() {
  135. if (this.interval != null) {
  136. clearInterval(this.interval);
  137. this.interval = null;
  138. }
  139. },
  140. loadConfig(config) {
  141. // console.log("config", config);
  142. const css = config.css;
  143. if (css != undefined && css.length > 0) {
  144. tools.loadCssCode(css);
  145. if (css.indexOf(".content-bg{") >= 0) {
  146. this.cssContentBg = "content-bg";
  147. }
  148. if (css.indexOf(".logo{") >= 0) {
  149. this.cssLogo = "logo";
  150. }
  151. }
  152. if (this.cssContentBg == "") {
  153. this.cssContentBg = "content-bg-default";
  154. }
  155. if (this.cssLogo == "") {
  156. this.cssLogo = "logo-default";
  157. }
  158. console.log("[loadConfig] cssContentBg:", this.cssContentBg);
  159. console.log("[loadConfig] cssLogo:", this.cssLogo);
  160. },
  161. // 获取倒计时
  162. getCountdown() {
  163. // console.log(this.endSecond)
  164. if (this.endSecond > 0) {
  165. const now = Date.now() / 1000;
  166. const dif = this.endSecond - now;
  167. // const dif = 3600*24 - 60;
  168. if (dif > 0) {
  169. this.countdown = "距结束 " + tools.convertSecondsToDHM(dif);
  170. } else {
  171. this.countdown = "已结束";
  172. this.isFinished = true;
  173. }
  174. // this.countdown = tools.convertSecondsToHMS(dif);
  175. } else {
  176. this.countdown = "距结束 --天--小时";
  177. }
  178. },
  179. // 卡片基本信息查询
  180. getCardBaseQuery() {
  181. uni.request({
  182. url: apiCardBaseQuery,
  183. header: {
  184. "Content-Type": "application/x-www-form-urlencoded",
  185. "token": this.token,
  186. },
  187. method: "POST",
  188. data: {
  189. ecId: this.ecId,
  190. pageName: this.pageName
  191. },
  192. success: (res) => {
  193. // console.log("getCardBaseQuery", res)
  194. const data = res.data.data;
  195. this.ecName = data.ecName;
  196. this.ecDesc = data.ecDesc;
  197. this.beginSecond = data.beginSecond;
  198. this.endSecond = data.endSecond;
  199. this.secondCardName = data.secondCardName;
  200. this.getCountdown();
  201. this.clear();
  202. this.interval = setInterval(this.getCountdown, 60000);
  203. },
  204. fail: (err) => {
  205. console.log("getCardBaseQuery err", err)
  206. },
  207. });
  208. },
  209. // 卡片配置信息查询
  210. getCardConfigQuery() {
  211. uni.request({
  212. url: apiCardConfigQuery,
  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("getCardConfigQuery", res);
  224. const data = res.data.data;
  225. const config = data.configJson != "" ? JSON.parse(data.configJson) : "";
  226. // console.log("configJson", config);
  227. /* const config = {
  228. "css": `
  229. .content-bg{
  230. background: url('static/cardbg/xfl3.jpg');
  231. background-size: cover;
  232. }
  233. .logo{
  234. width: 40vw;
  235. height: 40vw;
  236. background: url('static/logo/xfl.png') no-repeat center;
  237. background-size: contain;
  238. }
  239. .mod-text {
  240. color: #FF6203 !important;
  241. }
  242. .mod-button {
  243. color: #ffffff !important;
  244. background-color: #FF6203 !important;
  245. }
  246. `
  247. }; */
  248. this.loadConfig(config);
  249. },
  250. fail: (err) => {
  251. console.log("getCardConfigQuery err", err)
  252. },
  253. });
  254. },
  255. // 用户是否已经报名卡片对应赛事查询
  256. getUserJoinCardQuery() {
  257. uni.request({
  258. url: apiUserJoinCardQuery,
  259. header: {
  260. "Content-Type": "application/x-www-form-urlencoded",
  261. "token": this.token
  262. },
  263. method: "POST",
  264. data: {
  265. ecId: this.ecId
  266. },
  267. success: (res) => {
  268. // console.log("getUserJoinCardQuery", res)
  269. const code = res.data.code;
  270. const data = res.data.data;
  271. if (code == 0) {
  272. this.isJoin = data.isJoin;
  273. /*if (this.isJoin) {
  274. this.btnText = "已报名";
  275. } else {
  276. this.btnText = "未报名";
  277. } */
  278. }
  279. },
  280. fail: (err) => {
  281. console.log("getUserJoinCardQuery err", err)
  282. },
  283. });
  284. },
  285. // 卡片用户当前排名查询
  286. // getUserCurrentRankNumQuery() {
  287. // uni.request({
  288. // url: apiUserCurrentRankNumQuery,
  289. // header: {
  290. // "Content-Type": "application/x-www-form-urlencoded",
  291. // "token": this.token,
  292. // },
  293. // method: "POST",
  294. // data: {
  295. // ecId: this.ecId
  296. // },
  297. // success: (res) => {
  298. // // console.log("getUserCurrentRankNumQuery", res)
  299. // if (res.data.code == 0) {
  300. // const data = res.data.data;
  301. // const rankNum = data.rankNum;
  302. // this.dealNotice(rankNum);
  303. // }
  304. // },
  305. // fail: (err) => {
  306. // console.log("getUserCurrentRankNumQuery err", err)
  307. // },
  308. // });
  309. // },
  310. // 卡片对应线上赛多个活动查询
  311. matchRsDetailQuery() {
  312. uni.request({
  313. url: apiMatchRsDetailQuery,
  314. header: {
  315. "Content-Type": "application/x-www-form-urlencoded",
  316. "token": this.token,
  317. },
  318. method: "POST",
  319. data: {
  320. ecId: this.ecId
  321. },
  322. success: (res) => {
  323. // console.log("matchRsDetailQuery", res);
  324. if (res.data.code == 0) {
  325. const data = res.data.data;
  326. const rank = JSON.stringify(data);
  327. this.dealNotice(rank);
  328. }
  329. },
  330. fail: (err) => {
  331. console.log("matchRsDetailQuery err", err)
  332. },
  333. });
  334. },
  335. btnClick() {
  336. // this.playMusic();
  337. if (this.isJoin) { // 已报名
  338. // uni.reLaunch({
  339. // url: '/pages/bm/style1/rankList?full=true&' + this.queryString
  340. // });
  341. // const url = `${ossUrl}#/pages/bm/style2/rankOverview?${this.queryString}&full=true`;
  342. const url = `${ossUrl}#/pages/bm/style2/rankList?${this.queryString}&full=true`;
  343. tools.appAction(url);
  344. }
  345. else { // 未报名
  346. // uni.reLaunch({
  347. // url: '/pages/bm/style1/signup?full=true&' + this.queryString
  348. // });
  349. if (!this.isFinished) { // 赛事未结束
  350. if (this.secondCardName == 'rankList') {
  351. const url = `${ossUrl}#/pages/bm/style2/rankList?${this.queryString}&full=true`;
  352. tools.appAction(url);
  353. } else {
  354. const url = `${ossUrl}#/pages/bm/style2/signup?${this.queryString}&full=true`;
  355. tools.appAction(url);
  356. }
  357. }
  358. else { // 赛事已结束
  359. // const url = `${ossUrl}#/pages/bm/style2/rankOverview?${this.queryString}&full=true`;
  360. const url = `${ossUrl}#/pages/bm/style2/rankList?${this.queryString}&full=true`;
  361. tools.appAction(url);
  362. }
  363. }
  364. }
  365. }
  366. }
  367. </script>
  368. <style scoped>
  369. .content {
  370. width: 100vw;
  371. height: 100vh;
  372. }
  373. .content-bg-default {
  374. background: linear-gradient(180deg, #7aedff 0%, #047200 100%);
  375. /* background: linear-gradient(180deg, #178bff 0%, #004d9b 100%); */
  376. /* background: linear-gradient(180deg, #7aedff 0%, #8d2219 100%); */
  377. }
  378. .top {
  379. width: 100%;
  380. justify-content: flex-end;
  381. }
  382. .top-right {
  383. min-width: 180rpx;
  384. height: 80rpx;
  385. margin-top: 30rpx;
  386. margin-right: 30rpx;
  387. padding-left: 16rpx;
  388. padding-right: 16rpx;
  389. background-color: rgba(0, 0, 0, 0.3);
  390. border-radius: 12px;
  391. }
  392. .clock {
  393. width: 50rpx;
  394. height: 50rpx;
  395. margin-right: 12rpx;
  396. }
  397. .countdown {
  398. min-width: 120rpx;
  399. text-align: center;
  400. font-family: Roboto;
  401. color: #ffffff;
  402. font-size: 46rpx;
  403. /* letter-spacing: 2rpx; */
  404. }
  405. .main {
  406. width: 100%;
  407. height: 700rpx;
  408. margin-top: 20rpx;
  409. justify-content: space-evenly;
  410. }
  411. .logo-default {
  412. width: 50vw;
  413. height: 50vw;
  414. background-image: url('/static/logo/jbs.png');
  415. background-repeat: no-repeat;
  416. background-position-x: center;
  417. background-position-y: center;
  418. background-size: contain;
  419. }
  420. .notice {
  421. width: 30rpx;
  422. height: 30rpx;
  423. /* margin-right: 30rpx; */
  424. position: absolute;
  425. left: -60rpx;
  426. }
  427. .type {
  428. opacity: 60%;
  429. /* line-height: 25px; */
  430. font-family: Roboto;
  431. color: #ffffff;
  432. font-size: 40rpx;
  433. text-align: center;
  434. }
  435. .name {
  436. font-family: Roboto;
  437. color: #ffffff;
  438. font-size: 50rpx;
  439. text-align: center;
  440. }
  441. .button {
  442. width: 320rpx;
  443. height: 86rpx;
  444. margin-top: 30rpx;
  445. color: #000000;
  446. background: #ffffff;
  447. border-radius: 56rpx;
  448. font-size: 46rpx;
  449. line-height: 80rpx;
  450. }
  451. /* .mod-text {
  452. color: #FF6203 !important;
  453. }
  454. .mod-button {
  455. color: #ffffff !important;
  456. background-color: #FF6203 !important;
  457. } */
  458. </style>