index.uvue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. <template>
  2. <uni-navbar-lite :showLeft=false title="我的任务"></uni-navbar-lite>
  3. <view class="list-page">
  4. <!-- 搜索栏 -->
  5. <view class="search-bar">
  6. <view class="search-box">
  7. <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
  8. <input class="search-input" type="text" placeholder="搜索任务" v-model="keyword" @confirm="handleSearch" @blur="handleSearch" />
  9. <text v-if="keyword.length > 0" class="clear-icon" @click="clearSearch">✕</text>
  10. </view>
  11. </view>
  12. <view class="status-bar">
  13. <scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false">
  14. <view class="scroll-view-item_H uni-bg-red">
  15. <text class="status-txt" :class="{'stauts-sel': currentStatus == ''}" @click="switchStatus('')">全部</text>
  16. </view>
  17. <view class="scroll-view-item_H" v-if="!dealLoad">
  18. <text class="status-txt" :class="{'stauts-sel': currentStatus == '0'}" @click="switchStatus('0')">待执行</text>
  19. </view>
  20. <!-- <view class="scroll-view-item_H" v-if="!dealLoad">
  21. <text class="status-txt" :class="{'stauts-sel': currentStatus == '1'}" @click="switchStatus('1')">执行中</text>
  22. </view> -->
  23. <view class="scroll-view-item_H" v-if="!dealLoad">
  24. <text class="status-txt" :class="{'stauts-sel': currentStatus == '2'}" @click="switchStatus('2')">已完成</text>
  25. </view>
  26. <!-- <view class="scroll-view-item_H" v-if="!dealLoad">
  27. <text class="status-txt" :class="{'stauts-sel': currentStatus == '3'}" @click="switchStatus('3')">已超时</text>
  28. </view>
  29. <view class="scroll-view-item_H" v-if="!dealLoad">
  30. <text class="status-txt" :class="{'stauts-sel': currentStatus == '4'}" @click="switchStatus('4')">已逾期</text>
  31. </view> -->
  32. </scroll-view>
  33. </view>
  34. <!-- 列表内容 -->
  35. <common-list
  36. :dataList="dataList"
  37. :loading="loading"
  38. :refreshing="refreshing"
  39. :hasMore="hasMore"
  40. @refresh="handleRefresh"
  41. @loadMore="loadMore"
  42. @itemClick="handleView"
  43. >
  44. <template #default="{ item, index }">
  45. <view class="list-item">
  46. <view class="item-container">
  47. <view class="item-header">
  48. <text class="item-title">{{ (item as taskInfo).planName }}</text>
  49. <view class="task-badges">
  50. <text class="status-tag" :class="getTaskType(item)">{{ (item as taskInfo).planTypeText }}</text>
  51. <text class="status-tag" :class="getStatusClass((item as taskInfo).status)">{{ (item as taskInfo).statusText }}</text>
  52. </view>
  53. </view>
  54. <view class="info-row">
  55. <view class="info-label">
  56. <text class="text-gray">{{ (item as taskInfo).displayTime }}</text>
  57. </view>
  58. </view>
  59. <view class="info-row">
  60. <view class="info-label">
  61. <text class="text-gray">{{ (item as taskInfo).taskCount }}</text>
  62. </view>
  63. </view>
  64. <view class="btn-group">
  65. <view
  66. v-if="(item as taskInfo).status != '2' && (item as taskInfo).status != '4'"
  67. class="btn-primary info-value"
  68. @click.stop="handleItemClick(item,'start')"
  69. >
  70. <text class="btn-text">开始执行</text>
  71. </view>
  72. <view
  73. v-if="(item as taskInfo).status == '2' || (item as taskInfo).status == '4'"
  74. class="btn-primary info-value"
  75. @click.stop="handleItemClick(item,'detail')"
  76. >
  77. <text class="btn-text">查看</text>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. </common-list>
  84. <!-- <custom-tabbar :current="1" :hide0="tabbar[0]" :hide1="tabbar[1]" :hide2="tabbar[2]" :hide3="tabbar[3]"/> -->
  85. </view>
  86. </template>
  87. <script setup lang="uts">
  88. import { ref, onBeforeUnmount, onMounted, reactive, onShow, onHide } from 'vue'
  89. import type { SysDictData, DictDataResponse } from '../../types/dict'
  90. import {checkPermi, getUserInfo} from '../../utils/storage'
  91. import { getDictDataByType } from '../../api/dict/index'
  92. import { registerServer} from '../../api/index/index'
  93. import { getMyTaskList } from '../../api/task/list'
  94. type taskInfo = {
  95. taskId: Number
  96. planId: Number
  97. planType: string | null
  98. planName: string | null
  99. taskDate: string | null
  100. startTime: string | null
  101. endTime: string | null
  102. subjects: string | null
  103. machineryTypeName: string | null
  104. machineryCode: string | null
  105. machineryName: string | null
  106. machineries: string | null
  107. locations: string | null
  108. operator: string | null
  109. operatorId: Number
  110. status: string | null
  111. taskDesc: string | null
  112. sourceType: string | null
  113. locationCount: Number
  114. machineryCount: Number
  115. createTime: string | null
  116. updateTime: string | null
  117. // 前端计算字段
  118. planTypeText: string | null
  119. statusText: string | null
  120. displayTime: string | null
  121. taskCount: string | null
  122. checkType: string | null
  123. }
  124. const userId = ref<string>("")
  125. const roles = ref<string>('')
  126. // 列表数据
  127. const dataList = ref<taskInfo[]>([])
  128. let keyword = ref<string>("")
  129. const page = ref<number>(1)
  130. const pageSize: number = 10
  131. const hasMore = ref<boolean>(true)
  132. const loading = ref<boolean>(false)
  133. const refreshing = ref<boolean>(false)
  134. const total = ref<number>(0)
  135. let currentStatus = ref<string>('')
  136. let currentPlanType = ref<string>('')
  137. const statusDictList = ref<SysDictData[]>([]) // 工单状态字典列表
  138. const planTypeDictList = ref<SysDictData[]>([]) // 计划类型字典列表
  139. const tabbar = reactive([1,1,1,1])
  140. // 添加防重复请求的标志位(参考score/pending.uvue的实现)
  141. const isSearching = ref<boolean>(false)
  142. // 添加防重复刷新的标志
  143. const isRefreshing = ref<boolean>(false)
  144. // 添加刷新时间戳,用于防抖
  145. const lastRefreshTime = ref<number>(0)
  146. // 添加字典加载状态
  147. const dictLoaded = ref<boolean>(false)
  148. // 待处理工单加载
  149. const dealLoad = ref<boolean>(false)
  150. // 定时刷新定时器
  151. let refreshTimer: number | null = 0
  152. // 定时刷新间隔(毫秒)
  153. const REFRESH_INTERVAL = 10000 // 10秒
  154. // 获取任务类型
  155. const getTaskType = (item: any | null): string => {
  156. if (item == null) return ''
  157. const taskItem = item as taskInfo
  158. const rawType = taskItem.planType
  159. if (rawType == null || rawType.length == 0) return ''
  160. // 返回对应的状态类名
  161. return `type-${rawType}`
  162. }
  163. const getStatusClass = (rawStatus: string | null): string => {
  164. if (rawStatus == null) return ''
  165. // 返回对应的状态类名
  166. return `status-${rawStatus}`
  167. }
  168. const getStatusText = (rawStatus: string | null): string => {
  169. if (rawStatus == null || rawStatus.length == 0) return ''
  170. if (dictLoaded.value != true) {
  171. return rawStatus
  172. }
  173. const dictItem = statusDictList.value.find((dict: SysDictData) => dict.dictValue == rawStatus)
  174. return dictItem != null && dictItem.dictLabel != null ? dictItem.dictLabel : rawStatus
  175. }
  176. // 获取计划类型文本
  177. const getPlanTypeText = (planType: string | null): string => {
  178. if (planType == null || planType.length == 0) return ''
  179. if (dictLoaded.value != true) {
  180. return planType
  181. }
  182. const dictItem = planTypeDictList.value.find((dict: SysDictData) => dict.dictValue == planType)
  183. return dictItem != null && dictItem.dictLabel != null ? dictItem.dictLabel : planType
  184. }
  185. // 获取显示时间
  186. const getDisplayTime = (item: taskInfo): string | null => {
  187. if (item.taskDate == null || item.taskDate.length == 0) return null
  188. if (item.startTime != null && item.startTime.length > 0 && item.endTime != null && item.endTime.length > 0) {
  189. return `${item.taskDate} ${item.startTime}-${item.endTime}`
  190. }
  191. return item.taskDate
  192. }
  193. // 获取任务数量显示
  194. const getTaskCount = (item: taskInfo): string | null => {
  195. if (item.planType != null && item.planType == 'PATROL') {
  196. return `地点数量: ${item.locationCount != null ? item.locationCount : 0}个`
  197. } else {
  198. return `设备数量: ${item.machineryCount != null ? item.machineryCount : 0}台`
  199. }
  200. }
  201. // 获取检查类型
  202. const getCheckType = (item: taskInfo): string | null => {
  203. if (item.planType != null && item.planType == 'PATROL') {
  204. return 'area'
  205. } else {
  206. return 'device'
  207. }
  208. }
  209. // 获取任务状态字典列表
  210. const loadStatusDictList = async (): Promise<void> => {
  211. try {
  212. const result = await getDictDataByType('dv_task_status')
  213. const resultObj = result as UTSJSONObject
  214. if (resultObj['code'] == 200) {
  215. const data = resultObj['data'] as any[]
  216. const dictData: SysDictData[] = []
  217. if (data.length > 0) {
  218. for (let i = 0; i < data.length; i++) {
  219. const item = data[i] as UTSJSONObject
  220. const dictItem: SysDictData = {
  221. dictValue: item['dictValue'] as string | null,
  222. dictLabel: item['dictLabel'] as string | null,
  223. dictCode: null,
  224. dictSort: null,
  225. dictType: null,
  226. cssClass: null,
  227. listClass: null,
  228. isDefault: null,
  229. status: null,
  230. default: null,
  231. createTime: null,
  232. remark: null
  233. }
  234. dictData.push(dictItem)
  235. }
  236. }
  237. statusDictList.value = dictData
  238. dictLoaded.value = true
  239. }
  240. } catch (e: any) {
  241. console.error('获取任务状态字典失败:', e.message)
  242. dictLoaded.value = true
  243. }
  244. }
  245. // 获取计划类型字典列表
  246. const loadPlanTypeDictList = async (): Promise<void> => {
  247. try {
  248. const result = await getDictDataByType('dv_plan_type')
  249. const resultObj = result as UTSJSONObject
  250. if (resultObj['code'] == 200) {
  251. const data = resultObj['data'] as any[]
  252. const dictData: SysDictData[] = []
  253. if (data.length > 0) {
  254. for (let i = 0; i < data.length; i++) {
  255. const item = data[i] as UTSJSONObject
  256. const dictItem: SysDictData = {
  257. dictValue: item['dictValue'] as string | null,
  258. dictLabel: item['dictLabel'] as string | null,
  259. dictCode: null,
  260. dictSort: null,
  261. dictType: null,
  262. cssClass: null,
  263. listClass: null,
  264. isDefault: null,
  265. status: null,
  266. default: null,
  267. createTime: null,
  268. remark: null
  269. }
  270. dictData.push(dictItem)
  271. }
  272. }
  273. planTypeDictList.value = dictData
  274. }
  275. } catch (e: any) {
  276. console.error('获取计划类型字典失败:', e.message)
  277. }
  278. }
  279. // 加载列表数据
  280. const loadData = async (isRefresh: boolean | null, disablePullDown: boolean | null): Promise<void> => {
  281. // 防止重复请求的核心机制
  282. if (loading.value) {
  283. if (isRefresh != true) {
  284. refreshing.value = false;
  285. }
  286. return
  287. }
  288. const shouldRefresh = isRefresh != null ? isRefresh : false
  289. const shouldDisablePullDown = disablePullDown != null ? disablePullDown : false
  290. loading.value = true
  291. if (shouldRefresh && !shouldDisablePullDown) {
  292. page.value = 1
  293. refreshing.value = true
  294. } else if (shouldRefresh && shouldDisablePullDown) {
  295. page.value = 1
  296. refreshing.value = false
  297. } else {
  298. refreshing.value = false;
  299. }
  300. try {
  301. // 构建查询参数对象
  302. const queryParams: UTSJSONObject = {
  303. pageNum: page.value,
  304. pageSize: pageSize
  305. }
  306. // 添加当前用户ID过滤
  307. if (userId.value.length > 0) {
  308. queryParams['operatorId'] = userId.value
  309. }
  310. // 添加搜索关键字
  311. if (keyword.value.length > 0) {
  312. queryParams['planName'] = keyword.value
  313. }
  314. // 添加状态筛选
  315. /* if (currentStatus.value != 'all') {
  316. queryParams['status'] = currentStatus.value
  317. } */
  318. queryParams['status'] = currentStatus.value
  319. // 添加计划类型筛选
  320. if (currentPlanType.value.length > 0) {
  321. queryParams['planType'] = currentPlanType.value
  322. }
  323. const result = await getMyTaskList(queryParams)
  324. // 提取响应数据
  325. const resultObj = result as UTSJSONObject
  326. const code = resultObj['code'] as number
  327. const responseData = resultObj['rows'] as any[]
  328. const responseTotal = resultObj['total'] as number
  329. if (code == 200) {
  330. // 将 any[] 转换为 taskInfo[]
  331. const newData: taskInfo[] = []
  332. for (let i = 0; i < responseData.length; i++) {
  333. const item = responseData[i] as UTSJSONObject
  334. const taskItem: taskInfo = {
  335. taskId: item['taskId'] as Number,
  336. planId: item['planId'] as Number,
  337. planType: item['planType'] as string | null,
  338. planName: item['planName'] as string | null,
  339. taskDate: item['taskDate'] as string | null,
  340. startTime: item['startTime'] as string | null,
  341. endTime: item['endTime'] as string | null,
  342. subjects: item['subjects'] as string | null,
  343. machineryTypeName: item['machineryTypeName'] as string | null,
  344. machineryCode: item['machineryCode'] as string | null,
  345. machineryName: item['machineryName'] as string | null,
  346. machineries: item['machineries'] as string | null,
  347. locations: item['locations'] as string | null,
  348. operator: item['operator'] as string | null,
  349. operatorId: item['operatorId'] as Number,
  350. status: item['status'] as string | null,
  351. taskDesc: item['taskDesc'] as string | null,
  352. sourceType: item['sourceType'] as string | null,
  353. locationCount: item['locationCount'] != null ? (item['locationCount'] as Number) : 0,
  354. machineryCount: item['machineryCount'] != null ? (item['machineryCount'] as Number) : 0,
  355. createTime: item['createTime'] as string | null,
  356. updateTime: item['updateTime'] as string | null,
  357. // 前端计算字段初始化
  358. planTypeText: null,
  359. statusText: null,
  360. displayTime: null,
  361. taskCount: null,
  362. checkType: null
  363. }
  364. // 计算前端显示字段
  365. taskItem.planTypeText = getPlanTypeText(taskItem.planType)
  366. taskItem.statusText = getStatusText(taskItem.status)
  367. taskItem.displayTime = getDisplayTime(taskItem)
  368. taskItem.taskCount = getTaskCount(taskItem)
  369. taskItem.checkType = getCheckType(taskItem)
  370. newData.push(taskItem)
  371. }
  372. if (shouldRefresh) {
  373. dataList.value = newData
  374. } else {
  375. dataList.value = [...dataList.value, ...newData]
  376. }
  377. total.value = responseTotal
  378. hasMore.value = dataList.value.length < responseTotal
  379. } else {
  380. const msg = resultObj['msg'] as string | null
  381. uni.showToast({
  382. title: msg ?? '加载失败',
  383. icon: 'none'
  384. })
  385. }
  386. } catch (e: any) {
  387. uni.showToast({
  388. title: e.message ?? '加载失败',
  389. icon: 'none'
  390. })
  391. } finally {
  392. loading.value = false
  393. if (shouldRefresh) {
  394. refreshing.value = false;
  395. setTimeout(() => {
  396. isRefreshing.value = false;
  397. }, 50);
  398. }
  399. }
  400. }
  401. // 切换状态
  402. const switchStatus = (status: string): void => {
  403. // 添加防重复调用检查(参考score/pending.uvue的实现)
  404. if (loading.value) {
  405. return;
  406. }
  407. // 添加防重复请求检查
  408. if (isSearching.value) {
  409. return
  410. }
  411. isSearching.value = true
  412. currentStatus.value = status
  413. page.value = 1
  414. loadData(true, true) // 第二个参数为true表示禁用下拉刷新动画
  415. // 延迟重置标志位,确保请求发送后才允许下一次搜索
  416. setTimeout(() => {
  417. isSearching.value = false
  418. }, 100)
  419. }
  420. // 下拉刷新
  421. const handleRefresh = async (): Promise<void> => {
  422. console.log("handleRefresh被触发")
  423. // 防抖处理,避免频繁触发(参考score/pending.uvue的实现)
  424. const now = Date.now();
  425. if (now - lastRefreshTime.value < 1000) {
  426. refreshing.value = false;
  427. return;
  428. }
  429. lastRefreshTime.value = now;
  430. // 添加防重复调用检查
  431. if (loading.value || isRefreshing.value) {
  432. // 如果已经在加载或正在刷新,直接重置刷新状态
  433. refreshing.value = false;
  434. return;
  435. }
  436. // 设置刷新标志
  437. isRefreshing.value = true;
  438. try {
  439. await loadData(true, false); // 使用默认的下拉刷新行为
  440. } catch (error) {
  441. console.error('刷新失败:', error);
  442. refreshing.value = false;
  443. isRefreshing.value = false;
  444. }
  445. // 确保在一定时间后重置刷新标志,防止意外情况
  446. setTimeout(() => {
  447. isRefreshing.value = false
  448. }, 100) // 延迟重置,确保状态完全更新
  449. }
  450. // 加载更多
  451. const loadMore = (): void => {
  452. if (!hasMore.value || loading.value) {
  453. return
  454. }
  455. page.value++
  456. loadData(false, false)
  457. }
  458. // 搜索
  459. const handleSearch = (): void => {
  460. // 添加防重复调用检查(参考score/pending.uvue的实现)
  461. if (loading.value) {
  462. return;
  463. }
  464. // 添加防重复请求检查
  465. if (isSearching.value) {
  466. return
  467. }
  468. isSearching.value = true
  469. page.value = 1
  470. loadData(true, true) // 状态切换时禁用下拉刷新动画
  471. // 延迟重置标志位,确保请求发送后才允许下一次搜索
  472. setTimeout(() => {
  473. isSearching.value = false
  474. }, 100)
  475. }
  476. const handleSearchOnBlur = (): void => {
  477. handleSearch()
  478. }
  479. // 点击列表项
  480. const handleItemClick = (item: any | null, action: string): void => {
  481. if (item == null) return
  482. const taskItem = item as taskInfo
  483. if(action == 'start') {
  484. // 开始执行任务
  485. if(taskItem.checkType == 'device') {
  486. // 如果是设备检查类型,则跳转到设备清单页面
  487. uni.navigateTo({
  488. url: `/pages/task/device-list?taskId=${taskItem.taskId}&opType='execute'`
  489. });
  490. } else if(taskItem.checkType == 'area') {
  491. // 如果是地点巡查类型,则跳转到地点清单页面
  492. uni.navigateTo({
  493. url: `/pages/task/area-list?taskId=${taskItem.taskId}&opType='execute'`
  494. });
  495. }
  496. } else if(action == 'detail') {
  497. // 查看详情
  498. if(taskItem.checkType == 'device') {
  499. // 如果是设备检查类型,则跳转到设备清单页面
  500. uni.navigateTo({
  501. url: `/pages/task/device-list?taskId=${taskItem.taskId}&opType='view'`
  502. });
  503. } else if(taskItem.checkType == 'area') {
  504. // 如果是地点巡查类型,则跳转到地点清单页面
  505. uni.navigateTo({
  506. url: `/pages/task/area-list?taskId=${taskItem.taskId}&opType='view'`
  507. });
  508. }
  509. }
  510. }
  511. // 点击列表项
  512. const handleView = (item: any | null): void => {
  513. // handleItemClick(item, 'detail')
  514. // if (item == null) return
  515. // const taskItem = item as taskInfo
  516. // if(taskItem.checkType == 'device') {
  517. // // 如果是设备检查类型,则跳转到设备清单页面
  518. // const taskName = taskItem.taskName != null ? taskItem.taskName : '';
  519. // uni.navigateTo({
  520. // url: `/pages/task/device-list?taskId=${taskItem.id}&taskName=${encodeURIComponent(taskName)}`
  521. // });
  522. // } else if(taskItem.checkType == 'area') {
  523. // // 如果是地点巡查类型,则跳转到地点清单页面
  524. // const taskName = taskItem.taskName != null ? taskItem.taskName : '';
  525. // uni.navigateTo({
  526. // url: `/pages/task/area-list?taskId=${taskItem.id}&taskName=${encodeURIComponent(taskName)}`
  527. // });
  528. // } else {
  529. // // 其他类型任务的处理
  530. // uni.showToast({
  531. // title: `查看详情: ${taskItem.taskName}`,
  532. // icon: 'none'
  533. // });
  534. // }
  535. }
  536. // 清空搜索
  537. const clearSearch = (): void => {
  538. // 添加防重复调用检查(参考score/pending.uvue的实现)
  539. if (loading.value) {
  540. return;
  541. }
  542. // 添加防重复请求检查
  543. if (isSearching.value) {
  544. return
  545. }
  546. isSearching.value = true
  547. keyword.value = ""
  548. page.value = 1
  549. loadData(true, true) // 状态切换时禁用下拉刷新动画
  550. // 延迟重置标志位,确保请求发送后才允许下一次搜索
  551. setTimeout(() => {
  552. isSearching.value = false
  553. }, 100)
  554. }
  555. const registerPush =() =>{
  556. console.log("获取CID")
  557. uni.getPushClientId({
  558. success: (res) => {
  559. console.log(res.cid);
  560. registerServer(res.cid).then((result:any) => {
  561. console.log("注册成功");
  562. });
  563. },
  564. fail(err) {
  565. console.log(err)
  566. }
  567. })
  568. }
  569. // 停止定时刷新
  570. const stopAutoRefresh = (): void => {
  571. if (refreshTimer != null) {
  572. clearInterval(refreshTimer as number)
  573. refreshTimer = null
  574. }
  575. }
  576. // 启动定时刷新
  577. const startAutoRefresh = (): void => {
  578. // 清除已有的定时器
  579. stopAutoRefresh()
  580. // 创建新的定时器
  581. refreshTimer = setInterval(() => {
  582. console.log('定时刷新列表数据')
  583. // 只有在不在加载状态时才刷新
  584. if (!loading.value) {
  585. loadData(true, true)
  586. }
  587. }, REFRESH_INTERVAL)
  588. }
  589. // 初始化
  590. onLoad((options: any) => {
  591. const userInfo = getUserInfo()
  592. if (userInfo != null) {
  593. const userIdStr = userInfo['userId'].toString()
  594. userId.value = userIdStr
  595. roles.value = userInfo['roleNames'].toString()
  596. registerPush();
  597. }
  598. const params = options as UTSJSONObject
  599. const isDeal = params['isDeal'] as string | null
  600. if(isDeal != null) {
  601. dealLoad.value = true;
  602. }
  603. loadStatusDictList()
  604. loadPlanTypeDictList()
  605. currentStatus.value = '0'
  606. loadData(true, true) // 首次加载时禁用下拉刷新动画
  607. // 启动定时刷新
  608. startAutoRefresh()
  609. // 监听首页切换状态事件
  610. uni.$on('switchOrderStatus', (status: string) => {
  611. switchStatus(status)
  612. })
  613. })
  614. // 组件卸载前清理事件监听
  615. onBeforeUnmount(() => {
  616. refreshing.value = false
  617. loading.value = false
  618. isRefreshing.value = false
  619. // 停止定时刷新
  620. stopAutoRefresh()
  621. // 清理事件监听
  622. uni.$off('switchOrderStatus')
  623. })
  624. // 页面显示时检查是否需要刷新数据
  625. onShow(() => {
  626. // 检查是否有来自子页面的刷新标记
  627. const needRefresh = uni.getStorageSync('needRefresh')
  628. if (needRefresh == true) {
  629. // 清除标记
  630. uni.removeStorageSync('needRefresh')
  631. // 延迟一小段时间再执行刷新,避免状态冲突
  632. setTimeout(() => {
  633. loadData(true, false); // 使用默认的下拉刷新行为
  634. }, 500)
  635. }
  636. // 页面显示时重新启动定时刷新
  637. startAutoRefresh()
  638. })
  639. // 页面隐藏时停止定时刷新
  640. onHide(() => {
  641. stopAutoRefresh()
  642. })
  643. </script>
  644. <style lang="scss">
  645. .list-page {
  646. flex: 1;
  647. background-color: #e8f0f9;
  648. }
  649. .search-bar {
  650. padding: 20rpx 30rpx;
  651. background-color: #d7eafe;
  652. }
  653. .search-box {
  654. flex-direction: row;
  655. align-items: center;
  656. height: 72rpx;
  657. padding: 0 24rpx;
  658. background-color: #f5f5f5;
  659. border-radius: 36rpx;
  660. .search-icon {
  661. width: 32rpx;
  662. height: 32rpx;
  663. margin-right: 12rpx;
  664. }
  665. .search-input {
  666. flex: 1;
  667. font-size: 28rpx;
  668. color: #333333;
  669. }
  670. .clear-icon {
  671. margin-left: 12rpx;
  672. font-size: 28rpx;
  673. color: #999999;
  674. }
  675. }
  676. .status-bar{
  677. padding-bottom: 10px;
  678. padding-left:30rpx;
  679. background-color: #d7eafe;
  680. }
  681. .status-box {
  682. flex-direction: row;
  683. align-items: center;
  684. height: 72rpx;
  685. flex: 1;
  686. .status-txt{
  687. padding: 8px 12px;
  688. text-align: center;
  689. margin-right: 12rpx;
  690. border-radius: 36rpx;
  691. background-color: #fff;
  692. font-size: 28rpx;
  693. // cursor: pointer;
  694. }
  695. .stauts-sel{
  696. background-color: #007AFF;
  697. color: #fff;
  698. }
  699. }
  700. .list-item {
  701. margin: 12rpx 30rpx;
  702. background-color: #ffffff;
  703. border-radius: 16rpx;
  704. }
  705. .item-container {
  706. padding: 30rpx;
  707. }
  708. .item-header {
  709. flex-direction: row;
  710. align-items: flex-start;
  711. margin-bottom: 16rpx;
  712. justify-content: space-between; /* 主轴两端对齐 */
  713. min-height: 55rpx;
  714. .item-title {
  715. font-size: 30rpx;
  716. color: #333333;
  717. font-weight: bold;
  718. flex-wrap: wrap;
  719. flex: 0 1 75%;
  720. min-width: 0;
  721. }
  722. .task-badges {
  723. display: flex;
  724. flex-direction: row;
  725. align-items: center;
  726. gap: 10rpx; /* 添加间距 */
  727. }
  728. }
  729. .info-row {
  730. flex-direction: row;
  731. justify-content: space-between;
  732. align-items: center;
  733. .info-label {
  734. font-size: 26rpx;
  735. color: #666;
  736. }
  737. .info-value {
  738. font-size: 26rpx;
  739. // color: #666;
  740. }
  741. }
  742. .btn-group {
  743. flex-direction: row;
  744. align-items: center;
  745. justify-content: flex-end;
  746. margin-top: 20rpx;
  747. }
  748. .btn-primary {
  749. z-index: 999;
  750. border-radius: 10rpx;
  751. font-size: 24rpx;
  752. // white-space: nowrap;
  753. margin-left: 20rpx;
  754. background-color: #165DFF;
  755. line-height: 45rpx;
  756. color: #ffffff;
  757. .btn-text{
  758. color: #ffffff;
  759. font-size: 24rpx;
  760. padding: 5px 15px;
  761. }
  762. }
  763. .status-tag {
  764. padding: 8rpx 20rpx;
  765. border-radius: 20rpx;
  766. font-size: 24rpx;
  767. white-space: nowrap;
  768. // margin-left: 50rpx;
  769. // justify-content: flex-end;
  770. border: 1rpx solid;
  771. text-align: center;
  772. }
  773. /* 计划类型样式 */
  774. .type-CHECK {
  775. background-color: #ECF5FF;
  776. color: #409EFF;
  777. border-color: #d8ebff;
  778. }
  779. .type-PATROL {
  780. background-color: #F4F4F5;
  781. color: #909399;
  782. border-color: #e9e9eb;
  783. }
  784. .type-MAINTEN {
  785. background-color: #F0F9EB;
  786. color: #67C23A;
  787. border-color: #c2e7b0;
  788. }
  789. /* 任务状态样式 */
  790. .status-0 {
  791. background-color: #FDF6EC;
  792. color: #E6A23C;
  793. border-color: #faecd8;
  794. }
  795. .status-1 {
  796. background-color: #EBF5FF;
  797. color: #409EFF;
  798. border-color: #d8ebff;
  799. }
  800. .status-2 {
  801. background-color: #F0F9EB;
  802. color: #67C23A;
  803. border-color: #c2e7b0;
  804. }
  805. .status-3 {
  806. background-color: #FEF0F0;
  807. color: #F56C6C;
  808. border-color: #fbc4c4;
  809. }
  810. .status-4 {
  811. background-color: #FDF6EC;
  812. color: #E6A23C;
  813. border-color: #faecd8;
  814. }
  815. /* 保持其他原有样式 */
  816. .text-gray{
  817. font-size: 26rpx;
  818. color: #666;
  819. }
  820. .scroll-view_H {
  821. width: 100%;
  822. flex-direction: row;
  823. }
  824. .scroll-view-item_H {
  825. justify-content: center;
  826. align-items: center;
  827. .status-txt{
  828. padding: 8px 12px;
  829. text-align: center;
  830. margin-right: 12rpx;
  831. border-radius: 36rpx;
  832. background-color: #fff;
  833. font-size: 28rpx;
  834. }
  835. .stauts-sel{
  836. background-color: #007AFF;
  837. color: #fff;
  838. }
  839. }
  840. </style>