From 2ab5283eebdd74286dd6cede74d446e11fa94a12 Mon Sep 17 00:00:00 2001 From: luoyu Date: Wed, 21 May 2025 21:06:19 +0800 Subject: [PATCH] =?UTF-8?q?20250521=E4=BF=AE=E5=A4=8D=20=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E8=BF=87=E5=90=8E,=E7=82=B9=E5=87=BB=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=9F=A5=E7=9C=8B=E5=B9=B6=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=90=8E,=E7=AD=9B=E9=80=89=E6=9D=A1=E4=BB=B6=E9=83=BD?= =?UTF-8?q?=E6=B2=A1=E4=BA=86,=E8=BF=98=E9=9C=80=E8=A6=81=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E7=AD=9B=E9=80=89,=E7=94=A8=E6=88=B7=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=B5=B7=E6=9D=A5=E6=AF=94=E8=BE=83=E9=BA=BB=E7=83=A6?= =?UTF-8?q?=E6=AF=8F=E6=AC=A1=E9=83=BD=E9=9C=80=E8=A6=81=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E7=AD=9B=E9=80=89.=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=96=B9=E6=A1=88=EF=BC=9A=20=E9=87=87=E7=94=A8=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=AD=98=E5=82=A8=E3=80=81=E5=9C=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=A1=B5=E5=A2=9E=E5=8A=A0=E4=B8=A4=E4=B8=AA=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E4=BE=9B=E7=94=A8=E6=88=B7=E8=87=AA=E8=A1=8C=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=BF=9D=E5=AD=98=E7=AD=9B=E9=80=89=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E3=80=81=E8=AF=A6=E6=83=85=E9=A1=B5=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=88=97=E8=A1=A8=E6=8C=89=E9=92=AE=EF=BC=8C?= =?UTF-8?q?=E4=BE=BF=E4=BA=8E=E7=94=A8=E6=88=B7=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/admin/RepairList.vue | 174 +++++++++++++++++++++++++++++---- src/views/admin/RepairView.vue | 17 ++++ 2 files changed, 172 insertions(+), 19 deletions(-) diff --git a/src/views/admin/RepairList.vue b/src/views/admin/RepairList.vue index 6450406..6e3f937 100644 --- a/src/views/admin/RepairList.vue +++ b/src/views/admin/RepairList.vue @@ -84,6 +84,8 @@ 查询 重置 + 保存筛选条件 + 清除筛选条件 导出工单模版 导入 导出工单数据 @@ -382,6 +384,12 @@ export default { this.isShowModel = true } this.selectType() + // 恢复之前保存的筛选条件 + this.restoreFilterConditions() + }, + activated() { + // 从详情页返回时恢复筛选条件 + this.restoreFilterConditions() }, methods: { fatherMethod(val) { @@ -395,25 +403,8 @@ export default { this.selectedRows = selectedRows }, reset() { - this.queryParam = { - 'type': 'all', - 'explain': '', - 'sn': '', - 'typeId': '', - 'deviceId': '', - 'status': '', - 'repairLevel': '', - 'beginTime': '', - 'endTime': '', - 'evalService': '', - 'timeout': '', - 'remark': '', - 'name': '' - } - this.handleOk(true) - // this.queryParam = {} - // this.queryParam.typeId = '' - // this.selectRepairList() + // 直接调用清除筛选条件的方法 + this.clearUserFilterConditions() }, customRequest(file) { // file 是上传的文件 其内容会在放在下面截图中 @@ -580,6 +571,13 @@ export default { this.$refs.modal.add() }, handleView(repairId) { + // 不再自动保存筛选条件,而是依赖用户主动点击保存按钮 + // try { + // this.saveFilterConditions() + // } catch (e) { + // console.error('保存筛选条件失败', e) + // } + // 跳转到详情页 this.$router.push({ name: 'repairView', query: { repairId: repairId } }) }, handleEdit(record) { @@ -613,6 +611,144 @@ export default { onCancel() { } }) + }, + // 保存筛选条件到localStorage + saveFilterConditions() { + // 处理日期范围格式 + let formattedDateRange = null; + if (this.dateRange && this.dateRange.length === 2) { + formattedDateRange = [ + this.dateRange[0].format('YYYY-MM-DD'), + this.dateRange[1].format('YYYY-MM-DD') + ]; + } + + const filterConditions = { + queryParam: JSON.parse(JSON.stringify(this.queryParam)), // 深拷贝查询参数 + dateRange: formattedDateRange, + typeId: this.queryParam.typeId || '', + deviceId: this.queryParam.deviceId || '' + } + + // 保存到localStorage + localStorage.setItem('repairListFilterConditions', JSON.stringify(filterConditions)) + }, + + // 从localStorage恢复筛选条件 + restoreFilterConditions() { + const savedConditions = localStorage.getItem('repairListFilterConditions') + if (savedConditions) { + try { + const conditions = JSON.parse(savedConditions) + + // 恢复查询参数 + if (conditions.queryParam) { + this.queryParam = conditions.queryParam + } + + // 恢复日期范围 + if (conditions.dateRange && conditions.dateRange.length === 2) { + this.dateRange = [ + this.$moment(conditions.dateRange[0]), + this.$moment(conditions.dateRange[1]) + ] + this.queryParam.startTime = conditions.dateRange[0] + this.queryParam.endTime = conditions.dateRange[1] + } + + // 恢复设备类型及子类 + if (conditions.typeId) { + // 先加载设备类型 + this.selectDevice(conditions.typeId) + + // 确保设备子类被正确设置 + if (conditions.deviceId) { + this.$nextTick(() => { + this.queryParam.deviceId = conditions.deviceId + }) + } + } + + // 刷新表格 + this.$nextTick(() => { + if (this.$refs.table) { + this.$refs.table.refresh(true) + // 提示用户当前使用的是保存的筛选条件 + this.$message.info('已应用保存的筛选条件') + } + }) + } catch (e) { + console.error('恢复筛选条件失败:', e) + } + } + }, + saveUserFilterConditions() { + // 实现保存筛选条件的逻辑 + try { + // 检查是否有有效的筛选条件 + const hasFilter = Object.keys(this.queryParam).some(key => { + // 排除type为'all'的情况,这是默认值 + if (key === 'type' && this.queryParam[key] === 'all') { + return false + } + // 检查其他参数是否有值 + return this.queryParam[key] !== '' && this.queryParam[key] !== null && this.queryParam[key] !== undefined + }) + + // 检查日期范围 + const hasDateRange = this.dateRange && this.dateRange.length === 2 + + if (!hasFilter && !hasDateRange) { + this.$message.info('当前没有设置筛选条件,无需保存') + return + } + + // 保存筛选条件 + this.saveFilterConditions() + this.$message.success('筛选条件已保存,下次访问将自动应用') + } catch (e) { + console.error('保存筛选条件失败', e) + this.$message.error('保存筛选条件失败') + } + }, + clearUserFilterConditions() { + // 实现清除筛选条件的逻辑 + try { + // 清除localStorage中保存的筛选条件 + localStorage.removeItem('repairListFilterConditions') + + // 重置查询参数 + this.queryParam = { + 'type': 'all', + 'explain': '', + 'sn': '', + 'typeId': '', + 'deviceId': '', + 'status': '', + 'repairLevel': '', + 'beginTime': '', + 'endTime': '', + 'evalService': '', + 'timeout': '', + 'remark': '', + 'name': '' + } + + // 重置时间范围 + this.dateRange = [] + + // 刷新列表数据 + this.$nextTick(() => { + if (this.$refs.table) { + this.$refs.table.refresh(true) + } + }) + + this.$message.success('筛选条件已清除,列表已重置') + } catch (e) { + console.error('清除筛选条件失败', e) + this.$message.error('清除筛选条件失败') + } } }, watch: {} diff --git a/src/views/admin/RepairView.vue b/src/views/admin/RepairView.vue index 0722744..019c049 100644 --- a/src/views/admin/RepairView.vue +++ b/src/views/admin/RepairView.vue @@ -2,6 +2,9 @@
+