feat: 图标支持根据语言上传对应图标
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { getSysConf } from '@/api';
|
||||
import defaultLOGOIcon from '@/assets/logo_icon.png';
|
||||
import defaultLOGOBrand from '@/assets/logo_brand.png';
|
||||
import { CACHE_LOCAL_I18N } from '@/constants/cache-keys-constants';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { validHttp } from '@/utils/regular-utils';
|
||||
import { parseUrlPath } from '@/plugins/file-static-url';
|
||||
import { localGet } from '@/utils/cache-local-utils';
|
||||
import { defineStore } from 'pinia';
|
||||
import { sessionGet } from '@/utils/cache-session-utils';
|
||||
|
||||
/**应用参数类型 */
|
||||
type AppStore = {
|
||||
@@ -14,6 +13,7 @@ type AppStore = {
|
||||
appCode: string;
|
||||
/**应用版本 */
|
||||
appVersion: string;
|
||||
|
||||
/**应用版权声明 */
|
||||
copyright: string;
|
||||
/**LOGO显示类型 */
|
||||
@@ -29,6 +29,10 @@ type AppStore = {
|
||||
helpDoc: string;
|
||||
/**官方网址 */
|
||||
officialUrl: string;
|
||||
/**国际化切换 */
|
||||
i18nOpen: boolean;
|
||||
/**国际化默认语言 */
|
||||
i18nDefault: string;
|
||||
};
|
||||
|
||||
const useAppStore = defineStore('app', {
|
||||
@@ -36,6 +40,7 @@ const useAppStore = defineStore('app', {
|
||||
appName: import.meta.env.VITE_APP_NAME,
|
||||
appCode: import.meta.env.VITE_APP_CODE,
|
||||
appVersion: import.meta.env.VITE_APP_VERSION,
|
||||
|
||||
copyright: `Copyright ©2023 For ${import.meta.env.VITE_APP_NAME}`,
|
||||
logoType: 'icon',
|
||||
filePathIcon: '',
|
||||
@@ -44,85 +49,10 @@ const useAppStore = defineStore('app', {
|
||||
loginBackground: '',
|
||||
helpDoc: '',
|
||||
officialUrl: '',
|
||||
i18nOpen: true,
|
||||
i18nDefault: 'en_US',
|
||||
}),
|
||||
getters: {
|
||||
/**
|
||||
* 获取正确LOGO地址-icon
|
||||
* @param state 内部属性不用传入
|
||||
* @returns LOGO地址url
|
||||
*/
|
||||
getLOGOIcon(state) {
|
||||
const path = state.filePathIcon;
|
||||
if (!path || path === '#') {
|
||||
return defaultLOGOIcon;
|
||||
}
|
||||
if (validHttp(path)) {
|
||||
return path;
|
||||
}
|
||||
// 兼容旧前端可改配置文件
|
||||
const baseUrl = import.meta.env.PROD
|
||||
? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL
|
||||
: import.meta.env.VITE_API_BASE_URL;
|
||||
return `${baseUrl}${path}`;
|
||||
},
|
||||
/**
|
||||
* 获取正确LOGO地址-brand
|
||||
* @param state 内部属性不用传入
|
||||
* @returns LOGO地址url
|
||||
*/
|
||||
getLOGOBrand(state) {
|
||||
const path = state.filePathBrand;
|
||||
if (!path || path === '#') {
|
||||
return defaultLOGOBrand;
|
||||
}
|
||||
if (validHttp(path)) {
|
||||
return path;
|
||||
}
|
||||
// 兼容旧前端可改配置文件
|
||||
const baseUrl = import.meta.env.PROD
|
||||
? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL
|
||||
: import.meta.env.VITE_API_BASE_URL;
|
||||
return `${baseUrl}${path}`;
|
||||
},
|
||||
/**
|
||||
* 获取正确登录背景地址
|
||||
* @param state 内部属性不用传入
|
||||
* @returns 背景地址url
|
||||
*/
|
||||
getLoginBackground(state) {
|
||||
const path = state.loginBackground;
|
||||
if (!path || path === '#') {
|
||||
return '#';
|
||||
}
|
||||
if (validHttp(path)) {
|
||||
return path;
|
||||
}
|
||||
// 兼容旧前端可改配置文件
|
||||
const baseUrl = import.meta.env.PROD
|
||||
? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL
|
||||
: import.meta.env.VITE_API_BASE_URL;
|
||||
return `${baseUrl}${path}`;
|
||||
},
|
||||
/**
|
||||
* 获取正确使用手册地址
|
||||
* @param state 内部属性不用传入
|
||||
* @returns 手册地址url
|
||||
*/
|
||||
getHelpDoc(state) {
|
||||
const path = state.helpDoc;
|
||||
if (!path || path === '#') {
|
||||
return '#';
|
||||
}
|
||||
if (validHttp(path)) {
|
||||
return path;
|
||||
}
|
||||
// 兼容旧前端可改配置文件
|
||||
const baseUrl = import.meta.env.PROD
|
||||
? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL
|
||||
: import.meta.env.VITE_API_BASE_URL;
|
||||
return `${baseUrl}${path}`;
|
||||
},
|
||||
},
|
||||
getters: {},
|
||||
actions: {
|
||||
/**设置网页标题 */
|
||||
setTitle(title?: string) {
|
||||
@@ -136,16 +66,6 @@ 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();
|
||||
@@ -156,16 +76,25 @@ const useAppStore = defineStore('app', {
|
||||
this.filePathIcon = res.data.filePathIcon;
|
||||
this.filePathBrand = res.data.filePathBrand;
|
||||
// 修改html内容-小图当作favicon.ico
|
||||
if (this.logoType) {
|
||||
if (this.logoType) {
|
||||
const iconDom = document.querySelector("link[rel~='icon']");
|
||||
if (iconDom) {
|
||||
iconDom.setAttribute('href', this.getLOGOIcon);
|
||||
let url = parseUrlPath(this.filePathIcon);
|
||||
// 语言参数替换
|
||||
if (url.indexOf('{language}') !== -1) {
|
||||
const local = localGet(CACHE_LOCAL_I18N) || 'en_US';
|
||||
const lang = local.split('_')[0];
|
||||
url = url.replace('{language}', lang);
|
||||
}
|
||||
iconDom.setAttribute('href', url);
|
||||
}
|
||||
}
|
||||
this.registerUser = res.data.registerUser === 'true';
|
||||
this.loginBackground = res.data.loginBackground;
|
||||
this.helpDoc = res.data.helpDoc;
|
||||
this.officialUrl = res.data.officialUrl;
|
||||
this.i18nOpen = res.data.i18nOpen === 'true';
|
||||
this.i18nDefault = res.data.i18nDefault;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user