feat: 系统设置主要LOGO版权背景修改
This commit is contained in:
@@ -1,5 +1,26 @@
|
||||
import { getSysConf } from '@/api';
|
||||
import defaultLOGO from '@/assets/logo_icon.png';
|
||||
import defaultLoginBackground from '@/assets/background.svg';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { validHttp } from '@/utils/regular-utils';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
/**
|
||||
* 格式解析LOGO地址
|
||||
* @param 资源路径
|
||||
* @returns url地址
|
||||
*/
|
||||
function parseLOGO(path: string): string {
|
||||
if (!path) {
|
||||
return defaultLOGO;
|
||||
}
|
||||
if (validHttp(path)) {
|
||||
return path;
|
||||
}
|
||||
const baseApi = import.meta.env.VITE_API_BASE_URL;
|
||||
return `${baseApi}${path}`;
|
||||
}
|
||||
|
||||
/**应用参数类型 */
|
||||
type AppStore = {
|
||||
/**应用名称 */
|
||||
@@ -10,6 +31,15 @@ type AppStore = {
|
||||
appVersion: string;
|
||||
/**应用版权声明 */
|
||||
copyright: string;
|
||||
/**LOGO显示类型 */
|
||||
logoType: 'brand' | 'icon';
|
||||
/**LOGO文件路径 */
|
||||
filePathIcon: string;
|
||||
filePathBrand: string;
|
||||
/**开启用户注册 */
|
||||
registerUser: boolean;
|
||||
/**登录界面背景 */
|
||||
loginBackground: string;
|
||||
};
|
||||
|
||||
const useAppStore = defineStore('app', {
|
||||
@@ -18,7 +48,46 @@ const useAppStore = defineStore('app', {
|
||||
appCode: import.meta.env.VITE_APP_CODE,
|
||||
appVersion: import.meta.env.VITE_APP_VERSION,
|
||||
copyright: 'Copyright ©2023 For AGrand 千通科技',
|
||||
logoType: 'icon',
|
||||
filePathIcon: '',
|
||||
filePathBrand: '',
|
||||
registerUser: false,
|
||||
loginBackground: '',
|
||||
}),
|
||||
getters: {
|
||||
/**
|
||||
* 获取正确LOGO地址-icon
|
||||
* @param state 内部属性不用传入
|
||||
* @returns LOGO地址url
|
||||
*/
|
||||
getLOGOIcon(state) {
|
||||
return parseLOGO(state.filePathIcon);
|
||||
},
|
||||
/**
|
||||
* 获取正确LOGO地址-brand
|
||||
* @param state 内部属性不用传入
|
||||
* @returns LOGO地址url
|
||||
*/
|
||||
getLOGOBrand(state) {
|
||||
return parseLOGO(state.filePathBrand);
|
||||
},
|
||||
/**
|
||||
* 获取正确登录背景地址
|
||||
* @param state 内部属性不用传入
|
||||
* @returns 背景地址url
|
||||
*/
|
||||
getLoginBackground(state) {
|
||||
const path = state.loginBackground;
|
||||
if (!path) {
|
||||
return defaultLoginBackground;
|
||||
}
|
||||
if (validHttp(path)) {
|
||||
return path;
|
||||
}
|
||||
const baseApi = import.meta.env.VITE_API_BASE_URL;
|
||||
return `${baseApi}${path}`;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
/**设置网页标题 */
|
||||
setTitle(title?: string) {
|
||||
@@ -32,6 +101,48 @@ const useAppStore = defineStore('app', {
|
||||
setCopyright(text: string) {
|
||||
this.copyright = text;
|
||||
},
|
||||
/**设置LOGO */
|
||||
setLOGO(type: 'brand' | 'icon', filePath: string) {
|
||||
this.logoType = type;
|
||||
if (type === 'brand') {
|
||||
this.filePathBrand = filePath;
|
||||
}
|
||||
if (type === 'icon') {
|
||||
this.filePathIcon = filePath;
|
||||
}
|
||||
},
|
||||
// 获取系统配置信息
|
||||
async fnSysConf() {
|
||||
const res = await getSysConf();
|
||||
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||
if (res.data.title) {
|
||||
this.appName = res.data.title;
|
||||
}
|
||||
if (res.data.copyright) {
|
||||
this.copyright = res.data.copyright;
|
||||
}
|
||||
this.filePathIcon = res.data.filePathIcon;
|
||||
this.filePathBrand = res.data.filePathBrand;
|
||||
if (res.data.logoType) {
|
||||
this.logoType = res.data.logoType;
|
||||
// 修改html内容
|
||||
const iconDom = document.querySelector("link[rel~='icon']");
|
||||
if (iconDom) {
|
||||
if(this.logoType === 'icon'){
|
||||
iconDom.setAttribute('href', this.getLOGOIcon);
|
||||
}
|
||||
if(this.logoType === 'brand'){
|
||||
iconDom.setAttribute('href', this.getLOGOBrand);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.registerUser = res.data.registerUser === 'true';
|
||||
if (res.data.loginBackground) {
|
||||
this.loginBackground = res.data.loginBackground;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user