doomiwork 3.7.12 → 4.0.1
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/configuration/appsetting.js +2 -6
- package/configuration/routerconfig.js +126 -128
- package/core/actionresult.js +1 -1
- package/core/controller.js +73 -72
- package/core/database/mysqlbase.js +17 -13
- package/core/database/poolmanager.js +12 -14
- package/core/doomiwork.js +36 -21
- package/index.js +3 -1
- package/package.json +3 -3
- package/utilities/excelutility.js +139 -0
- package/utilities/keywordparse.js +87 -42
- package/utilities/requestparser.js +139 -203
- package/utilities/tokenutility.js +30 -15
- package/utilities/transferutility.js +96 -128
- package/core/Interceptor.js +0 -14
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* MySql 封装 (简单,应该尚未完善)
|
|
3
3
|
*/
|
|
4
|
-
//var mysql = require('mysql');
|
|
5
|
-
const apiResult = require('../actionresult');
|
|
6
|
-
const logHelper = require('doomi-helper').logHelper;
|
|
7
|
-
const PoolManager = require('./poolmanager')
|
|
8
4
|
const mysql = require('mysql');
|
|
5
|
+
const apiResult = require('../actionresult');
|
|
6
|
+
// const logHelper = require('doomi-helper').logHelper;
|
|
7
|
+
const { createDatabasePool } = require('./poolmanager')
|
|
9
8
|
const executeSqlWithConnection = Symbol("executeSqlWithConnection");
|
|
10
9
|
class Database {
|
|
11
10
|
/**
|
|
@@ -13,10 +12,14 @@ class Database {
|
|
|
13
12
|
* @param {*} connectionstring
|
|
14
13
|
*/
|
|
15
14
|
constructor(connectionstring) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
this.pool = createDatabasePool(connectionstring);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {{ trace: (arg0: string, arg1: any, arg2: string, arg3: any) => void; error: (arg0: string, arg1: any) => void; }} logUtility
|
|
20
|
+
*/
|
|
21
|
+
set logger(logUtility){
|
|
22
|
+
this.logger = logUtility;//logHelper.getInstance().getLogger("framework");
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* 防Sql注入进行编码
|
|
@@ -65,7 +68,7 @@ class Database {
|
|
|
65
68
|
* @returns
|
|
66
69
|
*/
|
|
67
70
|
getConnection() {
|
|
68
|
-
return new Promise((success
|
|
71
|
+
return new Promise((success) => {
|
|
69
72
|
if (!this.pool) {
|
|
70
73
|
return success(null);
|
|
71
74
|
}
|
|
@@ -81,7 +84,7 @@ class Database {
|
|
|
81
84
|
* @param {*} parameters 参数
|
|
82
85
|
*/
|
|
83
86
|
executeSql(sqlCommand, parameters, conn, autoclose = true) {
|
|
84
|
-
let logger = this.logger;
|
|
87
|
+
// let logger = this.logger;
|
|
85
88
|
// let that = this;
|
|
86
89
|
if (conn) {
|
|
87
90
|
return this[executeSqlWithConnection](sqlCommand, parameters, conn, autoclose)
|
|
@@ -93,7 +96,7 @@ class Database {
|
|
|
93
96
|
///创建出数据库连接,准备执行
|
|
94
97
|
this.pool.getConnection(async (err, connection) => {
|
|
95
98
|
if (err) {
|
|
96
|
-
logger.error("Database Connected Failed :" + err);
|
|
99
|
+
// if (logger) logger.error("Database Connected Failed :" + err);
|
|
97
100
|
return success(apiResult.DB_CONNECTED_FAILED);
|
|
98
101
|
}
|
|
99
102
|
let sqlResult = await this[executeSqlWithConnection](sqlCommand, parameters, connection, autoclose)
|
|
@@ -111,11 +114,12 @@ class Database {
|
|
|
111
114
|
[executeSqlWithConnection](sqlCommand, parameters, conn, autoclose = true) {
|
|
112
115
|
if (!conn) return Promise.resolve(apiResult.DB_CONNECTED_FAILED);
|
|
113
116
|
return new Promise((success) => {
|
|
114
|
-
this.logger.trace("SqlCommand:", sqlCommand, "Parameters:", parameters);
|
|
117
|
+
// this.logger.trace("SqlCommand:", sqlCommand, "Parameters:", parameters);
|
|
115
118
|
return conn.query(sqlCommand, parameters, (err, rows) => {
|
|
116
119
|
if (autoclose) conn.release();
|
|
117
120
|
if (err) {
|
|
118
|
-
this.logger.error("Database Query Error :" + err, sqlCommand);
|
|
121
|
+
// this.logger.error("Database Query Error :" + err, sqlCommand);
|
|
122
|
+
console.log('数据库操作错误', err, sqlCommand)
|
|
119
123
|
this.logError(null, '数据库操作错误:' + err + sqlCommand)
|
|
120
124
|
return success(Object.assign(apiResult.DB_EXECUTE_FAILED, { errmessage:'数据库操作错误'}));// err.message }));
|
|
121
125
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
const mysql = require('mysql');
|
|
2
2
|
const appsetting = require('../../configuration/appsetting').getCurrentApp();
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
const pool = mysql.createPool(appsetting.getConnection(connect || 'dev'));
|
|
13
|
-
PoolManager[connect] = pool;
|
|
14
|
-
return pool;
|
|
3
|
+
/**
|
|
4
|
+
* 创建和管理数据库链接池
|
|
5
|
+
* @param {*} connect
|
|
6
|
+
*/
|
|
7
|
+
let PoolManager = {};
|
|
8
|
+
module.exports.createDatabasePool=(connect)=>{
|
|
9
|
+
if (PoolManager[connect]!=null){
|
|
10
|
+
return PoolManager[connect];
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const pool = mysql.createPool(appsetting.getConnection(connect || 'dev'));
|
|
13
|
+
PoolManager[connect] = pool;
|
|
14
|
+
return pool;
|
|
15
|
+
}
|
package/core/doomiwork.js
CHANGED
|
@@ -2,38 +2,53 @@
|
|
|
2
2
|
Doomisoft框架入口类
|
|
3
3
|
自动加载配置与routerConfig中的路由配置
|
|
4
4
|
*/
|
|
5
|
-
const
|
|
5
|
+
const { loadController } = require('../configuration/routerconfig')
|
|
6
6
|
const config = require('../configuration/appsetting').getCurrentApp();
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const {redisHelper,logHelper} = require('doomi-helper');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path')
|
|
9
|
+
// const {redisHelper,logHelper} = require('doomi-helper');
|
|
11
10
|
class Doomiwork {
|
|
12
|
-
static startWork(application) {
|
|
13
|
-
const startupRoot = process.cwd();
|
|
11
|
+
static startWork(application,option) {
|
|
12
|
+
// const startupRoot = process.cwd();
|
|
14
13
|
///将configuration对象放置于app对象中.所有的controller都可以使用
|
|
15
14
|
application.config = config;
|
|
16
15
|
///启动redis进行缓存
|
|
17
16
|
////为每个controller注入同一个redis实例
|
|
18
|
-
if (config.getSetting("redis",false)===true){
|
|
19
|
-
application.redis =
|
|
17
|
+
if (config.getSetting("redis", false) === true && option.redis){
|
|
18
|
+
application.redis = option.redis;// redisHelper.getInstance();
|
|
20
19
|
}
|
|
21
20
|
////记录用户行为的日志记录器
|
|
22
|
-
const logHandler = config.getSetting("logaction", null)
|
|
23
|
-
if (logHandler){
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
// const logHandler = config.getSetting("logaction", null)
|
|
22
|
+
// if (logHandler){
|
|
23
|
+
// let actionLogger = path.join(startupRoot, logHandler);
|
|
24
|
+
// if (actionLogger && fs.existsSync(actionLogger)) {
|
|
25
|
+
// const logInstance = require(actionLogger);
|
|
26
|
+
// application.actionLogger = new logInstance();
|
|
27
|
+
// }
|
|
28
|
+
// }
|
|
29
|
+
///用户操作日志记录
|
|
30
|
+
if(config.getSetting("logaction", false)===true && option.logaction){
|
|
31
|
+
application.actionLogger = option.logaction;
|
|
32
|
+
}
|
|
33
|
+
///日志记录器
|
|
34
|
+
if (config.getSetting("logger", false) === true && option.logger) {
|
|
35
|
+
application.logger = option.logger;// redisHelper.getInstance();
|
|
29
36
|
}
|
|
30
|
-
|
|
31
|
-
application.logger = logHelper.getInstance().getLogger("framework");
|
|
32
|
-
|
|
37
|
+
//application.logger = logHelper.getInstance().getLogger("framework");
|
|
33
38
|
/**全局所有请求拦截器 */
|
|
34
|
-
application.use('/',
|
|
39
|
+
application.use('/',(req,res,next)=>{
|
|
40
|
+
req.user = req.headers;
|
|
41
|
+
return next();
|
|
42
|
+
});
|
|
35
43
|
/** 加载所有的控制器 */
|
|
36
|
-
|
|
44
|
+
if (!option.routes){
|
|
45
|
+
const roterfile = path.join(process.cwd(), 'routerconfig.json');
|
|
46
|
+
///将配置中的所有需要加载的controller文件都加载出来
|
|
47
|
+
if (fs.existsSync(roterfile)){
|
|
48
|
+
option.routes = require(roterfile)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
loadController(application, option.routes)
|
|
37
52
|
Doomiwork.app = application;
|
|
38
53
|
}
|
|
39
54
|
/**
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doomiwork",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "doomisoft nodejs web framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"author": "stephen.shen",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"doomi-helper": "^2.3.1",
|
|
18
17
|
"express": "^4.17.1",
|
|
19
18
|
"moment": "^2.29.1",
|
|
20
19
|
"mysql": "^2.18.1",
|
|
21
|
-
"node-uuid": "^1.4.8"
|
|
20
|
+
"node-uuid": "^1.4.8",
|
|
21
|
+
"node-xlsx": "^0.23.0"
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const xlsx = require('node-xlsx');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const uuid = require('node-uuid');
|
|
5
|
+
class ExcelUtility {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.exportFolder = path.join(process.cwd(), '/public/excel/');
|
|
8
|
+
let configfile = path.join(process.cwd(), 'excelconfig.json');
|
|
9
|
+
if (fs.existsSync(configfile))
|
|
10
|
+
this.excelConfig = require(configfile);
|
|
11
|
+
else
|
|
12
|
+
this.excelConfig = {};
|
|
13
|
+
}
|
|
14
|
+
static getInstance() {
|
|
15
|
+
if (!ExcelUtility.instance) ExcelUtility.instance = new ExcelUtility();
|
|
16
|
+
return ExcelUtility.instance;
|
|
17
|
+
}
|
|
18
|
+
///读取Excel的内容
|
|
19
|
+
readExcel(fileName) {
|
|
20
|
+
//读取文件内容
|
|
21
|
+
const obj = xlsx.parse(fileName);//__dirname+'/test.xlsx');
|
|
22
|
+
const excelObj = obj[0].data;
|
|
23
|
+
console.log(excelObj);
|
|
24
|
+
return excelObj;
|
|
25
|
+
}
|
|
26
|
+
///写Excel文件
|
|
27
|
+
createExcelBuffer(data, fileName, workSheetName) {
|
|
28
|
+
var sheetName = 'sheet1';
|
|
29
|
+
if (workSheetName == null) sheetName = workSheetName;
|
|
30
|
+
var buffer = xlsx.build([{ name: 'sheet1', data: data }]);
|
|
31
|
+
|
|
32
|
+
res.set({
|
|
33
|
+
"Content-type": "application/octet-stream",
|
|
34
|
+
"Content-Disposition": "attachment;filename=" + encodeURI(fileName)
|
|
35
|
+
});
|
|
36
|
+
fReadStream = fs.createReadStream(buffer);
|
|
37
|
+
fReadStream.on("data", (chunk) => res.write(chunk, "binary"));
|
|
38
|
+
fReadStream.on("end", function () {
|
|
39
|
+
res.end();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
///写Excel文件
|
|
43
|
+
async writeExcel(data, workSheetName) {
|
|
44
|
+
let sheetName = 'sheet1';
|
|
45
|
+
if (workSheetName == null) sheetName = workSheetName;
|
|
46
|
+
try {
|
|
47
|
+
let randomFile = uuid.v4() + '.xlsx';
|
|
48
|
+
let fileName = path.resolve(this.exportFolder, randomFile);
|
|
49
|
+
let _saveDir = path.dirname(fileName);
|
|
50
|
+
///创建本地文件夹
|
|
51
|
+
if (!fs.existsSync(_saveDir)) {
|
|
52
|
+
if (!this.mkdirsSync(_saveDir)) {
|
|
53
|
+
return { success: false, errorcode: 1, errmessage: 'create folder failed!' };
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const buffer = xlsx.build([{ name: workSheetName, data: data }]);
|
|
57
|
+
fs.writeFileSync(fileName, buffer, { 'flag': 'w' });
|
|
58
|
+
return { successed: true, fileName: randomFile };
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return { successed: false, errorcode: 1, errmessage: err };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
///导出记录集到Excel,写入
|
|
65
|
+
///dataRow :记录集
|
|
66
|
+
///exportConfig : 导出的映射配置,如没有则将dataRow直接导出
|
|
67
|
+
///workSheetName : 导出的Excel 文件 WorkSheet名
|
|
68
|
+
async recordset2ExcelFile(dataRow, exportConfig, readyDataFunc) {
|
|
69
|
+
let _instance = this;
|
|
70
|
+
//var setting = exportConfig ? excelConfig[exportConfig] : null;
|
|
71
|
+
let setting = exportConfig ? _instance.excelConfig[exportConfig] : null;
|
|
72
|
+
let dataBuffer = [],worksheetName = "sheet1", fieldKey = [], titleRow = [];
|
|
73
|
+
if (setting != null) {
|
|
74
|
+
worksheetName = setting.worksheet == null ? "sheet1" : setting.worksheet;
|
|
75
|
+
////第一行导出标题行
|
|
76
|
+
setting.columns.forEach((field) => {
|
|
77
|
+
var dataOption = { type: 'title', config: exportConfig, title: field.title, field: field.name };
|
|
78
|
+
if (readyDataFunc != null && typeof (readyDataFunc) == "function")
|
|
79
|
+
dataOption = readyDataFunc(dataOption)
|
|
80
|
+
titleRow.push(dataOption.title);
|
|
81
|
+
fieldKey.push(dataOption.field);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else if (dataRow.length > 0) {
|
|
85
|
+
var firstRow = dataRow[0];
|
|
86
|
+
Object.keys(firstRow).forEach(key => {
|
|
87
|
+
var dataOption = { type: 'title', config: null, title: key, field: key };
|
|
88
|
+
if (readyDataFunc != null && typeof (readyDataFunc) == "function")
|
|
89
|
+
dataOption = readyDataFunc(dataOption)
|
|
90
|
+
titleRow.push(dataOption.title);
|
|
91
|
+
fieldKey.push(dataOption.field);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (titleRow.length > 0) {
|
|
95
|
+
dataBuffer.push(titleRow);
|
|
96
|
+
dataRow.forEach((rowItem) => {
|
|
97
|
+
var dataRow = [];
|
|
98
|
+
fieldKey.forEach((field) => {
|
|
99
|
+
var dataOption = { type: 'data', config: exportConfig, field: field, data: rowItem, value: rowItem[field] };
|
|
100
|
+
if (readyDataFunc != null && typeof (readyDataFunc) == "function")
|
|
101
|
+
dataOption = readyDataFunc(dataOption)
|
|
102
|
+
dataRow.push(dataOption.value);
|
|
103
|
+
});
|
|
104
|
+
dataBuffer.push(dataRow);
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
var result = await _instance.writeExcel(dataBuffer, worksheetName);
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 递归创建多级目录
|
|
113
|
+
* @param {*} dirpath
|
|
114
|
+
* @param {*} mode
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
mkdirsSync(dirpath, mode) {
|
|
118
|
+
if (!fs.existsSync(dirpath)) {
|
|
119
|
+
var pathtmp;
|
|
120
|
+
var splitPath = dirpath.split(path.sep);
|
|
121
|
+
for (var nLoop = 0; nLoop < splitPath.length; nLoop++) {
|
|
122
|
+
var dirname = splitPath[nLoop];
|
|
123
|
+
if (dirname.length == 0) {
|
|
124
|
+
pathtmp = "/";
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (pathtmp)
|
|
128
|
+
pathtmp = path.join(pathtmp, dirname);
|
|
129
|
+
else
|
|
130
|
+
pathtmp = dirname;
|
|
131
|
+
if (!fs.existsSync(pathtmp)) {
|
|
132
|
+
fs.mkdirSync(pathtmp, mode)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports = module.exports = ExcelUtility;
|
|
@@ -4,50 +4,95 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const uuid = require('node-uuid');
|
|
6
6
|
const moment = require('moment')
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
case "null()": return null;
|
|
31
|
-
default: return (req.body && req.body[str])||(req.query && req.query[str]);
|
|
32
|
-
}
|
|
7
|
+
/*
|
|
8
|
+
* 从上下文 解析关键字
|
|
9
|
+
* 或者已固定的方式解析关键字
|
|
10
|
+
*/
|
|
11
|
+
module.exports.parseKeyValue=(req,str)=>{
|
|
12
|
+
if (!str) return str;
|
|
13
|
+
const strItems = str.split('.');
|
|
14
|
+
if (strItems.length===1)
|
|
15
|
+
{
|
|
16
|
+
switch(str.toLowerCase()){
|
|
17
|
+
case "userid()":
|
|
18
|
+
if (req.user && req.user.id) return req.user.id;
|
|
19
|
+
return uuid.v4();
|
|
20
|
+
case "uuid()" : return uuid.v4();
|
|
21
|
+
case "appid()" :
|
|
22
|
+
if (req.user && req.user.appid) return req.user.appid;
|
|
23
|
+
return null;
|
|
24
|
+
case "orgid()" :
|
|
25
|
+
if (req.user && req.user.id) return req.user.orgnizations;
|
|
26
|
+
return null;
|
|
27
|
+
case "now()": return moment().format('YYYY-MM-DD HH:mm:ss');
|
|
28
|
+
case "null()": return null;
|
|
29
|
+
default: return (req.body && req.body[str])||(req.query && req.query[str]);
|
|
33
30
|
}
|
|
34
|
-
|
|
31
|
+
}
|
|
32
|
+
else
|
|
33
|
+
{
|
|
34
|
+
let collection;
|
|
35
|
+
if (strItems[0]=="" || strItems[1]=="") return str;
|
|
36
|
+
switch(strItems[0].toLowerCase())
|
|
35
37
|
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
case "value": return strItems[1];
|
|
44
|
-
case "headers": collection = req.headers; break;
|
|
45
|
-
case "user": collection = req.user || {}; break;
|
|
46
|
-
default: collection = req.body; break;
|
|
47
|
-
}
|
|
48
|
-
if (collection) return collection[strItems[1]];
|
|
49
|
-
return '';
|
|
38
|
+
case "query" : collection = req.query; break;
|
|
39
|
+
case "form": collection = req.body;break;
|
|
40
|
+
case "params": collection = req.params; break;
|
|
41
|
+
case "value": return strItems[1];
|
|
42
|
+
case "headers": collection = req.headers; break;
|
|
43
|
+
case "user": collection = req.user || {}; break;
|
|
44
|
+
default: collection = req.body; break;
|
|
50
45
|
}
|
|
46
|
+
if (collection) return collection[strItems[1]];
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 校验参数的类型
|
|
53
|
+
* @param {*} value 数值
|
|
54
|
+
* @param {*} dataType 校验的类型
|
|
55
|
+
* @param {*} defaultValue 如果不满足,则返回默认的
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
module.exports.validatorParamsType=(value, dataType, defaultValue = null)=> {
|
|
59
|
+
if (!value || !dataType) return value;
|
|
60
|
+
switch (dataType.toLowerCase()) {
|
|
61
|
+
case 'guid': ///限制长度为36位的GUID
|
|
62
|
+
if (value.length != 36 || value.split('-').length != 5) return defaultValue;
|
|
63
|
+
break;
|
|
64
|
+
case 'number': ///限制为数字
|
|
65
|
+
if (isNaN(value)) return defaultValue;
|
|
66
|
+
break;
|
|
67
|
+
case 'date': ///限制为日期,格式输出为YYYY-MM-DD
|
|
68
|
+
let date = Date.parse(value);
|
|
69
|
+
if (isNaN(date)) return defaultValue;
|
|
70
|
+
return moment(date).format('YYYY-MM-DD');
|
|
71
|
+
case 'datetime': ///限制为包含时间的日期
|
|
72
|
+
let datetime = Date.parse(value);
|
|
73
|
+
if (isNaN(datetime)) return defaultValue;
|
|
74
|
+
return datetime;
|
|
51
75
|
}
|
|
76
|
+
return value;
|
|
52
77
|
}
|
|
53
|
-
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 将原始值format后输出
|
|
81
|
+
* @param {*} value 123
|
|
82
|
+
* @param {*} format ${value}
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
module.exports.formatValue = (value, format)=> {
|
|
86
|
+
if (!format) return value;
|
|
87
|
+
return format.replace(/\${value}/ig,value)
|
|
88
|
+
// let formatItem = format.split('|');
|
|
89
|
+
// let coll = {};
|
|
90
|
+
// formatItem.forEach(item => {
|
|
91
|
+
// if (item == '') return;
|
|
92
|
+
// var itemValues = item.split(':');
|
|
93
|
+
// if (itemValues.length != 2) return;
|
|
94
|
+
// coll[itemValues[keyIndex]] = itemValues[1 - keyIndex];
|
|
95
|
+
// })
|
|
96
|
+
// //let jsonFormat =JSON.parse('{'+format+'}');
|
|
97
|
+
// return coll[value];
|
|
98
|
+
}
|