rankList.vue 11 KB

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