fix: Fix node ip switch exception issue (#9874)

This commit is contained in:
ssongliu 2025-08-06 12:12:19 +08:00 committed by GitHub
parent b10de66ed3
commit 483b47ad63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 58 additions and 18 deletions

View file

@ -7,6 +7,7 @@ import { GlobalStore } from '@/store';
import { MsgError } from '@/utils/message';
import { Base64 } from 'js-base64';
import i18n from '@/lang';
import { changeToLocal } from '@/utils/node';
const globalStore = GlobalStore();
@ -66,7 +67,7 @@ class RequestHttp {
return Promise.reject(data);
}
if (data.code == ResultEnum.NodeUnBind) {
globalStore.currentNode = 'local';
changeToLocal();
window.location.reload();
return;
}

View file

@ -40,7 +40,7 @@
v-for="item in nodeOptions"
:key="item.name"
>
<div class="node">
<div class="node" v-if="item.name !== 'local'">
{{ item.name }}
<el-tooltip
v-if="item.status !== 'Healthy' || !item.isBound"
@ -89,6 +89,7 @@ import { logOutApi } from '@/api/modules/auth';
import router from '@/routers';
import { loadProductProFromDB } from '@/utils/xpack';
import { routerToNameWithQuery } from '@/utils/router';
import { setDefaultNodeInfo } from '@/utils/node';
const filter = ref();
const globalStore = GlobalStore();
@ -148,20 +149,21 @@ const loadNodes = async () => {
loading.value = true;
nodes.value = [];
if (!isMasterPro.value) {
globalStore.currentNode = 'local';
setDefaultNodeInfo();
loading.value = false;
return;
}
await listNodeOptions('')
await listNodeOptions('all')
.then((res) => {
if (!res) {
nodes.value = [];
setDefaultNodeInfo();
loading.value = false;
return;
}
nodes.value = res.data || [];
if (nodes.value.length === 0) {
globalStore.currentNode = 'local';
setDefaultNodeInfo();
}
nodeOptions.value = nodes.value || [];
loading.value = false;
@ -175,15 +177,15 @@ const changeNode = (command: string) => {
if (globalStore.currentNode === command) {
return;
}
if (command == 'local') {
globalStore.currentNode = command || 'local';
globalStore.currentNodeAddr = '';
loadProductProFromDB();
routerToNameWithQuery('home', { t: Date.now() });
return;
}
for (const item of nodes.value) {
if (item.name == command) {
if (command == 'local') {
globalStore.currentNode = 'local';
globalStore.currentNodeAddr = item.addr;
loadProductProFromDB();
routerToNameWithQuery('home', { t: Date.now() });
return;
}
if (!item.isBound) {
MsgError(i18n.global.t('xpack.node.nodeUnbindHelper'));
return;

View file

@ -0,0 +1,38 @@
import { listNodeOptions } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();
export const changeToLocal = async () => {
if (!globalStore.isMasterPro) {
setDefaultNodeInfo();
return;
}
await listNodeOptions('all')
.then((res) => {
if (!res) {
setDefaultNodeInfo();
return;
}
let nodes = res.data || [];
if (nodes.length === 0) {
setDefaultNodeInfo();
return;
}
for (const item of nodes) {
if (item.name === 'local') {
globalStore.currentNode = 'local';
globalStore.currentNodeAddr = item.addr;
return;
}
}
})
.catch(() => {
setDefaultNodeInfo();
});
};
export const setDefaultNodeInfo = () => {
globalStore.currentNode = 'local';
globalStore.currentNodeAddr = '';
};

View file

@ -172,9 +172,6 @@ const loadNodes = async () => {
return;
}
nodes.value = res.data || [];
if (nodes.value.length === 0) {
globalStore.currentNode = 'local';
}
})
.catch(() => {
nodes.value = [];

View file

@ -190,6 +190,7 @@ import { useI18n } from 'vue-i18n';
import { encryptPassword } from '@/utils/util';
import { getXpackSettingForTheme } from '@/utils/xpack';
import { routerToName } from '@/utils/router';
import { changeToLocal } from '@/utils/node';
const i18n = useI18n();
const themeConfig = computed(() => globalStore.themeConfig);
@ -343,7 +344,7 @@ const login = (formEl: FormInstance | undefined) => {
globalStore.setAgreeLicense(true);
menuStore.setMenuList([]);
tabsStore.removeAllTabs();
globalStore.currentNode = 'local';
changeToLocal();
MsgSuccess(i18n.t('commons.msg.loginSuccess'));
routerToName('home');
document.onkeydown = null;
@ -385,7 +386,7 @@ const mfaLogin = async (auto: boolean) => {
menuStore.setMenuList([]);
tabsStore.removeAllTabs();
MsgSuccess(i18n.t('commons.msg.loginSuccess'));
globalStore.currentNode = 'local';
changeToLocal();
routerToName('home');
document.onkeydown = null;
} catch (res) {

View file

@ -53,6 +53,7 @@ import { ElMessageBox, FormInstance } from 'element-plus';
import { Rules } from '@/global/form-rules';
import { GlobalStore } from '@/store';
import { loadTimeZoneOptions, updateDevice } from '@/api/modules/toolbox';
import { changeToLocal } from '@/utils/node';
const globalStore = GlobalStore();
interface DialogProps {
@ -105,7 +106,7 @@ const onSave = async (formEl: FormInstance | undefined) => {
let href = window.location.href;
window.open(href, '_self');
} else {
globalStore.currentNode = 'local';
changeToLocal();
location.reload();
}
})