Просмотр исходного кода

fix: 修复运行统计跳转时间参数异常

- 调整设备统计卡片跳转参数,创建时间保持数组传递
- 在填报列表页兼容解析路由创建时间参数,避免日期组件显示异常
- 清理统计页无效路由守卫和筛选区冗余注释
- 格式化填报列表页代码
Zimo 1 неделя назад
Родитель
Сommit
52e8df1efc

+ 45 - 41
src/views/pms/iotopeationfill/StatisticsForm.vue

@@ -13,16 +13,14 @@
           :model="queryParams"
           ref="queryFormRef"
           :inline="true"
-          label-width="68px"
-        >
+          label-width="68px">
           <el-form-item label="查询条件" prop="orderName">
             <el-input
               v-model="queryParams.orderName"
               placeholder="请输入查询条件"
               clearable
               @keyup.enter="handleQuery"
-              class="!w-240px"
-            />
+              class="!w-240px" />
           </el-form-item>
           <el-form-item label="创建时间" prop="createTime">
             <el-date-picker
@@ -32,19 +30,21 @@
               start-placeholder="开始日期"
               end-placeholder="结束日期"
               :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
-              class="!w-220px"
-            />
+              class="!w-220px" />
           </el-form-item>
           <el-form-item>
-            <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
-            <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
+            <el-button @click="handleQuery"
+              ><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button
+            >
+            <el-button @click="resetQuery"
+              ><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button
+            >
             <el-button
               type="success"
               plain
               @click="handleExport"
               :loading="exportLoading"
-              v-hasPermi="['rq:iot-opeation-fill:export']"
-            >
+              v-hasPermi="['rq:iot-opeation-fill:export']">
               <Icon icon="ep:download" class="mr-5px" /> 导出
             </el-button>
           </el-form-item>
@@ -73,20 +73,16 @@
             align="center"
             prop="createTime"
             :formatter="dateFormatter"
-            width="180px"
-          />
+            width="180px" />
         </el-table>
         <Pagination
           :total="total"
           v-model:page="queryParams.pageNo"
           v-model:limit="queryParams.pageSize"
-          @pagination="getList"
-        />
+          @pagination="getList" />
       </ContentWrap>
     </el-col>
   </el-row>
-
-
 </template>
 
 <script setup lang="ts">
@@ -94,15 +90,15 @@ import { dateFormatter } from '@/utils/formatTime'
 import download from '@/utils/download'
 import { IotOpeationFillApi, IotOpeationFillVO } from '@/api/pms/iotopeationfill'
 import IotOpeationFillForm from './IotOpeationFillForm.vue'
-import * as UserApi from "@/api/system/user";
-import {defaultProps,handleTree} from "@/utils/tree";
-import * as DeptApi from "@/api/system/dept";
-import * as PostApi from "@/api/system/post";
-import {onMounted, ref} from "vue";
-import {DeptTreeItem} from "@/api/system/dept";
-import DeptTree from "@/views/system/user/DeptTree.vue";
-import {useUserStore} from "@/store/modules/user";
-import {DICT_TYPE, getStrDictOptions} from "@/utils/dict";
+import * as UserApi from '@/api/system/user'
+import { defaultProps, handleTree } from '@/utils/tree'
+import * as DeptApi from '@/api/system/dept'
+import * as PostApi from '@/api/system/post'
+import { onMounted, ref } from 'vue'
+import { DeptTreeItem } from '@/api/system/dept'
+import DeptTree from '@/views/system/user/DeptTree.vue'
+import { useUserStore } from '@/store/modules/user'
+import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
 /** 运行记录填报 列表 */
 defineOptions({ name: 'FillOrderInfo2' })
 const deptList = ref<DeptTreeItem[]>([]) // 树形结构部门列表
@@ -113,14 +109,23 @@ const loading = ref(true) // 列表的加载中
 const list = ref<IotOpeationFillVO[]>([]) // 列表的数据
 const total = ref(0) // 列表的总页数
 const { params, name } = useRoute() // 查询参数
-const deptId = params.deptId;
-const isFill = params.isFill;
-const createTime = params.createTime;
+const deptId = params.deptId
+const isFill = params.isFill
+const createTime = params.createTime
+const normalizeRouteCreateTime = (value: unknown) => {
+  if (Array.isArray(value)) {
+    return value.filter((item): item is string => typeof item === 'string' && item)
+  }
+  if (typeof value === 'string') {
+    return value.split(',').filter(Boolean)
+  }
+  return []
+}
 const dialogVisible = ref(false) // 弹窗的是否展示
 const dialogTitle = ref('') // 弹窗的标题
 const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
 const formType = ref('') // 表单的类型:create - 新增;update - 修改
-const selectedDeptId = ref(null);  // 通过store存储的部门id 由父组件传递过来
+const selectedDeptId = ref(null) // 通过store存储的部门id 由父组件传递过来
 
 const queryParams = reactive({
   pageNo: 1,
@@ -138,7 +143,7 @@ const queryParams = reactive({
   teamName: undefined,
   dutyName: undefined,
   creDate: [],
-  createTime: [],
+  createTime: []
 })
 const queryFormRef = ref() // 搜索的表单
 const exportLoading = ref(false) // 导出的加载中
@@ -158,18 +163,16 @@ const getList = async () => {
   }
 }
 
-
 /** 打开弹窗 */
 const open = async (type: string, id?: number) => {
   dialogVisible.value = true
   dialogTitle.value = type
   formType.value = type
-  queryParams.deptId = id;
+  queryParams.deptId = id
   // 修改时,设置数据
   if (id) {
-    getList();
+    getList()
   }
-
 }
 defineExpose({ open }) // 提供 open 方法,用于打开弹窗
 
@@ -181,7 +184,7 @@ const handleQuery = () => {
 
 /** 重置按钮操作 */
 const resetQuery = () => {
-  queryParams.deptId = useUserStore().getUser.deptId;
+  queryParams.deptId = useUserStore().getUser.deptId
   queryParams.createTime = null
   queryFormRef.value.resetFields()
   handleQuery()
@@ -224,19 +227,20 @@ const handleExport = async () => {
 /** 初始化 **/
 onMounted(async () => {
   if (deptId) {
-    queryParams.deptId = deptId;
+    queryParams.deptId = deptId
   }
   if (isFill == 2) {
-    queryParams.isFill = null;
+    queryParams.isFill = null
   } else {
     if (isFill) {
-      queryParams.isFill = isFill;
+      queryParams.isFill = isFill
     }
   }
-  if(createTime){
-    queryParams.createTime = createTime;
+  const routeCreateTime = normalizeRouteCreateTime(createTime)
+  if (routeCreateTime.length) {
+    queryParams.createTime = routeCreateTime
   }
   getList()
-  deptList.value = handleTree(await DeptApi.getSimpleDeptList());
+  deptList.value = handleTree(await DeptApi.getSimpleDeptList())
 })
 </script>

+ 12 - 39
src/views/pms/iotopeationfill/statistics.vue

@@ -42,28 +42,13 @@
                   :default-time="datePickerDefaultTime"
                   class="!w-220px" />
               </el-form-item>
-              <!--          <el-form-item label="填写状态" prop="project_name">
-            <el-select
-              v-model="queryParams.status"
-              placeholder="填写状态"
-              clearable
-              class="!w-240px"
-            >
-              <el-option
-                v-for="dict in getIntDictOptions(DICT_TYPE.OPERATION_FILL_ORDER_STATUS)"
-                :key="dict.value"
-                :label="dict.label"
-                :value="dict.value"
-              />
-            </el-select>
-              </el-form-item>-->
               <el-form-item class="filter-actions">
-                <el-button class="action-btn" size="default" @click="handleQuery"
-                  ><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button
-                >
-                <el-button class="action-btn" size="default" @click="resetQuery"
-                  ><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button
-                >
+                <el-button class="action-btn" size="default" @click="handleQuery">
+                  <Icon icon="ep:search" class="mr-5px" /> 搜索
+                </el-button>
+                <el-button class="action-btn" size="default" @click="resetQuery">
+                  <Icon icon="ep:refresh" class="mr-5px" /> 重置
+                </el-button>
               </el-form-item>
             </el-form>
           </el-card>
@@ -203,7 +188,10 @@ const CHART_COLORS = {
   axis: '#24364f'
 }
 const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
-const datePickerDefaultTime = [dayjs().startOf('day').toDate(), dayjs().endOf('day').toDate()]
+const datePickerDefaultTime: [Date, Date] = [
+  dayjs().startOf('day').toDate(),
+  dayjs().endOf('day').toDate()
+]
 
 const getDefaultTimeRange = () => {
   const end = dayjs()
@@ -275,10 +263,10 @@ const handleQuery = () => {
 const initialQueryParams: QueryParams = { ...queryParams }
 
 const openForm = (deptId?: number | null, isFill?: number, createTime?: string[] | null) => {
-  const params: Record<string, string> = {}
+  const params: Record<string, string | string[]> = {}
   if (deptId != null) params.deptId = String(deptId)
   if (isFill != null) params.isFill = String(isFill)
-  if (createTime?.length) params.createTime = createTime.join(',')
+  if (createTime?.length) params.createTime = createTime
 
   push({ name: 'FillOrderInfo2', params })
 }
@@ -665,20 +653,6 @@ const handleResize = () => {
     instance.resize()
   }
 }
-const router = useRouter()
-const route = useRoute()
-// 监听路由变化
-const removeBeforeEach = router.beforeEach((to, from, next) => {
-  // 如果是从FillOrderInfo1页面返回
-  if (from.name === 'FillOrderInfo1' && to.name === route.name) {
-    // 恢复查询参数
-    Object.assign(queryParams, initialQueryParams)
-    // 阻止刷新,使用replace而不是push
-    next({ ...to, replace: true })
-  } else {
-    next()
-  }
-})
 
 /** 初始化 */
 onMounted(async () => {
@@ -696,7 +670,6 @@ onUnmounted(() => {
   window.removeEventListener('resize', handleResize)
   chartInstance?.dispose()
   chartInstance = null
-  removeBeforeEach()
 })
 </script>