feat: 站点个性化设置

This commit is contained in:
xiaojunnuo
2024-10-05 01:46:25 +08:00
parent ce9a9862f1
commit 11a9fe9014
57 changed files with 710 additions and 763 deletions
@@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import { Modal, theme } from "ant-design-vue";
import { Modal, notification, theme } from "ant-design-vue";
import _ from "lodash-es";
// @ts-ignore
import { LocalStorage } from "/src/utils/util.storage";
@@ -8,6 +8,8 @@ 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";
import { env } from "/@/utils/util.env";
import { toRef } from "vue";
export type ThemeToken = {
token: {
@@ -31,11 +33,26 @@ export interface SettingState {
accountServerBaseUrl?: string;
appKey?: string;
};
siteInfo?: {
title: string;
slogan: string;
logo: string;
};
siteInfo: SiteInfo;
plusInfo?: PlusInfo;
}
export type SiteInfo = {
title: string;
slogan: string;
logo: string;
loginLogo: string;
warningOff: boolean;
icpNo: string;
licenseTo?: string;
licenseToUrl?: string;
};
interface PlusInfo {
vipType?: string;
expireTime?: number;
isPlus: boolean;
isComm?: boolean;
}
const defaultThemeConfig = {
@@ -43,6 +60,16 @@ const defaultThemeConfig = {
mode: "light"
};
const SETTING_THEME_KEY = "SETTING_THEME";
const defaultSiteInfo = {
title: env.TITLE || "Certd",
slogan: env.SLOGAN || "让你的证书永不过期",
logo: env.LOGO || "/static/images/logo/logo.svg",
loginLogo: env.LOGIN_LOGO || "/static/images/logo/rect-block.svg",
warningOff: false,
icpNo: env.ICP_NO,
licenseTo: "",
licenseToUrl: ""
};
export const useSettingStore = defineStore({
id: "app.setting",
state: (): SettingState => ({
@@ -51,6 +78,10 @@ export const useSettingStore = defineStore({
token: {},
algorithm: theme.defaultAlgorithm
},
plusInfo: {
isPlus: false,
vipType: "free"
},
sysPublic: {
registerEnabled: false,
managerOtherUserPipeline: false,
@@ -63,11 +94,7 @@ export const useSettingStore = defineStore({
accountServerBaseUrl: "",
appKey: ""
},
siteInfo: {
title: "Certd",
slogan: "让你的证书永不过期",
logo: ""
}
siteInfo: defaultSiteInfo
}),
getters: {
getThemeConfig(): any {
@@ -78,30 +105,75 @@ export const useSettingStore = defineStore({
},
getInstallInfo(): SysInstallInfo {
return this.installInfo;
},
isPlus(): boolean {
return this.plusInfo?.isPlus && this.plusInfo?.expireTime > new Date().getTime();
},
isComm(): boolean {
return this.plusInfo?.isComm && this.plusInfo?.expireTime > new Date().getTime();
},
vipLabel(): string {
const vipLabelMap: any = {
free: "免费版",
plus: "专业版",
comm: "商业版"
};
return vipLabelMap[this.plusInfo?.vipType || "free"];
}
},
actions: {
checkPlus() {
if (!this.isPlus) {
notification.warn({
message: "此为专业版功能,请先升级到专业版"
});
throw new Error("此为专业版功能,请升级到专业版");
}
},
async loadSysSettings() {
const settings = await basicApi.getSysPublicSettings();
_.merge(this.sysPublic, settings);
const userStore = useUserStore();
if (userStore.isComm) {
const siteInfo = await basicApi.getSiteInfo();
_.merge(this.siteInfo, siteInfo);
}
await this.loadInstallInfo();
await this.loadPlusInfo();
if (this.isComm) {
await this.loadSiteInfo();
}
await this.checkUrlBound();
},
async loadInstallInfo() {
const installInfo = await basicApi.getInstallInfo();
_.merge(this.installInfo, installInfo);
},
async loadPlusInfo() {
this.plusInfo = await basicApi.getPlusInfo();
},
async loadSiteInfo() {
const isComm = this.isComm;
let siteInfo = {};
if (isComm) {
siteInfo = await basicApi.getSiteInfo();
if (siteInfo.logo) {
siteInfo.logo = `/api/basic/file/download?key=${siteInfo.logo}`;
}
if (siteInfo.loginLogo) {
siteInfo.loginLogo = `/api/basic/file/download?key=${siteInfo.loginLogo}`;
}
}
const sysPublic = this.getSysPublic;
if (sysPublic.icpNo) {
siteInfo.icpNo = sysPublic.icpNo;
}
this.siteInfo = _.merge({}, defaultSiteInfo, siteInfo);
},
async checkUrlBound() {
const userStore = useUserStore();
if (!userStore.isAdmin || !userStore.isPlus) {
const settingStore = useSettingStore();
if (!userStore.isAdmin || !settingStore.isPlus) {
return;
}