index.vue 11 KB

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