Files
ai_academy/miniprogram/utils/config.js
T
runny 7ec21f35b0 chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
2026-11-16 18:12:23 +08:00

55 lines
1.4 KiB
JavaScript

const STORAGE_KEY = "academy_settings";
function normalizeBaseUrl(baseUrl) {
if (!baseUrl || typeof baseUrl !== "string") {
return "";
}
return baseUrl.trim().replace(/\/+$/, "");
}
function normalizeLocale(locale) {
return locale === "en" ? "en" : "zh";
}
function getSettings() {
const stored = wx.getStorageSync(STORAGE_KEY) || {};
return {
baseUrl: normalizeBaseUrl(stored.baseUrl || ""),
apiKey: stored.apiKey || "",
selectedKnowledgeBaseId: stored.selectedKnowledgeBaseId || "",
locale: normalizeLocale(stored.locale || "zh")
};
}
function saveSettings(settings) {
const current = getSettings();
const nextBaseUrl =
settings.baseUrl !== undefined && settings.baseUrl !== null
? settings.baseUrl
: current.baseUrl;
const nextLocale =
settings.locale !== undefined && settings.locale !== null
? settings.locale
: current.locale;
const next = {
baseUrl: normalizeBaseUrl(nextBaseUrl),
apiKey: settings.apiKey !== undefined ? settings.apiKey : current.apiKey,
selectedKnowledgeBaseId:
settings.selectedKnowledgeBaseId !== undefined
? settings.selectedKnowledgeBaseId
: current.selectedKnowledgeBaseId,
locale: normalizeLocale(nextLocale)
};
wx.setStorageSync(STORAGE_KEY, next);
return next;
}
module.exports = {
STORAGE_KEY,
getSettings,
normalizeBaseUrl,
normalizeLocale,
saveSettings
};