2022-08-26 20:15:36 +08:00
|
|
|
|
import openApi from './openApi';
|
|
|
|
|
|
|
|
|
|
|
|
// 登录是否使用验证码配置key
|
2023-06-17 15:15:03 +08:00
|
|
|
|
const AccountLoginSecurity = "AccountLoginSecurity"
|
2022-08-26 20:15:36 +08:00
|
|
|
|
const UseLoginCaptchaConfigKey = "UseLoginCaptcha"
|
|
|
|
|
|
const UseWartermarkConfigKey = "UseWartermark"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取系统配置值
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key 配置key
|
|
|
|
|
|
* @returns 配置值
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function getConfigValue(key: string) : Promise<string> {
|
2023-04-13 20:11:22 +08:00
|
|
|
|
return await openApi.getConfigValue.request({key}) as string
|
2022-08-26 20:15:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取bool类型系统配置值
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key 配置key
|
|
|
|
|
|
* @param defaultValue 默认值
|
|
|
|
|
|
* @returns 是否为ture,1: 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
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function getAccountLoginSecurity() : Promise<any> {
|
|
|
|
|
|
const value = await getConfigValue(AccountLoginSecurity);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 是否使用登录验证码
|
|
|
|
|
|
*
|
|
|
|
|
|
* @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";
|
2022-08-26 20:15:36 +08:00
|
|
|
|
}
|