index.vue 15 KB

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