index.vue 16 KB

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