Files
mayfly-go/mayfly_go_web/src/common/sysconfig.ts

81 lines
1.9 KiB
TypeScript
Raw Normal View History

import openApi from './openApi';
// 登录是否使用验证码配置key
const AccountLoginSecurity = 'AccountLoginSecurity';
const UseLoginCaptchaConfigKey = 'UseLoginCaptcha';
const UseWartermarkConfigKey = 'UseWartermark';
/**
*
*
* @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 ture1: true其他: false
*/
export async function getBoolConfigValue(key: string, defaultValue: boolean): Promise<boolean> {
2023-06-17 15:15:03 +08:00
const value = await getConfigValue(key);
return convertBool(value, defaultValue);
}
/**
*
*
* @returns
2023-06-17 15:15:03 +08:00
*/
export async function getAccountLoginSecurity(): Promise<any> {
2023-06-17 15:15:03 +08:00
const value = await getConfigValue(AccountLoginSecurity);
if (!value) {
2023-06-17 15:15:03 +08:00
return null;
}
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;
}
/**
* 使
*
* @returns
*/
export async function useLoginCaptcha(): Promise<boolean> {
return await getBoolConfigValue(UseLoginCaptchaConfigKey, true);
}
/**
*
*
* @returns
*/
export async function useWartermark(): Promise<boolean> {
return await getBoolConfigValue(UseWartermarkConfigKey, true);
2023-06-17 15:15:03 +08:00
}
function convertBool(value: string, defaultValue: boolean) {
if (!value) {
return defaultValue;
}
return value == '1' || value == 'true';
}
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);
}