index.vue 11 KB

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