front/src/composables/useSystemConfig.ts
2026-03-23 10:00:44 +08:00

74 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ref } from 'vue';
// RBAC 系统暂不使用系统配置接口
// import { sysSysInfoGet } from '@/api/SimpleAdmin/common';
/**
* 系统配置 composable
*/
export function useSystemConfig() {
const sysInfo = ref<{
SYS_NAME?: string;
SYS_VERSION?: string;
SYS_LOGO?: string;
[key: string]: any;
}>({});
const loading = ref(false);
const logoUrl = ref<string>('');
/**
* 获取系统配置 - RBAC 系统使用默认值
*/
const fetchSysInfo = async () => {
try {
loading.value = true;
// RBAC 系统使用默认配置
const defaultConfig = {
SYS_NAME: '哪哪发物流',
SYS_VERSION: 'v1.0.0',
SYS_LOGO: '/src/assets/logo.png',
};
sysInfo.value = defaultConfig;
logoUrl.value = defaultConfig.SYS_LOGO;
return defaultConfig;
} catch (error) {
console.error('获取系统配置失败', error);
return {};
} finally {
loading.value = false;
}
};
/**
* 设置logo URL(直接使用,不进行blob转换,参考SimpleAdmin的实现)
*/
const loadLogoImage = (url: string) => {
// 直接使用URL,确保格式正确(SimpleAdmin也是直接使用URL)
if (url) {
// 确保URL以 / 开头(如果是相对路径)
const finalUrl = url.startsWith('/') || url.startsWith('http://') || url.startsWith('https://')
? url
: `/${url}`;
logoUrl.value = finalUrl;
} else {
logoUrl.value = '/src/assets/logo.png';
}
};
/**
* 获取系统Logo
*/
const getSysLogo = () => {
return logoUrl.value || sysInfo.value.SYS_LOGO || '/src/assets/logo.png';
};
return {
sysInfo,
loading,
logoUrl,
fetchSysInfo,
getSysLogo,
};
}