页面路由跳转返回后数据回显,记住原先的状态

This commit is contained in:
2026-05-12 08:57:26 +08:00
parent c2b64d5e22
commit ad1cbee74a
164 changed files with 5150 additions and 2246 deletions

View File

@@ -26,7 +26,7 @@ import bgBaseTongcheng from '@/assets/images/bgBase/桐城.png';
import bgBaseLuoyang from '@/assets/images/bgBase/洛阳.png';
import bgBaseHefei from '@/assets/images/bgBase/合肥.png';
import bgBaseSuqian from '@/assets/images/bgBase/宿迁.png';
import bgBaseQinhuangdao from '@/assets/images/bgBase/秦皇岛.png';// 补充:江苏
import bgBaseQinhuangdao from '@/assets/images/bgBase/秦皇岛.png';
export default {
name: "BaseSelector",
@@ -34,13 +34,11 @@ export default {
factory: {
type: [String, Number],
default: undefined,
validator: (val) => [5, 2, 7, 3, 8, 9, 10, 6].includes(val) // 校验序号范围匹配新的baseNameToIndexMap
validator: (val) => [5, 2, 7, 3, 8, 9, 10, 6].includes(val)
}
},
// 计算属性响应式levelList变化时会自动更新
computed: {
buttonLevelList() {
// 核心:通过$store.getters获取定义的getter
let arr = []
this.$store.getters.levelList.forEach(item => {
this.buttonList.forEach(item2 => {
@@ -49,7 +47,12 @@ export default {
}
})
})
this.activeButton = arr[0].id
const validIds = [5, 2, 7, 3, 8, 9, 10, 6]
if (this.factory != null && validIds.includes(Number(this.factory))) {
this.activeButton = Number(this.factory)
} else if (arr.length > 0) {
this.activeButton = arr[0].id
}
return arr
}
},
@@ -69,22 +72,13 @@ export default {
};
},
watch: {
// 监听父组件传递的factory变化同步本地选中索引
factory: {
handler(newVal) {
console.log('watch factory=======================:', newVal);
if (newVal) {
this.activeButton = newVal;
if (newVal != null) {
this.activeButton = Number(newVal);
}
// // 根据新的baseNameToIndexMap找到对应的基地名称
// const targetName = Object.keys(this.baseNameToIndexMap).find(name => this.baseNameToIndexMap[name] === newVal);
// // 根据名称找到buttonList中的索引
// const targetIndex = this.buttonList.indexOf(targetName);
// // 合法索引则更新,否则默认选中宜兴
// this.activeButton = targetIndex > -1 ? targetIndex : 2;
// console.log('当前选中基地:', this.buttonList[this.activeButton], '序号:', newVal);
},
// immediate: true // 初始化立即执行
immediate: true
}
},
methods: {
@@ -92,10 +86,6 @@ export default {
this.activeButton = id;
this.$emit('baseChange', id);
}
},
mounted() {
// 初始化时触发事件传递默认选中的宜兴序号7
// this.$emit('baseChange', 5);
}
};
</script>
@@ -115,7 +105,7 @@ export default {
text-align: center;
cursor: pointer;
white-space: nowrap;
margin-right: -35px; // 重叠效果,可根据需求调整
margin-right: -35px;
transition: all 0.2s ease;
&:hover,