index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. <text class="type">{{type}}</text>
  19. <text class="name">{{ecName}}</text>
  20. <button class="button button-txtcolor">{{btnText}}</button>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import tools from '../../../common/tools';
  27. import {
  28. token,
  29. ossUrl,
  30. apiCardBaseQuery,
  31. apiUserJoinCardQuery,
  32. apiCardConfigQuery
  33. } from '../../../common/api';
  34. export default {
  35. data() {
  36. return {
  37. pageName: "index",
  38. queryString: "",
  39. token: "",
  40. ecId: 0, // 卡片id
  41. ecName: '', // 卡片名称
  42. ecDesc: '', // 卡片简介
  43. beginSecond: null, // 卡片开始时间戳,单位秒
  44. endSecond: null, // 卡片结束时间戳,单位秒
  45. isJoin: null, // 是否报名
  46. // mcId: 0, // 赛事id
  47. // mcType: 0, // 赛事类型 1 普通活动 2 线下赛 3 线上赛
  48. // mcName: "", // 赛事名称
  49. countdown: "", // 倒计时
  50. interval: null,
  51. cssContentBg: "",
  52. cssLogo: "",
  53. // logoSrc: "",
  54. type: "",
  55. btnText: "",
  56. }
  57. },
  58. computed: {},
  59. onLoad(event) { // 类型非必填,可自动推导
  60. // console.log(event);
  61. this.queryString = tools.objectToQueryString(event);
  62. // console.log(queryString);
  63. this.token = event["token"] ?? token;
  64. this.ecId = event["id"] ?? 0;
  65. // this.contentBg = "content-bg-" + (event["bg"] ?? "green");
  66. // this.logoSrc = "/static/logo/" + (event["logo"] ?? "jbs") + '.png';
  67. this.type = event["type"] ?? "锦标赛";
  68. this.btnText = event["btnText"] ?? "开始比赛";
  69. tools.removeCssCode();
  70. this.getCardBaseQuery();
  71. this.getCardConfigQuery();
  72. this.getUserJoinCardQuery();
  73. },
  74. onUnload() {
  75. this.clear();
  76. },
  77. methods: {
  78. clear() {
  79. if (this.interval != null) {
  80. clearInterval(this.interval);
  81. this.interval = null;
  82. }
  83. },
  84. loadConfig(config) {
  85. // console.log("config", config);
  86. const css = config.css;
  87. if (css != undefined && css.length > 0) {
  88. tools.loadCssCode(css);
  89. if (css.indexOf(".content-bg{") >= 0) {
  90. this.cssContentBg = "content-bg";
  91. }
  92. if (css.indexOf(".logo{") >= 0) {
  93. this.cssLogo = "logo";
  94. }
  95. }
  96. if (this.cssContentBg == "") {
  97. this.cssContentBg = "content-bg-default";
  98. }
  99. if (this.cssLogo == "") {
  100. this.cssLogo = "logo-default";
  101. }
  102. console.log("[loadConfig] cssContentBg:", this.cssContentBg);
  103. console.log("[loadConfig] cssLogo:", this.cssLogo);
  104. },
  105. // 获取倒计时
  106. getCountdown() {
  107. // console.log(this.endSecond)
  108. if (this.endSecond > 0) {
  109. const now = Date.now() / 1000;
  110. const dif = this.endSecond - now;
  111. // const dif = 3600*24 - 60;
  112. if (dif > 0) {
  113. this.countdown = tools.convertSecondsToDHM(dif);
  114. } else {
  115. this.countdown = "已结束";
  116. }
  117. // this.countdown = tools.convertSecondsToHMS(dif);
  118. } else {
  119. this.countdown = "--天--小时";
  120. }
  121. },
  122. // 卡片基本信息查询
  123. getCardBaseQuery() {
  124. uni.request({
  125. url: apiCardBaseQuery,
  126. header: {
  127. "Content-Type": "application/x-www-form-urlencoded",
  128. "token": this.token,
  129. },
  130. method: "POST",
  131. data: {
  132. ecId: this.ecId,
  133. pageName: this.pageName
  134. },
  135. success: (res) => {
  136. // console.log("getCardBaseQuery", res)
  137. const data = res.data.data;
  138. this.ecName = data.ecName;
  139. this.ecDesc = data.ecDesc;
  140. this.beginSecond = data.beginSecond;
  141. this.endSecond = data.endSecond;
  142. this.getCountdown();
  143. this.clear();
  144. this.interval = setInterval(this.getCountdown, 60000);
  145. },
  146. fail: (err) => {
  147. console.log("getCardBaseQuery err", err)
  148. },
  149. });
  150. },
  151. // 卡片配置信息查询
  152. getCardConfigQuery() {
  153. uni.request({
  154. url: apiCardConfigQuery,
  155. header: {
  156. "Content-Type": "application/x-www-form-urlencoded",
  157. "token": this.token,
  158. },
  159. method: "POST",
  160. data: {
  161. ecId: this.ecId,
  162. pageName: this.pageName
  163. },
  164. success: (res) => {
  165. // console.log("getCardConfigQuery", res)
  166. const data = res.data.data;
  167. const config = data.configJson != "" ? JSON.parse(data.configJson) : "";
  168. // console.log("configJson", config);
  169. /* const config = {
  170. "css": `
  171. .content-bg {
  172. background: url('static/cardbg/xfl.png');
  173. background-size: cover;
  174. }
  175. .logo{
  176. width: 160px;
  177. height: 120px;
  178. background: url('static/logo/sqsj.png') no-repeat center;
  179. background-size: contain;
  180. }
  181. `
  182. }; */
  183. this.loadConfig(config);
  184. },
  185. fail: (err) => {
  186. console.log("getCardConfigQuery err", err)
  187. },
  188. });
  189. },
  190. // 用户是否已经报名卡片对应赛事查询
  191. getUserJoinCardQuery() {
  192. uni.request({
  193. url: apiUserJoinCardQuery,
  194. header: {
  195. "Content-Type": "application/x-www-form-urlencoded",
  196. "token": this.token
  197. },
  198. method: "POST",
  199. data: {
  200. ecId: this.ecId
  201. },
  202. success: (res) => {
  203. // console.log("getUserJoinCardQuery", res)
  204. const code = res.data.code;
  205. const data = res.data.data;
  206. if (code == 0) {
  207. this.isJoin = data.isJoin;
  208. }
  209. },
  210. fail: (err) => {
  211. console.log("getUserJoinCardQuery err", err)
  212. },
  213. });
  214. },
  215. btnClick() {
  216. if (this.isJoin) { // 已报名
  217. // uni.reLaunch({
  218. // url: '/pages/bm/sqsj/rankList?' + this.queryString
  219. // });
  220. window.location.href = `${ossUrl}#/pages/bm/style1/rankList?${this.queryString}`;
  221. }
  222. else { // 未报名
  223. // uni.reLaunch({
  224. // url: '/pages/bm/sqsj/signup?' + this.queryString
  225. // });
  226. window.location.href = `${ossUrl}#/pages/bm/style1/signup?${this.queryString}`;
  227. }
  228. }
  229. }
  230. }
  231. </script>
  232. <style>
  233. .content {
  234. width: 100vw;
  235. height: 100vh;
  236. }
  237. .content-bg-default {
  238. background: linear-gradient(180deg, #7aedff 0%, #047200 100%);
  239. /* background: linear-gradient(180deg, #178bff 0%, #004d9b 100%); */
  240. /* background: linear-gradient(180deg, #7aedff 0%, #8d2219 100%); */
  241. }
  242. .top {
  243. width: 100%;
  244. justify-content: flex-end;
  245. }
  246. .top-right {
  247. min-width: 180rpx;
  248. height: 80rpx;
  249. margin-top: 30rpx;
  250. margin-right: 30rpx;
  251. padding-left: 16rpx;
  252. padding-right: 16rpx;
  253. background-color: rgba(0, 0, 0, 0.3);
  254. border-radius: 12px;
  255. }
  256. .clock {
  257. width: 50rpx;
  258. height: 50rpx;
  259. margin-right: 12rpx;
  260. }
  261. .countdown {
  262. min-width: 120rpx;
  263. text-align: center;
  264. font-family: Roboto;
  265. color: #ffffff;
  266. font-size: 46rpx;
  267. /* letter-spacing: 2rpx; */
  268. }
  269. .main {
  270. width: 100%;
  271. height: 700rpx;
  272. margin-top: 20rpx;
  273. justify-content: space-evenly;
  274. }
  275. .logo-default {
  276. width: 120px;
  277. height: 120px;
  278. background-image: url('/static/logo/jbs.png');
  279. background-repeat: no-repeat;
  280. background-position-x: center;
  281. background-position-y: center;
  282. background-size: contain;
  283. }
  284. .type {
  285. opacity: 60%;
  286. /* line-height: 25px; */
  287. font-family: Roboto;
  288. color: #ffffff;
  289. font-size: 36rpx;
  290. text-align: center;
  291. }
  292. .name {
  293. font-family: Roboto;
  294. color: #ffffff;
  295. font-size: 46rpx;
  296. text-align: center;
  297. }
  298. .button {
  299. width: 320rpx;
  300. height: 86rpx;
  301. background: #ffffff;
  302. border-radius: 56rpx;
  303. font-size: 46rpx;
  304. line-height: 80rpx;
  305. }
  306. .button-txtcolor {
  307. color: #000000;
  308. }
  309. </style>