index.vue 11 KB

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