index.vue 10 KB

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