2022-08-26 20:15:36 +08:00
|
|
|
|
import openApi from './openApi';
|
|
|
|
|
|
|
|
|
|
|
|
// 登录是否使用验证码配置key
|
2024-01-05 12:09:12 +08:00
|
|
|
|
const AccountLoginSecurityKey = 'AccountLoginSecurity';
|
|
|
|
|
|
const MachineConfigKey = 'MachineConfig';
|
|
|
|
|
|
const SysStyleConfigKey = 'SysStyleConfig';
|
2023-06-17 15:15:03 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取账号登录安全配置
|
2023-07-06 20:59:22 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @returns
|
2023-06-17 15:15:03 +08:00
|
|
|
|
*/
|
2023-07-06 20:59:22 +08:00
|
|
|
|
export async function getAccountLoginSecurity(): Promise<any> {
|
2024-01-05 12:09:12 +08:00
|
|
|
|
const value = await getConfigValue(AccountLoginSecurityKey);
|
2022-08-26 20:15:36 +08:00
|
|
|
|
if (!value) {
|
2023-06-17 15:15:03 +08:00
|
|
|
|
return null;
|
2022-08-26 20:15:36 +08:00
|
|
|
|
}
|
2023-06-17 15:15:03 +08:00
|
|
|
|
const jsonValue = JSON.parse(value);
|
|
|
|
|
|
jsonValue.useCaptcha = convertBool(jsonValue.useCaptcha, true);
|
|
|
|
|
|
jsonValue.useOtp = convertBool(jsonValue.useOtp, true);
|
|
|
|
|
|
return jsonValue;
|
2022-08-26 20:15:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-05 12:09:12 +08:00
|
|
|
|
* 获取全局系统样式配置(logo、title等)
|
2023-07-06 20:59:22 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @returns
|
2022-08-26 20:15:36 +08:00
|
|
|
|
*/
|
2024-01-05 12:09:12 +08:00
|
|
|
|
export async function getSysStyleConfig(): Promise<any> {
|
|
|
|
|
|
const value = await getConfigValue(SysStyleConfigKey);
|
2023-10-31 12:36:04 +08:00
|
|
|
|
const defaultValue = {
|
2024-01-05 12:09:12 +08:00
|
|
|
|
useWatermark: true,
|
2023-10-31 12:36:04 +08:00
|
|
|
|
};
|
2023-10-14 00:38:51 +08:00
|
|
|
|
if (!value) {
|
2023-10-31 12:36:04 +08:00
|
|
|
|
return defaultValue;
|
|
|
|
|
|
}
|
2024-01-05 12:09:12 +08:00
|
|
|
|
|
|
|
|
|
|
const jsonValue = JSON.parse(value);
|
|
|
|
|
|
// 将字符串转为bool
|
|
|
|
|
|
jsonValue.useWatermark = convertBool(jsonValue.useWatermark, true);
|
|
|
|
|
|
return jsonValue;
|
2023-06-17 15:15:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-23 22:09:41 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取LDAP登录配置
|
|
|
|
|
|
*
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function getLdapEnabled(): Promise<any> {
|
|
|
|
|
|
const value = await openApi.getLdapEnabled();
|
|
|
|
|
|
return convertBool(value, false);
|
|
|
|
|
|
}
|
2023-12-09 16:17:26 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-05 12:09:12 +08:00
|
|
|
|
* 获取机器配置
|
2023-12-09 16:17:26 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function getMachineConfig(): Promise<any> {
|
2024-01-05 12:09:12 +08:00
|
|
|
|
const value = await getConfigValue(MachineConfigKey);
|
2023-12-09 16:17:26 +08:00
|
|
|
|
const defaultValue = {
|
|
|
|
|
|
// 默认1gb
|
|
|
|
|
|
uploadMaxFileSize: '1GB',
|
|
|
|
|
|
};
|
|
|
|
|
|
if (!value) {
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
const jsonValue = JSON.parse(value);
|
|
|
|
|
|
return jsonValue;
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-05 12:09:12 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取系统配置值
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key 配置key
|
|
|
|
|
|
* @returns 配置值
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function getConfigValue(key: string): Promise<string> {
|
|
|
|
|
|
return (await openApi.getConfigValue({ key })) as string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取bool类型系统配置值
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key 配置key
|
|
|
|
|
|
* @param defaultValue 默认值
|
|
|
|
|
|
* @returns 是否为ture,1: true;其他: false
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function getBoolConfigValue(key: string, defaultValue: boolean): Promise<boolean> {
|
|
|
|
|
|
const value = await getConfigValue(key);
|
|
|
|
|
|
return convertBool(value, defaultValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-09 16:17:26 +08:00
|
|
|
|
function convertBool(value: string, defaultValue: boolean) {
|
|
|
|
|
|
if (!value) {
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
return value == '1' || value == 'true';
|
|
|
|
|
|
}
|