diff --git a/src/views/admin/RepairList.vue b/src/views/admin/RepairList.vue index 780bd40..86e02a0 100644 --- a/src/views/admin/RepairList.vue +++ b/src/views/admin/RepairList.vue @@ -82,8 +82,10 @@ - 查询 + 查询 重置 + 保存筛选条件 + 清除筛选条件 导出工单模版 导入 导出工单数据 @@ -401,30 +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.dateRange = [] - - // 清除localStorage中保存的筛选条件 - localStorage.removeItem('repairListFilterConditions') - - this.handleOk(true) - // this.queryParam = {} - // this.queryParam.typeId = '' - // this.selectRepairList() + // 直接调用清除筛选条件的方法 + this.clearUserFilterConditions() }, customRequest(file) { // file 是上传的文件 其内容会在放在下面截图中 @@ -591,12 +571,12 @@ export default { this.$refs.modal.add() }, handleView(repairId) { - // 保存当前筛选条件 - try { - this.saveFilterConditions() - } catch (e) { - console.error('保存筛选条件失败', e) - } + // 不再自动保存筛选条件,而是依赖用户主动点击保存按钮 + // try { + // this.saveFilterConditions() + // } catch (e) { + // console.error('保存筛选条件失败', e) + // } // 跳转到详情页 this.$router.push({ name: 'repairView', query: { repairId: repairId } }) }, @@ -693,12 +673,111 @@ export default { 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('清除筛选条件失败') + } + }, + // 添加新方法,实现查询并自动保存筛选条件 + queryAndSave() { + // 先保存筛选条件 + 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.saveFilterConditions() + this.$message.success('筛选条件已自动保存') + } + } catch (e) { + console.error('自动保存筛选条件失败', e) + } + + // 然后刷新表格 + this.$refs.table.refresh(true) } }, watch: {}