doomiwork 4.1.9 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +1 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +22 -7
- package/configuration/appsetting.js +0 -42
- package/configuration/dataconfig.js +0 -55
- package/configuration/routerconfig.js +0 -144
- package/core/actionresult.js +0 -30
- package/core/controller.js +0 -380
- package/core/database/daoBase.js +0 -352
- package/core/database/mysqlbase.js +0 -173
- package/core/database/poolmanager.js +0 -15
- package/core/doomiwork.js +0 -76
- package/core/enumconst.js +0 -52
- package/index.js +0 -13
- package/utilities/excelutility.js +0 -202
- package/utilities/keywordparse.js +0 -115
- package/utilities/requestparser-bak.js +0 -163
- package/utilities/requestparser.js +0 -239
- package/utilities/tokenutility.js +0 -45
- package/utilities/transferutility.js +0 -105
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
const { parseKeyValue, validatorParamsType } = require('./keywordparse');
|
|
2
|
-
const dataconfig = require('../configuration/dataconfig').getCurrent();
|
|
3
|
-
const mysql = require('mysql');
|
|
4
|
-
const ORDER_STRING = ['asc', 'desc']
|
|
5
|
-
const FORBID_SQL_KEYWORD = /;|(--)|(\bWHERE\b)|(\bCASE\b)|(\bWHEN\b)|(\bSLEEP\b)|(\bSHOW\b)|(\bCOUNT\(\b)|(\bCREATE\b)|(\bCALL\b)|(\bBY\b)|(\bORDER\b)|(\bJOIN\b)|(\bUNION\b)|(\bFROM\b)|(\bSELECT\b)|(\bDROP\b)|(\bTRUNCATE\b)|(\bDELETE\b)|(\bUPDATE\b)|(\bINSERT\b)|(\bEXEC\b)|(\bEXECUTE\b)/gi;
|
|
6
|
-
|
|
7
|
-
function appendSearchCondition2Count(originSql, searchCondition) {
|
|
8
|
-
///如果包含了这个特定的字符,则替换
|
|
9
|
-
if (originSql.indexOf('#APPENDSEARCH#') >= 0)
|
|
10
|
-
return originSql.replace('#APPENDSEARCH#', searchCondition);
|
|
11
|
-
return originSql + ' ' + searchCondition;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* 检查是否有Sql注入的风险
|
|
15
|
-
* @param {*} sql
|
|
16
|
-
*/
|
|
17
|
-
function checkSqlInjection(sql) {
|
|
18
|
-
if (!sql) return sql;
|
|
19
|
-
if (FORBID_SQL_KEYWORD.test(sql)) return '';
|
|
20
|
-
return sql;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isEmptyValue(value){
|
|
24
|
-
if (value === undefined || value === null || value === '') return true;
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
/*
|
|
28
|
-
* 根据对应列表的配置(dataConfig.list.search),从请求上下文中获取用户进行搜索的参数信息
|
|
29
|
-
*/
|
|
30
|
-
module.exports.getSearchCondition = (option) => {
|
|
31
|
-
let paraCopy = option || {};
|
|
32
|
-
if (!paraCopy.request || !paraCopy.refer) return { filter:'', params:[] };
|
|
33
|
-
if (!paraCopy.valueFrom) paraCopy.valueFrom = "all";
|
|
34
|
-
const request = paraCopy.request;
|
|
35
|
-
let retSearch = [],params = [];
|
|
36
|
-
paraCopy.refer.forEach(element => {
|
|
37
|
-
const paramSql = this.parseTagForParameterize(request, element);
|
|
38
|
-
if (paramSql.sql) {
|
|
39
|
-
retSearch.push(paramSql.sql);
|
|
40
|
-
params = params.concat(paramSql.params||[]);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return {filter:retSearch.join(''),params}
|
|
44
|
-
//return retSearch.join('');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 解析sql字符串中特殊的占位符
|
|
49
|
-
* @param {*} req
|
|
50
|
-
* @param {*} sql
|
|
51
|
-
* @param {*} allowNull
|
|
52
|
-
* @returns
|
|
53
|
-
*/
|
|
54
|
-
module.exports.parseTagInSql = (req, sql, allowNull = true) => {
|
|
55
|
-
if (!sql) return '';
|
|
56
|
-
///定义正则准备查找sql中的特定关键字
|
|
57
|
-
const matched = sql.match(/@.*?@/g);
|
|
58
|
-
if (!matched || matched.length <= 0) return sql;
|
|
59
|
-
let parseKeyWordIsNull = false;
|
|
60
|
-
const charReg = /\s+|:|=/gi
|
|
61
|
-
matched.forEach(ele => {
|
|
62
|
-
let matchValue = ele.substring(1, ele.length - 1);
|
|
63
|
-
///不允许特殊字符出现
|
|
64
|
-
let notdo = matchValue.match(charReg);
|
|
65
|
-
if (notdo && notdo.length > 0) return;
|
|
66
|
-
|
|
67
|
-
let noQuoteProtect = matchValue[0] == '!';
|
|
68
|
-
if (noQuoteProtect) matchValue = matchValue.substring(1);
|
|
69
|
-
///是否有格式要求
|
|
70
|
-
let validformat = matchValue.split('|');
|
|
71
|
-
matchValue = validformat[0];
|
|
72
|
-
let keyValue = (parseKeyValue(req, matchValue) || '')+''; //utility.ifNull(keyParse.parseKeyValue(req, matchValue), '')+'';
|
|
73
|
-
if (!keyValue) {
|
|
74
|
-
parseKeyWordIsNull = true;
|
|
75
|
-
} else if (typeof (keyValue) === 'string') {
|
|
76
|
-
keyValue = noQuoteProtect ? checkSqlInjection(mysql.escape(keyValue)) : mysql.escape(keyValue)
|
|
77
|
-
keyValue = keyValue.substring(1, keyValue.length - 1);
|
|
78
|
-
///验证参数的格式合法性
|
|
79
|
-
if (keyValue && validformat.length > 1) keyValue = validatorParamsType(keyValue, validformat[1], validformat[2])
|
|
80
|
-
if (!keyValue) {
|
|
81
|
-
parseKeyWordIsNull = true;
|
|
82
|
-
}
|
|
83
|
-
///没有引号保护下发现了sql注入,则用1=0不返回任何结果
|
|
84
|
-
if (!keyValue && noQuoteProtect) keyValue = '1=0'
|
|
85
|
-
} else { ////数组形式的参数,目前框架不支持,统一认为为sql注入攻击,全部忽略
|
|
86
|
-
// console.log(`参数非法==>类型${typeof (keyValue)}:${matchValue} = ${keyValue}`)
|
|
87
|
-
parseKeyWordIsNull = true;
|
|
88
|
-
keyValue = ''
|
|
89
|
-
}
|
|
90
|
-
sql = sql.replace(ele, keyValue);
|
|
91
|
-
});
|
|
92
|
-
if (!allowNull && parseKeyWordIsNull) return '';
|
|
93
|
-
return sql;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 为列表查询定义参数化查询
|
|
99
|
-
* @param {*} req
|
|
100
|
-
* @param {*} sql
|
|
101
|
-
* @param {*} allowNull
|
|
102
|
-
* @param {*} isSearch
|
|
103
|
-
* @returns
|
|
104
|
-
*/
|
|
105
|
-
module.exports.parseTagForParameterize = (req, filterSetting={}) => {
|
|
106
|
-
///type=parameter表示参数化方式查询
|
|
107
|
-
///type=joint 表示拼接sql语句查询
|
|
108
|
-
///scope=[] 表示需要解析的字段必须在此列表内容中
|
|
109
|
-
let {pattern:sql,type='parameter',inscope=[],allowEmpty=false} = filterSetting;
|
|
110
|
-
if (!sql) return {sql:''};
|
|
111
|
-
///定义正则准备查找sql中的特定关键字
|
|
112
|
-
const matched = sql.match(/@.*?@/g);
|
|
113
|
-
let params = [];
|
|
114
|
-
if (!matched || matched.length <= 0) return {sql};
|
|
115
|
-
for(const ele of matched){
|
|
116
|
-
let matchValue = ele.substring(1, ele.length - 1);
|
|
117
|
-
///检查是否有特殊的字符比如 % 等
|
|
118
|
-
const specialRegex = /^[^a-zA-Z0-9]*(.*?)[^a-zA-Z0-9]*$/
|
|
119
|
-
const matchContent = matchValue.match(specialRegex);
|
|
120
|
-
matchValue = matchContent ? matchContent[1]:matchValue;
|
|
121
|
-
if (!matchValue) return {sql:'',params:[]};
|
|
122
|
-
///是否有格式要求
|
|
123
|
-
let validformat = matchValue.split('|');
|
|
124
|
-
matchValue = validformat[0];
|
|
125
|
-
|
|
126
|
-
let keyValue = parseKeyValue(req, matchValue)||''; //utility.ifNull(keyParse.parseKeyValue(req, matchValue), '')+'';
|
|
127
|
-
if (keyValue && validformat.length > 1) keyValue = validatorParamsType(keyValue, validformat[1], validformat[2], inscope)
|
|
128
|
-
///如果解析不出这个KeyValue ,则认为当前这条SQL过滤无效
|
|
129
|
-
if (isEmptyValue(keyValue) && !allowEmpty) return {sql:'',params:[]};
|
|
130
|
-
// if (keyValue) {
|
|
131
|
-
if(type.toLowerCase() === 'parameter'){
|
|
132
|
-
sql = sql.replace(ele, '?'); ///变成参数化查询
|
|
133
|
-
if (Array.isArray(keyValue))
|
|
134
|
-
params.push(keyValue)
|
|
135
|
-
else
|
|
136
|
-
params.push(matchContent[0].replace(matchContent[1], keyValue));// '%' + keyValue + '%')
|
|
137
|
-
} else if (type.toLowerCase() === 'joint'){ ///拼接sql语句查询
|
|
138
|
-
///拼接的SQL语句,keyvalue必须在scope列表中,否则不予拼接
|
|
139
|
-
const result = inscope.some(item => item.toLowerCase() === matchValue.toLowerCase());
|
|
140
|
-
if (result)sql = sql.replace(ele, keyValue||'');
|
|
141
|
-
}
|
|
142
|
-
// }
|
|
143
|
-
}
|
|
144
|
-
return {sql,params};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 检查排序字段是否合法
|
|
149
|
-
* @param {*} sortField
|
|
150
|
-
* @returns
|
|
151
|
-
*/
|
|
152
|
-
function sortFieldIsLegal(sortField,allowedFields = []){
|
|
153
|
-
/// 没有传递排序字段,则不用检查
|
|
154
|
-
if (!sortField) return sortField;
|
|
155
|
-
/// 检查排序字段是否在允许的字段列表中,如果存在allowedFields,则只允许在allowedFields中排序
|
|
156
|
-
if (allowedFields && allowedFields.length) {
|
|
157
|
-
if(allowedFields.map(item => item.toLowerCase()).includes(sortField.toLowerCase())) return sortField;
|
|
158
|
-
/// 如果不在allowedFields中,则不允许使用传入的字段名进行排序,防止sql注入
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
/// 如果allowedFields为空,则检查排序的字段是否合法,防止sql注入
|
|
162
|
-
if (sortField.indexOf(' ') >= 0 || sortField.indexOf('(') >= 0 || sortField.indexOf(')') >= 0) return null;
|
|
163
|
-
return checkSqlInjection(sortField);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/*
|
|
167
|
-
* 列表请求上下文中获取需要的信息
|
|
168
|
-
* 如Page ,PageSize , Sort 等等
|
|
169
|
-
*/
|
|
170
|
-
module.exports.getListInfo = (req, dataKey, cfgType = 0, dao) => {
|
|
171
|
-
if (!dataKey) return null;
|
|
172
|
-
const dataConfig = dataconfig.getConfig(dataKey, cfgType);
|
|
173
|
-
if (!dataConfig?.list) return null;
|
|
174
|
-
///确认是否是需要导出Excel
|
|
175
|
-
const export2Excel = (req.query.exportexcel + "").toLowerCase() === "true";
|
|
176
|
-
let { page = 1, rows: pageSize = 100, sort, order, clientFilter: filter } = req.query
|
|
177
|
-
///防止sortSql 注入在排序的参数中
|
|
178
|
-
if (sort) sort = sortFieldIsLegal(sort, dataConfig.list.allow_sort_fields) //checkSqlInjection(sort);
|
|
179
|
-
// 防止页面数据传入非数字
|
|
180
|
-
if (isNaN(pageSize)) pageSize = 30;
|
|
181
|
-
// 防止页面数据传入非数字
|
|
182
|
-
if (!page || isNaN(page)) page = 1
|
|
183
|
-
///最大允许获取100条数据
|
|
184
|
-
pageSize =Math.max(0,Math.min(pageSize, 10000));
|
|
185
|
-
///拼接排序的语句
|
|
186
|
-
if (order && sort && ORDER_STRING.includes(order.toLowerCase())) sort = sort + ' ' + order
|
|
187
|
-
//req.order =req.sort? utility.ifNull((req.body.order || req.query.order), ""):'';
|
|
188
|
-
|
|
189
|
-
if (dataConfig && dataConfig.list) {
|
|
190
|
-
req.dataConfig = dataConfig
|
|
191
|
-
let { sql, listsql, countsql, sqltype = 'sql', field, footer, search, sort: constsort } = dataConfig.list
|
|
192
|
-
/**解析查询条件 */
|
|
193
|
-
const searchCondition = this.getSearchCondition({ request: req, refer: search });
|
|
194
|
-
/**排序方式 *///
|
|
195
|
-
sort = sort || constsort;
|
|
196
|
-
/**来自req请求参数中的过滤条件 */
|
|
197
|
-
const clientfilter = null;// 不再支持可以通过客户端传递过滤条件,防止sql注入 //checkSqlInjection(this.parseTagInSql(req, filter, false));
|
|
198
|
-
let SqlParameters = [];
|
|
199
|
-
//如果配置文件中不是直接的sql语句,则从DAO对象中的指定方法来获取sql
|
|
200
|
-
if (sqltype !== 'sql' && listsql && typeof (dao[listsql]) === 'function') {
|
|
201
|
-
sql = dao[sql](req, { page, rows: pageSize, sort, filter: searchCondition.filter, client: clientfilter });
|
|
202
|
-
if (dao[countsql] && typeof (dao[countsql]) === 'function')
|
|
203
|
-
countsql = dao[countsql](req, { page, rows: pageSize, sort, filter: searchCondition.filter, client: clientfilter });
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**根据过滤条件、排序条件、分页获取的方式,和原始sql拼接成最终获取数据的sql */
|
|
207
|
-
if (sqltype==='sql'){
|
|
208
|
-
const mainParameterlizedSql = this.parseTagForParameterize(req, { pattern: sql, allowEmpty:true });
|
|
209
|
-
if (!mainParameterlizedSql.sql) return null;
|
|
210
|
-
sql = `${mainParameterlizedSql.sql} ${searchCondition.filter ||''} ${sort ? (' order by ' + sort) : ''} ${export2Excel ? '' : ' limit ' + Number(pageSize) + ' OFFSET ' + (Math.max(Number(page), 1) - 1) * Number(pageSize)};SELECT FOUND_ROWS() AS total;`;
|
|
211
|
-
SqlParameters = SqlParameters.concat(mainParameterlizedSql.params || [], searchCondition.params);
|
|
212
|
-
/*** 如果存在汇总列的sql,则把SQL放置在最末尾 */
|
|
213
|
-
if (countsql) {
|
|
214
|
-
const countParameterlizedSql = this.parseTagForParameterize(req, { pattern: countsql, allowEmpty: true });
|
|
215
|
-
if (!countParameterlizedSql.sql) return null;
|
|
216
|
-
sql += appendSearchCondition2Count(countParameterlizedSql.sql, searchCondition.filter||'')
|
|
217
|
-
SqlParameters = SqlParameters.concat(countParameterlizedSql.params || [], searchCondition.params);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
///如果存在统计的SQL,则参数需要Double一次
|
|
221
|
-
// const sqlParams = countsql ? [].concat(searchCondition.params, searchCondition.params):searchCondition.params;
|
|
222
|
-
return { sql, fields: field, params: SqlParameters, footers: footer, page, hascounter: countsql?true:false };
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
/*
|
|
226
|
-
* 详细页面请求上下文中获取需要的信息
|
|
227
|
-
* 如Page ,PageSize , Sort 等等
|
|
228
|
-
*/
|
|
229
|
-
module.exports.getDetailInfo = (req,dataKey) => {
|
|
230
|
-
if (dataKey) {
|
|
231
|
-
const dataConfig = dataconfig.getConfig(dataKey);
|
|
232
|
-
if (dataConfig && dataConfig.detail) {
|
|
233
|
-
req.dataConfig = dataConfig;
|
|
234
|
-
const { primary, field: fields, primaryIsAutoIncrease } = dataConfig.detail;
|
|
235
|
-
return { primary, fields, autoincrease: primaryIsAutoIncrease }
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 后台路由授权访问的Token验证
|
|
3
|
-
*/
|
|
4
|
-
// const cache = require('doomi-helper').redisHelper.getInstance();
|
|
5
|
-
class TokenUtility {
|
|
6
|
-
constructor(cacheinstance){
|
|
7
|
-
this.cache = cacheinstance;
|
|
8
|
-
}
|
|
9
|
-
setToken(token, tokenObject, expire) {
|
|
10
|
-
// if (typeof tokenObject != "string") tokenObject = JSON.stringify(tokenObject);
|
|
11
|
-
return this.cache.set(token, tokenObject, expire);
|
|
12
|
-
}
|
|
13
|
-
///从缓存中获取用户
|
|
14
|
-
async getToken(token,isObject=true) {
|
|
15
|
-
let value = await this.cache.get(token);
|
|
16
|
-
if (!value) return value;
|
|
17
|
-
return isObject ? JSON.parse(value) : value;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* token是否有效
|
|
21
|
-
* @param {*} token
|
|
22
|
-
*/
|
|
23
|
-
async tokenIsValid(token){
|
|
24
|
-
return (await this.getToken(token,false))!=null
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 删除Token
|
|
28
|
-
* @param {*} token
|
|
29
|
-
*/
|
|
30
|
-
deleteToken(token){
|
|
31
|
-
this.cache.delete(token);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 延长token的有效期
|
|
35
|
-
* @param {*} token
|
|
36
|
-
* @param {*} tokenObject
|
|
37
|
-
* @param {*} expire
|
|
38
|
-
*/
|
|
39
|
-
extendToken(token,expire) {
|
|
40
|
-
return this.cache.expire(token,expire);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports = module.exports.TokenHelper = (cacheinstance)=>{
|
|
44
|
-
return new TokenUtility(cacheinstance)
|
|
45
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
const { parseKeyValue, formatValue, validatorParamsType } = require('./keywordparse');
|
|
2
|
-
/**
|
|
3
|
-
* 将结果转化为Mapping对应的键值输出
|
|
4
|
-
* @param {*} originalResult
|
|
5
|
-
* @param {*} fieldConfig
|
|
6
|
-
* @returns transferName2Mapping
|
|
7
|
-
*/
|
|
8
|
-
module.exports.Data2View = (originalResult, fieldConfig) => {
|
|
9
|
-
if (!originalResult) return { successed: true, data: null };
|
|
10
|
-
if (!fieldConfig || fieldConfig.length == 0) return { successed: true, data: originalResult };//return success({successed:true,data:originalResult});
|
|
11
|
-
|
|
12
|
-
let retResult = [];
|
|
13
|
-
for (const row of originalResult) {
|
|
14
|
-
let item = {};
|
|
15
|
-
for (const element of fieldConfig) {
|
|
16
|
-
///如果该字段的序列化仅用于向后保存,则序列化到
|
|
17
|
-
///前端页面的时候就不再输出了
|
|
18
|
-
if (element.direction == "backonly") continue;
|
|
19
|
-
let rawValue = row[element.name];
|
|
20
|
-
if (!rawValue && element.nullValue) rawValue = element.nullValue;
|
|
21
|
-
///格式化输出
|
|
22
|
-
if (element.format) {
|
|
23
|
-
rawValue = formatValue(rawValue, element.format)
|
|
24
|
-
}
|
|
25
|
-
item[element.mapping || element.name] = rawValue;
|
|
26
|
-
}
|
|
27
|
-
retResult.push(item);
|
|
28
|
-
}
|
|
29
|
-
return { successed: true, data: retResult };
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 数据准备保存到数据库中,从视图提交的数据中进行转换
|
|
34
|
-
* @param {*} req
|
|
35
|
-
* @param {*} fieldConfig
|
|
36
|
-
* @param {*} doWhat
|
|
37
|
-
* @returns transferMapping2Name
|
|
38
|
-
*/
|
|
39
|
-
module.exports.View2Data = (req, fieldConfig, doWhat) => {
|
|
40
|
-
let model = {}, tmpModel = {};
|
|
41
|
-
// var ingoreKey = req.query.ingoreNullKey != null && req.query.ingoreNullKey == 'true';
|
|
42
|
-
if (Array.isArray(fieldConfig)) {
|
|
43
|
-
for (const element of fieldConfig) {
|
|
44
|
-
///如果该字段的序列化仅用于向前端输出,保存时忽略
|
|
45
|
-
if (element.direction == "frontonly") continue;
|
|
46
|
-
if (element.action && element.action.indexOf(doWhat) < 0) continue;
|
|
47
|
-
let bodyKey = element.mapping || element.name;
|
|
48
|
-
let postValue = req.body[bodyKey];
|
|
49
|
-
////body中没有这个属性
|
|
50
|
-
//&& element.ignoreundefined == true
|
|
51
|
-
if (postValue === undefined) {
|
|
52
|
-
if ((doWhat == 'update' && !element.required) ||
|
|
53
|
-
(doWhat == 'create' && !element.required && !element.default && !element.nullValue))
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
///去除两边的空格,默认是去掉空格
|
|
57
|
-
if (typeof (postValue) === 'string') {
|
|
58
|
-
if ((!element.trim || element.trim == true)) postValue.trim();
|
|
59
|
-
if (element.maxlength && postValue.length > element.maxlength) {
|
|
60
|
-
return { successed: false, errcode: 6, errmsg: '输入的长度超出,最大允许' + element.maxlength, name: element.mapping }
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
///如果提交的值为空
|
|
65
|
-
if (!postValue) { // if (commonHelper.isNullOrEmpty(postValue)) {
|
|
66
|
-
if (element.nullValue)
|
|
67
|
-
postValue = parseKeyValue(req, element.nullValue);
|
|
68
|
-
else
|
|
69
|
-
postValue = null;
|
|
70
|
-
}
|
|
71
|
-
if (!postValue && element.default) postValue = element.default;
|
|
72
|
-
///不允许为空值
|
|
73
|
-
if (element.required === true && !postValue) return { successed: false, errcode: 5, errmsg: '请填写必填字段内容', name: bodyKey }
|
|
74
|
-
// //空值则不替换或不设置该字段
|
|
75
|
-
// if (!postValue && element.ignorenull===true){
|
|
76
|
-
// continue;
|
|
77
|
-
// }
|
|
78
|
-
//验证值的类型是否正确,主要验证是否数字
|
|
79
|
-
if (element.type && postValue && !validatorParamsType(postValue, element.type)) {
|
|
80
|
-
return { successed: false, errcode: 4, errmsg: `提交的值与要求的类型不匹配:(${bodyKey},${element.type})`, name: bodyKey }
|
|
81
|
-
}
|
|
82
|
-
///格式化结果 : 这个可以用,暂时先去掉
|
|
83
|
-
// if (postValue && element.format) {
|
|
84
|
-
// if (stringHelper.startWith(element.format, '{') && stringHelper.endsWith(element.format, '}'))
|
|
85
|
-
// postValue = stringHelper.format(element.format, postValue);
|
|
86
|
-
// else {
|
|
87
|
-
// postValue = ViewHelper.specialFormatValue(element.format, postValue, false);
|
|
88
|
-
// }
|
|
89
|
-
// }
|
|
90
|
-
////这个字段是否需要放在其他对象中
|
|
91
|
-
if (element.model) {
|
|
92
|
-
let modelitem = tmpModel[element.model] || {};
|
|
93
|
-
modelitem[element.name] = postValue;
|
|
94
|
-
tmpModel[element.model] = modelitem;
|
|
95
|
-
}
|
|
96
|
-
else
|
|
97
|
-
model[element.name] = postValue;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
else
|
|
102
|
-
model = req.body;
|
|
103
|
-
req.modellist = tmpModel;
|
|
104
|
-
return { successed: true, data: model };
|
|
105
|
-
}
|