1
This commit is contained in:
@@ -5,27 +5,7 @@
|
||||
|
||||
const Framework = require("../../framework/node-core-framework.js");
|
||||
|
||||
const normalizeConfigValue = (config) => {
|
||||
if (!config) {
|
||||
return config;
|
||||
}
|
||||
|
||||
const normalized = { ...config };
|
||||
|
||||
if (normalized.configType === 'json' && normalized.configValue) {
|
||||
try {
|
||||
normalized.configValue = JSON.parse(normalized.configValue);
|
||||
} catch (e) {
|
||||
// 解析失败,保持原值
|
||||
}
|
||||
} else if (normalized.configType === 'boolean') {
|
||||
normalized.configValue = normalized.configValue === 'true' || normalized.configValue === '1';
|
||||
} else if (normalized.configType === 'number') {
|
||||
normalized.configValue = parseFloat(normalized.configValue) || 0;
|
||||
}
|
||||
|
||||
return normalized;
|
||||
};
|
||||
// sys_parameter 表直接存储字符串值,不需要类型转换
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
@@ -55,7 +35,7 @@ module.exports = {
|
||||
'GET /config/get': async (ctx) => {
|
||||
try {
|
||||
const models = await Framework.getModels();
|
||||
const { system_config, op } = models;
|
||||
const { sys_parameter, op } = models;
|
||||
const { configKey, configKeys } = ctx.query;
|
||||
|
||||
// 如果没有提供配置键,返回失败
|
||||
@@ -75,10 +55,10 @@ module.exports = {
|
||||
return ctx.fail('配置键不能为空');
|
||||
}
|
||||
|
||||
// 查询配置
|
||||
const configs = await system_config.findAll({
|
||||
// 查询配置(使用 sys_parameter 表)
|
||||
const configs = await sys_parameter.findAll({
|
||||
where: {
|
||||
configKey: {
|
||||
param_key: {
|
||||
[op.in]: keys
|
||||
},
|
||||
is_delete: 0
|
||||
@@ -91,17 +71,17 @@ module.exports = {
|
||||
|
||||
// 如果只有一个配置键,返回单个配置值
|
||||
if (keys.length === 1) {
|
||||
const config = normalizeConfigValue(configs[0].toJSON());
|
||||
const config = configs[0].toJSON();
|
||||
return ctx.success({
|
||||
[config.configKey]: config.configValue
|
||||
[config.param_key]: config.param_value
|
||||
});
|
||||
}
|
||||
|
||||
// 多个配置键,返回对象
|
||||
const result = {};
|
||||
configs.forEach(config => {
|
||||
const normalized = normalizeConfigValue(config.toJSON());
|
||||
result[normalized.configKey] = normalized.configValue;
|
||||
const configData = config.toJSON();
|
||||
result[configData.param_key] = configData.param_value;
|
||||
});
|
||||
|
||||
return ctx.success(result);
|
||||
|
||||
Reference in New Issue
Block a user