refactor: 切换项目时不刷新页面

This commit is contained in:
Captain.B 2021-06-05 17:50:04 +08:00 committed by 刘瑞斌
parent fd532cc0d6
commit 261acc98f4
2 changed files with 29 additions and 23 deletions

View File

@ -19,7 +19,7 @@
</el-col> </el-col>
</el-row> </el-row>
<ms-view/> <ms-view v-if="isShow"/>
<theme/> <theme/>
</el-col> </el-col>
@ -52,6 +52,7 @@ export default {
logoId: '_blank', logoId: '_blank',
color: '', color: '',
sessionTimer: null, sessionTimer: null,
isShow: true,
}; };
}, },
created() { created() {
@ -102,6 +103,12 @@ export default {
window.location.href = "/login"; window.location.href = "/login";
}); });
}, },
//
provide() {
return {
reload: this.reload
}
},
methods: { methods: {
initSessionTimer() { initSessionTimer() {
this.$get('/system/timeout') this.$get('/system/timeout')
@ -137,6 +144,15 @@ export default {
this.$refs.headerUser.logout(); this.$refs.headerUser.logout();
}, 1000 * timeout); }, 1000 * timeout);
}, },
reload() {
//
this.isShow = false
// $nextTick() DOM
this.$nextTick(() => {
this.isShow = true
})
}
}, },
components: { components: {
MsLanguageSwitch, MsLanguageSwitch,

View File

@ -26,8 +26,7 @@
</template> </template>
<script> <script>
import {getCurrentProjectID, getCurrentUser, getCurrentUserId, hasRoles} from "@/common/js/utils"; import {getCurrentProjectID, getCurrentUser, getCurrentUserId, saveLocalStorage} from "@/common/js/utils";
import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "@/common/js/constants";
import {mapGetters} from "vuex"; import {mapGetters} from "vuex";
export default { export default {
@ -39,14 +38,14 @@ export default {
created() { created() {
this.init(); this.init();
}, },
inject: [
'reload'
],
computed: { computed: {
...mapGetters([ ...mapGetters([
'isNewVersion', 'isNewVersion',
'isOldVersion', 'isOldVersion',
]), ]),
currentProjectId() {
return localStorage.getItem(PROJECT_ID)
}
}, },
data() { data() {
return { return {
@ -55,6 +54,7 @@ export default {
searchArray: [], searchArray: [],
searchString: '', searchString: '',
userId: getCurrentUser().id, userId: getCurrentUser().id,
currentProjectId: getCurrentProjectID(),
} }
}, },
watch: { watch: {
@ -64,7 +64,7 @@ export default {
}, },
methods: { methods: {
init: function () { init: function () {
this.result = this.$post("/project/list/related",{userId: getCurrentUserId()}, response => { this.result = this.$post("/project/list/related", {userId: getCurrentUserId()}, response => {
this.items = response.data; this.items = response.data;
this.searchArray = response.data; this.searchArray = response.data;
let projectId = getCurrentProjectID(); let projectId = getCurrentProjectID();
@ -94,22 +94,12 @@ export default {
if (projectId === currentProjectId) { if (projectId === currentProjectId) {
return; return;
} }
this.$post("/user/update/current", {id: this.userId, lastProjectId: projectId}, () => { this.$post("/user/update/current", {id: this.userId, lastProjectId: projectId}, (response) => {
localStorage.setItem(PROJECT_ID, projectId); saveLocalStorage(response);
this.$store.commit('setProjectId', projectId); this.currentProjectId = projectId;
let path = this.$route.matched[0].path ? this.$route.matched[0].path : '/'; //
if (path === '/api') { this.reload();
if (this.isNewVersion) {
path = "/api/home";
} else if (this.isOldVersion) {
path = "/api/home_obsolete";
} else {
path = '/';
}
}
this.$router.push(path).then(() => {
window.location.reload()
}).catch(err => err);
this.changeProjectName(projectId); this.changeProjectName(projectId);
}); });
}, },