index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <!--
  2. * @Author: wanglj wanglijie@dashoo.cn
  3. * @Date: 2025-03-11 18:02:10
  4. * @LastEditors: wanglj wanglijie@dashoo.cn
  5. * @LastEditTime: 2025-04-10 17:33:26
  6. * @Description: 首页重构优化 (适配 uni-app)
  7. -->
  8. <template>
  9. <view class="app-container">
  10. <uv-loading-page :loading="isLogining && !token" text="正在登录中..." iconSize="40"></uv-loading-page>
  11. <view v-if="token">
  12. <view class="card">
  13. <view class="card-title">常用功能</view>
  14. <view class="nav">
  15. <view class="nav-item" v-for="(item, index) in HOME_NAV_LIST" :key="index" @click="onRouterPush(item.path)" v-hasPermi="[item.permission]">
  16. <image :src="item.icon" mode="aspectFit" />
  17. <text>{{ item.name }}</text>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="section-box mt20" v-hasPermi="['todo:list']">
  22. <view class="section-header flex justify-between align-center">
  23. <view class="flex align-center">
  24. <text class="section-title">待办事项</text>
  25. <text class="badge">{{ todoStore.total }}</text>
  26. </view>
  27. <text class="link" @click="onRouterPush('/pages/todo/index')">查看更多 ></text>
  28. </view>
  29. <view class="todo-list">
  30. <view v-if="!todoStore.list.length && !isLogining" class="home-empty-row">
  31. <uv-icon name="file-text" size="22" color="#cbd5f5"></uv-icon>
  32. <text class="home-empty-text">暂无待办事项</text>
  33. </view>
  34. <view v-else>
  35. <view
  36. class="todo-item"
  37. v-for="item in todoStore.list"
  38. :key="item.taskId"
  39. >
  40. <view class="todo-img-placeholder"></view>
  41. <view class="todo-content">
  42. <view class="todo-title">{{ item.instTitle || '审批任务' }}</view>
  43. <view class="todo-info">
  44. <text class="label">发起人:</text>
  45. <text class="value">{{ item.startUserName || '-' }}</text>
  46. </view>
  47. <view class="todo-time">
  48. <text class="label">发起时间:</text>
  49. <text class="value">{{ formatDate(item.createdTime, 'YYYY-MM-DD HH:mm') }}</text>
  50. </view>
  51. </view>
  52. <view class="todo-btn" @click="handleApprove(item)">去处理</view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 报销提醒 -->
  58. <!-- <view class="section-box mt20" v-hasPermi="['fund:reimbursement:list']">
  59. <view class="section-header flex justify-between align-center">
  60. <text class="section-title">报销提醒</text>
  61. <text class="link" @click="onRouterPush('/pages/fund/reimbursement-remind/index')">查看更多 ></text>
  62. </view>
  63. <view class="fund-list">
  64. <view v-if="!expendseList.length && !isLogining" class="home-empty-row">
  65. <uv-icon name="order" size="22" color="#cbd5f5"></uv-icon>
  66. <text class="home-empty-text">暂无报销提醒</text>
  67. </view>
  68. <view v-else>
  69. <view
  70. class="fund-item"
  71. v-for="item in expendseList"
  72. :key="item.id"
  73. @click="onRouterPush(`/pages/fund/reimbursement/edit?id=${item.id}`)"
  74. >
  75. <view class="fund-title">{{ `项目编号:${item.projectCode || '-'}` }}</view>
  76. <view class="fund-footer flex justify-between">
  77. <text class="user">采购人:{{ item.buyerName || '-' }}</text>
  78. <text class="date">{{ formatDate(item.createdTime) }}</text>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </view> -->
  84. <!-- 通知公告列表 -->
  85. <view class="section-box mt20">
  86. <view class="section-header flex justify-between align-center">
  87. <text class="section-title">通知公告</text>
  88. <text class="link" @click="onRouterPush('/pages/notice/index')">查看更多 ></text>
  89. </view>
  90. <view class="notice-card">
  91. <view v-if="!noticeList.length && !isLogining" class="home-empty-row">
  92. <uv-icon name="file-text" size="22" color="#cbd5f5"></uv-icon>
  93. <text class="home-empty-text">暂无通知公告</text>
  94. </view>
  95. <view v-else>
  96. <view
  97. class="notice-item"
  98. v-for="item in noticeList"
  99. :key="item.id"
  100. @click="onRouterPush(`/pages/notice/detail?id=${item.id}`)"
  101. >
  102. <view class="notice-content">
  103. <view class="notice-title">{{ item.noticeTitle }}</view>
  104. <view class="notice-date">{{ formatDate(item.noticeTime, 'YYYY-MM-DD HH:mm') }}</view>
  105. </view>
  106. <view class="notice-action">
  107. <text>详情</text>
  108. <text class="arrow">></text>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. </view>
  116. </template>
  117. <script name="home" lang="ts" setup>
  118. import { ref, watch, onMounted } from 'vue';
  119. import { storeToRefs } from 'pinia';
  120. import { onShow } from '@dcloudio/uni-app';
  121. import { useUserStore } from '@/store/modules/user';
  122. import { useTodoStore } from '@/store/modules/todo';
  123. import type { TodoItem } from '@/types/todo';
  124. import { onRouterPush } from '@/utils/router';
  125. import { formatDate } from '@/utils/date';
  126. import { HOME_NAV_LIST } from '@/constants';
  127. import { useFundApi, useExpenseRemindApi } from '@/api/fund';
  128. import { useSystemApi } from '@/api/system';
  129. import { useExecutionApi } from '@/api/execution';
  130. import { useProjectApi } from '@/api/project';
  131. import to from 'await-to-js';
  132. const userStore = useUserStore();
  133. const { token, isLogining } = storeToRefs(userStore);
  134. const todoStore = useTodoStore();
  135. const fundApi = useFundApi();
  136. const expenseRemindApi = useExpenseRemindApi();
  137. const systemApi = useSystemApi();
  138. const executionApi = useExecutionApi();
  139. const projectApi = useProjectApi();
  140. /**
  141. * 状态变量定义
  142. * noticeList: 轮播图通知公告列表
  143. */
  144. const noticeList = ref<any[]>([]);
  145. const fundsList = ref<any[]>([]);
  146. const expendseList = ref<any[]>([]);
  147. /**
  148. * 获取通知公告列表 (GetList)
  149. */
  150. const getNoticeList = async () => {
  151. try {
  152. const res: any = await systemApi.getNoticeList({
  153. noticeTitle: "",
  154. pageNum: 1,
  155. pageSize: 3,
  156. noticeStatus: "20"
  157. });
  158. if (res.code == 200) {
  159. noticeList.value = res.data?.list || [];
  160. }
  161. } catch (err) {
  162. console.error(err);
  163. }
  164. };
  165. /**
  166. * 获取经费认领简要列表
  167. */
  168. const getFundList = async () => {
  169. try {
  170. const res: any = await fundApi.getList({ pageNum: 1, pageSize: 3, status: '10' });
  171. if (res.code == 200) {
  172. fundsList.value = res.data?.list || res.list || [];
  173. }
  174. } catch (err) {
  175. console.error(err);
  176. }
  177. };
  178. /**
  179. * 获取报销提醒简要列表
  180. */
  181. // const getExpendseList = async () => {
  182. // try {
  183. // const res: any = await expenseRemindApi.getList({ pageNum: 1, pageSize: 3, expenseStatus: '10' });
  184. // if (res.code == 200) {
  185. // expendseList.value = res.data?.list || res.list || [];
  186. // }
  187. // } catch (err) {
  188. // console.error(err);
  189. // }
  190. // };
  191. /**
  192. * 处理审批跳转逻辑
  193. * 根据待办事项的属性跳转到相应的详情页面
  194. * @param item 待办事项对象
  195. */
  196. const handleApprove = async (item: TodoItem) => {
  197. // 审批前增加学术不端行为校验
  198. uni.showLoading({ title: '校验中...', mask: true });
  199. // 1. 获取参与者列表,找出发起人
  200. const [err, res] = await to(executionApi.getParticipantByProcInstID({ id: item.id }));
  201. if (err || !res?.data) {
  202. uni.hideLoading();
  203. // 如果获取失败,出于流程通畅考虑,直接跳转
  204. onRouterPush(`/pages/todo/detail?mode=approval&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  205. return;
  206. }
  207. const participants = res.data as any[];
  208. const startUser = participants.find(p => p.type === 'start');
  209. const startUserId = startUser?.userId;
  210. if (!startUserId) {
  211. uni.hideLoading();
  212. onRouterPush(`/pages/todo/detail?mode=approval&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  213. return;
  214. }
  215. // 2. 调用学术不端校验接口
  216. const [err2, res2] = await to(projectApi.checkUserViolationStatus({ personId: startUserId }));
  217. uni.hideLoading();
  218. if (!err2 && res2?.data?.hasViolation) {
  219. const { restrictions } = res2.data;
  220. let restrictionList = [];
  221. if (restrictions.limitProjectApply) restrictionList.push('限制项目申报');
  222. if (restrictions.limitFundApply) restrictionList.push('限制申请经费');
  223. if (restrictions.limitRewardApply) restrictionList.push('限制成为奖励对象');
  224. uni.showModal({
  225. title: '学术不端行为提醒',
  226. content: `发起人 [${startUser?.userName || '未知'}] 存在学术不端记录,已被限制:${restrictionList.join('、')}。`,
  227. confirmText: '我知道了',
  228. showCancel: false
  229. });
  230. // 不跳转
  231. } else {
  232. onRouterPush(`/pages/todo/detail?mode=approval&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  233. }
  234. };
  235. /**
  236. * 刷新首页所有数据
  237. */
  238. const refreshAllData = () => {
  239. if (!token.value) return;
  240. todoStore.fetchHomeTodoList();
  241. getFundList();
  242. // getExpendseList();
  243. getNoticeList();
  244. };
  245. /**
  246. * 页面生命周期:每次显示页面时刷新待办列表
  247. */
  248. onShow(() => {
  249. if (token.value) {
  250. refreshAllData();
  251. } else {
  252. // 如果没有 token,则跳转登录
  253. const launchCode = uni.getLaunchOptionsSync()?.query?.code;
  254. if (!launchCode && !isLogining.value) {
  255. setTimeout(() => {
  256. if (!token.value) {
  257. uni.reLaunch({ url: '/pages/login/index' });
  258. }
  259. }, 500);
  260. }
  261. }
  262. });
  263. // 监听 token,登录成功后立即加载数据
  264. watch(token, (newVal) => {
  265. if (newVal) {
  266. refreshAllData();
  267. }
  268. });
  269. // token 获取后自动加载首页数据
  270. onMounted(() => {
  271. if (token.value) {
  272. refreshAllData();
  273. }
  274. });
  275. </script>
  276. <style lang="scss" scoped>
  277. .app-container {
  278. min-height: calc(100vh - var(--window-top) - var(--window-bottom));
  279. box-sizing: border-box;
  280. background-color: #f5f7fa;
  281. padding: 20rpx;
  282. .flex {
  283. display: flex;
  284. }
  285. .justify-between {
  286. justify-content: space-between;
  287. }
  288. .align-center {
  289. align-items: center;
  290. }
  291. /* 通用卡片样式 */
  292. .card {
  293. min-height: 120rpx;
  294. border-radius: 16rpx;
  295. background-color: #fff;
  296. padding: 24rpx;
  297. box-shadow: 0px 4rpx 20rpx rgba(0, 0, 0, 0.04);
  298. .card-title {
  299. font-size: 32rpx;
  300. font-weight: bold;
  301. color: #343A3F;
  302. display: flex;
  303. align-items: center;
  304. .link {
  305. font-weight: normal;
  306. font-size: 26rpx;
  307. color: #999;
  308. }
  309. &::before {
  310. display: inline-block;
  311. content: '';
  312. width: 8rpx;
  313. height: 32rpx;
  314. background-color: #1c9bfd;
  315. margin-right: 16rpx;
  316. border-radius: 4rpx;
  317. }
  318. }
  319. .time {
  320. color: #f69a4d;
  321. font-size: 24rpx;
  322. }
  323. /* 导航 */
  324. .nav {
  325. display: flex;
  326. flex-wrap: wrap;
  327. margin-top: 20rpx;
  328. .nav-item {
  329. flex: 0 0 25%;
  330. display: flex;
  331. flex-direction: column;
  332. align-items: center;
  333. justify-content: center;
  334. margin-bottom: 24rpx;
  335. text {
  336. font-size: 26rpx;
  337. color: #585858;
  338. margin-top: 14rpx;
  339. }
  340. image {
  341. height: 88rpx;
  342. width: 88rpx;
  343. padding: 18rpx;
  344. border-radius: 20rpx;
  345. box-sizing: border-box;
  346. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  347. }
  348. &:nth-child(1) image {
  349. background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  350. }
  351. &:nth-child(2) image {
  352. background: linear-gradient(135deg, #ff9a44 0%, #fc6076 100%);
  353. }
  354. &:nth-child(3) image {
  355. background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  356. }
  357. &:nth-child(4) image {
  358. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  359. }
  360. &:nth-child(5) image {
  361. background: linear-gradient(135deg, #ff0844 0%, #ffb199 100%);
  362. }
  363. &:nth-child(6) image {
  364. background: linear-gradient(135deg, #fccb90 0%, #d57eeb 100%);
  365. }
  366. &:nth-child(n+7) image {
  367. background: linear-gradient(135deg, #2af598 0%, #009efd 100%);
  368. }
  369. }
  370. }
  371. }
  372. /* 区块通用样式 (待办事项 & 通知公告) */
  373. .section-box {
  374. margin-top: 30rpx;
  375. .section-header {
  376. margin-bottom: 24rpx;
  377. .section-title {
  378. font-size: 34rpx;
  379. font-weight: bold;
  380. color: #343A3F;
  381. }
  382. .link {
  383. font-size: 26rpx;
  384. color: #888;
  385. }
  386. }
  387. .badge {
  388. background-color: #ff4d4f;
  389. color: #fff;
  390. font-size: 20rpx;
  391. font-weight: bold;
  392. width: 32rpx;
  393. height: 32rpx;
  394. border-radius: 50%;
  395. display: flex;
  396. justify-content: center;
  397. align-items: center;
  398. margin-left: 12rpx;
  399. box-shadow: 0 4rpx 8rpx rgba(255, 77, 79, 0.3);
  400. }
  401. .home-empty-row {
  402. display: flex;
  403. align-items: center;
  404. gap: 12rpx;
  405. padding: 20rpx 0 10rpx;
  406. color: #94a3b8;
  407. font-size: 26rpx;
  408. }
  409. .home-empty-text {
  410. color: #94a3b8;
  411. }
  412. .todo-list {
  413. .home-empty-row {
  414. padding: 24rpx;
  415. margin-bottom: 24rpx;
  416. background-color: #fff;
  417. border-radius: 16rpx;
  418. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.05);
  419. }
  420. .todo-item {
  421. display: flex;
  422. align-items: center;
  423. padding: 30rpx 24rpx;
  424. background-color: #fff;
  425. margin-bottom: 24rpx;
  426. border: none;
  427. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.05);
  428. border-radius: 16rpx;
  429. .todo-img-placeholder {
  430. width: 80rpx;
  431. height: 80rpx;
  432. border-radius: 50%;
  433. border: none;
  434. margin-right: 24rpx;
  435. flex-shrink: 0;
  436. background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
  437. display: flex;
  438. align-items: center;
  439. justify-content: center;
  440. color: #fff;
  441. font-size: 24rpx;
  442. font-weight: bold;
  443. box-shadow: 0 6rpx 12rpx rgba(142, 197, 252, 0.4);
  444. &::after {
  445. content: "审";
  446. }
  447. }
  448. .todo-content {
  449. flex: 1;
  450. overflow: hidden;
  451. .todo-title {
  452. font-size: 32rpx;
  453. font-weight: 600;
  454. color: #343A3F;
  455. margin-bottom: 12rpx;
  456. white-space: nowrap;
  457. overflow: hidden;
  458. text-overflow: ellipsis;
  459. }
  460. .todo-info {
  461. font-size: 24rpx;
  462. margin-bottom: 10rpx;
  463. display: flex;
  464. align-items: center;
  465. .label {
  466. color: #343A3F;
  467. }
  468. .value {
  469. color: #585858;
  470. }
  471. .dept {
  472. margin-left: 16rpx;
  473. color: #1c9bfd;
  474. background: rgba(28, 155, 253, 0.1);
  475. padding: 2rpx 10rpx;
  476. border-radius: 6rpx;
  477. }
  478. }
  479. .todo-time {
  480. font-size: 22rpx;
  481. .label {
  482. color: #343A3F;
  483. }
  484. .value {
  485. color: #585858;
  486. }
  487. }
  488. }
  489. .todo-btn {
  490. background: linear-gradient(135deg, #1fc199 0%, #15a982 100%);
  491. color: #fff;
  492. font-size: 26rpx;
  493. padding: 12rpx 36rpx;
  494. border-radius: 30rpx;
  495. margin-left: 20rpx;
  496. flex-shrink: 0;
  497. box-shadow: 0 6rpx 12rpx rgba(31, 193, 153, 0.3);
  498. font-weight: 500;
  499. }
  500. }
  501. }
  502. /* 通知公告卡片 */
  503. .notice-card {
  504. background-color: #fff;
  505. border-radius: 16rpx;
  506. padding: 0 30rpx;
  507. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.05);
  508. .notice-item {
  509. display: flex;
  510. justify-content: space-between;
  511. align-items: center;
  512. padding: 29rpx 0;
  513. border-bottom: 2rpx solid #f5f5f5;
  514. &:last-child {
  515. border-bottom: none;
  516. }
  517. .notice-content {
  518. flex: 1;
  519. .notice-title {
  520. font-size: 30rpx;
  521. color: #343A3F;
  522. margin-bottom: 12rpx;
  523. font-weight: 500;
  524. }
  525. .notice-date {
  526. font-size: 24rpx;
  527. color: #aaa;
  528. }
  529. }
  530. .notice-action {
  531. display: flex;
  532. align-items: center;
  533. color: #aaa;
  534. font-size: 24rpx;
  535. .arrow {
  536. margin-left: 8rpx;
  537. }
  538. }
  539. }
  540. }
  541. /* 经费列表摘要 */
  542. .fund-list {
  543. background-color: #fff;
  544. border-radius: 16rpx;
  545. padding: 0 24rpx;
  546. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.05);
  547. .fund-item {
  548. padding: 24rpx 0;
  549. border-bottom: 1rpx solid #f2f2f2;
  550. &:last-child {
  551. border-bottom: none;
  552. }
  553. .fund-title {
  554. font-size: 28rpx;
  555. font-weight: bold;
  556. color: #333;
  557. margin-bottom: 8rpx;
  558. white-space: nowrap;
  559. overflow: hidden;
  560. text-overflow: ellipsis;
  561. }
  562. .fund-footer {
  563. font-size: 24rpx;
  564. color: #999;
  565. .amount {
  566. font-weight: 500;
  567. color: #ff9a44;
  568. }
  569. }
  570. }
  571. }
  572. }
  573. }
  574. </style>