index.vue 16 KB

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