index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <!--
  2. 每月挑战 - 卡片页
  3. http://localhost:5173/card/#/pages/mytz/index
  4. https://oss-mbh5.colormaprun.com/card/#/pages/mytz/index
  5. -->
  6. <template>
  7. <view class="body body-radius">
  8. <view class="content uni-column" :class="contentBg" @click="btnClick">
  9. <view class="main uni-column">
  10. <image mode="aspectFit" class="logo" :src="logoSrc"></image>
  11. <view class="uni-row" style="position: relative;">
  12. <image v-if="notice" mode="aspectFit" src="/static/common/notice.png" class="notice"></image>
  13. <text class="type">{{ecName}}</text>
  14. </view>
  15. <text class="name">{{name}}</text>
  16. <button class="button button-txtcolor">{{btnText}}</button>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import tools from '../../common/tools';
  23. import {
  24. ossUrl,
  25. token,
  26. apiCardBaseQuery,
  27. apiCurrentMonthlyChallengeQuery,
  28. } from '../../common/api';
  29. export default {
  30. data() {
  31. return {
  32. pageName: "index",
  33. rankKey: "rank-mytz",
  34. queryObj: {},
  35. queryString: "",
  36. token: "",
  37. ecId: 0, // 卡片id
  38. ecName: '', // 卡片名称
  39. ecDesc: '', // 卡片简介
  40. beginSecond: null, // 卡片开始时间戳,单位秒
  41. endSecond: null, // 卡片结束时间戳,单位秒
  42. month: '', // 月名称
  43. realNum: 0, // 实际完赛次数
  44. targetNum: 0, // 要求完赛次数
  45. contentBg: "",
  46. logoSrc: "",
  47. type: "",
  48. name: "",
  49. btnText: "",
  50. notice: false, // 是否显示(小红点)通知图标
  51. }
  52. },
  53. computed: {
  54. curYearMonth() {
  55. var currentDate = new Date();
  56. var currentYear = currentDate.getFullYear();
  57. var currentMonth = currentDate.getMonth() + 1; // 月份从0开始,所以要加1
  58. return `${currentYear}年${currentMonth}月`;
  59. }
  60. },
  61. onLoad(query) { // 类型非必填,可自动推导
  62. // console.log(query);
  63. this.queryObj = query;
  64. this.queryString = tools.objectToQueryString(this.queryObj);
  65. // console.log(queryString);
  66. this.token = query["token"] ?? token;
  67. this.ecId = query["id"] ?? 0;
  68. this.contentBg = "content-bg-" + (query["bg"] ?? "blue");
  69. this.logoSrc = "/static/logo/" + (query["logo"] ?? "mytz") + '.png';
  70. // this.type = query["type"] ?? "每月挑战";
  71. this.name = query["name"] ?? this.curYearMonth;
  72. this.btnText = query["btnText"] ?? "开始挑战";
  73. this.getCardBaseQuery();
  74. this.getCurrentMonthlyChallengeQuery();
  75. },
  76. onUnload() {
  77. },
  78. methods: {
  79. dealNotice(rank) {
  80. // console.log('[dealFirstEnter]');
  81. let that = this;
  82. uni.getStorage({
  83. key: that.rankKey,
  84. success: (res) => {
  85. console.log('[getStorage]', that.rankKey, res.data);
  86. const oldRank = res.data;
  87. if (oldRank != rank) {
  88. that.notice = true;
  89. // that.setRankValue(rank);
  90. }
  91. },
  92. fail: (e) => {
  93. console.log('[getStorage] fail', that.rankKey, e);
  94. that.notice = true;
  95. // that.setRankValue(rank);
  96. },
  97. })
  98. },
  99. setRankValue(data) {
  100. let that = this;
  101. uni.setStorage({
  102. key: that.rankKey,
  103. data: data,
  104. success: () => {
  105. console.log('[setStorage] success', that.rankKey, data);
  106. },
  107. fail: (e) => {
  108. console.log('[setStorage] fail', that.rankKey, e);
  109. },
  110. })
  111. },
  112. // 卡片基本信息查询
  113. getCardBaseQuery() {
  114. uni.request({
  115. url: apiCardBaseQuery,
  116. header: {
  117. "Content-Type": "application/x-www-form-urlencoded",
  118. "token": this.token,
  119. },
  120. method: "POST",
  121. data: {
  122. ecId: this.ecId
  123. },
  124. success: (res) => {
  125. // console.log("getCardBaseQuery", res)
  126. const data = res.data.data;
  127. this.ecName = data.ecName;
  128. this.ecDesc = data.ecDesc;
  129. this.beginSecond = data.beginSecond;
  130. this.endSecond = data.endSecond;
  131. },
  132. fail: (err) => {
  133. console.log("getCardBaseQuery err", err)
  134. },
  135. });
  136. },
  137. // 玩家当前月挑战记录查询
  138. getCurrentMonthlyChallengeQuery() {
  139. uni.request({
  140. url: apiCurrentMonthlyChallengeQuery,
  141. header: {
  142. "Content-Type": "application/x-www-form-urlencoded",
  143. "token": this.token,
  144. },
  145. method: "POST",
  146. data: {},
  147. success: (res) => {
  148. // console.log("getCurrentMonthlyChallengeQuery", res);
  149. if (res.data.code == 0) {
  150. const data = res.data.data;
  151. this.month = data.month;
  152. this.realNum = data.realNum;
  153. this.targetNum = data.targetNum;
  154. this.dealNotice(this.realNum);
  155. }
  156. },
  157. fail: (err) => {
  158. console.log("getCurrentMonthlyChallengeQuery err", err)
  159. },
  160. });
  161. },
  162. btnClick() {
  163. // uni.reLaunch({
  164. // url: '/pages/mytz/detail?full=true&' + this.queryString
  165. // });
  166. window.location.href = `${ossUrl}#/pages/mytz/detail?${this.queryString}&full=true`;
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped>
  172. .content {
  173. width: 100vw;
  174. height: 100vh;
  175. justify-content: center;
  176. }
  177. .content-bg-blue {
  178. background: linear-gradient(180deg,#178bff 0%,#004d9b 100%);
  179. }
  180. .content-bg-green {
  181. background: linear-gradient(180deg,#7aedff 0%,#047200 100%);
  182. }
  183. .content-bg-brown {
  184. background: linear-gradient(180deg,#ad4301 0%,#8d2219 100%);
  185. }
  186. .main {
  187. width: 100%;
  188. height: 700rpx;
  189. /* margin-top: 20rpx; */
  190. justify-content: space-evenly;
  191. }
  192. .logo {
  193. /* width: 230rpx; */
  194. height: 230rpx;
  195. }
  196. .notice {
  197. width: 30rpx;
  198. height: 30rpx;
  199. /* margin-right: 30rpx; */
  200. position: absolute;
  201. left: -60rpx;
  202. }
  203. .type {
  204. opacity: 60%;
  205. /* line-height: 25px; */
  206. font-family: Roboto;
  207. color: #ffffff;
  208. font-size: 40rpx;
  209. text-align: center;
  210. }
  211. .name {
  212. font-family: Roboto;
  213. color: #ffffff;
  214. font-size: 50rpx;
  215. text-align: center;
  216. }
  217. .button {
  218. width: 320rpx;
  219. height: 86rpx;
  220. margin-top: 20rpx;
  221. background: #ffffff;
  222. border-radius: 56rpx;
  223. font-size: 46rpx;
  224. line-height: 80rpx;
  225. }
  226. .button-txtcolor {
  227. color: #0458ad;
  228. }
  229. </style>