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

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

@@ -20,7 +20,7 @@
<el-dropdown-item divided @click.native='handleToggle'>切换账号</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-button type="text" class="return-btn" :title="'返回'" @click="handleReturn">
<el-button type="text" class="return-btn" :title="'返回'" v-if="showReturnBtn" @click="handleReturn">
<svg-icon style="color: #0B58FF;" icon-class="returnIcon" />
</el-button>
<el-button type="text" class="screen-btn" :title="isFullScreen ? '退出全屏' : '全屏'" @click="changeFullScreen">
@@ -46,6 +46,7 @@
import { mapGetters } from 'vuex'
import moment from 'moment'; // 引入moment
import {getPath} from "@/utils/ruoyi";
import { getNavStackLength, popNavigation } from '@/utils/navigationReturnState';
export default {
name: 'Header',
props: {
@@ -67,12 +68,30 @@ export default {
timeTimer: null,
date: Date.now(), // 使用当前时间戳作为初始值
activeTime: 1, // 默认月维度0=日1=月2=年)
navStackLength: 0,
}
},
computed:{
...mapGetters(['nickname']),
showReturnBtn() {
return this.navStackLength > 0;
}
},
watch: {
// 监听菜单参数变化,菜单进入时立即更新
'$route.query.menu': {
immediate: true,
handler(menuFlag) {
if (menuFlag === '1') {
this.$nextTick(() => {
this.updateNavStackLength();
});
}
}
},
$route() {
this.updateNavStackLength();
},
activeTime(newVal, oldVal) {
if (newVal !== oldVal) {
this.date = Date.now();
@@ -95,10 +114,18 @@ export default {
}
},
mounted() {
// 初始化默认日期为当前月份
console.log('初始化日期选择器,当前时间戳:', this.date);
// 初始化导航栈长度
this.updateNavStackLength();
// 监听导航清空事件
window.addEventListener('navigation-cleared', this.handleNavigationCleared);
this.$nextTick(() => {
this.emitTimeRange();
const hasRange =
this.dateData &&
((this.dateData.startTime != null && this.dateData.startTime !== 0) ||
(this.dateData.endTime != null && this.dateData.endTime !== 0));
if (!hasRange) {
this.emitTimeRange();
}
});
},
beforeDestroy() {
@@ -106,15 +133,32 @@ export default {
if (this.timeTimer) {
clearInterval(this.timeTimer);
}
// 移除导航清空事件监听
window.removeEventListener('navigation-cleared', this.handleNavigationCleared);
},
methods: {
// 处理导航清空事件
handleNavigationCleared() {
this.updateNavStackLength();
},
// 更新导航栈长度
updateNavStackLength() {
this.navStackLength = getNavStackLength();
},
changeFullScreen() {
this.$emit('screenfullChange');
},
handleReturn() {
console.log('返回上一页');
if (this.$router) {
this.$router.go(-1);
// 出栈获取前一个页面信息
const prev = popNavigation();
if (prev && prev.path) {
// 有前一个页面跳转到该页面showReturnBtn 会自动从 sessionStorage 读取最新值)
this.$router.push(prev.path);
} else {
// 没有前一个页面,使用默认返回
this.$router.go(-1);
}
}
},
async logout() {