feat(miniprogram): add WeChat mini program plugin

This commit is contained in:
wolfkill
2026-04-27 16:08:22 +08:00
committed by lyingbug
parent d55b52652c
commit d06111e5f7
27 changed files with 705 additions and 6 deletions
+36
View File
@@ -0,0 +1,36 @@
const STORAGE_KEY = "weknora_settings";
function normalizeBaseUrl(baseUrl) {
if (!baseUrl || typeof baseUrl !== "string") {
return "";
}
return baseUrl.trim().replace(/\/+$/, "");
}
function getSettings() {
const stored = wx.getStorageSync(STORAGE_KEY) || {};
return {
baseUrl: normalizeBaseUrl(stored.baseUrl || ""),
apiKey: stored.apiKey || "",
selectedKnowledgeBaseId: stored.selectedKnowledgeBaseId || ""
};
}
function saveSettings(settings) {
const current = getSettings();
const next = {
...current,
...settings,
baseUrl: normalizeBaseUrl(settings.baseUrl ?? current.baseUrl)
};
wx.setStorageSync(STORAGE_KEY, next);
return next;
}
module.exports = {
STORAGE_KEY,
getSettings,
normalizeBaseUrl,
saveSettings
};