index.vue 11 KB

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