rankList.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <!--
  2. 锦标赛排名列表
  3. http://localhost:5173/card/#/pages/jbs/rankList
  4. https://oss-mbh5.colormaprun.com/card/#/pages/jbs/rankList
  5. -->
  6. <template>
  7. <view class="body">
  8. <view class="content">
  9. <view class="uni-column" :class="cssTop">
  10. <view class="topbar uni-row">
  11. <image mode="aspectFit" class="topbar-back" @click="btnBack" src="/static/default/back.png"></image>
  12. <text class="mcName">{{mcName}}</text>
  13. <image mode="aspectFit" class="topbar-info" @click="btnInfo" src="/static/default/info.png"></image>
  14. </view>
  15. <view :class="cssLogo"></view>
  16. <view class="topcontent uni-row">
  17. <text class="countdown">结束倒计时:</text>
  18. <image mode="aspectFit" class="cal" src="/static/default/cal.png"></image>
  19. <text class="countdown">{{countdown}}</text>
  20. </view>
  21. <!-- <text class="mcName">{{ecId}} - {{mcId}} - {{token}}</text> -->
  22. </view>
  23. <view class="main uni-column">
  24. <my-ranklist :rankRs="rankList.totalRankRs"></my-ranklist>
  25. <button class="btnStart btnStart-disable" v-if="mcState==0">活动尚未开始</button>
  26. <button class="btnStart btnStart-enable" v-if="mcState==1" @click="btnStart">开始比赛</button>
  27. <button class="btnStart btnStart-disable" v-if="mcState==2">活动已结束</button>
  28. </view>
  29. <my-popup ref="mypopup" :dataList="popupDataList"></my-popup>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import tools from '../../common/tools';
  35. import {
  36. defaultPopUpDataList
  37. } from '/common/define';
  38. import {
  39. token,
  40. apiCardDetailQuery,
  41. apiCardRankDetailQuery,
  42. apiUserCurrentRankNumQuery,
  43. apiCardConfigQuery,
  44. apiOnlineMcSignUp,
  45. checkResCode
  46. } from '../../common/api';
  47. export default {
  48. data() {
  49. return {
  50. pageName: "rankList",
  51. firstEnterKey: 'firstEnter-jbs_rankList',
  52. rankKey: "rank-jbs",
  53. queryString: "",
  54. token: "",
  55. ecId: 0, // 卡片id
  56. coiId: 0, // 单位id
  57. mcId: 0, // 赛事id
  58. mcType: 0, // 赛事类型 1 普通活动 2 线下赛 3 线上赛
  59. mcName: "", // 赛事名称
  60. beginSecond: null, // 活动或赛事开始时间戳,单位秒
  61. endSecond: null, // 活动或赛事结束时间戳,单位秒
  62. mcState: 0, // 赛事/活动状态 0: 未开始 1: 进行中 2: 已结束
  63. countdown: "", // 倒计时
  64. rankList: { // 排名列表
  65. totalRankRs: [],
  66. teamRankRs: [],
  67. inTeamRs: [],
  68. },
  69. interval: null,
  70. dispArrStr: "total", // 要显示的集合范围 (total,team,in,other)
  71. cssTop: "",
  72. cssLogo: "",
  73. popupDataList: [],
  74. }
  75. },
  76. computed: {},
  77. onLoad(event) { // 类型非必填,可自动推导
  78. // console.log(event);
  79. this.queryString = tools.objectToQueryString(event);
  80. // console.log(queryString);
  81. this.token = event["token"] ?? token;
  82. this.ecId = event["id"] ?? 0;
  83. this.firstEnterKey += "-" + this.ecId;
  84. console.log("firstEnterKey:", this.firstEnterKey);
  85. this.rankKey += "-" + this.ecId;
  86. console.log("rankKey:", this.rankKey);
  87. tools.removeCssCode();
  88. this.getCardConfigQuery();
  89. this.getUserCurrentRankNumQuery();
  90. // this.getCardDetailQuery();
  91. },
  92. // 页面初次渲染完成,此时组件已挂载完成,DOM 树($el)已可用
  93. onReady() {
  94. // this.dealFirstEnter();
  95. },
  96. onUnload() {
  97. this.clear();
  98. },
  99. methods: {
  100. dealNotice(rank) {
  101. // console.log('[dealFirstEnter]');
  102. let that = this;
  103. uni.getStorage({
  104. key: that.rankKey,
  105. success: (res) => {
  106. console.log('[getStorage]', that.rankKey, res.data);
  107. const oldRank = res.data;
  108. if (oldRank != rank) {
  109. // that.notice = true;
  110. that.setRankValue(rank);
  111. }
  112. },
  113. fail: (e) => {
  114. console.log('[getStorage] fail', that.rankKey, e);
  115. // that.notice = false;
  116. that.setRankValue(rank);
  117. },
  118. })
  119. },
  120. setRankValue(data) {
  121. let that = this;
  122. uni.setStorage({
  123. key: that.rankKey,
  124. data: data,
  125. success: () => {
  126. console.log('[setStorage] success', that.rankKey, data);
  127. },
  128. fail: (e) => {
  129. console.log('[setStorage] fail', that.rankKey, e);
  130. },
  131. })
  132. },
  133. dealFirstEnter() {
  134. let that = this;
  135. uni.getStorage({
  136. key: that.firstEnterKey,
  137. success: (res) => {
  138. console.log('[getStorage]', that.firstEnterKey, res.data);
  139. },
  140. fail: (e) => {
  141. console.log('[getStorage] fail', that.firstEnterKey, e);
  142. that.btnInfo();
  143. that.setFirstEnterValue(true);
  144. },
  145. })
  146. },
  147. setFirstEnterValue(data) {
  148. let that = this;
  149. uni.setStorage({
  150. key: that.firstEnterKey,
  151. data: data,
  152. success: () => {
  153. console.log('[setStorage] success', that.firstEnterKey, data);
  154. },
  155. fail: (e) => {
  156. console.log('[setStorage] fail', that.firstEnterKey, e);
  157. },
  158. })
  159. },
  160. clear() {
  161. if (this.interval != null) {
  162. clearInterval(this.interval);
  163. this.interval = null;
  164. }
  165. },
  166. loadConfig(config) {
  167. // console.log("config", config);
  168. // 加载CSS样式
  169. const css = config.css;
  170. if (css != undefined && css.length > 0) {
  171. tools.loadCssCode(css);
  172. if (css.indexOf(".top{") >= 0) {
  173. this.cssTop = "top";
  174. }
  175. if (css.indexOf(".logo{") >= 0) {
  176. this.cssLogo = "logo";
  177. }
  178. }
  179. if (this.cssTop == "") {
  180. this.cssTop = "top-default";
  181. }
  182. if (this.cssLogo == "") {
  183. this.cssLogo = "logo-default";
  184. }
  185. console.log("[loadConfig] cssTop:", this.cssTop);
  186. console.log("[loadConfig] cssLogo:", this.cssLogo);
  187. // 加载弹窗数据
  188. const popupDataList = config.popupDataList;
  189. // console.log("[loadConfig] popupDataList:", popupDataList);
  190. if (popupDataList != undefined && popupDataList.length > 0) {
  191. for (var i = 0; i < popupDataList.length; i++) {
  192. // console.log("[loadConfig] popupDataList", i, popupDataList[i]);
  193. if (popupDataList[i] == 'default') {
  194. for (var j = 0; j < defaultPopUpDataList.length; j++) {
  195. this.popupDataList.push(defaultPopUpDataList[j]);
  196. }
  197. } else {
  198. this.popupDataList.push(popupDataList[i]);
  199. }
  200. }
  201. } else {
  202. this.popupDataList = defaultPopUpDataList;
  203. console.log("[loadConfig] popupDataList 加载默认列表");
  204. }
  205. // console.log("[loadConfig] popupDataList:", this.popupDataList);
  206. },
  207. // 获取倒计时
  208. getCountdown() {
  209. if (this.endSecond > 0) {
  210. const now = Date.now() / 1000;
  211. const dif = this.endSecond - now;
  212. // const dif = 3600*24 - 60;
  213. if (dif > 0) {
  214. this.countdown = tools.convertSecondsToDHM(dif);
  215. } else {
  216. this.countdown = "已结束";
  217. }
  218. // this.countdown = tools.convertSecondsToHMS(dif);
  219. } else {
  220. this.countdown = "--天--小时";
  221. }
  222. },
  223. getCardConfigQuery() {
  224. uni.request({
  225. url: apiCardConfigQuery,
  226. header: {
  227. "Content-Type": "application/x-www-form-urlencoded",
  228. "token": this.token,
  229. },
  230. method: "POST",
  231. data: {
  232. ecId: this.ecId,
  233. pageName: this.pageName
  234. },
  235. success: (res) => {
  236. // console.log("getCardConfigQuery", res)
  237. const data = res.data.data;
  238. const config = data.configJson != "" ? JSON.parse(data.configJson) : "";
  239. // console.log("configJson", data.configJson);
  240. /* const config = {
  241. "css": `
  242. .top{
  243. width: 100%;
  244. height: 26vh;
  245. padding-top: 36px;
  246. justify-content: space-between;
  247. background-image: url('static/backgroud/top_colorbar.png'), linear-gradient(180deg,#178bff 0%,#004d9b 100%);
  248. background-repeat: no-repeat;
  249. background-position: center, 0px 0px;
  250. background-size: auto 22vh , cover;
  251. }
  252. .logo{
  253. width: 150px;
  254. height: 150px;
  255. margin-top: 10px;
  256. background-image: url('static/logo/xfl.png');
  257. background-repeat: no-repeat;
  258. background-position-x: center;
  259. background-position-y: center;
  260. background-size: contain;
  261. }
  262. `,
  263. "popupDataList": [
  264. {
  265. "type": 1,
  266. "data": {
  267. "title": "山青活动",
  268. "img": "/static/logo/sqsj.png",
  269. "content": "山青世界为广大青少年提供了亲近自然、劳动实践、拓展培训、军事教育、科普体验、自然探索的平台和机会,也为企事业单位青年团队提供会议培训、拓展训练等服务",
  270. }
  271. },
  272. "default"
  273. ]
  274. }; */
  275. this.loadConfig(config);
  276. this.getCardDetailQuery();
  277. setTimeout(this.dealFirstEnter, 500);
  278. },
  279. fail: (err) => {
  280. console.log("getCardConfigQuery err", err)
  281. },
  282. });
  283. },
  284. // 卡片信息查询
  285. getCardDetailQuery() {
  286. uni.request({
  287. url: apiCardDetailQuery,
  288. header: {
  289. "Content-Type": "application/x-www-form-urlencoded",
  290. "token": this.token,
  291. },
  292. method: "POST",
  293. data: {
  294. ecId: this.ecId
  295. },
  296. success: (res) => {
  297. // console.log("getCardDetailQuery", res)
  298. const data = res.data.data;
  299. this.coiId = data.coiId;
  300. this.mcId = data.mcId;
  301. this.mcType = data.mcType;
  302. this.mcName = data.mcName;
  303. this.beginSecond = data.beginSecond;
  304. this.endSecond = data.endSecond;
  305. this.mcState = tools.checkMcState(this.beginSecond, this.endSecond);
  306. this.getCountdown();
  307. this.getCardRankDetailQuery();
  308. this.clear();
  309. this.interval = setInterval(this.getCountdown, 60000);
  310. },
  311. fail: (err) => {
  312. console.log("getCardDetailQuery err", err)
  313. },
  314. });
  315. },
  316. // 排名查询
  317. getCardRankDetailQuery() {
  318. uni.request({
  319. url: apiCardRankDetailQuery,
  320. header: {
  321. "Content-Type": "application/x-www-form-urlencoded",
  322. "token": this.token,
  323. },
  324. method: "POST",
  325. data: {
  326. mcIdListStr: this.mcId,
  327. mcType: this.mcType,
  328. dispArrStr: this.dispArrStr
  329. },
  330. success: (res) => {
  331. // console.log("getCardRankDetailQuery", res)
  332. const rankdata = res.data.data;
  333. this.rankList.totalRankRs = rankdata.totalRankRs;
  334. this.rankList.teamRankRs = rankdata.teamRankRs;
  335. this.rankList.inTeamRs = rankdata.inTeamRs;
  336. },
  337. fail: (err) => {
  338. console.log("getCardRankDetailQuery err", err)
  339. },
  340. });
  341. },
  342. // 卡片用户当前排名查询
  343. getUserCurrentRankNumQuery() {
  344. uni.request({
  345. url: apiUserCurrentRankNumQuery,
  346. header: {
  347. "Content-Type": "application/x-www-form-urlencoded",
  348. "token": this.token,
  349. },
  350. method: "POST",
  351. data: {
  352. ecId: this.ecId
  353. },
  354. success: (res) => {
  355. // console.log("getUserCurrentRankNumQuery", res)
  356. if (res.data.code == 0) {
  357. const data = res.data.data;
  358. const rankNum = data.rankNum;
  359. this.dealNotice(rankNum);
  360. }
  361. },
  362. fail: (err) => {
  363. console.log("getUserCurrentRankNumQuery err", err)
  364. },
  365. });
  366. },
  367. // 线上赛报名(重新分组)
  368. onlineMcSignUp() {
  369. uni.request({
  370. url: apiOnlineMcSignUp,
  371. header: {
  372. "Content-Type": "application/x-www-form-urlencoded",
  373. "token": this.token,
  374. },
  375. method: "POST",
  376. data: {
  377. mcId: this.mcId,
  378. coiId: this.coiId,
  379. selectTeam: 0
  380. },
  381. success: (res) => {
  382. // console.log("onlineMcSignUp", res)
  383. if (checkResCode(res)) {
  384. // uni.showToast({
  385. // title: '比赛报名成功!',
  386. // icon: 'none',
  387. // duration: 3000
  388. // });
  389. window.location.href =
  390. `action://to_detail/?id=${this.mcId}&matchType=${this.mcType}`;
  391. }
  392. },
  393. fail: (err) => {
  394. console.log("onlineMcSignUp err", err)
  395. uni.showToast({
  396. title: '出错了,比赛报名失败',
  397. icon: 'none',
  398. duration: 3000
  399. });
  400. },
  401. });
  402. },
  403. btnBack() {
  404. // window.history.back();
  405. window.location.href = `action://to_home/`;
  406. },
  407. btnStart() {
  408. this.onlineMcSignUp();
  409. // window.location.href = `action://to_detail/?id=${this.mcId}&matchType=${this.mcType}`;
  410. },
  411. btnInfo() {
  412. this.$refs.mypopup.popupOpen();
  413. },
  414. }
  415. }
  416. </script>
  417. <style scoped>
  418. .content {
  419. width: 100vw;
  420. height: 100vh;
  421. }
  422. .top-default {
  423. width: 100%;
  424. height: 28vh;
  425. /* height: 500rpx; */
  426. padding-top: 36px;
  427. justify-content: flex-start;
  428. background-image: url("/static/backgroud/top_medal.png"), url("/static/backgroud/top_bg1.png");
  429. background-repeat: no-repeat;
  430. background-position-x: center, center;
  431. background-position-y: 15vh, center;
  432. background-size: 55vw auto, cover;
  433. }
  434. .logo-default {
  435. /* width: 150px;
  436. height: 150px;
  437. margin-top: 10px;
  438. background-image: url('/static/logo/jbs.png');
  439. background-repeat: no-repeat;
  440. background-position-x: center;
  441. background-position-y: center;
  442. background-size: contain; */
  443. }
  444. .topbar {
  445. width: 90%;
  446. /* padding: 0rpx 30rpx; */
  447. justify-content: space-between;
  448. }
  449. .topbar-back {
  450. width: 43rpx;
  451. height: 43rpx;
  452. /* opacity: 0; */
  453. }
  454. .topbar-info {
  455. width: 46rpx;
  456. height: 46rpx;
  457. }
  458. .mcName {
  459. color: white;
  460. font-size: 32rpx;
  461. }
  462. .topcontent {
  463. min-width: 300rpx;
  464. height: 100rpx;
  465. justify-content: space-evenly;
  466. }
  467. .countdown {
  468. color: white;
  469. font-size: 32rpx;
  470. }
  471. .cal {
  472. width: 30rpx;
  473. margin-right: 20rpx;
  474. }
  475. .main {
  476. width: 100%;
  477. height: 66vh;
  478. justify-content: space-between;
  479. }
  480. .btnStart {
  481. width: 70%;
  482. height: 5vh;
  483. /* height: 80rpx; */
  484. margin-bottom: 1vh;
  485. font-weight: bold;
  486. line-height: 5vh;
  487. background-color: #ffb40b;
  488. }
  489. .btnStart-enable {
  490. background-color: #ffb40b;
  491. }
  492. .btnStart-disable {
  493. background-color: #c3c3c3;
  494. }
  495. </style>
  496. <style lang="scss" scoped>
  497. ::v-deep .list {
  498. height: 58vh;
  499. margin-top: 5px;
  500. }
  501. </style>