index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <!--
  2. [报名] 样式4 - 卡片页
  3. http://localhost:5173/card/#/pages/bm/style4/index
  4. https://oss-mbh5.colormaprun.com/card/#/pages/bm/style4/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. <view class="name mod-text">{{ecName}}</view>
  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-style4",
  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/shanda_jjyjy.png');
  233. background-size: cover;
  234. }
  235. .logo{
  236. width: 40vw;
  237. height: 40vw;
  238. background: url('static/logo/sddx2.png') no-repeat center;
  239. background-size: contain;
  240. }
  241. .mod-text{
  242. color: #FFC300 !important;
  243. }
  244. .mod-button{
  245. color: #942914 !important;
  246. background-color: #ffffff !important;
  247. }
  248. `
  249. };
  250. */
  251. this.loadConfig(config);
  252. },
  253. fail: (err) => {
  254. console.log("getCardConfigQuery err", err)
  255. },
  256. });
  257. },
  258. // 用户是否已经报名卡片对应赛事查询
  259. getUserJoinCardQuery() {
  260. uni.request({
  261. url: apiUserJoinCardQuery,
  262. header: {
  263. "Content-Type": "application/x-www-form-urlencoded",
  264. "token": this.token
  265. },
  266. method: "POST",
  267. data: {
  268. ecId: this.ecId
  269. },
  270. success: (res) => {
  271. // console.log("getUserJoinCardQuery", res)
  272. const code = res.data.code;
  273. const data = res.data.data;
  274. if (code == 0) {
  275. this.isJoin = data.isJoin;
  276. /*if (this.isJoin) {
  277. this.btnText = "已报名";
  278. } else {
  279. this.btnText = "未报名";
  280. } */
  281. }
  282. },
  283. fail: (err) => {
  284. console.log("getUserJoinCardQuery err", err)
  285. },
  286. });
  287. },
  288. // 卡片用户当前排名查询
  289. // getUserCurrentRankNumQuery() {
  290. // uni.request({
  291. // url: apiUserCurrentRankNumQuery,
  292. // header: {
  293. // "Content-Type": "application/x-www-form-urlencoded",
  294. // "token": this.token,
  295. // },
  296. // method: "POST",
  297. // data: {
  298. // ecId: this.ecId
  299. // },
  300. // success: (res) => {
  301. // // console.log("getUserCurrentRankNumQuery", res)
  302. // if (res.data.code == 0) {
  303. // const data = res.data.data;
  304. // const rankNum = data.rankNum;
  305. // this.dealNotice(rankNum);
  306. // }
  307. // },
  308. // fail: (err) => {
  309. // console.log("getUserCurrentRankNumQuery err", err)
  310. // },
  311. // });
  312. // },
  313. // 卡片对应线上赛多个活动查询
  314. matchRsDetailQuery() {
  315. uni.request({
  316. url: apiMatchRsDetailQuery,
  317. header: {
  318. "Content-Type": "application/x-www-form-urlencoded",
  319. "token": this.token,
  320. },
  321. method: "POST",
  322. data: {
  323. ecId: this.ecId
  324. },
  325. success: (res) => {
  326. // console.log("matchRsDetailQuery", res);
  327. if (res.data.code == 0) {
  328. const data = res.data.data;
  329. const rank = JSON.stringify(data);
  330. this.dealNotice(rank);
  331. }
  332. },
  333. fail: (err) => {
  334. console.log("matchRsDetailQuery err", err)
  335. },
  336. });
  337. },
  338. btnClick() {
  339. // this.playMusic();
  340. if (this.isJoin) { // 已报名
  341. const url = `${ossUrl}#/pages/bm/style4/rankList?${this.queryString}&full=true`;
  342. tools.appAction(url);
  343. }
  344. else { // 未报名
  345. if (!this.isFinished) { // 赛事未结束
  346. if (this.secondCardName == 'rankList') {
  347. const url = `${ossUrl}#/pages/bm/style4/rankList?${this.queryString}&full=true`;
  348. tools.appAction(url);
  349. } else {
  350. const url = `${ossUrl}#/pages/bm/style4/signup?${this.queryString}&full=true`;
  351. tools.appAction(url);
  352. }
  353. }
  354. else { // 赛事已结束
  355. // const url = `${ossUrl}#/pages/bm/style4/rankOverview?${this.queryString}&full=true`;
  356. const url = `${ossUrl}#/pages/bm/style4/rankList?${this.queryString}&full=true`;
  357. tools.appAction(url);
  358. }
  359. }
  360. }
  361. }
  362. }
  363. </script>
  364. <style scoped>
  365. .content {
  366. width: 100vw;
  367. height: 100vh;
  368. }
  369. .content-bg-default {
  370. background: linear-gradient(180deg, #7aedff 0%, #047200 100%);
  371. /* background: linear-gradient(180deg, #178bff 0%, #004d9b 100%); */
  372. /* background: linear-gradient(180deg, #7aedff 0%, #8d2219 100%); */
  373. }
  374. .top {
  375. width: 100%;
  376. justify-content: flex-end;
  377. }
  378. .top-right {
  379. min-width: 180rpx;
  380. height: 80rpx;
  381. margin-top: 30rpx;
  382. margin-right: 30rpx;
  383. padding-left: 16rpx;
  384. padding-right: 16rpx;
  385. background-color: rgba(0, 0, 0, 0.3);
  386. border-radius: 12px;
  387. }
  388. .clock {
  389. width: 50rpx;
  390. height: 50rpx;
  391. margin-right: 12rpx;
  392. }
  393. .countdown {
  394. min-width: 120rpx;
  395. text-align: center;
  396. font-family: Roboto;
  397. color: #ffffff;
  398. font-size: 46rpx;
  399. /* letter-spacing: 2rpx; */
  400. }
  401. .main {
  402. width: 100%;
  403. /* height: 700rpx; */
  404. height: 660rpx;
  405. margin-top: 20rpx;
  406. justify-content: space-evenly;
  407. }
  408. .logo-default {
  409. width: 50vw;
  410. height: 50vw;
  411. background-image: url('/static/logo/jbs.png');
  412. background-repeat: no-repeat;
  413. background-position-x: center;
  414. background-position-y: center;
  415. background-size: contain;
  416. }
  417. .notice {
  418. width: 30rpx;
  419. height: 30rpx;
  420. /* margin-right: 30rpx; */
  421. position: absolute;
  422. left: -60rpx;
  423. }
  424. .type {
  425. opacity: 60%;
  426. /* line-height: 25px; */
  427. font-family: Roboto;
  428. color: #ffffff;
  429. font-size: 40rpx;
  430. text-align: center;
  431. }
  432. .name {
  433. font-family: Roboto;
  434. color: #ffffff;
  435. font-size: 50rpx;
  436. text-align: center;
  437. }
  438. .button {
  439. width: 320rpx;
  440. height: 86rpx;
  441. margin-top: 30rpx;
  442. color: #000000;
  443. background: #ffffff;
  444. border-radius: 56rpx;
  445. font-size: 46rpx;
  446. line-height: 80rpx;
  447. }
  448. /* .mod-text {
  449. color: #FF6203 !important;
  450. }
  451. .mod-button {
  452. color: #ffffff !important;
  453. background-color: #FF6203 !important;
  454. } */
  455. </style>