index.vue 5.7 KB

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