index.vue 9.9 KB

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