更新
This commit is contained in:
@@ -151,6 +151,7 @@ import { Search, Refresh } from "@element-plus/icons-vue";
|
|||||||
import { checkAndUpdateStatus } from "@/api/fire/facility";
|
import { checkAndUpdateStatus } from "@/api/fire/facility";
|
||||||
import { getReportData, getDetailData, getAllData } from "@/api/fire/report";
|
import { getReportData, getDetailData, getAllData } from "@/api/fire/report";
|
||||||
import DictTag from "@/components/DictTag/index.vue";
|
import DictTag from "@/components/DictTag/index.vue";
|
||||||
|
import { getCurrentInstance } from "vue"; // 补充导入
|
||||||
|
|
||||||
// 获取当前实例
|
// 获取当前实例
|
||||||
const { proxy } = getCurrentInstance();
|
const { proxy } = getCurrentInstance();
|
||||||
@@ -161,11 +162,15 @@ const { fire_facility_type, fire_facility_status } = proxy.useDict(
|
|||||||
"fire_facility_status"
|
"fire_facility_status"
|
||||||
);
|
);
|
||||||
|
|
||||||
// 计算属性
|
// 计算属性 - 优化字典加载判断逻辑
|
||||||
const facilityTypes = computed(() => fire_facility_type.value || []);
|
const facilityTypes = computed(() => fire_facility_type.value || []);
|
||||||
const facilityStatuses = computed(() => fire_facility_status.value || []);
|
const facilityStatuses = computed(() => fire_facility_status.value || []);
|
||||||
const isDictLoaded = computed(() => {
|
const isDictLoaded = computed(() => {
|
||||||
return facilityTypes.value.length > 0 && facilityStatuses.value.length > 0;
|
// 不仅判断长度,还要验证是否包含有效数据(避免空数组误判)
|
||||||
|
return facilityTypes.value.length > 0 &&
|
||||||
|
facilityStatuses.value.length > 0 &&
|
||||||
|
facilityTypes.value.some(item => item.value !== undefined) &&
|
||||||
|
facilityStatuses.value.some(item => item.value !== undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. 响应式数据
|
// 2. 响应式数据
|
||||||
@@ -188,7 +193,7 @@ const pagination = reactive({
|
|||||||
total: 0
|
total: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
// 查询参数
|
// 查询参数 - 确保初始值为null(符合后端预期)
|
||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
facilityType: null,
|
facilityType: null,
|
||||||
});
|
});
|
||||||
@@ -196,8 +201,11 @@ const queryParams = reactive({
|
|||||||
// 3. 核心方法:查询报表数据
|
// 3. 核心方法:查询报表数据
|
||||||
const handleQuery = () => {
|
const handleQuery = () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
// 打印查询参数,便于调试
|
||||||
|
console.log("查询参数:", queryParams);
|
||||||
getReportData(queryParams)
|
getReportData(queryParams)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
console.log("报表数据返回:", res);
|
||||||
reportData.value = Array.isArray(res.data) ? res.data : [];
|
reportData.value = Array.isArray(res.data) ? res.data : [];
|
||||||
totalCount.value = reportData.value.reduce(
|
totalCount.value = reportData.value.reduce(
|
||||||
(sum, item) => sum + (item.total || 0),
|
(sum, item) => sum + (item.total || 0),
|
||||||
@@ -241,7 +249,7 @@ const showStatusDetail = async (statusValue) => {
|
|||||||
detailDialog.value = true;
|
detailDialog.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 加载指定页的状态详情数据(保留状态更新)
|
// 加载指定页的状态详情数据
|
||||||
const loadStatusDetailPage = async () => {
|
const loadStatusDetailPage = async () => {
|
||||||
detailLoading.value = true;
|
detailLoading.value = true;
|
||||||
try {
|
try {
|
||||||
@@ -266,7 +274,7 @@ const loadStatusDetailPage = async () => {
|
|||||||
pagination.total = Number(responseData.total) || 0;
|
pagination.total = Number(responseData.total) || 0;
|
||||||
const currentPageList = Array.isArray(responseData.list) ? responseData.list : [];
|
const currentPageList = Array.isArray(responseData.list) ? responseData.list : [];
|
||||||
|
|
||||||
// 状态详情弹窗仍调用状态更新
|
// 状态详情弹窗调用状态更新
|
||||||
for (const item of currentPageList) {
|
for (const item of currentPageList) {
|
||||||
await checkAndUpdateStatus(item.id);
|
await checkAndUpdateStatus(item.id);
|
||||||
}
|
}
|
||||||
@@ -302,7 +310,7 @@ const showTotalDetail = async () => {
|
|||||||
detailDialog.value = true;
|
detailDialog.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 加载指定页的总数详情数据(不调用状态更新)
|
// 加载指定页的总数详情数据
|
||||||
const loadTotalDetailPage = async () => {
|
const loadTotalDetailPage = async () => {
|
||||||
detailLoading.value = true;
|
detailLoading.value = true;
|
||||||
try {
|
try {
|
||||||
@@ -321,10 +329,10 @@ const loadTotalDetailPage = async () => {
|
|||||||
const allData = Array.isArray(allDataRes.data) ? allDataRes.data : [];
|
const allData = Array.isArray(allDataRes.data) ? allDataRes.data : [];
|
||||||
pagination.total = allData.length; // 总条数
|
pagination.total = allData.length; // 总条数
|
||||||
|
|
||||||
// 执行前端分页(不调用状态更新接口)
|
// 执行前端分页
|
||||||
const start = (pagination.currentPage - 1) * pagination.pageSize;
|
const start = (pagination.currentPage - 1) * pagination.pageSize;
|
||||||
const end = start + pagination.pageSize;
|
const end = start + pagination.pageSize;
|
||||||
detailList.value = allData.slice(start, end); // 直接使用原始数据
|
detailList.value = allData.slice(start, end);
|
||||||
|
|
||||||
// 空数据提示
|
// 空数据提示
|
||||||
if (detailList.value.length === 0 && pagination.total > 0) {
|
if (detailList.value.length === 0 && pagination.total > 0) {
|
||||||
@@ -394,20 +402,35 @@ const getExpiryTagType = (expiryDate) => {
|
|||||||
return diffDays < 0 ? "danger" : diffDays <= 30 ? "warning" : "success";
|
return diffDays < 0 ? "danger" : diffDays <= 30 ? "warning" : "success";
|
||||||
};
|
};
|
||||||
|
|
||||||
// 10. 初始化与监听
|
// 10. 初始化与监听 - 核心优化点
|
||||||
watch(isDictLoaded, (loaded) => {
|
onMounted(() => {
|
||||||
if (loaded) {
|
// 检查状态配置错误
|
||||||
handleQuery();
|
const invalidStatus = facilityStatuses.value.filter(item => !item.tagType);
|
||||||
}
|
// if (invalidStatus.length) {
|
||||||
|
// console.error("以下状态缺少tagType配置:", invalidStatus);
|
||||||
|
// proxy.$message.warning(`检测到${invalidStatus.length}个状态样式配置错误`);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 初始化查询逻辑(确保字典加载后执行)
|
||||||
|
const initQuery = () => {
|
||||||
|
if (isDictLoaded.value) {
|
||||||
|
handleQuery();
|
||||||
|
} else {
|
||||||
|
// 等待字典加载完成后执行查询
|
||||||
|
const unwatch = watch(isDictLoaded, (loaded) => {
|
||||||
|
if (loaded) {
|
||||||
|
handleQuery();
|
||||||
|
unwatch(); // 执行后销毁监听,避免重复调用
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 立即执行初始化查询
|
||||||
|
initQuery();
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
// 移除原有的watch(isDictLoaded),改用onMounted中的逻辑
|
||||||
const invalidStatus = facilityStatuses.value.filter(item => !item.tagType);
|
|
||||||
if (invalidStatus.length) {
|
|
||||||
console.error("以下状态缺少tagType配置:", invalidStatus);
|
|
||||||
proxy.$message.warning(`检测到${invalidStatus.length}个状态样式配置错误`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
Reference in New Issue
Block a user