重构
This commit is contained in:
@ -27,10 +27,6 @@
|
||||
prop="siteId"
|
||||
label="站点ID">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="siteName"
|
||||
label="站点名称">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="deviceId"
|
||||
label="设备ID"
|
||||
@ -111,6 +107,17 @@ export default {
|
||||
}
|
||||
this.siteId = normalizedSiteId
|
||||
this.onSearch()
|
||||
},
|
||||
'$route.query.siteName'(newSiteName) {
|
||||
const normalizedSiteName = this.getSelectedSiteName(newSiteName)
|
||||
if (normalizedSiteName === this.selectedSiteName) {
|
||||
return
|
||||
}
|
||||
this.selectedSiteName = normalizedSiteName
|
||||
this.tableData = (this.tableData || []).map(item => ({
|
||||
...item,
|
||||
siteName: normalizedSiteName
|
||||
}))
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@ -119,6 +126,7 @@ export default {
|
||||
mode: '',//新增、编辑设备
|
||||
editDeviceId: '',//编辑设备id
|
||||
siteId: '',
|
||||
selectedSiteName: '',
|
||||
deviceCategory: '',//搜索栏设备类型
|
||||
deviceCategoryList: [],//设备类别
|
||||
tableData: [],
|
||||
@ -153,6 +161,17 @@ export default {
|
||||
hasValidSiteId(siteId) {
|
||||
return !!(siteId !== undefined && siteId !== null && String(siteId).trim())
|
||||
},
|
||||
getSelectedSiteName(routeSiteName) {
|
||||
const name = routeSiteName === undefined || routeSiteName === null ? '' : String(routeSiteName).trim()
|
||||
if (name) {
|
||||
return name
|
||||
}
|
||||
const matchedSite = (this.$store.getters.zdList || []).find(item => item.siteId === this.siteId)
|
||||
if (matchedSite && matchedSite.siteName) {
|
||||
return matchedSite.siteName
|
||||
}
|
||||
return this.siteId || ''
|
||||
},
|
||||
// 获取设备类别
|
||||
getDeviceCategoryList() {
|
||||
getAllDeviceCategory().then(response => {
|
||||
@ -259,7 +278,12 @@ export default {
|
||||
this.loading = true
|
||||
const {siteId, deviceCategory, pageNum, pageSize} = this
|
||||
getDeviceInfoList({siteId, deviceCategory, pageNum, pageSize}).then(response => {
|
||||
this.tableData = response?.rows || [];
|
||||
const selectedSiteName = this.getSelectedSiteName(this.$route.query.siteName)
|
||||
this.selectedSiteName = selectedSiteName
|
||||
this.tableData = (response?.rows || []).map(item => ({
|
||||
...item,
|
||||
siteName: selectedSiteName
|
||||
}));
|
||||
this.totalSize = response?.total || 0
|
||||
}).finally(() => {
|
||||
this.loading = false
|
||||
@ -268,6 +292,7 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
this.siteId = this.hasValidSiteId(this.$route.query.siteId) ? String(this.$route.query.siteId).trim() : ''
|
||||
this.selectedSiteName = this.getSelectedSiteName(this.$route.query.siteName)
|
||||
this.pageNum = 1//每次搜索从1开始搜索
|
||||
this.getDeviceCategoryList()
|
||||
this.getData()
|
||||
|
||||
Reference in New Issue
Block a user