index.vue 12 KB

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