feat(B批收尾): B1门禁可信/B7-1菜单环防护/B2空值守卫/B7-2分页/B7-3字段清洗/B3空态/B4索引key/B5-3 comment三集合选A新建schema(漂移清零)/B6清理+admin配置+changelog
This commit is contained in:
@@ -1,38 +1,22 @@
|
||||
module.exports = (templateData, user) => {
|
||||
|
||||
const data = {}
|
||||
|
||||
for (const template of templateData) {
|
||||
|
||||
// 检查模板是否包含动态值
|
||||
const isDynamic = /\{.*?\}/.test(template.value)
|
||||
|
||||
// 仅支持uni-id-users
|
||||
if (isDynamic) {
|
||||
// 从模板中提取出集合和字段名
|
||||
const [collection, field] = template.value.replace(/\{|\}/g, '').split('.')
|
||||
// 如果是uni-id-users,提取相应字段的值
|
||||
// 否则使用模板值本身
|
||||
data[template.field] = collection === 'uni-id-users' ? user[field] || template.value: template.value
|
||||
} else {
|
||||
// 如果没有动态值,则使用模板值本身
|
||||
data[template.field] = template.value
|
||||
}
|
||||
// 下面是一些注释的代码
|
||||
// switch (template.type) {
|
||||
// case 'static':
|
||||
// // 对于静态值,直接使用模板值本身
|
||||
// data[template.field] = template.value
|
||||
// break
|
||||
// case 'dynamic':
|
||||
// // 对于动态值,使用用户对象中的相应字段
|
||||
// data[template.field] = user[template.value] || ''
|
||||
// break
|
||||
// default:
|
||||
// // 抛出不支持的模板类型错误
|
||||
// throw new Error(`template type [${template.type}] not supported`)
|
||||
// }
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
module.exports = (templateData = [], user = {}) => {
|
||||
const data = {};
|
||||
|
||||
if (!Array.isArray(templateData)) return data;
|
||||
for (const template of templateData) {
|
||||
if (!template || typeof template.field !== 'string') continue;
|
||||
const value = template.value;
|
||||
const isDynamic = typeof value === 'string' && /\{.*?\}/.test(value);
|
||||
|
||||
if (isDynamic) {
|
||||
const [collection, field] = value.replace(/\{|\}/g, '').split('.');
|
||||
// 保留 0、false、空字符串;仅在用户字段确实缺失时使用模板原值。
|
||||
const userValue = collection === 'uni-id-users' && field &&
|
||||
Object.prototype.hasOwnProperty.call(user, field) ? user[field] : undefined;
|
||||
data[template.field] = userValue === undefined || userValue === null ? value : userValue;
|
||||
} else {
|
||||
data[template.field] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user