rankList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <!--
  2. 每月挑战 - 月排名列表
  3. http://localhost:5173/card/#/pages/mytz/rankList?id=3
  4. https://oss-mbh5.colormaprun.com/card/#/pages/mytz/rankList
  5. -->
  6. <template>
  7. <view class="body">
  8. <view v-if="pageReady" class="content uni-column">
  9. <view class="page-top uni-column">
  10. <my-topbar :mcName="title" class="topbar-color" @btnBackClick="btnBack"
  11. @btnInfoClick="btnInfo"></my-topbar>
  12. <view class="topContent uni-row uni-jcse">
  13. <view class="tc-monthBox uni-column uni-jcc" @click="onMonthBoxClick">
  14. <view class="tc-monthName">{{selectMonthName}}</view>
  15. <view class="tc-monthRank">查询排行榜</view>
  16. </view>
  17. <view class="tc-count uni-column">
  18. <text>挑战次数</text>
  19. <text>{{realNum}}/{{targetNum}}</text>
  20. </view>
  21. <view class="tc-cup" :style="getCupStyle('cup')">
  22. <view class="cup-gray" :style="getCupStyle('cup-gray')"></view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="main uni-column">
  27. <my-tab ref="tab" :tabItems="tabItems" :tabItemsMark="tabItemsMark" :type="0"
  28. :initActIndex="configParam.tabInitActIndex" @onTabClick="onTabClick" :fontSize="12"></my-tab>
  29. <view class="tab-view uni-column">
  30. <template v-for="(item, index) in rankRsList" :key="index">
  31. <my-ranklist v-show="tabCurrent === index" :rankRs="rankList[item]"
  32. :rank-type="rankTypeList[index]"></my-ranklist>
  33. </template>
  34. </view>
  35. </view>
  36. <my-popup ref="mypopup" :config="cardConfigData.popupRuleConfig"
  37. :dataList="cardConfigData.popupRuleList"></my-popup>
  38. <uni-popup ref="popupMonthPick" :mask-click="false" maskBackgroundColor="rgba(0, 0, 0, 0.6)">
  39. <view class="uni-column uni-jcse popupMonthPick">
  40. <view class="uni-row uni-jcsb pmp-top">
  41. <view class="pmp-title">选择月排行榜</view>
  42. <view class="pmp-fullyear" @click="onMonthPick(0)">查看全年</view>
  43. </view>
  44. <view class="uni-row uni-jcsa pmp-main">
  45. <view v-for="index in 12" :key="index" :class="index <= currentMonth ? 'tc-monthBox-small' : 'tc-monthBox-small-gray'">
  46. <view class="tc-monthName-small" @click="onMonthPick(index)">{{index}}月</view>
  47. </view>
  48. </view>
  49. </view>
  50. </uni-popup>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import tools from '/common/tools';
  56. import cardfunc from '/common/cardfunc';
  57. import {
  58. localCardConfig
  59. } from "./cardconfig/test.js";
  60. import {
  61. token,
  62. apiCardBaseQuery,
  63. apiCurrentMonthlyChallengeQuery,
  64. apiMonthRankDetailQuery,
  65. checkResCode,
  66. checkToken
  67. } from '/common/api';
  68. export default {
  69. data() {
  70. return {
  71. cardConfigData: cardfunc.cardConfigData,
  72. pageReady: false,
  73. pageName: "rankList",
  74. firstEnterKey: 'firstEnter-mytz',
  75. rankKey: "rank-mytz",
  76. queryObj: {},
  77. queryString: "",
  78. token: "",
  79. tokenValid: false,
  80. ecId: 0, // 卡片id
  81. ecName: '', // 卡片名称
  82. ecDesc: '', // 卡片简介
  83. currentYear: 0,
  84. currentMonth: 0,
  85. selectYear: 0,
  86. selectMonth: 0,
  87. realNum: 0, // 实际完赛次数
  88. targetNum: 0, // 要求完赛次数
  89. cupProgress: 100, // 奖杯进度 (100 - 实际进度,初始值为100)
  90. dispArrStr: "grad,mapNum", // 要显示的集合范围
  91. tabItems: ["积分排名", "通关场地排名"],
  92. rankTypeList: ["grad", "mapNum"],
  93. tabCurrent: 0,
  94. tabItemsMark: [],
  95. rankRsList: ["gradRs", "mapNumRs"],
  96. rankList: [], // 排名列表
  97. configParam: {
  98. tabInitActIndex: 0
  99. }
  100. }
  101. },
  102. computed: {
  103. selectMonthName() {
  104. if (this.selectMonth > 0) {
  105. return `${this.selectMonth}月`;
  106. }
  107. else {
  108. return this.selectYear;
  109. }
  110. },
  111. title() {
  112. if (this.selectMonth > 0) {
  113. return `${this.selectMonth}月挑战赛`;
  114. }
  115. else {
  116. return `${this.selectYear}年挑战赛`;
  117. }
  118. },
  119. },
  120. onLoad(query) { // 类型非必填,可自动推导
  121. // console.log(query);
  122. this.queryObj = query;
  123. this.queryString = tools.objectToQueryString(this.queryObj);
  124. // console.log(queryString);
  125. this.token = query["token"] ?? token;
  126. this.ecId = query["id"] ?? 0;
  127. this.firstEnterKey += "-" + this.ecId;
  128. console.log("firstEnterKey:", this.firstEnterKey);
  129. this.rankKey += "-" + this.ecId;
  130. console.log("rankKey:", this.rankKey);
  131. this.getCurYearMonth();
  132. cardfunc.init(this, this.token, this.ecId);
  133. cardfunc.getCardConfig(this.cardConfigQueryCallback, localCardConfig);
  134. },
  135. // 页面初次渲染完成,此时组件已挂载完成,DOM 树($el)已可用
  136. onReady() {},
  137. onUnload() {},
  138. methods: {
  139. getCurYearMonth() {
  140. const currentDate = new Date();
  141. const currentYear = currentDate.getFullYear();
  142. const currentMonth = currentDate.getMonth() + 1; // 月份从0开始,所以要加1
  143. // console.log("[getCurYearMonth]", currentYear, currentMonth);
  144. this.currentYear = currentYear;
  145. this.currentMonth = currentMonth;
  146. this.selectYear = currentYear;
  147. this.selectMonth = currentMonth;
  148. },
  149. cardConfigQueryCallback(cardconfig) {
  150. this.loadConfig(cardconfig);
  151. this.getCardBaseQuery();
  152. this.getCurrentMonthlyChallengeQuery();
  153. this.monthRankDetailQuery();
  154. setTimeout(this.dealFirstEnter, 500);
  155. },
  156. loadConfig(cardconfig) {
  157. cardconfig = cardfunc.parseCardConfig(cardconfig);
  158. // console.log("[loadCardConfig] cardconfig:", cardconfig);
  159. // 加载卡片通用配置
  160. if (cardconfig.common != undefined) {
  161. cardfunc.loadCardCommonConfig(cardconfig.common);
  162. }
  163. // -------- 加载当前页面的配置 --------
  164. const config = cardfunc.parseCardConfig(cardconfig[this.pageName]);
  165. // console.log("[loadConfig] config_page:", config);
  166. if (config == undefined || config == null) {
  167. this.pageReady = true;
  168. return;
  169. }
  170. // 加载CSS样式
  171. const css = config.css;
  172. if (css != undefined && css.length > 0) {
  173. tools.loadCssCode(css);
  174. }
  175. // 加载成绩参数
  176. const rankParam = config.rankParam;
  177. if (rankParam != undefined) {
  178. if (rankParam.tabItemsMark != undefined) {
  179. this.tabItemsMark = rankParam.tabItemsMark;
  180. }
  181. if (rankParam.dispArrStr != undefined && rankParam.dispArrStr.length > 0) {
  182. this.dispArrStr = rankParam.dispArrStr;
  183. // console.log("[loadConfig] dispArrStr:", rankParam.dispArrStr);
  184. }
  185. if (rankParam.tabItems != undefined && rankParam.tabItems.length > 0) {
  186. this.tabItems = rankParam.tabItems;
  187. // console.log("[loadConfig] tabItems:", rankParam.tabItems);
  188. }
  189. if (rankParam.rankTypeList != undefined && rankParam.rankTypeList.length > 0) {
  190. this.rankTypeList = rankParam.rankTypeList;
  191. }
  192. if (rankParam.rankRsList != undefined && rankParam.rankRsList.length > 0) {
  193. this.rankRsList = rankParam.rankRsList;
  194. }
  195. }
  196. // console.log("[loadConfig] rankParam:", rankParam);
  197. // 加载页面参数
  198. const param = config.param;
  199. if (param != undefined) {
  200. if (param.tabInitActIndex != undefined && param.tabInitActIndex >= 0) {
  201. this.configParam.tabInitActIndex = param.tabInitActIndex;
  202. this.tabCurrent = param.tabInitActIndex;
  203. }
  204. }
  205. this.pageReady = true;
  206. },
  207. dealNotice(rank) {
  208. // console.log('[dealFirstEnter]');
  209. let that = this;
  210. uni.getStorage({
  211. key: that.rankKey,
  212. success: (res) => {
  213. console.log('[getStorage]', that.rankKey, res.data);
  214. const oldRank = res.data;
  215. if (oldRank != rank) {
  216. // that.notice = true;
  217. that.setRankValue(rank);
  218. }
  219. },
  220. fail: (e) => {
  221. console.log('[getStorage] fail', that.rankKey, e);
  222. // that.notice = false;
  223. that.setRankValue(rank);
  224. },
  225. })
  226. },
  227. setRankValue(data) {
  228. let that = this;
  229. uni.setStorage({
  230. key: that.rankKey,
  231. data: data,
  232. success: () => {
  233. console.log('[setStorage] success', that.rankKey, data);
  234. },
  235. fail: (e) => {
  236. console.log('[setStorage] fail', that.rankKey, e);
  237. },
  238. })
  239. },
  240. dealFirstEnter() {
  241. // console.log('[dealFirstEnter]');
  242. let that = this;
  243. uni.getStorage({
  244. key: that.firstEnterKey,
  245. success: (res) => {
  246. console.log('[getStorage]', that.firstEnterKey, res.data);
  247. },
  248. fail: (e) => {
  249. console.log('[getStorage] fail', that.firstEnterKey, e);
  250. that.btnInfo();
  251. that.setFirstEnterValue(true);
  252. },
  253. })
  254. },
  255. setFirstEnterValue(data) {
  256. let that = this;
  257. uni.setStorage({
  258. key: that.firstEnterKey,
  259. data: data,
  260. success: () => {
  261. console.log('[setStorage] success', that.firstEnterKey, data);
  262. },
  263. fail: (e) => {
  264. console.log('[setStorage] fail', that.firstEnterKey, e);
  265. },
  266. })
  267. },
  268. getCupProgress() {
  269. if (this.targetNum > 0 && this.realNum > 0) {
  270. if (this.realNum < this.targetNum) {
  271. const progress = this.realNum / this.targetNum * 100;
  272. this.cupProgress = 100 - progress;
  273. } else {
  274. this.cupProgress = 0;
  275. }
  276. } else {
  277. this.cupProgress = 100;
  278. }
  279. // console.log("cupProgress:", this.cupProgress);
  280. },
  281. getCupStyle(type) {
  282. if (!(this.selectMonth >= 0)) {
  283. return '';
  284. }
  285. let group = 1;
  286. if (type == 'cup') {
  287. return `background-image: url("static/cup/${group}/${this.selectMonth}.png")`;
  288. } else if (type == 'cup-gray') {
  289. return `background-image: url("static/cup/${group}/${this.selectMonth}h.png"); height:${this.cupProgress}% ;`;
  290. }
  291. },
  292. // 卡片基本信息查询
  293. getCardBaseQuery() {
  294. uni.request({
  295. url: apiCardBaseQuery,
  296. header: {
  297. "Content-Type": "application/x-www-form-urlencoded",
  298. "token": this.token,
  299. },
  300. method: "POST",
  301. data: {
  302. ecId: this.ecId
  303. },
  304. success: (res) => {
  305. // console.log("getCardBaseQuery", res);
  306. const data = res.data.data;
  307. this.ecName = data.ecName;
  308. this.ecDesc = data.ecDesc;
  309. },
  310. fail: (err) => {
  311. console.log("getCardBaseQuery err", err);
  312. },
  313. });
  314. },
  315. // 玩家当前月挑战记录查询
  316. getCurrentMonthlyChallengeQuery() {
  317. uni.request({
  318. url: apiCurrentMonthlyChallengeQuery,
  319. header: {
  320. "Content-Type": "application/x-www-form-urlencoded",
  321. "token": this.token,
  322. },
  323. method: "POST",
  324. data: {
  325. year: this.selectYear,
  326. month: this.selectMonth,
  327. },
  328. success: (res) => {
  329. // console.log("getCurrentMonthlyChallengeQuery", res);
  330. if (checkResCode(res)) {
  331. if (res.statusCode == 401) { // 未登录
  332. this.tokenValid = false;
  333. } else {
  334. this.tokenValid = true;
  335. }
  336. const data = res.data.data;
  337. this.realNum = data.realNum;
  338. // this.realNum = 2;
  339. this.targetNum = data.targetNum;
  340. this.dealNotice(this.realNum);
  341. this.getCupProgress();
  342. }
  343. },
  344. fail: (err) => {
  345. console.log("getCurrentMonthlyChallengeQuery err", err);
  346. },
  347. });
  348. },
  349. // 月挑战排名查询
  350. monthRankDetailQuery() {
  351. uni.request({
  352. url: apiMonthRankDetailQuery,
  353. header: {
  354. "Content-Type": "application/x-www-form-urlencoded",
  355. "token": this.token,
  356. },
  357. method: "POST",
  358. data: {
  359. year: this.selectYear,
  360. month: this.selectMonth,
  361. dispArrStr: this.dispArrStr
  362. },
  363. success: (res) => {
  364. // console.log("monthRankDetailQuery", res);
  365. const rankdata = res.data.data;
  366. this.rankList = rankdata;
  367. },
  368. fail: (err) => {
  369. console.log("monthRankDetailQuery err", err);
  370. },
  371. });
  372. },
  373. btnBack() {
  374. // window.history.back();
  375. const url = `action://to_home/`;
  376. tools.appAction(url);
  377. },
  378. btnInfo() {
  379. this.$refs.mypopup.popupOpen();
  380. },
  381. onTabClick(val) {
  382. // console.log("onTabClick: ", val);
  383. this.tabCurrent = val;
  384. },
  385. onMonthBoxClick() {
  386. this.$refs.popupMonthPick.open();
  387. },
  388. onMonthPick(month) {
  389. // console.log("[onMonthPick] month", month);
  390. if (month <= this.currentMonth) {
  391. this.selectMonth = month;
  392. this.$refs.popupMonthPick.close();
  393. this.getCurrentMonthlyChallengeQuery();
  394. this.monthRankDetailQuery();
  395. } else {
  396. uni.showToast({
  397. icon: "none",
  398. title: "暂无该月记录",
  399. duration: 1000
  400. })
  401. }
  402. }
  403. }
  404. }
  405. </script>
  406. <style scoped>
  407. .content {
  408. width: 100vw;
  409. height: 100vh;
  410. }
  411. .page-top {
  412. width: 100%;
  413. height: 150px;
  414. padding-top: 36px;
  415. justify-content: space-between;
  416. background-image: url("/static/backgroud/top_run.png"), linear-gradient(180deg, #178bff 0%, #004d9b 100%);
  417. background-repeat: no-repeat;
  418. background-position: 25px 36px, 0px 0px;
  419. background-size: auto 150px, contain;
  420. }
  421. .topbar-color {
  422. color: #ffffff;
  423. }
  424. .topContent {
  425. width: 90%;
  426. height: 130px;
  427. }
  428. .tc-monthBox {
  429. width: 80px;
  430. height: 80px;
  431. background: url("/static/mytz/month_bg.png") no-repeat center;
  432. background-size: contain;
  433. color: #ff870d;
  434. }
  435. .tc-monthName {
  436. margin-top: 18px;
  437. font-size: 22px;
  438. font-weight: 700;
  439. }
  440. .tc-monthRank {
  441. font-size: 12px;
  442. font-weight: 500;
  443. }
  444. .tc-count {
  445. font-size: 14px;
  446. font-weight: 500;
  447. color: #FFFFFF;
  448. }
  449. .tc-cup {
  450. width: 70px;
  451. height: 70px;
  452. border-radius: 3px;
  453. border: solid #FFFFFF 1px;
  454. background-position-x: center;
  455. background-repeat: no-repeat;
  456. background-size: 70px auto;
  457. }
  458. .cup-gray {
  459. width: 70px;
  460. background-position-x: center;
  461. background-repeat: no-repeat;
  462. background-size: 70px auto;
  463. overflow: hidden;
  464. }
  465. .main {
  466. width: 100%;
  467. flex-grow: 1;
  468. justify-content: space-around;
  469. }
  470. .main-tab {
  471. width: 90%;
  472. margin-top: 20rpx;
  473. }
  474. .tab-view {
  475. width: 100%;
  476. flex-grow: 1;
  477. }
  478. .popupMonthPick {
  479. width: 90vw;
  480. height: 200px;
  481. background-color: #FEFBF6;
  482. border-radius: 25px;
  483. }
  484. .pmp-top {
  485. width: 90%;
  486. font-size: 16px;
  487. }
  488. .pmp-main {
  489. width: 90%;
  490. height: 120px;
  491. flex-wrap: wrap;
  492. }
  493. .pmp-title {
  494. font-weight: 500;
  495. }
  496. .pmp-fullyear {
  497. padding: 5px 10px;
  498. border-radius: 8px;
  499. border: 1px solid rgba(255, 135, 13, 1);
  500. color: #FF870D;
  501. font-weight: 500;
  502. }
  503. .tc-monthBox-small {
  504. width: 50px;
  505. height: 50px;
  506. flex-shrink: 0;
  507. background: url("/static/mytz/month_bg.png") no-repeat center;
  508. background-size: contain;
  509. color: #ff870d;
  510. }
  511. .tc-monthBox-small-gray {
  512. width: 50px;
  513. height: 50px;
  514. flex-shrink: 0;
  515. background: url("/static/mytz/month_bg_gray.png") no-repeat center;
  516. background-size: contain;
  517. color: #C4C4C4;
  518. }
  519. .tc-monthName-small {
  520. margin-top: 20px;
  521. font-size: 16px;
  522. font-weight: 700;
  523. text-align: center;
  524. }
  525. </style>