diff --git a/src/views/dataManagement/components/data/device.vue b/src/views/dataManagement/components/data/device.vue index 9897df1..23efd69 100644 --- a/src/views/dataManagement/components/data/device.vue +++ b/src/views/dataManagement/components/data/device.vue @@ -5,15 +5,7 @@ import { colors } from '../environment/colors' import { device } from './img' import { getRangeAllTime } from '@/utils/date' -import { - getBaseInfo, - getDeptExpire, - getDeviceMaintain, - getDeviceStatus, - getDeviceType, - getStandardDeviceType, - getTraceAnalyse, -} from '@/api/dataManagement/data/device' +import { getBaseInfo, getDeptExpire, getDeviceMaintain, getDeviceStatus, getDeviceType, getStandardDeviceType, getTraceAnalyse, } from '@/api/dataManagement/data/device' const props = defineProps({ lab: { type: String, @@ -30,15 +22,12 @@ const year = ref('') // 年度 const yearList = ref([]) -watch( - () => props.lab, - (newVal) => { - if (newVal) { - searchQueryResult.value.labCode = props.lab - fetchData() - } - }, -) +watch(() => props.lab, (newVal) => { + if (newVal) { + searchQueryResult.value.labCode = props.lab + fetchData() + } +}) // 基础信息展示数据 const baseInfo = ref([ { @@ -86,6 +75,8 @@ data: [], smooth: false, gradient: true, + loading: false, // 加载中 + isEmpty: false, // 是否为空 }, { name: '设备类型分析', @@ -95,6 +86,8 @@ labelPosition: 'outside', radius: '70%', data: [], + loading: false, // 加载中 + isEmpty: false, // 是否为空 }, { name: '标准设备种类分析', @@ -113,11 +106,15 @@ align: 'center', }, ], + loading: false, // 加载中 + isEmpty: false, // 是否为空 }, { name: '设备状态分析', type: 'bar-vertical', source: 'system', + loading: false, // 加载中 + isEmpty: false, // 是否为空 }, { name: '设备维护保养情况', @@ -159,39 +156,43 @@ width: '95', }, ], + loading: false, // 加载中 + isEmpty: false, // 是否为空 }, { name: '设备溯源分析', type: 'bar-horizontal', source: 'system', + loading: false, // 加载中 + isEmpty: false, // 是否为空 }, ]) -watch( - () => showChart.value.length, - () => { - setTimeout(() => { - const resize = new Event('resize') - window.dispatchEvent(resize) - }) - }, -) +watch(() => showChart.value.length, () => { + setTimeout(() => { + const resize = new Event('resize') + window.dispatchEvent(resize) + }) +}) // 模拟数据 -const loading = ref(false) +const loadingBase = ref(false) function fetchData() { // 获取基础数据 + loadingBase.value = true getBaseInfo(searchQueryResult.value).then((res) => { baseInfo.value.forEach((item) => { item.data = res.data[item.value] }) + loadingBase.value = false + }).catch(() => { + loadingBase.value = false }) // 近一年部门设备到期趋势 + const current1 = showChart.value.filter(item => item.name === '近一年部门设备到期趋势')[0] + current1.loading = true getDeptExpire(searchQueryResult.value).then((res) => { - console.log(res.data, '近一年部门设备到期趋势') - const current = showChart.value.filter( - item => item.name === '近一年部门设备到期趋势', - )[0] - current.xAxisData = res.data.map((item: any) => item.dimension) + // console.log(res.data, '近一年部门设备到期趋势') + current1.xAxisData = res.data.map((item: any) => item.dimension) const data = [ { name: '电学电源组', @@ -210,15 +211,20 @@ value: 'glAmount', }, ] - current.data = data.map((item: any) => ({ + current1.data = data.map((item: any) => ({ name: item.name, symbol: 'emptyCircle', data: res.data.map((citem: any) => String(citem[item.value])), })) + current1.loading = false + }).catch(() => { + current1.loading = false }) // 设备类型分析 + const current2 = showChart.value.filter(item => item.name === '设备类型分析')[0] + current2.loading = true getDeviceType(searchQueryResult.value).then((res) => { - console.log(res.data, '设备类型分析') + // console.log(res.data, '设备类型分析') const data = [ { name: '标准设备', @@ -236,20 +242,26 @@ data: '', }, ] - const current = showChart.value.filter( - item => item.name === '设备类型分析', - )[0] data.forEach((item) => { item.data = res.data[item.value] }) - current.data = data.map(item => ({ name: item.name, value: String(item.data) })) + current2.data = data.map(item => ({ name: item.name, value: String(item.data) })) + current2.loading = false + // 判断是否为空 + if(current2.data.every((item: any) => item.value === '0')) { + current2.isEmpty = true + } + else { + current2.isEmpty = false + } + }).catch(() => { + current2.loading = false }) // 设备状态分析 + const current3 = showChart.value.filter(item => item.name === '设备状态分析')[0] + current3.loading = true getDeviceStatus(searchQueryResult.value).then((res) => { - console.log(res.data, '设备状态分析') - const current = showChart.value.filter( - item => item.name === '设备状态分析', - )[0] + // console.log(res.data, '设备状态分析') const data = [ { name: '在用', @@ -280,20 +292,22 @@ data.forEach((item) => { item.data = res.data[item.value] }) - current.xAxisData = data.map((item: any) => item.name) - current.data = [ + current3.xAxisData = data.map((item: any) => item.name) + current3.data = [ { name: '数量', data: data.map((item: any) => String(item.data)), }, ] + current3.loading = false + }).catch(() => { + current3.loading = false }) // 设备溯源分析 + const current4 = showChart.value.filter(item => item.name === '设备溯源分析')[0] + current4.loading = true getTraceAnalyse(searchQueryResult.value).then((res) => { - console.log(res.data, '设备溯源分析') - const current = showChart.value.filter( - item => item.name === '设备溯源分析', - )[0] + // console.log(res.data, '设备溯源分析') const data = [ { name: '合格', @@ -314,34 +328,48 @@ data.forEach((item) => { item.data = res.data[item.value] }) - current.xAxisData = data.map((item: any) => item.name) - current.data = [ + current4.xAxisData = data.map((item: any) => item.name) + current4.data = [ { name: '数量', data: data.map((item: any) => String(item.data)), }, ] + current4.loading = false + // 判断是否为空 + if(data.every((item: any) => String(item.data) === '0')) { + current4.isEmpty = true + } + else { + current4.isEmpty = false + } + }).catch(() => { + current4.loading = false }) // 标准设备种类分析 + const current5 = showChart.value.filter(item => item.name === '标准设备种类分析')[0] + current5.loading = true getStandardDeviceType(searchQueryResult.value).then((res) => { - console.log(res.data, '标准设备种类分析') - const current = showChart.value.filter( - item => item.name === '标准设备种类分析', - )[0] - current.data = [] + // console.log(res.data, '标准设备种类分析') + current5.data = [] for (const i in res.data) { - current.data.push({ name: i, count: res.data[i] }) + current5.data.push({ name: i, count: res.data[i] }) } - current.data.reverse() + current5.data.reverse() + current5.loading = false + }).catch(() => { + current5.loading = false }) // 设备维护保养情况 + const current6 = showChart.value.filter(item => item.name === '设备维护保养情况')[0] + current6.loading = true getDeviceMaintain({ ...searchQueryResult.value, offset: 1, limit: 9999 }).then((res) => { - console.log(res.data, '设备维护保养情况') - const current = showChart.value.filter( - item => item.name === '设备维护保养情况', - )[0] - current.data = [] - current.data = res.data.rows + // console.log(res.data, '设备维护保养情况') + current6.data = [] + current6.data = res.data.rows + current6.loading = false + }).catch(() => { + current6.loading = false }) // loading.value = true // // 近一年部门设备到期趋势 @@ -398,19 +426,16 @@ yearList.value.push(String(currentYear - i)) } -watch( - () => year.value, - (newVal) => { - if (newVal) { - console.log(newVal, '当前年度') - searchQueryResult.value.timeStart = `${newVal}-01-01` - searchQueryResult.value.timeEnd = `${newVal}-12-31` - setTimeout(() => { - fetchData() - }) - } - }, -) +watch(() => year.value, (newVal) => { + if (newVal) { + console.log(newVal, '当前年度') + searchQueryResult.value.timeStart = `${newVal}-01-01` + searchQueryResult.value.timeEnd = `${newVal}-12-31` + setTimeout(() => { + fetchData() + }) + } +}) onMounted(() => { year.value = String(currentYear) if (props.lab) { @@ -427,24 +452,14 @@
- - + +
-
+
@@ -461,156 +476,40 @@
- +