【类 型】:factor

【原  因】:多处通过重量判断是否挂有货物 改为主入口判断 解耦
【过  程】:1.飞机状态里面 增加一个是否挂有货物的状态字段 PS:判断重量状态更新 2.凡是之前通重量判断来更新图标状态的位置 全部改成判断 这个新字段来实现
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
air 2025-09-18 16:51:38 +08:00
parent 2f991d8934
commit be9fb71e66
6 changed files with 43 additions and 15 deletions

View File

@ -918,13 +918,11 @@ export default {
makePlane (plane, index = 0) {
const customIcon = document.createElement('div')
customIcon.className = 'custom-marker'
// 线
// 线
// : online === false 线( undefined/null) 线
const isOnline = !((plane && plane.planeState && plane.planeState.online) === false)
const lwRaw0 = plane && plane.planeState ? plane.planeState.loadweight : 0
const lwNum0 = Number(lwRaw0)
const loadWeight = Number.isFinite(lwNum0) ? lwNum0 : 0
const iconToUse = !isOnline ? unlineIcon : (loadWeight > 300 ? planeRunIcon : planeIcon)
const hasGoods = !!(plane && plane.planeState && plane.planeState.hasGoods)
const iconToUse = !isOnline ? unlineIcon : (hasGoods ? planeRunIcon : planeIcon)
// 使 important
customIcon.style.setProperty('background-image', `url(${iconToUse})`, 'important')
customIcon.style.setProperty('background-repeat', 'no-repeat', 'important')
@ -1111,18 +1109,16 @@ export default {
if (!el) return
// : online === false 线( undefined/null) 线
const isOnline = !((stateObj && stateObj.online) === false)
const lwRaw = stateObj ? stateObj.loadweight : 0
const lwNum = Number(lwRaw)
const loadWeight = Number.isFinite(lwNum) ? lwNum : 0
const iconToUse = !isOnline ? unlineIcon : (loadWeight > 300 ? planeRunIcon : planeIcon)
const hasGoods = !!(stateObj && stateObj.hasGoods)
const iconToUse = !isOnline ? unlineIcon : (hasGoods ? planeRunIcon : planeIcon)
// 使 important
el.style.setProperty('background-image', `url(${iconToUse})`, 'important')
el.style.setProperty('background-repeat', 'no-repeat', 'important')
el.style.setProperty('background-size', 'contain', 'important')
//
try {
el.dataset.icon = !isOnline ? 'unline' : (loadWeight > 300 ? 'run' : 'normal')
console.debug('[updatePlaneIcon]', { index, online: stateObj && stateObj.online, loadweight: lwRaw, parsedLoad: loadWeight, chosen: el.dataset.icon })
el.dataset.icon = !isOnline ? 'unline' : (hasGoods ? 'run' : 'normal')
console.debug('[updatePlaneIcon]', { index, online: stateObj && stateObj.online, hasGoods, chosen: el.dataset.icon })
} catch (e) { /* noop */ }
},
/**

View File

@ -394,6 +394,7 @@ const store = new Vuex.Store({
acceState: null, // 加速度计校准状态
getPlaneMode: null, // 飞机模式
loadweight: null, // 重量
hasGoods: false, // 是否有货
hookstatus: null, // 钩子状态
position: [], // [[经度,维度,相对高度]]累计数组
battCapacity: null, // 电池容量

View File

@ -50,10 +50,9 @@ export default {
planeIconStates () {
return this.planeList.map(plane => {
const s = plane.planeState || {}
const n = Number(s.loadweight)
return {
offline: s.online === false,
run: Number.isFinite(n) && n > 300
run: !!s.hasGoods
}
})
},

View File

@ -181,10 +181,9 @@ export default {
*/
planeIconState () {
const s = this.planeState || {}
const n = Number(s.loadweight)
return {
offline: s.online === false,
run: Number.isFinite(n) && n > 300
run: !!s.hasGoods
}
}
},

View File

@ -79,6 +79,20 @@ export default {
return Array.isArray(posArr) ? posArr : []
})
},
/**
* @description: 派生出与图标选择强相关的轻量状态供独立 watcher 监控
* offline: 是否离线run: 载重是否超过阈值>300
*/
planeIconStates () {
return this.planeList.map(plane => {
const s = plane.planeState || {}
const n = Number(s.loadweight)
return {
offline: s.online === false,
run: Number.isFinite(n) && n > 300
}
})
},
/**
* @description: 侧边栏显隐
*/
@ -293,6 +307,20 @@ export default {
},
deep: true
},
// DOM
planeIconStates: {
handler (val, oldVal) {
val.forEach((iconState, index) => {
const prev = Array.isArray(oldVal) ? oldVal[index] : undefined
const changed = !prev || prev.offline !== iconState.offline || prev.run !== iconState.run
if (changed) {
const stateObj = this.planeList[index].planeState || {}
this.$refs.mapbox.updatePlaneIcon(stateObj, index)
}
})
},
deep: true
},
//
planePositions: {
handler (allPositions) {

View File

@ -223,6 +223,11 @@ export default {
this.$store.dispatch('fetchLog', { content: `${plane.name}--${jsonData[key]}`, color: '#f57c00' })
} else {
plane.planeState[key] = jsonData[key] //
//
if (key === 'loadweight') {
const n = Number(jsonData[key])
plane.planeState.hasGoods = Number.isFinite(n) && n > 300
}
}
}
} catch (error) {