index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view class="layout-container">
  3. <!-- 顶部填充区 -->
  4. <view class="top-fill" :style="{height: safeArea.statusBarHeight+'px'}"></view>
  5. <!-- 顶部胶囊区 -->
  6. <view class="capsule-container" :style="{
  7. height: safeArea.capsuleBarHeight+'px',
  8. width: safeArea.capsuleBarLeft+'px',
  9. 'padding-top': safeArea.capsuleBarMarginTop+'px',
  10. 'padding-bottom': safeArea.capsuleBarMarginBottom+'px'}">
  11. <view class="user-info-container" @click="goUserInfoPage">
  12. <view class="user-info"
  13. :style="{height: safeArea.capsuleBarContentHeight+'px',width: safeArea.capsuleBarContentHeight+'px'}">
  14. <image v-if="userInfo" :style="{
  15. height: safeArea.capsuleBarContentHeight+'px',
  16. width: safeArea.capsuleBarContentHeight+'px',
  17. }" mode="aspectFill" :src="userInfo.avatar"></image>
  18. <uni-icons v-else type="person" :size="safeArea.capsuleBarContentHeight" color="#FFFFFF"></uni-icons>
  19. </view>
  20. <view class="nickname" v-if="userInfo">{{userInfo.nickname}}</view>
  21. <view class="nickname" v-else>登录</view>
  22. </view>
  23. </view>
  24. <!-- 内容区 -->
  25. <view class="content-container">
  26. <view class="settle-container">
  27. <view class="settle-text-container">
  28. <view class="settle-title">待领取奖励数</view>
  29. <view class="settle-num">{{reward}}</view>
  30. </view>
  31. <view class="settle-btn" @click="claimReward">领取</view>
  32. </view>
  33. <view class="task-container">
  34. <view class="task-header">
  35. <view class="task-title" v-if="punchIns.length && punchIns.length > 0">任务({{punchIns.lengt}}个)
  36. </view>
  37. <view class="task-title" v-else>任务</view>
  38. <view class="task-add-btn" @click="goPunchInDetailPage">
  39. <uni-icons type="plusempty" size="30" color="#406CE7"></uni-icons>
  40. </view>
  41. </view>
  42. <view class="task-item" v-for="punchIn in punchIns" :key="punchIn.punchInId">
  43. <view class="item-header">
  44. <view class="item-title">{{punchIn.taskName}}</view>
  45. <navigator :url="'/pages/detail/detail?id='+punchIn.punchInId">
  46. <uni-icons class="item-icon" type="settings" size="30" color="#C4C4C4"></uni-icons>
  47. </navigator>
  48. <view class="item-tag-container">
  49. <view class="item-tag" v-if="punchIn.fullAttendanceFlag">全勤奖励</view>
  50. <view class="item-tag" v-if="punchIn.weekendDoubleFlag">周末双倍</view>
  51. </view>
  52. <view class="item-btn" @click="doPunchIn(punchIn.punchInId)">完成</view>
  53. </view>
  54. <view class="item-detail-list">
  55. <view class="item-detail" v-for="punchInRecord in punchIn.punchInRecords"
  56. :key="punchInRecord.punchInDate">
  57. <view class="detail-text">
  58. <uni-dateformat :date="punchInRecord.punchInDate" format="M月d日"></uni-dateformat>
  59. </view>
  60. <view class="detail-box" style="background-color: #E5E5E5;"
  61. v-if="punchInRecord.punchInStatus == 'uncreated'"></view>
  62. <view class="detail-box" style="background-color: #A5D63F;"
  63. v-if="punchInRecord.punchInStatus == 'punchIn'"></view>
  64. <view class="detail-box" style="background-color: #D43030;"
  65. v-if="punchInRecord.punchInStatus == 'unPunchIn'"></view>
  66. <view class="detail-box"
  67. v-if="punchInRecord.punchInStatus == 'futureTime' || punchInRecord.punchInStatus == 'todayUnknown'">
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <!-- 弹出框 -->
  75. <view>
  76. <uni-popup ref="claimRewardDialog" type="dialog">
  77. <uni-popup-dialog ref="inputClose" mode="input" title="领取奖励" value="对话框预置提示内容!" placeholder="请输入领取的奖励数"
  78. @confirm="claimRewardConfirm"></uni-popup-dialog>
  79. </uni-popup>
  80. </view>
  81. <!-- 底部填充区 -->
  82. <view class="bottom-fill" :style="{height: safeArea.bottomHeight+'px'}"></view>
  83. </view>
  84. </template>
  85. <script setup>
  86. import {
  87. onMounted,
  88. ref
  89. } from 'vue';
  90. import {
  91. onLoad,
  92. onPullDownRefresh,
  93. onShow
  94. } from "@dcloudio/uni-app";
  95. import {
  96. rewardApi,
  97. punchInApi
  98. } from '@/service/apis.js';
  99. import {
  100. getSafeArea
  101. } from '@/utils/system.js';
  102. /**
  103. * 可领取奖励
  104. */
  105. const reward = ref(0);
  106. /**
  107. * 打卡任务
  108. */
  109. const punchIns = ref([]);
  110. /**
  111. * 领取奖励对话框
  112. */
  113. const claimRewardDialog = ref(null);
  114. /**
  115. * 安全区
  116. */
  117. const safeArea = ref({});
  118. /**
  119. * 用户信息
  120. */
  121. const userInfo = ref(null);
  122. /**
  123. * 领取奖励
  124. */
  125. const claimReward = () => {
  126. claimRewardDialog.value.open();
  127. }
  128. /**
  129. * 确认领取奖励
  130. */
  131. const claimRewardConfirm = async (val) => {
  132. await rewardApi.claimReward({
  133. "claimRewardNum": val
  134. });
  135. getReward();
  136. claimRewardDialog.value.close();
  137. }
  138. /**
  139. * 获取奖励
  140. */
  141. const getReward = async () => {
  142. let res = await rewardApi.queryReward();
  143. reward.value = res.unclaimedRewardNum;
  144. }
  145. /**
  146. * 获取打卡
  147. */
  148. const getPunchIn = async () => {
  149. let res = await punchInApi.queryPunchIn();
  150. punchIns.value = res;
  151. }
  152. /**
  153. * 打卡
  154. */
  155. const doPunchIn = async (id) => {
  156. await punchInApi.doPunchIn({
  157. id
  158. });
  159. getPunchIn();
  160. }
  161. /**
  162. * 跳转用户用心
  163. */
  164. const goUserInfoPage = () => {
  165. uni.navigateTo({
  166. url: "/pages/userInfo/userInfo"
  167. });
  168. }
  169. /**
  170. * 获取打卡编辑页面
  171. */
  172. const goPunchInDetailPage = () => {
  173. uni.navigateTo({
  174. url: "/pages/detail/detail"
  175. })
  176. };
  177. /**
  178. * 加载数据
  179. */
  180. const loadData = async () => {
  181. let token = uni.getStorageSync("token");
  182. // 如果还没登录就结束获取数据
  183. if (!token) {
  184. reward.value = 0;
  185. punchIns.value = [];
  186. return;
  187. }
  188. try {
  189. uni.showLoading({
  190. title: '加载中',
  191. mask: true
  192. });
  193. // 获取奖励
  194. getReward();
  195. // 获取打卡
  196. getPunchIn();
  197. } finally {
  198. uni.hideLoading();
  199. }
  200. };
  201. onLoad(() => {
  202. safeArea.value = getSafeArea();
  203. });
  204. onShow(() => {
  205. console.log("onSHow");
  206. userInfo.value = uni.getStorageSync("userInfo");
  207. loadData();
  208. });
  209. onPullDownRefresh(() => {
  210. loadData();
  211. uni.stopPullDownRefresh();
  212. });
  213. </script>
  214. <style lang="scss" scoped>
  215. .user-info-container {
  216. display: flex;
  217. align-items: center;
  218. .user-info {
  219. display: flex;
  220. justify-content: center;
  221. align-items: center;
  222. border-radius: 50%;
  223. background: rgba(210, 239, 243, 1);
  224. }
  225. .nickname {
  226. display: flex;
  227. /* 水平居中 */
  228. justify-content: center;
  229. /* 垂直居中 */
  230. align-items: center;
  231. margin-left: 10rpx;
  232. color: rgba(0, 0, 0, 1);
  233. }
  234. }
  235. .content-container {
  236. .settle-container {
  237. // margin-top: 16rpx;
  238. height: 228rpx;
  239. position: relative;
  240. border-radius: 20rpx;
  241. background: rgba(64, 108, 231, 1);
  242. box-shadow: 1rpx 2rpx 4rpx rgba(0, 0, 0, 0.25);
  243. .settle-text-container {
  244. position: absolute;
  245. left: 108rpx;
  246. top: 20rpx;
  247. .settle-title {
  248. font-size: 24rpx;
  249. line-height: 34.75rpx;
  250. color: rgba(255, 255, 255, 1);
  251. }
  252. .settle-num {
  253. font-size: 100rpx;
  254. font-weight: 700;
  255. line-height: 144.8rpx;
  256. color: rgba(255, 255, 255, 1);
  257. display: flex;
  258. justify-content: center;
  259. /* 水平居中 */
  260. align-items: center;
  261. /* 垂直居中 */
  262. }
  263. }
  264. .settle-btn {
  265. position: absolute;
  266. left: 503rpx;
  267. top: 76rpx;
  268. width: 164rpx;
  269. height: 99rpx;
  270. border-radius: 40rpx;
  271. background: rgba(242, 247, 255, 1);
  272. font-size: 48rpx;
  273. font-weight: 700;
  274. line-height: 69.5px;
  275. color: rgba(64, 108, 231, 1);
  276. display: flex;
  277. justify-content: center;
  278. /* 水平居中 */
  279. align-items: center;
  280. /* 垂直居中 */
  281. }
  282. }
  283. .task-container {
  284. margin-top: 16rpx;
  285. .task-header {
  286. position: relative;
  287. height: 80rpx;
  288. display: flex;
  289. justify-content: center;
  290. /* 水平居中 */
  291. align-items: center;
  292. /* 垂直居中 */
  293. .task-title {
  294. position: absolute;
  295. left: 0rpx;
  296. font-size: 30rpx;
  297. font-weight: 400;
  298. line-height: 43.44rpx;
  299. color: rgba(0, 0, 0, 1);
  300. }
  301. .task-add-btn {
  302. display: inline-flex;
  303. justify-content: center;
  304. align-items: center;
  305. position: absolute;
  306. right: 0rpx;
  307. width: 60rpx;
  308. height: 60rpx;
  309. border-radius: 10rpx;
  310. border: 3px solid rgba(64, 108, 231, 1);
  311. }
  312. }
  313. .task-item {
  314. margin-top: 16rpx;
  315. width: 100%;
  316. height: 201rpx;
  317. border-radius: 20px;
  318. background: #FFFFFF;
  319. box-shadow: 1px 2px 4px #000000;
  320. box-sizing: border-box;
  321. padding: 16rpx;
  322. .item-header {
  323. position: relative;
  324. display: flex;
  325. align-items: center;
  326. .item-title {
  327. display: inline-block;
  328. // margin-left: 20rpx;
  329. font-size: 36rpx;
  330. font-weight: 400;
  331. letter-spacing: 0rpx;
  332. line-height: 52.13rpx;
  333. color: rgba(0, 0, 0, 1);
  334. }
  335. .item-icon {
  336. margin-left: 10rpx;
  337. }
  338. .item-tag-container {
  339. display: inline-block;
  340. margin-left: 10rpx;
  341. .item-tag:not(:first-child) {
  342. margin-left: 10rpx;
  343. }
  344. .item-tag {
  345. display: inline-block;
  346. background-color: #F2F7FF;
  347. padding: 10rpx;
  348. border-radius: 40rpx;
  349. background: #F2F7FF;
  350. font-size: 16rpx;
  351. font-weight: 400;
  352. line-height: 23.17rpx;
  353. color: rgba(0, 0, 0, 1);
  354. text-align: center;
  355. vertical-align: top;
  356. }
  357. }
  358. .item-btn {
  359. display: inline-flex;
  360. position: absolute;
  361. right: 0rpx;
  362. width: 123rpx;
  363. height: 42rpx;
  364. border-radius: 30rpx;
  365. border: 1rpx solid #2A82E4;
  366. justify-content: center;
  367. align-items: center;
  368. font-size: 20rpx;
  369. font-weight: 400;
  370. line-height: 28.96px;
  371. color: rgba(64, 108, 231, 1);
  372. }
  373. }
  374. .item-detail-list {
  375. margin-top: 16rpx;
  376. display: grid;
  377. grid-template-columns: repeat(7, 1fr);
  378. .item-detail {
  379. display: flex;
  380. flex-direction: column;
  381. justify-content: center;
  382. align-items: center;
  383. .detail-text {
  384. font-size: 20rpx;
  385. font-weight: 400;
  386. letter-spacing: 0rpx;
  387. line-height: 28.96rpx;
  388. color: rgba(0, 0, 0, 1);
  389. }
  390. .detail-box {
  391. // display: block;
  392. width: 42rpx;
  393. height: 42rpx;
  394. margin-top: 5rpx;
  395. border: 5rpx solid #000000;
  396. }
  397. }
  398. }
  399. }
  400. }
  401. }
  402. </style>