index.vue 12 KB

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