mm_os 4.3.7 → 5.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/README.md +102 -504
- package/index.js +26 -19
- package/lib/os.js +536 -0
- package/package.json +60 -84
- package/LICENSE +0 -21
- package/README_EN.md +0 -505
- package/adapter/adapter.js +0 -484
- package/adapter/custom_persistence.js +0 -661
- package/adapter/mqtt.js +0 -254
- package/adapter/socket.js +0 -244
- package/adapter/web.js +0 -92
- package/adapter/websocket.js +0 -43
- package/ai.js +0 -130
- package/com/api/README.md +0 -3
- package/com/api/com.json +0 -5
- package/com/api/config.tpl.json +0 -41
- package/com/api/drive.js +0 -732
- package/com/api/index.js +0 -201
- package/com/api/oauth.js +0 -200
- package/com/api/script.tpl.js +0 -32
- package/com/cmd/README.md +0 -11
- package/com/cmd/com.json +0 -5
- package/com/cmd/config.tpl.json +0 -48
- package/com/cmd/drive.js +0 -176
- package/com/cmd/index.js +0 -287
- package/com/cmd/job/config.json +0 -66
- package/com/cmd/job/index.js +0 -241
- package/com/cmd/job/test.js +0 -188
- package/com/cmd/msg.json +0 -48
- package/com/cmd/script.tpl.js +0 -12
- package/com/db/README.md +0 -3
- package/com/db/com.json +0 -5
- package/com/db/drive.js +0 -2206
- package/com/db/index.js +0 -241
- package/com/event/README.md +0 -4
- package/com/event/com.json +0 -5
- package/com/event/config.tpl.json +0 -20
- package/com/event/drive.js +0 -61
- package/com/event/index.js +0 -438
- package/com/event/script.tpl.js +0 -23
- package/com/mqtt/README.md +0 -47
- package/com/mqtt/com.json +0 -5
- package/com/mqtt/config.tpl.json +0 -42
- package/com/mqtt/drive.js +0 -704
- package/com/mqtt/index.js +0 -1052
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/script.tpl.js +0 -719
- package/com/nav/README.md +0 -2
- package/com/nav/com.json +0 -5
- package/com/nav/config.tpl.json +0 -84
- package/com/nav/drive.js +0 -702
- package/com/nav/index.js +0 -228
- package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
- package/com/nav/tpl/admin_pc/page_config.vue +0 -280
- package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
- package/com/nav/tpl/admin_pc/page_default.vue +0 -247
- package/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
- package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
- package/com/nav/tpl/admin_pc/page_table.vue +0 -296
- package/com/nav/tpl/admin_pc/page_type.vue +0 -321
- package/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
- package/com/nav/tpl/dev_pc/page_config.vue +0 -253
- package/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/com/nav/tpl/dev_pc/page_form.vue +0 -162
- package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
- package/com/nav/tpl/dev_pc/page_table.vue +0 -247
- package/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/com/nav/tpl/home_pc/page_channel.vue +0 -234
- package/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/com/nav/tpl/home_phone/page_list.vue +0 -234
- package/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/com/nav/viewmodel.js +0 -446
- package/com/param/README.md +0 -2
- package/com/param/com.json +0 -5
- package/com/param/config.tpl.json +0 -136
- package/com/param/drive.js +0 -502
- package/com/param/index.js +0 -158
- package/com/param/script.tpl.js +0 -12
- package/com/pendant/README.md +0 -3
- package/com/pendant/com.json +0 -5
- package/com/pendant/config.tpl.json +0 -32
- package/com/pendant/drive.js +0 -204
- package/com/pendant/index.js +0 -467
- package/com/pendant/pendant.html +0 -16
- package/com/pendant/script.tpl.js +0 -18
- package/com/socket/README.md +0 -47
- package/com/socket/com.json +0 -5
- package/com/socket/config.tpl.json +0 -12
- package/com/socket/drive.js +0 -679
- package/com/socket/index.js +0 -402
- package/com/socket/script.tpl.js +0 -41
- package/com/sql/README.md +0 -3
- package/com/sql/com.json +0 -5
- package/com/sql/config.tpl.json +0 -74
- package/com/sql/drive.js +0 -1328
- package/com/sql/index.js +0 -152
- package/com/sql/script.tpl.js +0 -47
- package/com/static/README.md +0 -2
- package/com/static/com.json +0 -5
- package/com/static/config.tpl.json +0 -24
- package/com/static/drive.js +0 -194
- package/com/static/index.js +0 -237
- package/com/static/script.tpl.js +0 -28
- package/com/task/README.md +0 -3
- package/com/task/com.json +0 -5
- package/com/task/config.tpl.json +0 -24
- package/com/task/drive.js +0 -428
- package/com/task/index.js +0 -159
- package/com/task/script.tpl.js +0 -40
- package/com/template/com.json +0 -5
- package/com/template/config.tpl.json +0 -16
- package/com/template/drive.js +0 -81
- package/com/template/index.js +0 -141
- package/com.js +0 -237
- package/common/README.md +0 -2
- package/common/middleware/web_after/index.js +0 -26
- package/common/middleware/web_after/middleware.json +0 -9
- package/common/middleware/web_base/index.js +0 -113
- package/common/middleware/web_base/middleware.json +0 -19
- package/common/middleware/web_before/index.js +0 -33
- package/common/middleware/web_before/middleware.json +0 -9
- package/common/middleware/web_cors/index.js +0 -87
- package/common/middleware/web_cors/middleware.json +0 -24
- package/common/middleware/web_error/index.js +0 -131
- package/common/middleware/web_error/middleware.json +0 -19
- package/common/middleware/web_ip/index.js +0 -15
- package/common/middleware/web_ip/middleware.json +0 -14
- package/common/middleware/web_logger/index.js +0 -156
- package/common/middleware/web_logger/middleware.json +0 -14
- package/common/middleware/web_main/index.js +0 -26
- package/common/middleware/web_main/middleware.json +0 -9
- package/common/middleware/web_static/index.js +0 -73
- package/common/middleware/web_static/middleware.json +0 -54
- package/common/middleware/web_waf/index.js +0 -395
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -711
- package/core/app/script.tpl.js +0 -52
- package/core/channel/index.js +0 -899
- package/core/channel/matcher.js +0 -585
- package/core/com/config.tpl.json +0 -16
- package/core/com/index.js +0 -77
- package/core/com/script.tpl.js +0 -5
- package/core/component/component.js +0 -42
- package/core/component/config.tpl.json +0 -63
- package/core/component/index.js +0 -273
- package/core/component/script.tpl.js +0 -19
- package/core/controller/config.tpl.json +0 -14
- package/core/controller/index.js +0 -371
- package/core/controller/script.tpl.js +0 -27
- package/core/factory/config.tpl.json +0 -14
- package/core/factory/entity.js +0 -275
- package/core/factory/index.js +0 -241
- package/core/factory/script.tpl.js +0 -16
- package/core/game/bat/index.js +0 -137
- package/core/game/bat/world.js +0 -622
- package/core/game/config.tpl.json +0 -16
- package/core/game/entity_admin.js +0 -230
- package/core/game/index.js +0 -186
- package/core/handler/config.tpl.json +0 -22
- package/core/handler/index.js +0 -181
- package/core/handler/script.tpl.js +0 -23
- package/core/logic/config.tpl.json +0 -14
- package/core/logic/index.js +0 -59
- package/core/logic/script.tpl.js +0 -19
- package/core/middleware/config.tpl.json +0 -16
- package/core/middleware/index.js +0 -117
- package/core/middleware/script.tpl.js +0 -37
- package/core/mod/config.tpl.json +0 -22
- package/core/mod/index.js +0 -136
- package/core/mod/script.tpl.js +0 -34
- package/core/model/config.tpl.json +0 -219
- package/core/model/index.js +0 -272
- package/core/model/model.js +0 -27
- package/core/model/script.tpl.js +0 -20
- package/core/notifier/config.tpl.json +0 -14
- package/core/notifier/index.js +0 -77
- package/core/notifier/script.tpl.js +0 -20
- package/core/plugin/config.tpl.json +0 -36
- package/core/plugin/index.js +0 -267
- package/core/plugin/script.tpl.js +0 -51
- package/core/pusher/config.tpl.json +0 -14
- package/core/pusher/index.js +0 -158
- package/core/pusher/script.tpl.js +0 -20
- package/core/room/bat/index.js +0 -170
- package/core/room/bat/room.js +0 -524
- package/core/room/config.tpl.json +0 -20
- package/core/room/index.js +0 -249
- package/core/room/room.js +0 -61
- package/core/scene/config.tpl.json +0 -14
- package/core/scene/index.js +0 -467
- package/core/scene/loop.js +0 -1306
- package/core/scene/map.js +0 -28
- package/core/scene/script.tpl.js +0 -22
- package/core/sender/config.tpl.json +0 -14
- package/core/sender/index.js +0 -79
- package/core/sender/script.tpl.js +0 -20
- package/core/service/config.tpl.json +0 -14
- package/core/service/index.js +0 -100
- package/core/service/script.tpl.js +0 -25
- package/core/store/config.tpl.json +0 -26
- package/core/store/index.js +0 -1794
- package/core/store/script.tpl.js +0 -22
- package/core/system/config.tpl.json +0 -18
- package/core/system/index.js +0 -312
- package/core/system/script.tpl.js +0 -77
- package/core/view/config.tpl.json +0 -14
- package/core/view/index.js +0 -91
- package/core/view/script.tpl.js +0 -20
- package/core/zone/bat/index.js +0 -744
- package/core/zone/config.tpl.json +0 -54
- package/core/zone/index.js +0 -655
- package/core/zone/script.tpl.js +0 -10
- package/core/zone/zone_bat.js +0 -136
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
- package/os.js +0 -53
- package/server.js +0 -602
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
package/com/param/drive.js
DELETED
|
@@ -1,502 +0,0 @@
|
|
|
1
|
-
const Item = require('mm_machine').Drive;
|
|
2
|
-
const Check = require('mm_check');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Param参数驱动类
|
|
6
|
-
* @augments {Item}
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class Drive extends Item {
|
|
10
|
-
static config = {
|
|
11
|
-
// 函数入口
|
|
12
|
-
'main': '',
|
|
13
|
-
// 参数过滤
|
|
14
|
-
'filter': true,
|
|
15
|
-
// 默认监听方法, 当查询参数中出现监听的关键词时,选择以该键值作为请求方式,否则默认为get
|
|
16
|
-
'method': 'method',
|
|
17
|
-
// 增
|
|
18
|
-
'add': {
|
|
19
|
-
// body参数
|
|
20
|
-
'body': [],
|
|
21
|
-
// body中的必填参数
|
|
22
|
-
'body_required': []
|
|
23
|
-
},
|
|
24
|
-
// 删
|
|
25
|
-
'del': {
|
|
26
|
-
// url中的query参数
|
|
27
|
-
'query': [],
|
|
28
|
-
// query中的必填参数
|
|
29
|
-
'query_required': []
|
|
30
|
-
},
|
|
31
|
-
// 改
|
|
32
|
-
'set': {
|
|
33
|
-
// url中的query参数
|
|
34
|
-
'query': [],
|
|
35
|
-
// query中的必填参数
|
|
36
|
-
'query_required': [],
|
|
37
|
-
// body参数
|
|
38
|
-
'body': [],
|
|
39
|
-
// body中的必填参数
|
|
40
|
-
'body_required': [],
|
|
41
|
-
// 不包含参数
|
|
42
|
-
'body_not': []
|
|
43
|
-
},
|
|
44
|
-
// 查
|
|
45
|
-
'get': {
|
|
46
|
-
// url中的query参数
|
|
47
|
-
'query': [],
|
|
48
|
-
// query中的必填参数
|
|
49
|
-
'query_required': []
|
|
50
|
-
},
|
|
51
|
-
// 导入
|
|
52
|
-
'import': {
|
|
53
|
-
// body中的参数
|
|
54
|
-
'body': ['name'],
|
|
55
|
-
// body中的必填参数
|
|
56
|
-
'body_required': ['file']
|
|
57
|
-
},
|
|
58
|
-
// 导出
|
|
59
|
-
'export': {
|
|
60
|
-
// url中的query参数
|
|
61
|
-
'query': [],
|
|
62
|
-
// query中的必填参数
|
|
63
|
-
'query_required': []
|
|
64
|
-
},
|
|
65
|
-
// 去重
|
|
66
|
-
'del_req': {
|
|
67
|
-
// query中的必填参数
|
|
68
|
-
'query_required': ['groupby', 'sort']
|
|
69
|
-
},
|
|
70
|
-
// 合计
|
|
71
|
-
'sum': {
|
|
72
|
-
// query中的必填参数
|
|
73
|
-
'query_required': ['field', 'groupby']
|
|
74
|
-
},
|
|
75
|
-
// 总数
|
|
76
|
-
'count': {
|
|
77
|
-
// query中的必填参数
|
|
78
|
-
'query_required': ['field', 'groupby']
|
|
79
|
-
},
|
|
80
|
-
// 提交
|
|
81
|
-
// "post": {
|
|
82
|
-
// // url中的query参数
|
|
83
|
-
// "query": [],
|
|
84
|
-
// // query中的必填参数
|
|
85
|
-
// "query_required": [],
|
|
86
|
-
// // body参数
|
|
87
|
-
// "body": [],
|
|
88
|
-
// // body中的必填参数
|
|
89
|
-
// "body_required": [],
|
|
90
|
-
// // 不包含参数
|
|
91
|
-
// "body_not": []
|
|
92
|
-
// },
|
|
93
|
-
// 验证参数集
|
|
94
|
-
'list': []
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 构造函数
|
|
99
|
-
* @param {object} config 配置参数
|
|
100
|
-
* @param {object} parent 父对象
|
|
101
|
-
* @class
|
|
102
|
-
*/
|
|
103
|
-
constructor(config, parent) {
|
|
104
|
-
super({ ...Drive.config, ...config }, parent);
|
|
105
|
-
// 默认启用热更新
|
|
106
|
-
this.mode = 3;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 获取模板目录
|
|
112
|
-
* @returns {string} 模板目录
|
|
113
|
-
*/
|
|
114
|
-
Drive.prototype._getTplDir = function () {
|
|
115
|
-
return __dirname;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 更新验证对象
|
|
120
|
-
*/
|
|
121
|
-
Drive.prototype.updateCheck = function () {
|
|
122
|
-
var lt = this.config.list;
|
|
123
|
-
var len = lt.length;
|
|
124
|
-
for (var i = 0; i < len; i++) {
|
|
125
|
-
var o = lt[i];
|
|
126
|
-
if (!o.load_check) {
|
|
127
|
-
lt[i] = new Check(o);
|
|
128
|
-
lt[i].load_check = true;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 预设
|
|
135
|
-
*/
|
|
136
|
-
Drive.prototype._preset = function () {
|
|
137
|
-
this.updateCheck();
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/// 新建配置参数模型, 用于动态创建配置时
|
|
141
|
-
Drive.prototype.model = function () {
|
|
142
|
-
return new Check({
|
|
143
|
-
// 参数名
|
|
144
|
-
'name': 'name',
|
|
145
|
-
// 参数介绍名
|
|
146
|
-
'title': '名称',
|
|
147
|
-
// 参数做用描述
|
|
148
|
-
'description': '用户名称,传入字符串',
|
|
149
|
-
// 函数入口
|
|
150
|
-
'main': '',
|
|
151
|
-
// 是否唯一值, 需配合数据库验证
|
|
152
|
-
'only': false,
|
|
153
|
-
// 分隔符号, 用于查询时判断多个传参
|
|
154
|
-
'splitter': '|',
|
|
155
|
-
// 是否主键
|
|
156
|
-
'key': false,
|
|
157
|
-
// 参数类型 string字符串、number数字、bool布尔、dateTime时间、object对象类型、array数组类型
|
|
158
|
-
'type': 'string',
|
|
159
|
-
// 数据存储类型 tinyint布尔型(0,1),smallint短整数型,mediumint中整数型,int长整数型,float浮点数型,double双精度型,timestamp时间戳型,date日期型,time时间型,varchar字符串型,text长文本型
|
|
160
|
-
'dataType': '',
|
|
161
|
-
// 字符串相关验证
|
|
162
|
-
'string': {
|
|
163
|
-
// 非空
|
|
164
|
-
'notEmpty': false,
|
|
165
|
-
// 最小长度
|
|
166
|
-
'min': 0,
|
|
167
|
-
// 最大长度
|
|
168
|
-
'max': 0,
|
|
169
|
-
// 验证字符串范围, 传入两个成员, 最小长度和最大长度。例如:[0, 0]
|
|
170
|
-
'range': [],
|
|
171
|
-
// 验证正则表达式
|
|
172
|
-
'regex': '',
|
|
173
|
-
// 验证与某个参数值是否相同
|
|
174
|
-
'identical': '',
|
|
175
|
-
// 验证与某个参数值是否不同
|
|
176
|
-
'different': '',
|
|
177
|
-
// 后缀名, 多个后缀名用“|”分隔
|
|
178
|
-
'extension': '',
|
|
179
|
-
// 格式验证 email、url、date、dateISO、number、digits、phone
|
|
180
|
-
'format': ''
|
|
181
|
-
},
|
|
182
|
-
// 数值相关验证
|
|
183
|
-
'number': {
|
|
184
|
-
// 最小值
|
|
185
|
-
'min': 0,
|
|
186
|
-
// 最大值
|
|
187
|
-
'max': 0,
|
|
188
|
-
// 验证字符串范围
|
|
189
|
-
'range': []
|
|
190
|
-
},
|
|
191
|
-
'default': ''
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* 验证值是否符合
|
|
197
|
-
* @param {object} model 验证模型
|
|
198
|
-
* @param {object} value 被验证的值
|
|
199
|
-
* @param {Array} requireds 必填项名称数组
|
|
200
|
-
* @returns {object} 没通过返回信息,否则返回空
|
|
201
|
-
*/
|
|
202
|
-
Drive.prototype.checkVal = function (model, value, requireds) {
|
|
203
|
-
var msg;
|
|
204
|
-
if (value === '' || value === undefined || value === null) {
|
|
205
|
-
if (requireds.has(model.name)) {
|
|
206
|
-
msg = model.msgHead(model) + model.msg('required');
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
msg = model.run(value);
|
|
210
|
-
if (!msg) {
|
|
211
|
-
msg = this.main(model, value);
|
|
212
|
-
}
|
|
213
|
-
if (msg) {
|
|
214
|
-
return msg;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return msg;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* 获取模型
|
|
222
|
-
* @param {string} name 名称
|
|
223
|
-
* @returns {object} 配置模型
|
|
224
|
-
*/
|
|
225
|
-
Drive.prototype.getCheckModel = function (name) {
|
|
226
|
-
var model;
|
|
227
|
-
var lt = this.config.list;
|
|
228
|
-
for (var i = 0, o; o = lt[i++];) {
|
|
229
|
-
if (o['name'] === name) {
|
|
230
|
-
model = o;
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return model;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* 执行验证
|
|
239
|
-
* @param {object} params 请求参数集合
|
|
240
|
-
* @param {Array} arr 要验证的参数名数组
|
|
241
|
-
* @param {Array} required 必填项名称数组
|
|
242
|
-
* @returns {string|undefined} 返回验证结果
|
|
243
|
-
*/
|
|
244
|
-
Drive.prototype.checkSub = function (params, arr, required) {
|
|
245
|
-
if (!params) {
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
for (var i = 0; i < arr.length; i++) {
|
|
249
|
-
var msg = this._checkParam(params, arr[i], required);
|
|
250
|
-
if (msg) {
|
|
251
|
-
return msg;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return undefined;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* 检查单个参数
|
|
259
|
-
* @param {object} params 请求参数集合
|
|
260
|
-
* @param {string} key 参数名
|
|
261
|
-
* @param {Array} required 必填项名称数组
|
|
262
|
-
* @returns {string|undefined} 返回验证结果
|
|
263
|
-
* @private
|
|
264
|
-
*/
|
|
265
|
-
Drive.prototype._checkParam = function (params, key, required) {
|
|
266
|
-
var o = this.getCheckModel(key);
|
|
267
|
-
if (!o) {
|
|
268
|
-
return undefined;
|
|
269
|
-
}
|
|
270
|
-
var value = params[key];
|
|
271
|
-
var msg = this.checkVal(o, value, required);
|
|
272
|
-
if (msg) {
|
|
273
|
-
return msg;
|
|
274
|
-
}
|
|
275
|
-
if (value && o.string) {
|
|
276
|
-
return this._checkStringRules(o, value, params);
|
|
277
|
-
}
|
|
278
|
-
return undefined;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* 检查字符串规则
|
|
283
|
-
* @param {object} model 验证模型
|
|
284
|
-
* @param {string} value 参数值
|
|
285
|
-
* @param {object} params 请求参数集合
|
|
286
|
-
* @returns {string|undefined} 返回验证结果
|
|
287
|
-
* @private
|
|
288
|
-
*/
|
|
289
|
-
Drive.prototype._checkStringRules = function (model, value, params) {
|
|
290
|
-
if (model.string.identical) {
|
|
291
|
-
return this._checkIdenRule(model, value, params);
|
|
292
|
-
} else if (model.string.different) {
|
|
293
|
-
return this._checkDiffRule(model, value, params);
|
|
294
|
-
}
|
|
295
|
-
return undefined;
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* 检查相同规则
|
|
300
|
-
* @param {object} model 验证模型
|
|
301
|
-
* @param {string} value 参数值
|
|
302
|
-
* @param {object} params 请求参数集合
|
|
303
|
-
* @returns {string|undefined} 返回验证结果
|
|
304
|
-
* @private
|
|
305
|
-
*/
|
|
306
|
-
Drive.prototype._checkIdenRule = function (model, value, params) {
|
|
307
|
-
var iden_key = model.string.identical;
|
|
308
|
-
var val = params[iden_key];
|
|
309
|
-
if (val !== value) {
|
|
310
|
-
var m = this.getCheckModel(iden_key);
|
|
311
|
-
if (m) {
|
|
312
|
-
return model.msg('identical', model.title + '(' + model.name + ')', m.title + '(' + m.name + ')');
|
|
313
|
-
} else {
|
|
314
|
-
return model.msg('identical', model.title + '(' + model.name + ')', iden_key);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return undefined;
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* 检查不同规则
|
|
322
|
-
* @param {object} model 验证模型
|
|
323
|
-
* @param {string} value 参数值
|
|
324
|
-
* @param {object} params 请求参数集合
|
|
325
|
-
* @returns {string|undefined} 返回验证结果
|
|
326
|
-
* @private
|
|
327
|
-
*/
|
|
328
|
-
Drive.prototype._checkDiffRule = function (model, value, params) {
|
|
329
|
-
var diff_key = model.string.different;
|
|
330
|
-
var val = params[diff_key];
|
|
331
|
-
if (val === value) {
|
|
332
|
-
var m = this.getCheckModel(diff_key);
|
|
333
|
-
if (m) {
|
|
334
|
-
return model.msg('different', model.title + '(' + model.name + ')', m.title + '(' + m.name + ')');
|
|
335
|
-
} else {
|
|
336
|
-
return model.msg('different', model.title + '(' + model.name + ')', diff_key);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return undefined;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* 验证参数是否符合
|
|
344
|
-
* @param {object} query url参数集合
|
|
345
|
-
* @param {object} body 正文参数集合
|
|
346
|
-
* @param {string} method 请求方式,get增、del删、set改、get查、import导入、export导出
|
|
347
|
-
* @returns {object} 没通过返回信息,否则返回空
|
|
348
|
-
*/
|
|
349
|
-
Drive.prototype.check = function (query, body, method) {
|
|
350
|
-
var m = this._getMethodConfig(method, query);
|
|
351
|
-
var msg = this._checkQueryParams(query, m);
|
|
352
|
-
if (!msg) {
|
|
353
|
-
this._processBodyNot(m, body);
|
|
354
|
-
msg = this._checkBodyParams(body, m);
|
|
355
|
-
}
|
|
356
|
-
return msg;
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* 获取方法配置
|
|
361
|
-
* @param {string} method 请求方式
|
|
362
|
-
* @param {object} query url参数集合
|
|
363
|
-
* @returns {object} 方法配置
|
|
364
|
-
* @private
|
|
365
|
-
*/
|
|
366
|
-
Drive.prototype._getMethodConfig = function (method, query) {
|
|
367
|
-
var md = method;
|
|
368
|
-
if (md !== 'GET') {
|
|
369
|
-
md = md.toLowerCase();
|
|
370
|
-
}
|
|
371
|
-
var m = this.config[md];
|
|
372
|
-
if (!m) {
|
|
373
|
-
m = this._getConfigFromQuery(query);
|
|
374
|
-
}
|
|
375
|
-
if (!m) {
|
|
376
|
-
m = this.config['get'];
|
|
377
|
-
}
|
|
378
|
-
return m;
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* 从查询参数获取方法配置
|
|
383
|
-
* @param {object} query url参数集合
|
|
384
|
-
* @returns {object} 方法配置
|
|
385
|
-
* @private
|
|
386
|
-
*/
|
|
387
|
-
Drive.prototype._getConfigFromQuery = function (query) {
|
|
388
|
-
var m_key = this.config.method;
|
|
389
|
-
if (m_key) {
|
|
390
|
-
var md = query[m_key];
|
|
391
|
-
if (md) {
|
|
392
|
-
return this.config[md];
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return null;
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* 检查查询参数
|
|
400
|
-
* @param {object} query url参数集合
|
|
401
|
-
* @param {object} config 方法配置
|
|
402
|
-
* @returns {string|undefined} 返回验证结果
|
|
403
|
-
* @private
|
|
404
|
-
*/
|
|
405
|
-
Drive.prototype._checkQueryParams = function (query, config) {
|
|
406
|
-
var arr = this._getParamList(config['query'], query);
|
|
407
|
-
var arr_query = config['query_required'] || [];
|
|
408
|
-
arr.addList(arr_query);
|
|
409
|
-
return this.checkSub(query, arr, arr_query);
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* 处理不需要的Body参数
|
|
414
|
-
* @param {object} config 方法配置
|
|
415
|
-
* @param {object} body 正文参数集合
|
|
416
|
-
* @private
|
|
417
|
-
*/
|
|
418
|
-
Drive.prototype._processBodyNot = function (config, body) {
|
|
419
|
-
var ar = config['body_not'];
|
|
420
|
-
if (ar && body && ar.length > 0) {
|
|
421
|
-
for (var i = 0; i < ar.length; i++) {
|
|
422
|
-
delete body[ar[i]];
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* 检查Body参数
|
|
429
|
-
* @param {object} body 正文参数集合
|
|
430
|
-
* @param {object} config 方法配置
|
|
431
|
-
* @returns {string|undefined} 返回验证结果
|
|
432
|
-
* @private
|
|
433
|
-
*/
|
|
434
|
-
Drive.prototype._checkBodyParams = function (body, config) {
|
|
435
|
-
var arr = this._getParamList(config['body'], body);
|
|
436
|
-
var arr_body = config['body_required'] || [];
|
|
437
|
-
arr.addList(arr_body);
|
|
438
|
-
return this.checkSub(body, arr, arr_body);
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* 获取参数列表
|
|
443
|
-
* @param {Array} configArr 配置中的参数数组
|
|
444
|
-
* @param {object} params 参数集合
|
|
445
|
-
* @returns {Array} 参数列表
|
|
446
|
-
* @private
|
|
447
|
-
*/
|
|
448
|
-
Drive.prototype._getParamList = function (configArr, params) {
|
|
449
|
-
if (configArr && configArr.length > 0) {
|
|
450
|
-
return configArr;
|
|
451
|
-
}
|
|
452
|
-
var arr = [];
|
|
453
|
-
for (var k in params) {
|
|
454
|
-
if (arr.indexOf(k) === -1) {
|
|
455
|
-
arr.push(k);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
return arr;
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* 取字段
|
|
463
|
-
* @param {object} model 验证模型
|
|
464
|
-
* @returns {string} 返回名称
|
|
465
|
-
*/
|
|
466
|
-
Drive.prototype.title = function (model) {
|
|
467
|
-
if (!model.title) {
|
|
468
|
-
return model.name + ' ';
|
|
469
|
-
} else {
|
|
470
|
-
return model.title + '(' + model.name + ') ';
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* 验证回调函数
|
|
476
|
-
* @param {object} model 当前的验证模型
|
|
477
|
-
* @param {object} value 当前的验证值
|
|
478
|
-
* @returns {object} 没通过返回信息,否则返回空
|
|
479
|
-
*/
|
|
480
|
-
Drive.prototype.main = function (model, value) {
|
|
481
|
-
return null;
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* 获取模型
|
|
486
|
-
* @param {string} type 模型类型
|
|
487
|
-
* @returns {object} 返回获取到的模型
|
|
488
|
-
*/
|
|
489
|
-
Drive.prototype.getModel = function (type) {
|
|
490
|
-
let model = { ...this.config };
|
|
491
|
-
let dir = this.getDir();
|
|
492
|
-
let l = $.slash;
|
|
493
|
-
let app_name = dir.between('app' + l, l);
|
|
494
|
-
let plugin_name = dir.between('plugin' + l, l);
|
|
495
|
-
let name = dir.basename();
|
|
496
|
-
model.app = app_name;
|
|
497
|
-
model.plugin = plugin_name;
|
|
498
|
-
model.name = model.name || app_name + '_' + name;
|
|
499
|
-
return model;
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
module.exports = Drive;
|
package/com/param/index.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
const Manager = require("mm_machine").Manager;
|
|
2
|
-
const Drive = require("./drive");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 参数类
|
|
6
|
-
* @augments {Manager}
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class Param extends Manager {
|
|
10
|
-
/**
|
|
11
|
-
* 配置参数
|
|
12
|
-
* @type {object}
|
|
13
|
-
*/
|
|
14
|
-
static config = {
|
|
15
|
-
/**
|
|
16
|
-
* 名称
|
|
17
|
-
* @type {string}
|
|
18
|
-
*/
|
|
19
|
-
name: "",
|
|
20
|
-
/**
|
|
21
|
-
* 标题
|
|
22
|
-
* @type {string}
|
|
23
|
-
*/
|
|
24
|
-
title: "参数管理",
|
|
25
|
-
/**
|
|
26
|
-
* 描述
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
description: "这是参数管理器",
|
|
30
|
-
/**
|
|
31
|
-
* 检索文件名
|
|
32
|
-
* @type {string}
|
|
33
|
-
*/
|
|
34
|
-
filename: "param.json",
|
|
35
|
-
/**
|
|
36
|
-
* 模板目录
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
|
-
tpl_dir: __dirname,
|
|
40
|
-
/**
|
|
41
|
-
* 基础目录
|
|
42
|
-
* @type {string}
|
|
43
|
-
*/
|
|
44
|
-
base_dir: "../common/param".fullname(__dirname),
|
|
45
|
-
/**
|
|
46
|
-
* 自定义目录,加载项目自定义资源
|
|
47
|
-
* @type {string}
|
|
48
|
-
*/
|
|
49
|
-
dir: "./app".fullname(),
|
|
50
|
-
/**
|
|
51
|
-
* 搜索模式 dir按目录搜索 | file按文件名搜索
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
|
-
search_way: "file",
|
|
55
|
-
/**
|
|
56
|
-
* 是否懒加载
|
|
57
|
-
* @type {boolean}
|
|
58
|
-
*/
|
|
59
|
-
lazy_load: true,
|
|
60
|
-
/**
|
|
61
|
-
* 模式
|
|
62
|
-
* 1.生产模式,改变文件不会重新加载
|
|
63
|
-
* 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
|
|
64
|
-
* 3.热重载模式,改变配置文件都会加载配置和脚本
|
|
65
|
-
* 4.重载模式,执行完后重新加载脚本,避免变量污染
|
|
66
|
-
* 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
|
|
67
|
-
* @type {number}
|
|
68
|
-
*/
|
|
69
|
-
mode: process.env.NODE_ENV === "production" ? 1 : 3,
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 构造函数
|
|
74
|
-
* @param {object} config 配置参数
|
|
75
|
-
* @param {object} parent 父级模块
|
|
76
|
-
*/
|
|
77
|
-
constructor(config, parent) {
|
|
78
|
-
super({ ...Param.config, ...config }, parent);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 参数驱动类
|
|
84
|
-
* @type {Drive}
|
|
85
|
-
*/
|
|
86
|
-
Param.prototype.Drive = Drive;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 排序
|
|
90
|
-
*/
|
|
91
|
-
Param.prototype.sort = function () {
|
|
92
|
-
let infos = this.getInfos();
|
|
93
|
-
infos.sortBy("asc", "name");
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 配置对象或配置路径
|
|
98
|
-
* @param {object} db 数据库管理器 (object) 只支持可用sql语句的数据库
|
|
99
|
-
* @param {string} name 名称
|
|
100
|
-
* @param {object} query url参数
|
|
101
|
-
* @param {object} body 正文参数
|
|
102
|
-
* @returns {object} 验证失败返回错误信息,成功返回null
|
|
103
|
-
*/
|
|
104
|
-
Param.prototype.run = async function (db, name, query, body) {
|
|
105
|
-
var obj = this.getMod(name);
|
|
106
|
-
if (obj) {
|
|
107
|
-
// 检查参数状态,状态为0时跳过执行
|
|
108
|
-
if (obj.config && obj.config.state === 0) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
if (!obj.isLoaded()) {
|
|
113
|
-
await obj.do("load");
|
|
114
|
-
}
|
|
115
|
-
return await obj.run(db, query, body);
|
|
116
|
-
} catch (error) {
|
|
117
|
-
this.log("error", "Param验证异常:", error);
|
|
118
|
-
// 参数验证异常时返回null
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return null;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
exports.Param = Param;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Param参数池
|
|
129
|
-
*/
|
|
130
|
-
if (!$.pool.param) {
|
|
131
|
-
$.pool.param = {};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Param管理器,用于创建缓存
|
|
136
|
-
* @param {string} scope 作用域
|
|
137
|
-
* @param {string} title 标题
|
|
138
|
-
* @returns {object} 返回一个缓存类
|
|
139
|
-
*/
|
|
140
|
-
function paramAdmin(scope, title) {
|
|
141
|
-
var sc = scope || $.val.scope + "";
|
|
142
|
-
var obj = $.pool.param[sc];
|
|
143
|
-
if (!obj) {
|
|
144
|
-
$.pool.param[sc] = new Param({
|
|
145
|
-
name: sc,
|
|
146
|
-
title: title,
|
|
147
|
-
});
|
|
148
|
-
obj = $.pool.param[sc];
|
|
149
|
-
}
|
|
150
|
-
return obj;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @module 导出Param管理器
|
|
155
|
-
*/
|
|
156
|
-
if ($.admin) {
|
|
157
|
-
$.admin.param = paramAdmin;
|
|
158
|
-
}
|
package/com/param/script.tpl.js
DELETED
package/com/pendant/README.md
DELETED
package/com/pendant/com.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// 应用于,根据应用而判断使用
|
|
3
|
-
"app": "${app || 'admin'}",
|
|
4
|
-
// 名称, 用于动态增删改配置
|
|
5
|
-
"name": "${name}",
|
|
6
|
-
// 标题, 用于查询时
|
|
7
|
-
"title": "${title || '挂件管理器'}",
|
|
8
|
-
// 描述, 用于介绍该组件的作用
|
|
9
|
-
"description": "${description || '描述挂件使用方法'}",
|
|
10
|
-
// 执行顺序, 数值越小的越优先显示
|
|
11
|
-
"sort": 100,
|
|
12
|
-
// 分组, 可以将特有的分一个组, 方便用户查询
|
|
13
|
-
"group": "${group || 'default'}",
|
|
14
|
-
// 分类, 例如: 查询生活类、监测类、便民类
|
|
15
|
-
"type": "${type || '默认'}",
|
|
16
|
-
// 脚本文件, 非必传,可和渲染文件二选一传
|
|
17
|
-
"main": "./pendant.js",
|
|
18
|
-
// 渲染, 非必传,可和脚本文件二选一传
|
|
19
|
-
"template": "./pendant.html",
|
|
20
|
-
// 状态, 0为未开启 1为开启
|
|
21
|
-
"state": 1,
|
|
22
|
-
// 配置
|
|
23
|
-
"options": [],
|
|
24
|
-
// 定位 由后台指定的展示位置
|
|
25
|
-
"location": [
|
|
26
|
-
{
|
|
27
|
-
"path": "/${app}/index",
|
|
28
|
-
"position": "main",
|
|
29
|
-
"available": 1
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
}
|