index.vue 11 KB

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