index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. type: 'home',
  5. style: {
  6. navigationBarTitleText: '首页',
  7. navigationStyle: 'custom',
  8. disableScroll: true,
  9. 'app-plus': {
  10. bounce: 'none',
  11. },
  12. },
  13. }
  14. </route>
  15. <template>
  16. <view class="home-container">
  17. <scroll-view class="scroll-view" scroll-y>
  18. <!-- 状态栏占位 -->
  19. <view class="status-bar-placeholder" :style="{ height: statusBarHeight + 'px' }"></view>
  20. <!-- 头部 -->
  21. <view class="header">
  22. <text class="header-title">广州特检院</text>
  23. </view>
  24. <!-- Tab 栏 -->
  25. <view class="tab-bar">
  26. <view class="tab-item tab-item-active">
  27. <text class="tab-item-text-active">检验检测</text>
  28. </view>
  29. </view>
  30. <!-- 待办事项标题 -->
  31. <view class="todo-title-box">
  32. <text class="todo-title">我的待办事项</text>
  33. <picker
  34. class="equip-picker"
  35. :range="equipmentOptions"
  36. range-key="label"
  37. @change="onEquipTypeChange"
  38. >
  39. <view class="picker-value">
  40. <text>{{ currentEquipLabel }}</text>
  41. <text class="picker-arrow">▼</text>
  42. </view>
  43. </picker>
  44. </view>
  45. <!-- 待办卡片列表 -->
  46. <view class="todo-cards">
  47. <CardItem
  48. v-for="card in cardList"
  49. :key="card.id"
  50. :ref="(el: any) => (cardItemRef[card.id] = el)"
  51. :card="card"
  52. :user-id="userId"
  53. :width="windowWidth"
  54. @navigate="pushCard"
  55. />
  56. </view>
  57. <!-- 功能栏 -->
  58. <view class="home-section">
  59. <view class="section-header">
  60. <text class="todo-title">功能栏</text>
  61. </view>
  62. <view class="cap-section-content">
  63. <view
  64. v-for="cap in capabilityList"
  65. :key="cap.title"
  66. class="section-item"
  67. :style="{ backgroundColor: cap.backgroundColor }"
  68. @click="pushCard(cap)"
  69. >
  70. <view class="cap-info">
  71. <text class="cap-title">{{ cap.title }}</text>
  72. <text class="cap-desc">{{ cap.desc }}</text>
  73. </view>
  74. <image class="cap-section-image" :src="cap.iconUrl" mode="aspectFit" />
  75. </view>
  76. </view>
  77. </view>
  78. </scroll-view>
  79. <!-- 网络状态提示 -->
  80. <view v-if="!networkStatus" class="network-toast">
  81. <text class="network-toast-text">当前网络不可用</text>
  82. </view>
  83. </view>
  84. </template>
  85. <script lang="ts" setup>
  86. import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
  87. import { useUserStore } from '@/store/user'
  88. import { useConfigStore } from '@/store/config'
  89. import { EquipmentType } from '@/utils/dictMap'
  90. import { getTaskOrder } from '@/api/task'
  91. import iconMap from '@/utils/imagesMap'
  92. import CardItem, { type CardObj } from './components/CardItem.vue'
  93. import { requestFunc, IndexFuncName } from '@/api/ApiRouter/index'
  94. defineOptions({
  95. name: 'home',
  96. })
  97. // 常量
  98. const NUM = 2 // 一行多少个卡片
  99. const SPACE = 15 // 卡片之间的间距
  100. const PADDING = 20 // 左右边距
  101. // 状态
  102. const refresh = ref(false)
  103. const userId = ref('')
  104. const cardItemRef = reactive<Record<string, any>>({})
  105. const windowWidth = ref(0)
  106. const statusBarHeight = ref(20)
  107. const networkStatus = ref(true)
  108. const userStore = useUserStore()
  109. const userInfo = computed(() => userStore.userInfo)
  110. const configStore = useConfigStore()
  111. const equipType = computed(() => configStore.getEquipType())
  112. const equipmentOptions = [
  113. { label: '锅炉', value: EquipmentType.BOILER },
  114. { label: '管道', value: EquipmentType.PIPE },
  115. // { label: '压力容器', value: EquipmentType.CONTAINER },
  116. ]
  117. const currentEquipLabel = computed(() => {
  118. return equipmentOptions.find((item) => item.value === equipType.value)?.label || '请选择'
  119. })
  120. const onEquipTypeChange = (e: any) => {
  121. const index = e.detail.value
  122. const selected = equipmentOptions[index]
  123. if (selected && selected.value !== equipType.value) {
  124. configStore.switchEquipType(selected.value)
  125. uni.reLaunch({ url: '/pages/home/index' })
  126. }
  127. }
  128. // 获取屏幕宽度
  129. const getWindowWidth = () => {
  130. const systemInfo = uni.getSystemInfoSync()
  131. windowWidth.value = systemInfo.windowWidth || 375
  132. statusBarHeight.value = systemInfo.statusBarHeight || 20
  133. }
  134. // 监听网络状态
  135. const onNetworkStatusChange = (res: any) => {
  136. networkStatus.value = res.isConnected
  137. }
  138. // 检查网络状态
  139. const checkNetworkStatus = () => {
  140. uni.getNetworkType({
  141. success: (res) => {
  142. networkStatus.value = res.networkType !== 'none'
  143. },
  144. fail: () => {
  145. networkStatus.value = false
  146. },
  147. })
  148. }
  149. // 防抖刷新函数
  150. const refreshAllCards = () => {
  151. const currentUserInfo = userStore.userInfo
  152. if (currentUserInfo?.id) {
  153. console.log('🔄 Home 页面自动刷新任务状态')
  154. cardList.forEach((card) => {
  155. cardItemRef[card.id]?.getCount(currentUserInfo.id)
  156. })
  157. }
  158. }
  159. onMounted(() => {
  160. getWindowWidth()
  161. getUserId()
  162. checkNetworkStatus()
  163. // 监听网络状态变化
  164. uni.onNetworkStatusChange(onNetworkStatusChange)
  165. })
  166. onUnmounted(() => {
  167. uni.offNetworkStatusChange(onNetworkStatusChange)
  168. })
  169. // 获取用户 id
  170. const getUserId = async () => {
  171. try {
  172. const res = await uni.getStorage({ key: 'USER_INFO' })
  173. if (res.data?.id) {
  174. userId.value = res.data.id
  175. } else if (userInfo.value?.id) {
  176. userId.value = userInfo.value.id
  177. }
  178. } catch (e) {
  179. console.error('获取用户信息失败', e)
  180. }
  181. }
  182. // 查询待认领数量
  183. const getUnClaimNum = async () => {
  184. const params = {
  185. pageNo: 1,
  186. pageSize: 10,
  187. taskStatus: 100,
  188. }
  189. const result = await requestFunc(IndexFuncName.PreClaimNumberApi, equipType.value, params)
  190. const num = result?.data?.total
  191. return num || 0
  192. }
  193. // 查询本地待下载的任务
  194. const queryLocalTask = async (userId: string) => {
  195. const getServer = async () => {
  196. const result = await getTaskOrder({ pageNo: 1, pageSize: 5 })
  197. return result?.data?.total || 0
  198. }
  199. // TODO: 需要实现本地数据库查询
  200. const getLocal = async () => {
  201. return 0
  202. }
  203. const result = await Promise.all([getServer(), getLocal()])
  204. const num = result[0] - result[1]
  205. return num || 0
  206. }
  207. // 获取待录入数量
  208. const getUnEnterNum = async (userId: string) => {
  209. // TODO: 需要实现本地数据库查询
  210. return 0
  211. }
  212. // 获取分配项目数量
  213. const getCheckerOwnTaskNum = async () => {
  214. const result = await requestFunc(IndexFuncName.TaskEquipNumberApi, equipType.value, {
  215. pageNo: 1,
  216. pageSize: 10,
  217. taskStatusList: [400, 500, 510],
  218. isClaim: false,
  219. planCheckUserIds: userInfo.value?.id ? [userInfo.value.id] : [],
  220. })
  221. if (result?.code == 0 && result?.data?.total) {
  222. return result.data.total
  223. }
  224. return 0
  225. }
  226. // 获取待校核数量
  227. const getVerificationListNum = async () => {
  228. if (!userInfo.value || !userInfo.value.id) return 0
  229. const result = await requestFunc(IndexFuncName.PendingVerificationNumberApi, equipType.value, {
  230. pageNo: 1,
  231. pageSize: 10,
  232. recheckStrIds: userInfo.value.id,
  233. })
  234. if (result?.code == 0 && result?.data?.total) {
  235. return result.data.total
  236. }
  237. return 0
  238. }
  239. // 获取待编制数量
  240. const getPendingPreparationListNum = async () => {
  241. if (!userInfo.value || !userInfo.value.id) return 0
  242. const result = await requestFunc(IndexFuncName.PendingPreparationNumberApi, equipType.value, {
  243. pageNo: 1,
  244. pageSize: 10,
  245. mainCheckerStrIds: userInfo.value.id,
  246. })
  247. if (result?.code == 0 && result?.data?.total) {
  248. return result.data.total
  249. }
  250. return 0
  251. }
  252. // 获取待审核数量
  253. const getApprovalListNum = async () => {
  254. if (!userInfo.value || !userInfo.value.id) return 0
  255. const result = await requestFunc(IndexFuncName.ApprovalNumberApi, equipType.value, {
  256. pageNo: 1,
  257. pageSize: 10,
  258. approveStrIds: userInfo.value.id,
  259. })
  260. if (result?.code == 0 && result?.data?.total) {
  261. return result.data.total
  262. }
  263. return 0
  264. }
  265. // 获取待审批数量
  266. const getRatifyListNum = async () => {
  267. if (!userInfo.value || !userInfo.value.id) return 0
  268. const result = await requestFunc(IndexFuncName.RatifyNumberApi, equipType.value, {
  269. pageNo: 1,
  270. pageSize: 10,
  271. ratifyStrIds: userInfo.value.id,
  272. })
  273. if (result?.code == 0 && result?.data?.total) {
  274. return result.data.total
  275. }
  276. return 0
  277. }
  278. // 获取检验方案审核数量
  279. const getInspectionPlanAuditListNum = async (params: Record<string, any>) => {
  280. if (!userInfo.value || !userInfo.value.id) return 0
  281. const result = await requestFunc(IndexFuncName.MajorIssuesAuditNumberApi, equipType.value, {
  282. pageNo: 1,
  283. pageSize: 10,
  284. ...params,
  285. })
  286. if (result?.code == 0 && result?.data?.total) {
  287. return result.data.total || 0
  288. }
  289. return 0
  290. }
  291. // 卡片列表
  292. const cardList: CardObj[] = [
  293. {
  294. title: '待认领',
  295. id: 'unClaim',
  296. description: '条任务待认领',
  297. path: '/pages/unClaim/unClaimList',
  298. iconUrl: 'deviceExam',
  299. getCountFun: getUnClaimNum,
  300. netWork: true,
  301. },
  302. {
  303. title: '在线录入',
  304. id: 'taskOnlinePage',
  305. description: '条待完成',
  306. path: '/pages/taskOnlinePage/taskOnline',
  307. iconUrl: 'unitQuery',
  308. getCountFun: getCheckerOwnTaskNum,
  309. netWork: true,
  310. },
  311. {
  312. title: '待校核',
  313. id: 'pendingVerification',
  314. description: '条待校核',
  315. path: '/pages/pendingVerification/list/PendingVerificationList',
  316. iconUrl: 'unitQuery',
  317. getCountFun: getVerificationListNum,
  318. netWork: true,
  319. },
  320. // {
  321. // title: '待编制',
  322. // id: 'endingPreparation',
  323. // description: '条待编制',
  324. // path: '/pages/pendingPreparation/list/PendingPreparationList',
  325. // iconUrl: 'unitQuery',
  326. // getCountFun: getPendingPreparationListNum,
  327. // netWork: true,
  328. // },
  329. // {
  330. // title: '待审核',
  331. // id: 'pendingApproval',
  332. // description: '条待审核',
  333. // path: '/pages/pendingApproval/list/PendingApprovalList',
  334. // iconUrl: 'unitQuery',
  335. // getCountFun: getApprovalListNum,
  336. // netWork: true,
  337. // },
  338. // {
  339. // title: '待审批',
  340. // id: 'pendingRatify',
  341. // description: '条待审批',
  342. // path: '/pages/pendingRatify/list/PendingRatifyList',
  343. // iconUrl: 'unitQuery',
  344. // getCountFun: getRatifyListNum,
  345. // netWork: true,
  346. // },
  347. {
  348. title: '检验方案审批',
  349. id: 'inspectionPlanAudit',
  350. description: '条待审批',
  351. path: '/pages/inspectionPlanAudit/list/InspectionPlanAuditList',
  352. iconUrl: 'unitQuery',
  353. getCountFun: () =>
  354. getInspectionPlanAuditListNum({
  355. reportType: 600,
  356. status: 100,
  357. bpmUserId: userInfo.value?.id,
  358. }),
  359. netWork: true,
  360. },
  361. // {
  362. // title: '检验方案批准',
  363. // id: 'inspectionApproval',
  364. // description: '条待审批',
  365. // path: '/pages/inspectionApproval/list/inspectionApprovalList',
  366. // iconUrl: 'unitQuery',
  367. // getCountFun: () =>
  368. // getInspectionPlanAuditListNum({
  369. // reportType: 600,
  370. // secondStatus: 100,
  371. // flag: 1,
  372. // bpmUserId: userInfo.value?.id,
  373. // isInspectionSchemeRatify: true,
  374. // }),
  375. // netWork: true,
  376. // },
  377. {
  378. title: '操作指导书批准',
  379. id: 'workInstructionAudit',
  380. description: '条待审批',
  381. path: '/pages/workInstructionAudit/list/WorkInstructionAuditList',
  382. iconUrl: 'unitQuery',
  383. getCountFun: () =>
  384. getInspectionPlanAuditListNum({
  385. reportType: 700,
  386. status: 100,
  387. bpmUserId: userInfo.value?.id,
  388. }),
  389. netWork: true,
  390. },
  391. ]
  392. // 功能栏列表
  393. const capabilityList = [
  394. {
  395. title: '设备查询',
  396. desc: '查看全部设备',
  397. iconUrl: iconMap.deviceExam,
  398. path: '/pages/deviceExam/deviceExam',
  399. backgroundColor: '#F6FAFE',
  400. },
  401. {
  402. title: '单位信息',
  403. desc: '查看单位信息',
  404. iconUrl: iconMap.unitQuery,
  405. path: '/pages/unitQuery/unitQuery',
  406. backgroundColor: '#FEF7F6',
  407. },
  408. {
  409. title: '体系文件',
  410. desc: '查看体系文件',
  411. iconUrl: iconMap.systemFile,
  412. path: '/pages/systemFile/systemFile',
  413. backgroundColor: '#F6FBF6',
  414. },
  415. ]
  416. // 跳转
  417. const pushCard = (card: CardObj) => {
  418. // 检查网络状态
  419. if (card?.netWork && !networkStatus.value) {
  420. return uni.showToast({ title: '当前网络不可用', icon: 'error' })
  421. }
  422. uni.navigateTo({ url: card.path })
  423. }
  424. // 下拉刷新
  425. const onRefresh = () => {
  426. refresh.value = true
  427. const currentUserInfo = userStore.userInfo
  428. cardList.forEach((card) => {
  429. cardItemRef[card.id]?.getCount(currentUserInfo.id + '')
  430. })
  431. setTimeout(() => {
  432. refresh.value = false
  433. }, 500)
  434. }
  435. </script>
  436. <style lang="scss" scoped>
  437. .home-container {
  438. display: flex;
  439. flex-direction: column;
  440. min-height: 100vh;
  441. background-color: #f2f2f2;
  442. }
  443. .scroll-view {
  444. flex: 1;
  445. background-color: #f2f2f2;
  446. }
  447. .status-bar-placeholder {
  448. width: 100%;
  449. background-color: #071f50;
  450. }
  451. .header {
  452. padding: 0 20px 20px;
  453. padding-top: 50px;
  454. background-color: #071f50;
  455. }
  456. .header-title {
  457. font-size: 32px;
  458. color: #fff;
  459. }
  460. .tab-bar {
  461. display: flex;
  462. flex-direction: row;
  463. align-items: flex-start;
  464. background-color: #071f50;
  465. }
  466. .tab-item {
  467. display: flex;
  468. flex: 1;
  469. flex-direction: row;
  470. align-items: center;
  471. justify-content: center;
  472. max-width: calc(100vw / 3);
  473. padding: 12px;
  474. }
  475. .tab-item-active {
  476. background-color: #fff;
  477. border-top-left-radius: 15px;
  478. border-top-right-radius: 15px;
  479. }
  480. .tab-item-text-active {
  481. font-size: 15px;
  482. font-weight: bold;
  483. color: rgb(59, 59, 59);
  484. }
  485. .todo-title-box {
  486. display: flex;
  487. flex-direction: row;
  488. align-items: center;
  489. justify-content: space-between;
  490. padding: 20px;
  491. background-color: #fff;
  492. }
  493. .equip-picker {
  494. flex-shrink: 0;
  495. }
  496. .picker-value {
  497. display: flex;
  498. flex-direction: row;
  499. gap: 4px;
  500. align-items: center;
  501. padding: 4px 8px;
  502. font-size: 14px;
  503. color: #333;
  504. background-color: #f5f5f5;
  505. border-radius: 4px;
  506. }
  507. .picker-arrow {
  508. font-size: 10px;
  509. color: #999;
  510. }
  511. .todo-title {
  512. font-size: 18px;
  513. color: rgb(51, 51, 51);
  514. }
  515. .todo-cards {
  516. display: flex;
  517. flex-direction: row;
  518. flex-wrap: wrap;
  519. justify-content: space-between;
  520. padding: 0 10px;
  521. margin: 0 10px;
  522. background-color: #fff;
  523. border-radius: 0 0 12px 12px;
  524. }
  525. .home-section {
  526. padding: 0 12px 20px 12px;
  527. margin: 10px;
  528. background-color: #ffffff;
  529. border-radius: 6px;
  530. }
  531. .section-header {
  532. padding: 16px 8px 16px 8px;
  533. border-bottom: 1px solid #eee;
  534. }
  535. .cap-section-content {
  536. display: flex;
  537. flex-direction: row;
  538. flex-wrap: nowrap;
  539. gap: 12px;
  540. padding: 0 8px 15px;
  541. margin-top: 15px;
  542. }
  543. .section-item {
  544. position: relative;
  545. flex: 1;
  546. padding: 20px 15px;
  547. }
  548. .cap-info {
  549. width: 100%;
  550. }
  551. .cap-title {
  552. display: block;
  553. margin-bottom: 4px;
  554. font-size: 15px;
  555. font-weight: 500;
  556. color: #333333;
  557. }
  558. .cap-desc {
  559. display: block;
  560. font-size: 12px;
  561. color: #666;
  562. }
  563. .cap-section-image {
  564. display: block;
  565. width: 100%;
  566. height: 50px;
  567. }
  568. .network-toast {
  569. position: fixed;
  570. top: 50%;
  571. left: 50%;
  572. z-index: 9999;
  573. padding: 15px 25px;
  574. background-color: rgba(0, 0, 0, 0.7);
  575. border-radius: 8px;
  576. transform: translate(-50%, -50%);
  577. }
  578. .network-toast-text {
  579. font-size: 14px;
  580. color: #fff;
  581. }
  582. </style>