This commit is contained in:
xiaojunnuo
2024-09-24 02:42:08 +08:00
parent 154f627f2a
commit 92aa4a6d63
12 changed files with 169 additions and 11 deletions
@@ -1,11 +1,13 @@
import { defineStore } from "pinia";
import { theme } from "ant-design-vue";
import { Modal, theme } from "ant-design-vue";
import _ from "lodash-es";
// @ts-ignore
import { LocalStorage } from "/src/utils/util.storage";
import * as basicApi from "/@/api/modules/api.basic";
import { SysInstallInfo, SysPublicSetting } from "/@/api/modules/api.basic";
import { useUserStore } from "/@/store/modules/user";
import { mitter } from "/@/utils/util.mitt";
export type ThemeToken = {
token: {
@@ -24,6 +26,16 @@ export interface SettingState {
installInfo?: {
siteId: string;
installTime?: number;
bindUserId?: number;
bindUrl?: string;
accountServerBaseUrl?: string;
appKey?: string;
};
siteInfo?: {
TITLE: string;
SLOGAN: string;
LOGO: string;
ICP_NO: string;
};
}
@@ -45,7 +57,17 @@ export const useSettingStore = defineStore({
managerOtherUserPipeline: false
},
installInfo: {
siteId: ""
siteId: "",
bindUserId: null,
bindUrl: "",
accountServerBaseUrl: "",
appKey: ""
},
siteInfo: {
TITLE: "",
SLOGAN: "",
LOGO: "",
ICP_NO: ""
}
}),
getters: {
@@ -64,9 +86,59 @@ export const useSettingStore = defineStore({
const settings = await basicApi.getSysPublicSettings();
_.merge(this.sysPublic, settings);
const siteInfo = await basicApi.getSiteInfo();
_.merge(this.siteInfo, siteInfo);
await this.loadInstallInfo();
await this.checkUrlBound();
},
async loadInstallInfo() {
const installInfo = await basicApi.getInstallInfo();
_.merge(this.installInfo, installInfo);
},
async checkUrlBound() {
const userStore = useUserStore();
if (!userStore.isAdmin || !userStore.isPlus) {
return;
}
const bindUrl = this.installInfo.bindUrl;
function getBaseUrl() {
let url = window.location.href;
//只要hash前面的部分
url = url.split("#")[0];
return url;
}
const doBindUrl = async (url: string) => {
await basicApi.bindUrl({ url });
await this.loadInstallInfo();
};
const baseUrl = getBaseUrl();
if (!bindUrl) {
//绑定url
await doBindUrl(baseUrl);
} else {
//检查当前url 是否与绑定的url一致
const url = window.location.href;
if (!url.startsWith(bindUrl)) {
Modal.confirm({
title: "URL地址有变化",
content: "以后都用这个新地址访问本系统吗?",
onOk: async () => {
await doBindUrl(baseUrl);
},
okText: "是的,继续",
cancelText: "不是,回到原来的地址",
onCancel: () => {
window.location.href = bindUrl;
}
});
}
}
},
persistThemeConfig() {
LocalStorage.set(SETTING_THEME_KEY, this.getThemeConfig);
},
@@ -109,3 +181,7 @@ export const useSettingStore = defineStore({
}
}
});
mitter.on("app.login", async () => {
await useSettingStore().init();
});