index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <!--
  2. 成就
  3. http://localhost:5173/card/#/pages/achievement/index
  4. https://oss-mbh5.colormaprun.com/card/#/pages/achievement/index
  5. -->
  6. <template>
  7. <view class="body">
  8. <view class="content uni-column">
  9. <view class="topbar uni-row">
  10. <view></view>
  11. <text>成就</text>
  12. <text style="color: rgba(46, 133, 236, 1);"></text>
  13. </view>
  14. <view class="tab uni-row">
  15. <text :class="tabCurrent == 0 ? 'tab-active' : 'tab-unactive'" @click="tabCurrent=0">挑战</text>
  16. <text :class="tabCurrent == 1 ? 'tab-active' : 'tab-unactive'" @click="tabCurrent=1">奖牌</text>
  17. </view>
  18. <view class="main">
  19. <view v-if="tabCurrent == 0">
  20. <view class="norecord" v-if="challengeRs == null || challengeRs.length == 0">暂无记录</view>
  21. <view class="uni-column" v-for="(item, index) in challengeRs" :key="index">
  22. <text class="year">{{item.year}}</text>
  23. <view class="list uni-row">
  24. <view class="item uni-column" v-for="(item2, index2) in item.monthRs" :key="index2">
  25. <view class="item-cup" :style="getCupStyle('cup', item2.month)">
  26. <view class="item-cup-gray"
  27. :style="getCupStyle('cup-gray', item2.month, getCupProgress(item2.targetNum, item2.realNum))">
  28. </view>
  29. </view>
  30. <view class="item-title uni-row">
  31. <text class="item-title-month">{{item2.month}}月</text>
  32. <view class="item-title-divide"></view>
  33. <text class="item-title-progress">{{item2.realNum}}/{{item2.targetNum}}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view v-if="tabCurrent == 1">
  40. <view class="norecord" v-if="activityRs == null || activityRs.length == 0">暂无记录</view>
  41. <view class="uni-column" v-for="(item, index) in activityRs" :key="index">
  42. <text class="year">{{item.year}}</text>
  43. <view class="list uni-row">
  44. <view class="item item-bg uni-column" v-for="(item2, index2) in item.aiRs" :key="index2">
  45. <view class="item-medal" :style="getMedalStyle(item2.iconUrl)"></view>
  46. <view class="item-title uni-column">
  47. <view class="item-title-ainame">{{item2.aiName}}</view>
  48. <view class="item-title-aitime">{{fmtTime(item2.aiTime)}}</view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <my-popup ref="mypopup" :dataList="popupDataList" @popup-close="onPopupClose"></my-popup>
  57. <!-- <my-popup-map ref="mypopupmap" :point="point"></my-popup-map> -->
  58. </view>
  59. </template>
  60. <script>
  61. import tools from '../../common/tools';
  62. import {
  63. token,
  64. apiMonthlyChallengeQuery,
  65. apiAchievementQuery,
  66. apiUnReadMessageQuery,
  67. apiReadMessage,
  68. checkResCode
  69. } from '../../common/api';
  70. export default {
  71. data() {
  72. return {
  73. queryString: "",
  74. token: "",
  75. tokenValid: false,
  76. challengeRs: [], // 挑战成就集合
  77. activityRs: [], // 活动成就集合
  78. unReadMessageRs: [], // 未读消息列表
  79. mqIdListStr: "", // 已读消息id列表 逗号分隔
  80. tabCurrent: 0,
  81. popupDataList: [],
  82. point: {
  83. longitude: 117.022194,
  84. latitude: 36.661612,
  85. name: "泉城广场定向赛起始点",
  86. },
  87. }
  88. },
  89. computed: {},
  90. onLoad(event) { // 类型非必填,可自动推导
  91. // console.log(event);
  92. this.queryString = tools.objectToQueryString(event);
  93. // console.log(queryString);
  94. this.token = event["token"] ?? token;
  95. this.getMonthlyChallengeQuery();
  96. this.getAchievementQuery();
  97. this.getUnReadMessageQuery();
  98. },
  99. // 页面初次渲染完成,此时组件已挂载完成,DOM 树($el)已可用
  100. onReady() {},
  101. onUnload() {},
  102. methods: {
  103. getCupProgress(targetNum, realNum) {
  104. let cupProgress = 100;
  105. if (targetNum > 0 && realNum > 0) {
  106. if (realNum < targetNum) {
  107. const progress = realNum / targetNum * 100;
  108. cupProgress = 100 - progress;
  109. } else {
  110. cupProgress = 0;
  111. }
  112. }
  113. // console.log("cupProgress:", cupProgress);
  114. return cupProgress;
  115. },
  116. getCupStyle(type, month, cupProgress = 0) {
  117. if (!(month > 0)) {
  118. return '';
  119. }
  120. let group = 1;
  121. if (type == 'cup') {
  122. return `background-image: url("static/cup/${group}/${month}.png")`;
  123. } else if (type == 'cup-gray') {
  124. return `background-image: url("static/cup/${group}/${month}h.png"); height:${cupProgress}% ;`;
  125. }
  126. },
  127. getMedalStyle(bgurl) {
  128. return `background-image: url("${bgurl}")`;
  129. },
  130. fmtTime(timestamp) {
  131. return tools.timestampToTime(timestamp * 1000, 2);
  132. },
  133. // 玩家所有月挑战记录查询
  134. getMonthlyChallengeQuery() {
  135. uni.request({
  136. url: apiMonthlyChallengeQuery,
  137. header: {
  138. "Content-Type": "application/x-www-form-urlencoded",
  139. "token": this.token,
  140. },
  141. method: "POST",
  142. data: {},
  143. success: (res) => {
  144. // console.log("getMonthlyChallengeQuery", res);
  145. if (checkResCode(res)) {
  146. if (res.statusCode == 401) { // 未登录
  147. this.tokenValid = false;
  148. } else {
  149. this.tokenValid = true;
  150. }
  151. this.challengeRs = res.data.data;
  152. }
  153. },
  154. fail: (err) => {
  155. console.log("getMonthlyChallengeQuery err", err)
  156. },
  157. });
  158. },
  159. // 玩家活动成就查询
  160. getAchievementQuery() {
  161. uni.request({
  162. url: apiAchievementQuery,
  163. header: {
  164. "Content-Type": "application/x-www-form-urlencoded",
  165. "token": this.token,
  166. },
  167. method: "POST",
  168. data: {},
  169. success: (res) => {
  170. // console.log("getAchievementQuery", res);
  171. if (checkResCode(res)) {
  172. if (res.statusCode == 401) { // 未登录
  173. this.tokenValid = false;
  174. } else {
  175. this.tokenValid = true;
  176. }
  177. this.activityRs = res.data.data;
  178. }
  179. },
  180. fail: (err) => {
  181. console.log("getAchievementQuery err", err);
  182. },
  183. });
  184. },
  185. // 未读消息列表查询
  186. getUnReadMessageQuery() {
  187. uni.request({
  188. url: apiUnReadMessageQuery,
  189. header: {
  190. "Content-Type": "application/x-www-form-urlencoded",
  191. "token": this.token,
  192. },
  193. method: "POST",
  194. data: {},
  195. success: (res) => {
  196. // console.log("getUnReadMessageQuery", res);
  197. if (checkResCode(res)) {
  198. if (res.statusCode == 401) { // 未登录
  199. this.tokenValid = false;
  200. } else {
  201. this.tokenValid = true;
  202. }
  203. this.unReadMessageRs = res.data.data;
  204. this.mqIdListStr = "";
  205. for (var i = 0; i < this.unReadMessageRs.length; i++) {
  206. let popupData = {
  207. type: 3,
  208. data: {}
  209. };
  210. if (this.unReadMessageRs[i].mqType == 1) { // 消息类型 1: 成就
  211. popupData.data.title = "恭喜";
  212. }
  213. popupData.data.img = this.unReadMessageRs[i].iconUrl;
  214. popupData.data.content = "恭喜获得成就 \r\n" + this.unReadMessageRs[i].aiName;
  215. this.popupDataList.push(popupData)
  216. this.mqIdListStr += this.unReadMessageRs[i].mqId;
  217. if (i < this.unReadMessageRs.length - 1) {
  218. this.mqIdListStr += ",";
  219. }
  220. }
  221. if (this.popupDataList.length > 0) {
  222. this.$refs.mypopup.popupOpen();
  223. }
  224. }
  225. },
  226. fail: (err) => {
  227. console.log("getUnReadMessageQuery err", err);
  228. },
  229. });
  230. },
  231. // 标记消息已读
  232. readMessage() {
  233. uni.request({
  234. url: apiReadMessage,
  235. header: {
  236. "Content-Type": "application/x-www-form-urlencoded",
  237. "token": this.token,
  238. },
  239. method: "POST",
  240. data: {
  241. "mqIdListStr": this.mqIdListStr
  242. },
  243. success: (res) => {
  244. // console.log("readMessage", res);
  245. },
  246. fail: (err) => {
  247. console.log("readMessage err", err);
  248. },
  249. });
  250. },
  251. onPopupClose() {
  252. // console.log("onPopupClose");
  253. this.readMessage();
  254. },
  255. test() {
  256. // this.$refs.mypopupmap.popupOpen();
  257. window.location.href = `action://to_map_app?title=${this.point.name}&latitude=${this.point.latitude}&longitude=${this.point.longitude}`;
  258. }
  259. }
  260. }
  261. </script>
  262. <style scoped>
  263. .content {
  264. width: 100vw;
  265. height: 100vh;
  266. justify-content: flex-start;
  267. }
  268. .topbar {
  269. width: 90%;
  270. margin-top: 70rpx;
  271. justify-content: space-between;
  272. font-weight: 550;
  273. color: #333333;
  274. font-size: 16px;
  275. }
  276. .tab {
  277. width: 90%;
  278. height: 60rpx;
  279. margin-top: 30rpx;
  280. background: #e7ecef;
  281. border-radius: 18px;
  282. justify-content: space-around;
  283. }
  284. .tab-active {
  285. width: 50%;
  286. height: 60rpx;
  287. background: #2e85ec;
  288. border-radius: 18px;
  289. font-weight: 500;
  290. color: #ffffff;
  291. font-size: 16px;
  292. text-align: center;
  293. line-height: 60rpx;
  294. }
  295. .tab-unactive {
  296. width: 50%;
  297. height: 60rpx;
  298. font-weight: 500;
  299. color: #818181;
  300. font-size: 16px;
  301. text-align: center;
  302. line-height: 60rpx;
  303. }
  304. .main {
  305. width: 90%;
  306. padding-top: 30rpx;
  307. padding-bottom: 30rpx;
  308. }
  309. .norecord {
  310. font-weight: 500;
  311. color: #818181;
  312. font-size: 14px;
  313. text-align: center;
  314. line-height: 80vh;
  315. }
  316. .year {
  317. width: 100%;
  318. margin-left: 20rpx;
  319. text-align: left;
  320. font-weight: 550;
  321. color: #818181;
  322. font-size: 16px;
  323. }
  324. .list {
  325. width: 100%;
  326. padding-bottom: 10rpx;
  327. flex-wrap: wrap;
  328. justify-content: flex-start;
  329. }
  330. .item {
  331. width: 31.85%;
  332. margin: 20rpx 5rpx;
  333. }
  334. .item-bg {
  335. background: #e7ecef;
  336. border-radius: 5px;
  337. }
  338. .item-cup {
  339. width: 28vw;
  340. height: 28vw;
  341. /* background: #e7ecef; */
  342. border-radius: 5px;
  343. background-image: url("/static/cup/1/004.png");
  344. background-position-x: center;
  345. /* background-position-y: center; */
  346. background-repeat: no-repeat;
  347. background-size: 100% auto;
  348. /* background-clip: padding-box; */
  349. mask-image: url('/static/backgroud/mask.png');
  350. mask-size: 100%;
  351. mask-repeat: no-repeat;
  352. mask-clip: padding-box;
  353. }
  354. .item-cup-gray {
  355. width: 100%;
  356. /* height: 60%; */
  357. background-image: url("/static/cup/1/004h.png");
  358. background-position-x: center;
  359. background-repeat: no-repeat;
  360. background-size: 100% auto;
  361. overflow: hidden;
  362. /* filter: grayscale(1); */
  363. }
  364. .item-medal {
  365. width: 20vw;
  366. height: 20vw;
  367. margin-top: 25rpx;
  368. background-position-x: center;
  369. /* background-position-y: center; */
  370. background-repeat: no-repeat;
  371. background-size: auto 100%;
  372. }
  373. .item-title {
  374. width: 100%;
  375. margin-top: 10rpx;
  376. justify-content: center;
  377. }
  378. .item-title-month {
  379. color: #333333;
  380. font-size: 14px;
  381. font-weight: 550;
  382. }
  383. .item-title-divide {
  384. width: 4px;
  385. height: 14px;
  386. margin: 0 12rpx;
  387. background: #c6c6c6;
  388. border-radius: 2px;
  389. }
  390. .item-title-progress {
  391. color: #818181;
  392. font-size: 13px;
  393. font-weight: 500;
  394. }
  395. .item-title-ainame {
  396. margin-top: 12rpx;
  397. font-weight: 500;
  398. color: #333333;
  399. font-size: 12px;
  400. }
  401. .item-title-aitime {
  402. margin-top: 12rpx;
  403. margin-bottom: 20rpx;
  404. color: #818181;
  405. font-size: 11px;
  406. }
  407. </style>