index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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 * as dd from 'dingtalk-jsapi';
  100. const userStore = useUserStore();
  101. const { token, isLogining } = storeToRefs(userStore);
  102. const todoStore = useTodoStore();
  103. const fundApi = useFundApi();
  104. const expenseRemindApi = useExpenseRemindApi();
  105. const systemApi = useSystemApi();
  106. /**
  107. * 状态变量定义
  108. * noticeList: 轮播图通知公告列表
  109. */
  110. const noticeList = ref<any[]>([]);
  111. const fundsList = ref<any[]>([]);
  112. const expendseList = ref<any[]>([]);
  113. /**
  114. * 获取通知公告列表 (GetList)
  115. */
  116. const getNoticeList = async () => {
  117. try {
  118. const res: any = await systemApi.getNoticeList({
  119. noticeTitle: "",
  120. pageNum: 1,
  121. pageSize: 3,
  122. noticeStatus: "20"
  123. });
  124. if (res.code == 200) {
  125. noticeList.value = res.data?.list || [];
  126. }
  127. } catch (err) {
  128. console.error(err);
  129. }
  130. };
  131. /**
  132. * 获取经费认领简要列表
  133. */
  134. const getFundList = async () => {
  135. try {
  136. const res: any = await fundApi.getList({ pageNum: 1, pageSize: 3, status: '10' });
  137. if (res.code == 200) {
  138. fundsList.value = res.data?.list || res.list || [];
  139. }
  140. } catch (err) {
  141. console.error(err);
  142. }
  143. };
  144. /**
  145. * 获取报销提醒简要列表
  146. */
  147. const getExpendseList = async () => {
  148. try {
  149. const res: any = await expenseRemindApi.getList({ pageNum: 1, pageSize: 3, expenseStatus: '10' });
  150. if (res.code == 200) {
  151. expendseList.value = res.data?.list || res.list || [];
  152. }
  153. } catch (err) {
  154. console.error(err);
  155. }
  156. };
  157. /**
  158. * 处理审批跳转逻辑
  159. * 根据待办事项的属性跳转到相应的详情页面
  160. * @param item 待办事项对象
  161. */
  162. const handleApprove = (item: TodoItem) => {
  163. onRouterPush(`/pages/todo/detail?mode=approval&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  164. };
  165. /**
  166. * 刷新首页所有数据
  167. */
  168. const refreshAllData = () => {
  169. if (!token.value) return;
  170. todoStore.fetchHomeTodoList();
  171. getFundList();
  172. getExpendseList();
  173. getNoticeList();
  174. };
  175. /**
  176. * 页面生命周期:每次显示页面时刷新待办列表
  177. */
  178. onShow(() => {
  179. if (token.value) {
  180. refreshAllData();
  181. } else {
  182. // 如果没有 token,且不在钉钉环境,跳转登录
  183. if (dd.env.platform === 'notInDingTalk' && !isLogining.value) {
  184. setTimeout(() => {
  185. if (!token.value) {
  186. uni.reLaunch({ url: '/pages/login/index' });
  187. }
  188. }, 500);
  189. }
  190. }
  191. });
  192. // 监听 token,登录成功后立即加载数据
  193. watch(token, (newVal) => {
  194. if (newVal) {
  195. refreshAllData();
  196. }
  197. });
  198. // 自动检测钉钉登录状态并引导
  199. onMounted(() => {
  200. if (token.value) {
  201. refreshAllData();
  202. }
  203. });
  204. </script>
  205. <style lang="scss" scoped>
  206. .app-container {
  207. min-height: calc(100vh - var(--window-top) - var(--window-bottom));
  208. box-sizing: border-box;
  209. background-color: #f5f7fa;
  210. padding: 20rpx;
  211. .flex {
  212. display: flex;
  213. }
  214. .justify-between {
  215. justify-content: space-between;
  216. }
  217. .align-center {
  218. align-items: center;
  219. }
  220. /* 通用卡片样式 */
  221. .card {
  222. min-height: 120rpx;
  223. border-radius: 16rpx;
  224. background-color: #fff;
  225. padding: 24rpx;
  226. box-shadow: 0px 4rpx 20rpx rgba(0, 0, 0, 0.04);
  227. .card-title {
  228. font-size: 32rpx;
  229. font-weight: bold;
  230. color: #343A3F;
  231. display: flex;
  232. align-items: center;
  233. .link {
  234. font-weight: normal;
  235. font-size: 26rpx;
  236. color: #999;
  237. }
  238. &::before {
  239. display: inline-block;
  240. content: '';
  241. width: 8rpx;
  242. height: 32rpx;
  243. background-color: #1c9bfd;
  244. margin-right: 16rpx;
  245. border-radius: 4rpx;
  246. }
  247. }
  248. .time {
  249. color: #f69a4d;
  250. font-size: 24rpx;
  251. }
  252. /* 导航 */
  253. .nav {
  254. display: flex;
  255. flex-wrap: wrap;
  256. margin-top: 20rpx;
  257. .nav-item {
  258. flex: 0 0 25%;
  259. display: flex;
  260. flex-direction: column;
  261. align-items: center;
  262. justify-content: center;
  263. margin-bottom: 24rpx;
  264. text {
  265. font-size: 26rpx;
  266. color: #585858;
  267. margin-top: 14rpx;
  268. }
  269. image {
  270. height: 88rpx;
  271. width: 88rpx;
  272. padding: 18rpx;
  273. border-radius: 20rpx;
  274. box-sizing: border-box;
  275. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  276. }
  277. &:nth-child(1) image {
  278. background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  279. }
  280. &:nth-child(2) image {
  281. background: linear-gradient(135deg, #ff9a44 0%, #fc6076 100%);
  282. }
  283. &:nth-child(3) image {
  284. background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  285. }
  286. &:nth-child(4) image {
  287. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  288. }
  289. &:nth-child(5) image {
  290. background: linear-gradient(135deg, #ff0844 0%, #ffb199 100%);
  291. }
  292. &:nth-child(6) image {
  293. background: linear-gradient(135deg, #fccb90 0%, #d57eeb 100%);
  294. }
  295. &:nth-child(n+7) image {
  296. background: linear-gradient(135deg, #2af598 0%, #009efd 100%);
  297. }
  298. }
  299. }
  300. }
  301. /* 区块通用样式 (待办事项 & 通知公告) */
  302. .section-box {
  303. margin-top: 30rpx;
  304. .section-header {
  305. margin-bottom: 24rpx;
  306. .section-title {
  307. font-size: 34rpx;
  308. font-weight: bold;
  309. color: #343A3F;
  310. }
  311. .link {
  312. font-size: 26rpx;
  313. color: #888;
  314. }
  315. }
  316. .badge {
  317. background-color: #ff4d4f;
  318. color: #fff;
  319. font-size: 20rpx;
  320. font-weight: bold;
  321. width: 32rpx;
  322. height: 32rpx;
  323. border-radius: 50%;
  324. display: flex;
  325. justify-content: center;
  326. align-items: center;
  327. margin-left: 12rpx;
  328. box-shadow: 0 4rpx 8rpx rgba(255, 77, 79, 0.3);
  329. }
  330. .todo-list {
  331. .todo-item {
  332. display: flex;
  333. align-items: center;
  334. padding: 30rpx 24rpx;
  335. background-color: #fff;
  336. margin-bottom: 24rpx;
  337. border: none;
  338. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.05);
  339. border-radius: 16rpx;
  340. .todo-img-placeholder {
  341. width: 80rpx;
  342. height: 80rpx;
  343. border-radius: 50%;
  344. border: none;
  345. margin-right: 24rpx;
  346. flex-shrink: 0;
  347. background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
  348. display: flex;
  349. align-items: center;
  350. justify-content: center;
  351. color: #fff;
  352. font-size: 24rpx;
  353. font-weight: bold;
  354. box-shadow: 0 6rpx 12rpx rgba(142, 197, 252, 0.4);
  355. &::after {
  356. content: "审";
  357. }
  358. }
  359. .todo-content {
  360. flex: 1;
  361. overflow: hidden;
  362. .todo-title {
  363. font-size: 32rpx;
  364. font-weight: 600;
  365. color: #343A3F;
  366. margin-bottom: 12rpx;
  367. white-space: nowrap;
  368. overflow: hidden;
  369. text-overflow: ellipsis;
  370. }
  371. .todo-info {
  372. font-size: 24rpx;
  373. margin-bottom: 10rpx;
  374. display: flex;
  375. align-items: center;
  376. .label {
  377. color: #343A3F;
  378. }
  379. .value {
  380. color: #585858;
  381. }
  382. .dept {
  383. margin-left: 16rpx;
  384. color: #1c9bfd;
  385. background: rgba(28, 155, 253, 0.1);
  386. padding: 2rpx 10rpx;
  387. border-radius: 6rpx;
  388. }
  389. }
  390. .todo-time {
  391. font-size: 22rpx;
  392. .label {
  393. color: #343A3F;
  394. }
  395. .value {
  396. color: #585858;
  397. }
  398. }
  399. }
  400. .todo-btn {
  401. background: linear-gradient(135deg, #1fc199 0%, #15a982 100%);
  402. color: #fff;
  403. font-size: 26rpx;
  404. padding: 12rpx 36rpx;
  405. border-radius: 30rpx;
  406. margin-left: 20rpx;
  407. flex-shrink: 0;
  408. box-shadow: 0 6rpx 12rpx rgba(31, 193, 153, 0.3);
  409. font-weight: 500;
  410. }
  411. }
  412. }
  413. /* 通知公告卡片 */
  414. .notice-card {
  415. background-color: #fff;
  416. border-radius: 16rpx;
  417. padding: 0 30rpx;
  418. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.05);
  419. .notice-item {
  420. display: flex;
  421. justify-content: space-between;
  422. align-items: center;
  423. padding: 29rpx 0;
  424. border-bottom: 2rpx solid #f5f5f5;
  425. &:last-child {
  426. border-bottom: none;
  427. }
  428. .notice-content {
  429. flex: 1;
  430. .notice-title {
  431. font-size: 30rpx;
  432. color: #343A3F;
  433. margin-bottom: 12rpx;
  434. font-weight: 500;
  435. }
  436. .notice-date {
  437. font-size: 24rpx;
  438. color: #aaa;
  439. }
  440. }
  441. .notice-action {
  442. display: flex;
  443. align-items: center;
  444. color: #aaa;
  445. font-size: 24rpx;
  446. .arrow {
  447. margin-left: 8rpx;
  448. }
  449. }
  450. }
  451. }
  452. /* 经费列表摘要 */
  453. .fund-list {
  454. background-color: #fff;
  455. border-radius: 16rpx;
  456. padding: 0 24rpx;
  457. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.05);
  458. .fund-item {
  459. padding: 24rpx 0;
  460. border-bottom: 1rpx solid #f2f2f2;
  461. &:last-child {
  462. border-bottom: none;
  463. }
  464. .fund-title {
  465. font-size: 28rpx;
  466. font-weight: bold;
  467. color: #333;
  468. margin-bottom: 8rpx;
  469. white-space: nowrap;
  470. overflow: hidden;
  471. text-overflow: ellipsis;
  472. }
  473. .fund-footer {
  474. font-size: 24rpx;
  475. color: #999;
  476. .amount {
  477. font-weight: 500;
  478. color: #ff9a44;
  479. }
  480. }
  481. }
  482. }
  483. }
  484. }
  485. </style>