index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. recheckStatus: '100',
  232. })
  233. if (result?.code == 0 && result?.data?.total) {
  234. return result.data.total
  235. }
  236. return 0
  237. }
  238. // 获取待编制数量
  239. const getPendingPreparationListNum = async () => {
  240. if (!userInfo.value || !userInfo.value.id) return 0
  241. const result = await requestFunc(IndexFuncName.PendingPreparationNumberApi, equipType.value, {
  242. pageNo: 1,
  243. pageSize: 10,
  244. mainCheckerStrIds: userInfo.value.id,
  245. })
  246. if (result?.code == 0 && result?.data?.total) {
  247. return result.data.total
  248. }
  249. return 0
  250. }
  251. // 获取待审核数量
  252. const getApprovalListNum = async () => {
  253. if (!userInfo.value || !userInfo.value.id) return 0
  254. const result = await requestFunc(IndexFuncName.ApprovalNumberApi, equipType.value, {
  255. pageNo: 1,
  256. pageSize: 10,
  257. approveStrIds: userInfo.value.id,
  258. })
  259. if (result?.code == 0 && result?.data?.total) {
  260. return result.data.total
  261. }
  262. return 0
  263. }
  264. // 获取待审批数量
  265. const getRatifyListNum = async () => {
  266. if (!userInfo.value || !userInfo.value.id) return 0
  267. const result = await requestFunc(IndexFuncName.RatifyNumberApi, equipType.value, {
  268. pageNo: 1,
  269. pageSize: 10,
  270. ratifyStrIds: userInfo.value.id,
  271. })
  272. if (result?.code == 0 && result?.data?.total) {
  273. return result.data.total
  274. }
  275. return 0
  276. }
  277. // 获取检验方案审核数量
  278. const getInspectionPlanAuditListNum = async (params: Record<string, any>) => {
  279. if (!userInfo.value || !userInfo.value.id) return 0
  280. const result = await requestFunc(IndexFuncName.MajorIssuesAuditNumberApi, equipType.value, {
  281. pageNo: 1,
  282. pageSize: 10,
  283. ...params,
  284. })
  285. if (result?.code == 0 && result?.data?.total) {
  286. return result.data.total || 0
  287. }
  288. return 0
  289. }
  290. // 卡片列表
  291. const cardList: CardObj[] = [
  292. {
  293. title: '待认领',
  294. id: 'unClaim',
  295. description: '条任务待认领',
  296. path: '/pages/unClaim/unClaimList',
  297. iconUrl: 'deviceExam',
  298. getCountFun: getUnClaimNum,
  299. netWork: true,
  300. },
  301. {
  302. title: '在线录入',
  303. id: 'taskOnlinePage',
  304. description: '条待完成',
  305. path: '/pages/taskOnlinePage/taskOnline',
  306. iconUrl: 'unitQuery',
  307. getCountFun: getCheckerOwnTaskNum,
  308. netWork: true,
  309. },
  310. {
  311. title: '待校核',
  312. id: 'pendingVerification',
  313. description: '条待校核',
  314. path: '/pages/pendingVerification/list/PendingVerificationList',
  315. iconUrl: 'unitQuery',
  316. getCountFun: getVerificationListNum,
  317. netWork: true,
  318. },
  319. // {
  320. // title: '待编制',
  321. // id: 'endingPreparation',
  322. // description: '条待编制',
  323. // path: '/pages/pendingPreparation/list/PendingPreparationList',
  324. // iconUrl: 'unitQuery',
  325. // getCountFun: getPendingPreparationListNum,
  326. // netWork: true,
  327. // },
  328. // {
  329. // title: '待审核',
  330. // id: 'pendingApproval',
  331. // description: '条待审核',
  332. // path: '/pages/pendingApproval/list/PendingApprovalList',
  333. // iconUrl: 'unitQuery',
  334. // getCountFun: getApprovalListNum,
  335. // netWork: true,
  336. // },
  337. // {
  338. // title: '待审批',
  339. // id: 'pendingRatify',
  340. // description: '条待审批',
  341. // path: '/pages/pendingRatify/list/PendingRatifyList',
  342. // iconUrl: 'unitQuery',
  343. // getCountFun: getRatifyListNum,
  344. // netWork: true,
  345. // },
  346. {
  347. title: '检验方案审批',
  348. id: 'inspectionPlanAudit',
  349. description: '条待审批',
  350. path: '/pages/inspectionPlanAudit/list/InspectionPlanAuditList',
  351. iconUrl: 'unitQuery',
  352. getCountFun: () =>
  353. getInspectionPlanAuditListNum({
  354. reportType: 600,
  355. status: 100,
  356. bpmUserId: userInfo.value?.id,
  357. }),
  358. netWork: true,
  359. },
  360. // {
  361. // title: '检验方案批准',
  362. // id: 'inspectionApproval',
  363. // description: '条待审批',
  364. // path: '/pages/inspectionApproval/list/inspectionApprovalList',
  365. // iconUrl: 'unitQuery',
  366. // getCountFun: () =>
  367. // getInspectionPlanAuditListNum({
  368. // reportType: 600,
  369. // secondStatus: 100,
  370. // flag: 1,
  371. // bpmUserId: userInfo.value?.id,
  372. // isInspectionSchemeRatify: true,
  373. // }),
  374. // netWork: true,
  375. // },
  376. {
  377. title: '操作指导书批准',
  378. id: 'workInstructionAudit',
  379. description: '条待审批',
  380. path: '/pages/workInstructionAudit/list/WorkInstructionAuditList',
  381. iconUrl: 'unitQuery',
  382. getCountFun: () =>
  383. getInspectionPlanAuditListNum({
  384. reportType: 700,
  385. status: 100,
  386. bpmUserId: userInfo.value?.id,
  387. }),
  388. netWork: true,
  389. },
  390. ]
  391. // 功能栏列表
  392. const capabilityList = [
  393. {
  394. title: '设备查询',
  395. desc: '查看全部设备',
  396. iconUrl: iconMap.deviceExam,
  397. path: '/pages/deviceExam/deviceExam',
  398. backgroundColor: '#F6FAFE',
  399. },
  400. {
  401. title: '单位信息',
  402. desc: '查看单位信息',
  403. iconUrl: iconMap.unitQuery,
  404. path: '/pages/unitQuery/unitQuery',
  405. backgroundColor: '#FEF7F6',
  406. },
  407. // {
  408. // title: '体系文件',
  409. // desc: '查看体系文件',
  410. // iconUrl: iconMap.systemFile,
  411. // path: '/pages/systemFile/systemFile',
  412. // backgroundColor: '#F6FBF6',
  413. // },
  414. ]
  415. // 跳转
  416. const pushCard = (card: CardObj) => {
  417. // 检查网络状态
  418. if (card?.netWork && !networkStatus.value) {
  419. return uni.showToast({ title: '当前网络不可用', icon: 'error' })
  420. }
  421. uni.navigateTo({ url: card.path })
  422. }
  423. // 下拉刷新
  424. const onRefresh = () => {
  425. refresh.value = true
  426. const currentUserInfo = userStore.userInfo
  427. cardList.forEach((card) => {
  428. cardItemRef[card.id]?.getCount(currentUserInfo.id + '')
  429. })
  430. setTimeout(() => {
  431. refresh.value = false
  432. }, 500)
  433. }
  434. </script>
  435. <style lang="scss" scoped>
  436. .home-container {
  437. display: flex;
  438. flex-direction: column;
  439. min-height: 100vh;
  440. background-color: #f2f2f2;
  441. }
  442. .scroll-view {
  443. flex: 1;
  444. background-color: #f2f2f2;
  445. }
  446. .status-bar-placeholder {
  447. width: 100%;
  448. background-color: #071f50;
  449. }
  450. .header {
  451. padding: 0 20px 20px;
  452. padding-top: 50px;
  453. background-color: #071f50;
  454. }
  455. .header-title {
  456. font-size: 32px;
  457. color: #fff;
  458. }
  459. .tab-bar {
  460. display: flex;
  461. flex-direction: row;
  462. align-items: flex-start;
  463. background-color: #071f50;
  464. }
  465. .tab-item {
  466. display: flex;
  467. flex: 1;
  468. flex-direction: row;
  469. align-items: center;
  470. justify-content: center;
  471. max-width: calc(100vw / 3);
  472. padding: 12px;
  473. }
  474. .tab-item-active {
  475. background-color: #fff;
  476. border-top-left-radius: 15px;
  477. border-top-right-radius: 15px;
  478. }
  479. .tab-item-text-active {
  480. font-size: 15px;
  481. font-weight: bold;
  482. color: rgb(59, 59, 59);
  483. }
  484. .todo-title-box {
  485. display: flex;
  486. flex-direction: row;
  487. align-items: center;
  488. justify-content: space-between;
  489. padding: 20px;
  490. background-color: #fff;
  491. }
  492. .equip-picker {
  493. flex-shrink: 0;
  494. }
  495. .todo-title {
  496. font-size: 18px;
  497. color: rgb(51, 51, 51);
  498. }
  499. .todo-cards {
  500. display: flex;
  501. flex-direction: row;
  502. flex-wrap: wrap;
  503. justify-content: space-between;
  504. padding: 0 10px;
  505. margin: 0 10px;
  506. background-color: #fff;
  507. border-radius: 0 0 12px 12px;
  508. }
  509. .home-section {
  510. padding: 0 12px 20px 12px;
  511. margin: 10px;
  512. background-color: #ffffff;
  513. border-radius: 6px;
  514. }
  515. .section-header {
  516. padding: 16px 8px 16px 8px;
  517. border-bottom: 1px solid #eee;
  518. }
  519. .cap-section-content {
  520. display: flex;
  521. flex-direction: row;
  522. flex-wrap: nowrap;
  523. gap: 12px;
  524. padding: 0 8px 15px;
  525. margin-top: 15px;
  526. }
  527. .section-item {
  528. position: relative;
  529. flex: 1;
  530. padding: 20px 15px;
  531. }
  532. .cap-info {
  533. width: 100%;
  534. }
  535. .cap-title {
  536. display: block;
  537. margin-bottom: 4px;
  538. font-size: 15px;
  539. font-weight: 500;
  540. color: #333333;
  541. }
  542. .cap-desc {
  543. display: block;
  544. font-size: 12px;
  545. color: #666;
  546. }
  547. .cap-section-image {
  548. display: block;
  549. width: 100%;
  550. height: 50px;
  551. }
  552. .network-toast {
  553. position: fixed;
  554. top: 50%;
  555. left: 50%;
  556. z-index: 9999;
  557. padding: 15px 25px;
  558. background-color: rgba(0, 0, 0, 0.7);
  559. border-radius: 8px;
  560. transform: translate(-50%, -50%);
  561. }
  562. .network-toast-text {
  563. font-size: 14px;
  564. color: #fff;
  565. }
  566. </style>