index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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.length}}个)
  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. userInfo.value = uni.getStorageSync("userInfo");
  206. loadData();
  207. });
  208. onPullDownRefresh(() => {
  209. loadData();
  210. uni.stopPullDownRefresh();
  211. });
  212. </script>
  213. <style lang="scss" scoped>
  214. .user-info-container {
  215. display: flex;
  216. align-items: center;
  217. .user-info {
  218. display: flex;
  219. justify-content: center;
  220. align-items: center;
  221. border-radius: 50%;
  222. background: rgba(210, 239, 243, 1);
  223. }
  224. .nickname {
  225. display: flex;
  226. /* 水平居中 */
  227. justify-content: center;
  228. /* 垂直居中 */
  229. align-items: center;
  230. margin-left: 10rpx;
  231. color: rgba(0, 0, 0, 1);
  232. }
  233. }
  234. .content-container {
  235. .settle-container {
  236. // margin-top: 16rpx;
  237. height: 228rpx;
  238. position: relative;
  239. border-radius: 20rpx;
  240. background: rgba(64, 108, 231, 1);
  241. box-shadow: 1rpx 2rpx 4rpx rgba(0, 0, 0, 0.25);
  242. .settle-text-container {
  243. position: absolute;
  244. left: 108rpx;
  245. top: 20rpx;
  246. .settle-title {
  247. font-size: 24rpx;
  248. line-height: 34.75rpx;
  249. color: rgba(255, 255, 255, 1);
  250. }
  251. .settle-num {
  252. font-size: 100rpx;
  253. font-weight: 700;
  254. line-height: 144.8rpx;
  255. color: rgba(255, 255, 255, 1);
  256. display: flex;
  257. justify-content: center;
  258. /* 水平居中 */
  259. align-items: center;
  260. /* 垂直居中 */
  261. }
  262. }
  263. .settle-btn {
  264. position: absolute;
  265. left: 503rpx;
  266. top: 76rpx;
  267. width: 164rpx;
  268. height: 99rpx;
  269. border-radius: 40rpx;
  270. background: rgba(242, 247, 255, 1);
  271. font-size: 48rpx;
  272. font-weight: 700;
  273. line-height: 69.5px;
  274. color: rgba(64, 108, 231, 1);
  275. display: flex;
  276. justify-content: center;
  277. /* 水平居中 */
  278. align-items: center;
  279. /* 垂直居中 */
  280. }
  281. }
  282. .task-container {
  283. margin-top: 16rpx;
  284. .task-header {
  285. position: relative;
  286. height: 80rpx;
  287. display: flex;
  288. justify-content: center;
  289. /* 水平居中 */
  290. align-items: center;
  291. /* 垂直居中 */
  292. .task-title {
  293. position: absolute;
  294. left: 0rpx;
  295. font-size: 30rpx;
  296. font-weight: 400;
  297. line-height: 43.44rpx;
  298. color: rgba(0, 0, 0, 1);
  299. }
  300. .task-add-btn {
  301. display: inline-flex;
  302. justify-content: center;
  303. align-items: center;
  304. position: absolute;
  305. right: 0rpx;
  306. width: 60rpx;
  307. height: 60rpx;
  308. border-radius: 10rpx;
  309. border: 3px solid rgba(64, 108, 231, 1);
  310. }
  311. }
  312. .task-item {
  313. margin-top: 16rpx;
  314. width: 100%;
  315. height: 201rpx;
  316. border-radius: 20px;
  317. background: #FFFFFF;
  318. box-shadow: 1px 2px 4px #000000;
  319. box-sizing: border-box;
  320. padding: 16rpx;
  321. .item-header {
  322. position: relative;
  323. display: flex;
  324. align-items: center;
  325. .item-title {
  326. display: inline-block;
  327. // margin-left: 20rpx;
  328. font-size: 36rpx;
  329. font-weight: 400;
  330. letter-spacing: 0rpx;
  331. line-height: 52.13rpx;
  332. color: rgba(0, 0, 0, 1);
  333. }
  334. .item-icon {
  335. margin-left: 10rpx;
  336. }
  337. .item-tag-container {
  338. display: inline-block;
  339. margin-left: 10rpx;
  340. .item-tag:not(:first-child) {
  341. margin-left: 10rpx;
  342. }
  343. .item-tag {
  344. display: inline-block;
  345. background-color: #F2F7FF;
  346. padding: 10rpx;
  347. border-radius: 40rpx;
  348. background: #F2F7FF;
  349. font-size: 16rpx;
  350. font-weight: 400;
  351. line-height: 23.17rpx;
  352. color: rgba(0, 0, 0, 1);
  353. text-align: center;
  354. vertical-align: top;
  355. }
  356. }
  357. .item-btn {
  358. display: inline-flex;
  359. position: absolute;
  360. right: 0rpx;
  361. width: 123rpx;
  362. height: 42rpx;
  363. border-radius: 30rpx;
  364. border: 1rpx solid #2A82E4;
  365. justify-content: center;
  366. align-items: center;
  367. font-size: 20rpx;
  368. font-weight: 400;
  369. line-height: 28.96px;
  370. color: rgba(64, 108, 231, 1);
  371. }
  372. }
  373. .item-detail-list {
  374. margin-top: 16rpx;
  375. display: grid;
  376. grid-template-columns: repeat(7, 1fr);
  377. .item-detail {
  378. display: flex;
  379. flex-direction: column;
  380. justify-content: center;
  381. align-items: center;
  382. .detail-text {
  383. font-size: 20rpx;
  384. font-weight: 400;
  385. letter-spacing: 0rpx;
  386. line-height: 28.96rpx;
  387. color: rgba(0, 0, 0, 1);
  388. }
  389. .detail-box {
  390. // display: block;
  391. width: 42rpx;
  392. height: 42rpx;
  393. margin-top: 5rpx;
  394. border: 5rpx solid #000000;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. </style>