2023-01-29 15:26:45 +08:00
|
|
|
import { defineStore } from "pinia";
|
2024-06-15 18:32:36 +00:00
|
|
|
import { theme } from "ant-design-vue";
|
|
|
|
|
import _ from "lodash-es";
|
2023-01-29 15:26:45 +08:00
|
|
|
// @ts-ignore
|
|
|
|
|
import { LocalStorage } from "/src/utils/util.storage";
|
2024-06-16 02:47:41 +08:00
|
|
|
|
2024-08-05 12:49:44 +08:00
|
|
|
import * as basicApi from "/@/api/modules/api.basic";
|
2024-08-25 01:55:34 +08:00
|
|
|
import { SysInstallInfo, SysPublicSetting } from "/@/api/modules/api.basic";
|
2023-01-29 15:26:45 +08:00
|
|
|
|
2024-06-15 18:32:36 +00:00
|
|
|
export type ThemeToken = {
|
|
|
|
|
token: {
|
|
|
|
|
colorPrimary?: string;
|
|
|
|
|
};
|
|
|
|
|
algorithm: any;
|
|
|
|
|
};
|
|
|
|
|
export type ThemeConfig = {
|
|
|
|
|
colorPrimary: string;
|
|
|
|
|
mode: string;
|
|
|
|
|
};
|
|
|
|
|
export interface SettingState {
|
|
|
|
|
themeConfig?: ThemeConfig;
|
|
|
|
|
themeToken: ThemeToken;
|
2024-08-05 12:49:44 +08:00
|
|
|
sysPublic?: SysPublicSetting;
|
2024-08-25 01:55:34 +08:00
|
|
|
installInfo?: {
|
|
|
|
|
siteId: string;
|
|
|
|
|
};
|
2023-01-29 15:26:45 +08:00
|
|
|
}
|
|
|
|
|
|
2024-06-15 18:32:36 +00:00
|
|
|
const defaultThemeConfig = {
|
|
|
|
|
colorPrimary: "#1890ff",
|
|
|
|
|
mode: "light"
|
|
|
|
|
};
|
2023-01-29 15:26:45 +08:00
|
|
|
const SETTING_THEME_KEY = "SETTING_THEME";
|
|
|
|
|
export const useSettingStore = defineStore({
|
|
|
|
|
id: "app.setting",
|
|
|
|
|
state: (): SettingState => ({
|
2024-06-15 18:32:36 +00:00
|
|
|
themeConfig: null,
|
|
|
|
|
themeToken: {
|
|
|
|
|
token: {},
|
|
|
|
|
algorithm: theme.defaultAlgorithm
|
2024-06-16 02:47:41 +08:00
|
|
|
},
|
2024-06-16 00:20:02 +08:00
|
|
|
sysPublic: {
|
2024-08-05 12:49:44 +08:00
|
|
|
registerEnabled: false,
|
|
|
|
|
managerOtherUserPipeline: false
|
2024-08-25 01:55:34 +08:00
|
|
|
},
|
|
|
|
|
installInfo: {
|
|
|
|
|
siteId: ""
|
2024-06-16 00:20:02 +08:00
|
|
|
}
|
2023-01-29 15:26:45 +08:00
|
|
|
}),
|
|
|
|
|
getters: {
|
2024-06-15 18:32:36 +00:00
|
|
|
getThemeConfig(): any {
|
|
|
|
|
return this.themeConfig || _.merge({}, defaultThemeConfig, LocalStorage.get(SETTING_THEME_KEY) || {});
|
2024-06-16 00:20:02 +08:00
|
|
|
},
|
2024-08-05 12:49:44 +08:00
|
|
|
getSysPublic(): SysPublicSetting {
|
|
|
|
|
return this.sysPublic;
|
2024-08-25 01:55:34 +08:00
|
|
|
},
|
|
|
|
|
getInstallInfo(): SysInstallInfo {
|
|
|
|
|
return this.installInfo;
|
2023-01-29 15:26:45 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
2024-08-05 12:49:44 +08:00
|
|
|
async loadSysSettings() {
|
|
|
|
|
const settings = await basicApi.getSysPublicSettings();
|
|
|
|
|
_.merge(this.sysPublic, settings);
|
2024-08-25 01:55:34 +08:00
|
|
|
|
|
|
|
|
const installInfo = await basicApi.getInstallInfo();
|
|
|
|
|
_.merge(this.installInfo, installInfo);
|
2024-06-16 00:20:02 +08:00
|
|
|
},
|
2024-06-15 18:32:36 +00:00
|
|
|
persistThemeConfig() {
|
|
|
|
|
LocalStorage.set(SETTING_THEME_KEY, this.getThemeConfig);
|
2023-01-29 15:26:45 +08:00
|
|
|
},
|
2024-06-15 18:32:36 +00:00
|
|
|
async setThemeConfig(themeConfig?: ThemeConfig) {
|
|
|
|
|
this.themeConfig = _.merge({}, this.themeConfig, themeConfig);
|
|
|
|
|
|
|
|
|
|
this.persistThemeConfig();
|
|
|
|
|
this.setPrimaryColor(this.themeConfig.colorPrimary);
|
|
|
|
|
this.setDarkMode(this.themeConfig.mode);
|
|
|
|
|
},
|
|
|
|
|
setPrimaryColor(color: any) {
|
|
|
|
|
this.themeConfig.colorPrimary = color;
|
|
|
|
|
_.set(this.themeToken, "token.colorPrimary", color);
|
|
|
|
|
this.persistThemeConfig();
|
2023-01-29 15:26:45 +08:00
|
|
|
},
|
2024-06-15 18:32:36 +00:00
|
|
|
setDarkMode(mode: string) {
|
|
|
|
|
this.themeConfig.mode = mode;
|
|
|
|
|
if (mode === "dark") {
|
|
|
|
|
this.themeToken.algorithm = theme.darkAlgorithm;
|
|
|
|
|
// const defaultSeed = theme.defaultSeed;
|
|
|
|
|
// const mapToken = theme.darkAlgorithm(defaultSeed);
|
|
|
|
|
// less.modifyVars(mapToken);
|
|
|
|
|
// less.modifyVars({
|
|
|
|
|
// "@colorPrimaryBg": "#111a2c",
|
|
|
|
|
// colorPrimaryBg: "#111a2c"
|
|
|
|
|
// });
|
|
|
|
|
// less.refreshStyles();
|
|
|
|
|
} else {
|
|
|
|
|
this.themeToken.algorithm = theme.defaultAlgorithm;
|
|
|
|
|
|
|
|
|
|
// const defaultSeed = theme.defaultSeed;
|
|
|
|
|
// const mapToken = theme.defaultAlgorithm(defaultSeed);
|
|
|
|
|
// less.modifyVars(mapToken);
|
|
|
|
|
}
|
|
|
|
|
this.persistThemeConfig();
|
2023-01-29 15:26:45 +08:00
|
|
|
},
|
|
|
|
|
async init() {
|
2024-06-15 18:32:36 +00:00
|
|
|
await this.setThemeConfig(this.getThemeConfig);
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.loadSysSettings();
|
2023-01-29 15:26:45 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|