【类 型】:factor
【原 因】:多处通过重量判断是否挂有货物 改为主入口判断 解耦 【过 程】:1.飞机状态里面 增加一个是否挂有货物的状态字段 PS:判断重量状态更新 2.凡是之前通重量判断来更新图标状态的位置 全部改成判断 这个新字段来实现 【影 响】: # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
This commit is contained in:
parent
2f991d8934
commit
be9fb71e66
@ -918,13 +918,11 @@ export default {
|
|||||||
makePlane (plane, index = 0) {
|
makePlane (plane, index = 0) {
|
||||||
const customIcon = document.createElement('div')
|
const customIcon = document.createElement('div')
|
||||||
customIcon.className = 'custom-marker'
|
customIcon.className = 'custom-marker'
|
||||||
// 根据在线状态与载重显示不同图标,空值安全处理
|
// 根据在线状态与是否有货显示不同图标,空值安全处理
|
||||||
// 约定: online === false 才判定为离线;其他(包括 undefined/null) 默认为在线
|
// 约定: online === false 才判定为离线;其他(包括 undefined/null) 默认为在线
|
||||||
const isOnline = !((plane && plane.planeState && plane.planeState.online) === false)
|
const isOnline = !((plane && plane.planeState && plane.planeState.online) === false)
|
||||||
const lwRaw0 = plane && plane.planeState ? plane.planeState.loadweight : 0
|
const hasGoods = !!(plane && plane.planeState && plane.planeState.hasGoods)
|
||||||
const lwNum0 = Number(lwRaw0)
|
const iconToUse = !isOnline ? unlineIcon : (hasGoods ? planeRunIcon : planeIcon)
|
||||||
const loadWeight = Number.isFinite(lwNum0) ? lwNum0 : 0
|
|
||||||
const iconToUse = !isOnline ? unlineIcon : (loadWeight > 300 ? planeRunIcon : planeIcon)
|
|
||||||
// 使用 important 确保覆盖样式表中的背景图设置
|
// 使用 important 确保覆盖样式表中的背景图设置
|
||||||
customIcon.style.setProperty('background-image', `url(${iconToUse})`, 'important')
|
customIcon.style.setProperty('background-image', `url(${iconToUse})`, 'important')
|
||||||
customIcon.style.setProperty('background-repeat', 'no-repeat', 'important')
|
customIcon.style.setProperty('background-repeat', 'no-repeat', 'important')
|
||||||
@ -1111,18 +1109,16 @@ export default {
|
|||||||
if (!el) return
|
if (!el) return
|
||||||
// 约定: online === false 才判定为离线;其他(包括 undefined/null) 默认为在线
|
// 约定: online === false 才判定为离线;其他(包括 undefined/null) 默认为在线
|
||||||
const isOnline = !((stateObj && stateObj.online) === false)
|
const isOnline = !((stateObj && stateObj.online) === false)
|
||||||
const lwRaw = stateObj ? stateObj.loadweight : 0
|
const hasGoods = !!(stateObj && stateObj.hasGoods)
|
||||||
const lwNum = Number(lwRaw)
|
const iconToUse = !isOnline ? unlineIcon : (hasGoods ? planeRunIcon : planeIcon)
|
||||||
const loadWeight = Number.isFinite(lwNum) ? lwNum : 0
|
|
||||||
const iconToUse = !isOnline ? unlineIcon : (loadWeight > 300 ? planeRunIcon : planeIcon)
|
|
||||||
// 使用 important 确保覆盖样式表中的背景图设置
|
// 使用 important 确保覆盖样式表中的背景图设置
|
||||||
el.style.setProperty('background-image', `url(${iconToUse})`, 'important')
|
el.style.setProperty('background-image', `url(${iconToUse})`, 'important')
|
||||||
el.style.setProperty('background-repeat', 'no-repeat', 'important')
|
el.style.setProperty('background-repeat', 'no-repeat', 'important')
|
||||||
el.style.setProperty('background-size', 'contain', 'important')
|
el.style.setProperty('background-size', 'contain', 'important')
|
||||||
// 调试信息,观察状态与最终图标选择
|
// 调试信息,观察状态与最终图标选择
|
||||||
try {
|
try {
|
||||||
el.dataset.icon = !isOnline ? 'unline' : (loadWeight > 300 ? 'run' : 'normal')
|
el.dataset.icon = !isOnline ? 'unline' : (hasGoods ? 'run' : 'normal')
|
||||||
console.debug('[updatePlaneIcon]', { index, online: stateObj && stateObj.online, loadweight: lwRaw, parsedLoad: loadWeight, chosen: el.dataset.icon })
|
console.debug('[updatePlaneIcon]', { index, online: stateObj && stateObj.online, hasGoods, chosen: el.dataset.icon })
|
||||||
} catch (e) { /* noop */ }
|
} catch (e) { /* noop */ }
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -394,6 +394,7 @@ const store = new Vuex.Store({
|
|||||||
acceState: null, // 加速度计校准状态
|
acceState: null, // 加速度计校准状态
|
||||||
getPlaneMode: null, // 飞机模式
|
getPlaneMode: null, // 飞机模式
|
||||||
loadweight: null, // 重量
|
loadweight: null, // 重量
|
||||||
|
hasGoods: false, // 是否有货
|
||||||
hookstatus: null, // 钩子状态
|
hookstatus: null, // 钩子状态
|
||||||
position: [], // [[经度,维度,相对高度]]累计数组
|
position: [], // [[经度,维度,相对高度]]累计数组
|
||||||
battCapacity: null, // 电池容量
|
battCapacity: null, // 电池容量
|
||||||
|
|||||||
@ -50,10 +50,9 @@ export default {
|
|||||||
planeIconStates () {
|
planeIconStates () {
|
||||||
return this.planeList.map(plane => {
|
return this.planeList.map(plane => {
|
||||||
const s = plane.planeState || {}
|
const s = plane.planeState || {}
|
||||||
const n = Number(s.loadweight)
|
|
||||||
return {
|
return {
|
||||||
offline: s.online === false,
|
offline: s.online === false,
|
||||||
run: Number.isFinite(n) && n > 300
|
run: !!s.hasGoods
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@ -181,10 +181,9 @@ export default {
|
|||||||
*/
|
*/
|
||||||
planeIconState () {
|
planeIconState () {
|
||||||
const s = this.planeState || {}
|
const s = this.planeState || {}
|
||||||
const n = Number(s.loadweight)
|
|
||||||
return {
|
return {
|
||||||
offline: s.online === false,
|
offline: s.online === false,
|
||||||
run: Number.isFinite(n) && n > 300
|
run: !!s.hasGoods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -79,6 +79,20 @@ export default {
|
|||||||
return Array.isArray(posArr) ? posArr : []
|
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: 侧边栏显隐
|
* @description: 侧边栏显隐
|
||||||
*/
|
*/
|
||||||
@ -293,6 +307,20 @@ export default {
|
|||||||
},
|
},
|
||||||
deep: true
|
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: {
|
planePositions: {
|
||||||
handler (allPositions) {
|
handler (allPositions) {
|
||||||
|
|||||||
@ -223,6 +223,11 @@ export default {
|
|||||||
this.$store.dispatch('fetchLog', { content: `${plane.name}--${jsonData[key]}`, color: '#f57c00' })
|
this.$store.dispatch('fetchLog', { content: `${plane.name}--${jsonData[key]}`, color: '#f57c00' })
|
||||||
} else {
|
} else {
|
||||||
plane.planeState[key] = jsonData[key] // 按订阅信息 刷新飞机状态
|
plane.planeState[key] = jsonData[key] // 按订阅信息 刷新飞机状态
|
||||||
|
// 重量更新时,派生更新是否有货标记
|
||||||
|
if (key === 'loadweight') {
|
||||||
|
const n = Number(jsonData[key])
|
||||||
|
plane.planeState.hasGoods = Number.isFinite(n) && n > 300
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user