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

View File

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