小组团队项目个人博客6.0
今天完成了“支持用户通过责任部门/工区、录入日期(日期范围:起始时间和结束时间) 、专业系统、风险类别、风险等级、危害程度等字段进行数据筛选”的功能


// 筛选查询数据
onSubmit2() {
var _this = this;
axios({
method: "post",
url: "http://localhost:8080/selectall",
data: JSON.stringify(this.form)
}).then(function (resp) {
_this.originalData = resp.data; // 保存原始数据
_this.applyFilters(); // 应用筛选条件
_this.extractRiskCategories(); // 提取风险类别
_this.$message({
message: '查询成功',
type: 'success'
});
}).catch(error => {
_this.$message.error('查询失败: ' + error.message);
});
},
// 应用筛选条件
applyFilters() {
if (!this.hasFilters()) {
this.filteredData = [...this.originalData];
return;
}
this.filteredData = this.originalData.filter(item => {
// 责任部门筛选
if (this.filterForm.responsibleDepartment &&
!item.responsibleDepartment.includes(this.filterForm.responsibleDepartment)) {
return false;
}
// 风险类别筛选
if (this.filterForm.riskCategory &&
item.riskCategory !== this.filterForm.riskCategory) {
return false;
}
// 风险等级筛选
if (this.filterForm.riskLevel &&
item.riskLevel !== this.filterForm.riskLevel) {
return false;
}
// 危害程度筛选
if (this.filterForm.harmDegree &&
item.harmDegree !== this.filterForm.harmDegree) {
return false;
}
// 录入日期范围筛选
if (this.filterForm.entryDate && this.filterForm.auditDate) {
const entryDate = new Date(item.entryDate);
const startDate = new Date(this.filterForm.entryDate);
const endDate = new Date(this.filterForm.auditDate);
if (entryDate < startDate || entryDate > endDate) {
return false;
}
}
return true;
});
// 更新表格数据,筛选结果在前
this.tableData = [...this.filteredData];
},
// 检查是否有筛选条件
hasFilters() {
return Object.values(this.filterForm).some(
value => value !== '' && value !== null && value !== undefined
);
},
// 从数据中提取风险类别选项
extractRiskCategories() {
const categories = new Set();
this.originalData.forEach(item => {
if (item.riskCategory) {
categories.add(item.riskCategory);
}
});
this.riskCategoryOptions = Array.from(categories);
},
// 重置筛选条件
resetFilter() {
this.filterForm = {
responsibleDepartment: '',
riskCategory: '',
riskLevel: '',
harmDegree: '',
entryDate: '',
auditDate: ''
};
this.tableData = [...this.originalData]; // 恢复原始数据
this.$message({
message: '筛选条件已重置',
type: 'success'
});
}


浙公网安备 33010602011771号