Refactor axios.js and Vue components to conditionally handle namespace settings based on server provider. Update request headers in axios.js to include site key and namespace password only for specific providers. Enhance NamespaceAccess and NamespaceSettingsCard components to show/hide based on provider, and streamline password management functionality.

This commit is contained in:
SunWuyuan
2025-05-18 15:09:10 +08:00
parent 31cff8a867
commit 4691114f9b
5 changed files with 153 additions and 24 deletions
+14 -10
View File
@@ -13,17 +13,21 @@ const axiosInstance = axios.create({
// 请求拦截器
axiosInstance.interceptors.request.use(
(requestConfig) => {
// 确保每次请求时都获取最新的 siteKey
const siteKey = getSetting("server.siteKey");
if (siteKey) {
requestConfig.headers["x-site-key"] = Base64.encode(siteKey);
}
const provider = getSetting("server.provider");
// 自动添加命名空间密码
const namespacePassword = getSetting("namespace.password");
if (namespacePassword) {
requestConfig.headers["x-namespace-password"] =
Base64.encode(namespacePassword);
// 只有在 kv-server 或 classworkscloud 模式下才添加请求头
if (provider === "kv-server" || provider === "classworkscloud") {
// 确保每次请求时都获取最新的 siteKey
const siteKey = getSetting("server.siteKey");
if (siteKey) {
requestConfig.headers["x-site-key"] = Base64.encode(siteKey);
}
// 自动添加命名空间密码
const namespacePassword = getSetting("namespace.password");
if (namespacePassword) {
requestConfig.headers["x-namespace-password"] = Base64.encode(namespacePassword);
}
}
return requestConfig;