Files
1Panel/frontend/src/utils/node.ts
T
ssongliu 75258bb465 fix: tighten frontend RBAC permission guards (#12717)
* fix: tighten frontend RBAC permission guards

* feat: add permission directive coverage

* refactor frontend global store usage
2026-05-21 12:39:47 +08:00

45 lines
1.3 KiB
Go

import { Setting } from '@/api/interface/setting';
import { listNodeOptions, loadNodeByUser } from '@/api/modules/setting';
import { useGlobalStore } from '@/composables/useGlobalStore';
export const changeToLocal = async () => {
const { currentNode, currentNodeAddr, isAdmin } = useGlobalStore();
let nodes = await listNodes('all');
if (nodes.length === 0) {
setDefaultNodeInfo();
return;
}
if (isAdmin.value) {
for (const item of nodes) {
if (item.name === 'local') {
currentNode.value = 'local';
currentNodeAddr.value = item.addr;
return;
}
}
}
currentNode.value = nodes[0].name;
currentNodeAddr.value = nodes[0].addr;
};
export async function listNodes(type: string): Promise<Array<Setting.NodeItem>> {
const { isAdmin } = useGlobalStore();
try {
if (isAdmin.value) {
const res = await listNodeOptions(type);
return res.data || [];
} else {
const res = await loadNodeByUser();
return res.data || [];
}
} catch (error) {
return [];
}
}
export const setDefaultNodeInfo = () => {
const { currentNode, currentNodeAddr } = useGlobalStore();
currentNode.value = 'local';
currentNodeAddr.value = '127.0.0.1';
};