refactor: 切换组织/工作空间/项目时添加loading
This commit is contained in:
parent
ba6f5d7072
commit
5b7d4d5d67
|
@ -154,7 +154,7 @@ export default {
|
||||||
this.isShow = true;
|
this.isShow = true;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
reloadTopMenus() {
|
reloadTopMenus(callback) {
|
||||||
this.$get("/isLogin").then(response => {
|
this.$get("/isLogin").then(response => {
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
this.$setLang(response.data.data.language);
|
this.$setLang(response.data.data.language);
|
||||||
|
@ -165,11 +165,17 @@ export default {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.isShow = true;
|
this.isShow = true;
|
||||||
this.isMenuShow = true;
|
this.isMenuShow = true;
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/login";
|
window.location.href = "/login";
|
||||||
}
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
window.location.href = "/login";
|
window.location.href = "/login";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,10 @@
|
||||||
:popper-append-to-body="true"
|
:popper-append-to-body="true"
|
||||||
:key="index">
|
:key="index">
|
||||||
<template v-slot:title>
|
<template v-slot:title>
|
||||||
<div @click="changeOrg(item)">
|
<el-menu-item @click="changeOrg(item)">
|
||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
<i class="el-icon-check" v-if="item.id === getCurrentOrganizationId()"></i>
|
<i class="el-icon-check" v-if="item.id === getCurrentOrganizationId()"></i>
|
||||||
</div>
|
</el-menu-item>
|
||||||
</template>
|
</template>
|
||||||
<el-input :placeholder="$t('project.search_by_name')"
|
<el-input :placeholder="$t('project.search_by_name')"
|
||||||
prefix-icon="el-icon-search"
|
prefix-icon="el-icon-search"
|
||||||
|
@ -55,7 +55,13 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {getCurrentOrganizationId, getCurrentUser, getCurrentWorkspaceId, saveLocalStorage} from "@/common/js/utils";
|
import {
|
||||||
|
fullScreenLoading,
|
||||||
|
getCurrentOrganizationId,
|
||||||
|
getCurrentUser,
|
||||||
|
getCurrentWorkspaceId,
|
||||||
|
saveLocalStorage, stopFullScreenLoading
|
||||||
|
} from "@/common/js/utils";
|
||||||
import {ORGANIZATION_ID, PROJECT_ID, WORKSPACE_ID} from "@/common/js/constants";
|
import {ORGANIZATION_ID, PROJECT_ID, WORKSPACE_ID} from "@/common/js/constants";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -166,6 +172,7 @@ export default {
|
||||||
if (!orgId) {
|
if (!orgId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const loading = fullScreenLoading(this);
|
||||||
this.$post("/user/switch/source/org/" + orgId, {}, response => {
|
this.$post("/user/switch/source/org/" + orgId, {}, response => {
|
||||||
saveLocalStorage(response);
|
saveLocalStorage(response);
|
||||||
|
|
||||||
|
@ -174,7 +181,7 @@ export default {
|
||||||
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
|
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
|
||||||
|
|
||||||
this.$router.push(this.getRedirectUrl(response.data)).then(() => {
|
this.$router.push(this.getRedirectUrl(response.data)).then(() => {
|
||||||
this.reloadTopMenus();
|
this.reloadTopMenus(stopFullScreenLoading(loading));
|
||||||
}).catch(err => err);
|
}).catch(err => err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -184,6 +191,7 @@ export default {
|
||||||
if (!workspaceId) {
|
if (!workspaceId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const loading = fullScreenLoading(this);
|
||||||
this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
|
this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
|
||||||
saveLocalStorage(response);
|
saveLocalStorage(response);
|
||||||
|
|
||||||
|
@ -192,7 +200,7 @@ export default {
|
||||||
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
|
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
|
||||||
|
|
||||||
this.$router.push(this.getRedirectUrl(response.data)).then(() => {
|
this.$router.push(this.getRedirectUrl(response.data)).then(() => {
|
||||||
this.reloadTopMenus();
|
this.reloadTopMenus(stopFullScreenLoading(loading));
|
||||||
}).catch(err => err);
|
}).catch(err => err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -27,11 +27,12 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {
|
import {
|
||||||
|
fullScreenLoading,
|
||||||
getCurrentProjectID,
|
getCurrentProjectID,
|
||||||
getCurrentUser,
|
getCurrentUser,
|
||||||
getCurrentUserId,
|
getCurrentUserId,
|
||||||
getCurrentWorkspaceId,
|
getCurrentWorkspaceId,
|
||||||
saveLocalStorage
|
saveLocalStorage, stopFullScreenLoading
|
||||||
} from "@/common/js/utils";
|
} from "@/common/js/utils";
|
||||||
import {mapGetters} from "vuex";
|
import {mapGetters} from "vuex";
|
||||||
import {PROJECT_ID} from "@/common/js/constants";
|
import {PROJECT_ID} from "@/common/js/constants";
|
||||||
|
@ -105,6 +106,7 @@ export default {
|
||||||
if (projectId === currentProjectId) {
|
if (projectId === currentProjectId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const loading = fullScreenLoading(this);
|
||||||
this.$post("/user/update/current", {id: this.userId, lastProjectId: projectId}, (response) => {
|
this.$post("/user/update/current", {id: this.userId, lastProjectId: projectId}, (response) => {
|
||||||
saveLocalStorage(response);
|
saveLocalStorage(response);
|
||||||
this.currentProjectId = projectId;
|
this.currentProjectId = projectId;
|
||||||
|
@ -114,8 +116,10 @@ export default {
|
||||||
sessionStorage.setItem(PROJECT_ID, projectId);
|
sessionStorage.setItem(PROJECT_ID, projectId);
|
||||||
// 刷新路由
|
// 刷新路由
|
||||||
this.reload();
|
this.reload();
|
||||||
|
stopFullScreenLoading(loading, 1500);
|
||||||
this.changeProjectName(projectId);
|
this.changeProjectName(projectId);
|
||||||
|
}, () => {
|
||||||
|
stopFullScreenLoading(loading, 1500);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
changeProjectName(projectId) {
|
changeProjectName(projectId) {
|
||||||
|
|
|
@ -289,3 +289,11 @@ textarea {
|
||||||
border-color: #409EFF;
|
border-color: #409EFF;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ms-full-loading .el-loading-text {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-full-loading .el-loading-spinner {
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
|
@ -508,3 +508,20 @@ export function getNodePath(id, moduleOptions) {
|
||||||
export function getDefaultTableHeight() {
|
export function getDefaultTableHeight() {
|
||||||
return document.documentElement.clientHeight - 200;
|
return document.documentElement.clientHeight - 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fullScreenLoading(component) {
|
||||||
|
return component.$loading({
|
||||||
|
lock: true,
|
||||||
|
text: '资源切换中...',
|
||||||
|
spinner: 'el-icon-loading',
|
||||||
|
background: 'rgba(246,241,241,0.6)',
|
||||||
|
customClass: 'ms-full-loading'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stopFullScreenLoading(loading, timeout) {
|
||||||
|
timeout = timeout ? timeout : 2000;
|
||||||
|
setTimeout(() => {
|
||||||
|
loading.close();
|
||||||
|
}, timeout);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue