mm_os 3.3.1 → 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/LICENSE +21 -201
- package/README.md +498 -99
- package/README_EN.md +505 -0
- package/adapter/adapter.js +431 -0
- package/adapter/custom_persistence.js +660 -0
- package/adapter/mqtt.js +273 -0
- package/adapter/socket.js +113 -0
- package/adapter/web.js +67 -0
- package/adapter/websocket.js +146 -0
- package/com/api/com.json +5 -0
- package/{core/com → com}/api/config.tpl.json +8 -8
- package/com/api/drive.js +708 -0
- package/com/api/index.js +198 -0
- package/com/api/oauth.js +200 -0
- package/com/api/script.tpl.js +32 -0
- package/com/cmd/README.md +11 -0
- package/com/cmd/com.json +5 -0
- package/com/cmd/config.tpl.json +122 -0
- package/com/cmd/drive.js +1548 -0
- package/com/cmd/index.js +1066 -0
- package/com/cmd/msg.json +48 -0
- package/com/cmd/nlp.js +525 -0
- package/com/cmd/script.tpl.js +32 -0
- package/com/db/com.json +5 -0
- package/com/db/drive.js +1999 -0
- package/com/db/index.js +242 -0
- package/{core/com → com}/event/README.md +4 -4
- package/com/event/com.json +5 -0
- package/{core/com → com}/event/config.tpl.json +18 -18
- package/com/event/drive.js +59 -0
- package/com/event/index.js +409 -0
- package/com/event/script.tpl.js +23 -0
- package/com/mqtt/com.json +5 -0
- package/{core/com → com}/mqtt/config.tpl.json +3 -5
- package/com/mqtt/drive.js +676 -0
- package/com/mqtt/index.js +822 -0
- package/com/mqtt/mm_mqtt.js +425 -0
- package/com/mqtt/script.tpl.js +723 -0
- package/com/nav/com.json +5 -0
- package/com/nav/config.tpl.json +84 -0
- package/com/nav/drive.js +702 -0
- package/com/nav/index.js +231 -0
- package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
- package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
- package/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/com/nav/tpl/admin_pc/page_view.vue +124 -0
- package/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/com/nav/tpl/dev_pc/page_type.vue +313 -0
- package/com/nav/tpl/home_pc/page_default.vue +234 -0
- package/com/nav/tpl/home_pc/page_form.vue +137 -0
- package/com/nav/tpl/home_pc/page_list.vue +234 -0
- package/com/nav/tpl/home_pc/page_nav.vue +221 -0
- package/com/nav/tpl/home_pc/page_type.vue +234 -0
- package/com/nav/tpl/home_pc/page_view.vue +125 -0
- package/com/nav/tpl/home_phone/page_channel.vue +234 -0
- package/com/nav/tpl/home_phone/page_default.vue +234 -0
- package/com/nav/tpl/home_phone/page_form.vue +137 -0
- package/com/nav/tpl/home_phone/page_nav.vue +237 -0
- package/com/nav/tpl/home_phone/page_type.vue +234 -0
- package/com/nav/tpl/home_phone/page_view.vue +125 -0
- package/com/nav/viewmodel.js +446 -0
- package/com/param/com.json +5 -0
- package/{core/com → com}/param/config.tpl.json +7 -1
- package/com/param/drive.js +502 -0
- package/com/param/index.js +155 -0
- package/com/param/script.tpl.js +12 -0
- package/com/pendant/com.json +5 -0
- package/{core/com/component → com/pendant}/config.tpl.json +15 -13
- package/com/pendant/drive.js +204 -0
- package/com/pendant/index.js +441 -0
- package/com/pendant/pendant.html +16 -0
- package/com/pendant/script.tpl.js +18 -0
- package/com/socket/com.json +5 -0
- package/com/socket/config.tpl.json +12 -0
- package/com/socket/drive.js +651 -0
- package/com/socket/index.js +351 -0
- package/com/socket/script.tpl.js +41 -0
- package/com/sql/com.json +5 -0
- package/{core/com → com}/sql/config.tpl.json +13 -9
- package/com/sql/drive.js +1259 -0
- package/com/sql/index.js +150 -0
- package/com/sql/script.tpl.js +47 -0
- package/com/static/com.json +5 -0
- package/{core/com → com}/static/config.tpl.json +10 -6
- package/com/static/drive.js +194 -0
- package/com/static/index.js +226 -0
- package/com/static/script.tpl.js +28 -0
- package/com/task/com.json +5 -0
- package/{core/com → com}/task/config.tpl.json +4 -6
- package/com/task/drive.js +405 -0
- package/com/task/index.js +148 -0
- package/com/task/script.tpl.js +37 -0
- package/com/template/com.json +5 -0
- package/com/template/config.tpl.json +16 -0
- package/com/template/drive.js +80 -0
- package/com/template/index.js +141 -0
- package/com.js +156 -0
- package/common/README.md +2 -0
- package/common/handler/msg/handler.json +22 -0
- package/common/handler/msg/index.js +23 -0
- package/common/handler/player/handler.json +22 -0
- package/common/handler/player/index.js +287 -0
- package/common/handler/user/handler.json +22 -0
- package/common/handler/user/index.js +23 -0
- package/common/middleware/web_after/index.js +29 -0
- package/common/middleware/web_after/middleware.json +9 -0
- package/common/middleware/web_base/index.js +113 -0
- package/common/middleware/web_base/middleware.json +19 -0
- package/common/middleware/web_before/index.js +33 -0
- package/common/middleware/web_before/middleware.json +9 -0
- package/common/middleware/web_cors/index.js +87 -0
- package/common/middleware/web_cors/middleware.json +24 -0
- package/common/middleware/web_error/index.js +119 -0
- package/common/middleware/web_error/middleware.json +18 -0
- package/common/middleware/web_ip/index.js +15 -0
- package/common/middleware/web_ip/middleware.json +14 -0
- package/common/middleware/web_logger/index.js +156 -0
- package/common/middleware/web_logger/middleware.json +14 -0
- package/common/middleware/web_main/index.js +24 -0
- package/common/middleware/web_main/middleware.json +9 -0
- package/common/middleware/web_static/index.js +73 -0
- package/common/middleware/web_static/middleware.json +54 -0
- package/common/middleware/web_waf/index.js +385 -0
- package/common/middleware/web_waf/middleware.json +13 -0
- package/common/model/msg/index.js +88 -0
- package/common/model/msg/model.json +401 -0
- package/common/model/player/index.js +63 -0
- package/common/model/player/model.json +185 -0
- package/common/model/user/index.js +11 -0
- package/common/model/user/model.json +219 -0
- package/core/app/config.tpl.json +67 -0
- package/core/app/index.js +632 -0
- package/core/app/script.tpl.js +52 -0
- package/core/channel/index.js +899 -0
- package/core/channel/matcher.js +585 -0
- package/core/com/config.tpl.json +16 -0
- package/core/com/index.js +74 -0
- package/core/com/script.tpl.js +5 -0
- package/core/component/component.js +42 -0
- package/core/component/config.tpl.json +63 -0
- package/core/component/index.js +273 -0
- package/core/component/script.tpl.js +19 -0
- package/core/controller/config.tpl.json +14 -0
- package/core/controller/index.js +373 -0
- package/core/controller/script.tpl.js +27 -0
- package/core/factory/config.tpl.json +14 -0
- package/core/factory/entity.js +275 -0
- package/core/factory/index.js +241 -0
- package/core/factory/script.tpl.js +16 -0
- package/core/game/bat/index.js +137 -0
- package/core/game/bat/world.js +622 -0
- package/core/game/config.tpl.json +16 -0
- package/core/game/entity_admin.js +230 -0
- package/core/game/index.js +186 -0
- package/core/handler/config.tpl.json +22 -0
- package/core/handler/index.js +181 -0
- package/core/handler/script.tpl.js +23 -0
- package/core/logic/config.tpl.json +14 -0
- package/core/logic/index.js +59 -0
- package/core/logic/script.tpl.js +19 -0
- package/core/middleware/config.tpl.json +16 -0
- package/core/middleware/index.js +125 -0
- package/core/middleware/script.tpl.js +37 -0
- package/core/mod/config.tpl.json +22 -0
- package/core/mod/index.js +130 -0
- package/core/mod/script.tpl.js +34 -0
- package/core/model/config.tpl.json +219 -0
- package/core/model/index.js +272 -0
- package/core/model/model.js +27 -0
- package/core/model/script.tpl.js +20 -0
- package/core/notifier/config.tpl.json +14 -0
- package/core/notifier/index.js +77 -0
- package/core/notifier/script.tpl.js +20 -0
- package/core/plugin/config.tpl.json +24 -0
- package/core/plugin/index.js +232 -0
- package/core/plugin/script.tpl.js +51 -0
- package/core/pusher/config.tpl.json +14 -0
- package/core/pusher/index.js +161 -0
- package/core/pusher/script.tpl.js +20 -0
- package/core/room/bat/index.js +170 -0
- package/core/room/bat/room.js +524 -0
- package/core/room/config.tpl.json +20 -0
- package/core/room/index.js +249 -0
- package/core/room/room.js +61 -0
- package/core/scene/config.tpl.json +14 -0
- package/core/scene/index.js +466 -0
- package/core/scene/loop.js +1255 -0
- package/core/scene/map.js +28 -0
- package/core/scene/script.tpl.js +22 -0
- package/core/sender/config.tpl.json +14 -0
- package/core/sender/index.js +79 -0
- package/core/sender/script.tpl.js +20 -0
- package/core/service/config.tpl.json +14 -0
- package/core/service/index.js +100 -0
- package/core/service/script.tpl.js +25 -0
- package/core/store/config.tpl.json +26 -0
- package/core/store/index.js +1755 -0
- package/core/store/script.tpl.js +22 -0
- package/core/store/sql.js +1464 -0
- package/core/system/config.tpl.json +18 -0
- package/core/system/index.js +312 -0
- package/core/system/script.tpl.js +77 -0
- package/core/view/config.tpl.json +14 -0
- package/core/view/index.js +91 -0
- package/core/view/script.tpl.js +20 -0
- package/core/zone/bat/index.js +725 -0
- package/core/zone/config.tpl.json +54 -0
- package/core/zone/index.js +614 -0
- package/core/zone/script.tpl.js +10 -0
- package/core/zone/zone_bat.js +136 -0
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
- package/index.js +17 -333
- package/os.js +57 -0
- package/package.json +65 -55
- package/server.js +598 -0
- package/README.en.md +0 -36
- package/conf.json +0 -3
- package/core/base/mqtt/index.js +0 -1110
- package/core/base/mqtt/lib.js +0 -40
- package/core/base/web/index.js +0 -245
- package/core/com/api/com.json +0 -4
- package/core/com/api/drive.js +0 -668
- package/core/com/api/index.js +0 -108
- package/core/com/api/oauth.js +0 -158
- package/core/com/api/script.js +0 -32
- package/core/com/app/README.md +0 -3
- package/core/com/app/com.json +0 -4
- package/core/com/app/config.tpl.json +0 -16
- package/core/com/app/drive.js +0 -309
- package/core/com/app/index.js +0 -211
- package/core/com/app/script.js +0 -155
- package/core/com/cmd/com.json +0 -4
- package/core/com/cmd/config.tpl.json +0 -66
- package/core/com/cmd/drive.js +0 -513
- package/core/com/cmd/index.js +0 -354
- package/core/com/cmd/old/5w2h.js +0 -54
- package/core/com/cmd/old/drive.js +0 -423
- package/core/com/cmd/script.js +0 -11
- package/core/com/component/README.md +0 -3
- package/core/com/component/com.json +0 -4
- package/core/com/component/component.html +0 -16
- package/core/com/component/drive.js +0 -197
- package/core/com/component/index.js +0 -312
- package/core/com/component/script.js +0 -18
- package/core/com/db/com.json +0 -4
- package/core/com/db/drive.js +0 -1160
- package/core/com/db/index.js +0 -176
- package/core/com/event/com.json +0 -4
- package/core/com/event/drive.js +0 -133
- package/core/com/event/index.js +0 -345
- package/core/com/event/script.js +0 -26
- package/core/com/eventer/com.js +0 -477
- package/core/com/eventer/com.json +0 -4
- package/core/com/middleware/com.js +0 -154
- package/core/com/middleware/com.json +0 -4
- package/core/com/middleware/config.tpl.json +0 -8
- package/core/com/middleware/script.js +0 -9
- package/core/com/mqtt/com.json +0 -4
- package/core/com/mqtt/drive.js +0 -600
- package/core/com/mqtt/index.js +0 -572
- package/core/com/mqtt/mm_mqtt.js +0 -330
- package/core/com/mqtt/script.js +0 -604
- package/core/com/msg/com.js +0 -296
- package/core/com/msg/com.json +0 -4
- package/core/com/nav/com.json +0 -4
- package/core/com/nav/config.tpl.json +0 -75
- package/core/com/nav/drive.js +0 -549
- package/core/com/nav/index.js +0 -182
- package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/core/com/nav/viewmodel.js +0 -296
- package/core/com/param/drive.js +0 -366
- package/core/com/param/index.js +0 -80
- package/core/com/param/script.js +0 -12
- package/core/com/param/test.js +0 -98
- package/core/com/plugin/README.md +0 -3
- package/core/com/plugin/com.json +0 -4
- package/core/com/plugin/config.tpl.json +0 -26
- package/core/com/plugin/drive.js +0 -536
- package/core/com/plugin/index.js +0 -259
- package/core/com/plugin/script.js +0 -213
- package/core/com/rpc/com.json +0 -4
- package/core/com/rpc/drive.js +0 -160
- package/core/com/rpc/index.js +0 -87
- package/core/com/rpc/rpc.js +0 -118
- package/core/com/socket/com.json +0 -4
- package/core/com/socket/config.tpl.json +0 -14
- package/core/com/socket/drive.js +0 -403
- package/core/com/socket/index.js +0 -62
- package/core/com/socket/script.js +0 -42
- package/core/com/sql/drive.js +0 -1087
- package/core/com/sql/index.js +0 -83
- package/core/com/sql/script.js +0 -48
- package/core/com/static/com.json +0 -4
- package/core/com/static/drive.js +0 -220
- package/core/com/static/index.js +0 -149
- package/core/com/static/script.js +0 -28
- package/core/com/task/com.json +0 -4
- package/core/com/task/drive.js +0 -403
- package/core/com/task/index.js +0 -110
- package/core/com/task/script.js +0 -37
- package/core/com/timer/com.js +0 -217
- package/core/com/timer/com.json +0 -4
- package/core/com/tpl/com.js +0 -19
- package/core/com/tpl/com.json +0 -4
- package/lib/actions.js +0 -50
- package/lib/base.js +0 -361
- package/lib/com.js +0 -29
- package/lib/ref.js +0 -121
- package/middleware/cors/index.js +0 -119
- package/middleware/cors/middleware.json +0 -20
- package/middleware/csrf/index.js +0 -202
- package/middleware/csrf/middleware.json +0 -24
- package/middleware/ip_firewall/index.js +0 -476
- package/middleware/ip_firewall/middleware.json +0 -109
- package/middleware/mqtt_base/index.js +0 -10
- package/middleware/mqtt_base/middleware.json +0 -11
- package/middleware/security_audit/index.js +0 -543
- package/middleware/security_audit/middleware.json +0 -48
- package/middleware/waf/index.js +0 -343
- package/middleware/waf/middleware.json +0 -10
- package/middleware/waf_ddos/index.js +0 -520
- package/middleware/waf_ddos/middleware.json +0 -38
- package/middleware/waf_xss/index.js +0 -269
- package/middleware/waf_xss/middleware.json +0 -18
- package/middleware/web_after/index.js +0 -33
- package/middleware/web_after/middleware.json +0 -10
- package/middleware/web_base/index.js +0 -90
- package/middleware/web_base/middleware.json +0 -10
- package/middleware/web_before/index.js +0 -27
- package/middleware/web_before/middleware.json +0 -10
- package/middleware/web_check/index.js +0 -28
- package/middleware/web_check/middleware.json +0 -10
- package/middleware/web_main/index.js +0 -28
- package/middleware/web_main/middleware.json +0 -10
- package/middleware/web_proxy/index.js +0 -37
- package/middleware/web_proxy/middleware.json +0 -10
- package/middleware/web_render/index.js +0 -87
- package/middleware/web_render/middleware.json +0 -10
- package/middleware/web_socket/index.js +0 -34
- package/middleware/web_socket/middleware.json +0 -10
- package/middleware/web_static/index.js +0 -115
- package/middleware/web_static/middleware.json +0 -10
- /package/{core/com → com}/api/README.md +0 -0
- /package/{core/com → com}/db/README.md +0 -0
- /package/{core/com → com}/mqtt/README.md +0 -0
- /package/{core/com → com}/nav/README.md +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
- /package/{core/com → com}/param/README.md +0 -0
- /package/{core/com/cmd → com/pendant}/README.md +0 -0
- /package/{core/com → com}/socket/README.md +0 -0
- /package/{core/com → com}/sql/README.md +0 -0
- /package/{core/com → com}/static/README.md +0 -0
- /package/{core/com → com}/task/README.md +0 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 视图模型
|
|
3
|
+
* @class
|
|
4
|
+
*/
|
|
5
|
+
class Model {
|
|
6
|
+
/**
|
|
7
|
+
* 配置参数
|
|
8
|
+
* @param {object} config 配置参数
|
|
9
|
+
*/
|
|
10
|
+
constructor(config) {
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 获取显示类型
|
|
17
|
+
* @param {string} key 键值
|
|
18
|
+
* @param {boolean} f 是否带格式
|
|
19
|
+
* @returns {string} 返回显示类型
|
|
20
|
+
*/
|
|
21
|
+
Model.prototype.getType = function(key, f) {
|
|
22
|
+
var typeMap = {
|
|
23
|
+
'search': f ? 'select' : '',
|
|
24
|
+
'view': 'text',
|
|
25
|
+
'table': f ? 'select' : 'text',
|
|
26
|
+
'edit': f ? 'select' : 'input',
|
|
27
|
+
'list': 'text',
|
|
28
|
+
'details': 'text',
|
|
29
|
+
'batch': f ? 'select' : '',
|
|
30
|
+
'filter': f ? 'select' : ''
|
|
31
|
+
};
|
|
32
|
+
return typeMap[key] !== undefined ? typeMap[key] : (f ? 'select' : '');
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 查询显示方式
|
|
37
|
+
* @param {Array} arr 显示类型数组
|
|
38
|
+
* @param {string} key 键值
|
|
39
|
+
* @param {boolean} f 是否带格式
|
|
40
|
+
* @returns {string} 返回显示方式
|
|
41
|
+
*/
|
|
42
|
+
Model.prototype.getShow = function(arr, key, f) {
|
|
43
|
+
var bl = false;
|
|
44
|
+
var show = '';
|
|
45
|
+
for (var i = 0; i < arr.length; i++) {
|
|
46
|
+
var str = arr[i];
|
|
47
|
+
if (str.indexOf(key + '_no') !== -1) {
|
|
48
|
+
bl = true;
|
|
49
|
+
break;
|
|
50
|
+
} else if (str.indexOf(key + '_input') !== -1) {
|
|
51
|
+
show = 'input';
|
|
52
|
+
break;
|
|
53
|
+
} else if (str.indexOf(key + '_select') !== -1) {
|
|
54
|
+
show = 'select';
|
|
55
|
+
break;
|
|
56
|
+
} else if (str.indexOf(key + '_text') !== -1) {
|
|
57
|
+
show = 'text';
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!show && !bl) {
|
|
62
|
+
show = this.getType(key, f);
|
|
63
|
+
}
|
|
64
|
+
return show;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 获取表格所需键值对
|
|
69
|
+
* @param {object} model 模型
|
|
70
|
+
* @returns {object} 返回视图所用模型
|
|
71
|
+
*/
|
|
72
|
+
Model.prototype.field = async function(model) {
|
|
73
|
+
var list = model.param.list;
|
|
74
|
+
if (!list) {
|
|
75
|
+
model.param.list = [];
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var field = this._getFieldByFileType(model);
|
|
80
|
+
var requireds = this._getRequiredFields(model);
|
|
81
|
+
var field_names = field.replace(/`/g, '').split(',');
|
|
82
|
+
|
|
83
|
+
return this._processFieldList(list, field_names, requireds, model);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 根据文件类型获取字段
|
|
88
|
+
* @param {object} model 模型
|
|
89
|
+
* @returns {string} 字段字符串
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
Model.prototype._getFieldByFileType = function(model) {
|
|
93
|
+
if (model.file.indexOf('_form') !== -1 || model.file.indexOf('_view') !== -1) {
|
|
94
|
+
return model.sql.field_obj || '';
|
|
95
|
+
}
|
|
96
|
+
return model.sql.field_default || '';
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 获取必填字段
|
|
101
|
+
* @param {object} model 模型
|
|
102
|
+
* @returns {Array} 必填字段数组
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
Model.prototype._getRequiredFields = function(model) {
|
|
106
|
+
var add = model.param.add;
|
|
107
|
+
return add ? add.body_required : [];
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 处理字段列表
|
|
112
|
+
* @param {Array} list 字段列表
|
|
113
|
+
* @param {Array} field_names 字段名数组
|
|
114
|
+
* @param {Array} requireds 必填字段数组
|
|
115
|
+
* @param {object} model 模型
|
|
116
|
+
* @returns {Array} 处理后的字段列表
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
Model.prototype._processFieldList = function(list, field_names, requireds, model) {
|
|
120
|
+
var pm = [];
|
|
121
|
+
for (var i = 0; i < list.length; i++) {
|
|
122
|
+
var o = list[i];
|
|
123
|
+
var name = o.name;
|
|
124
|
+
if (field_names.indexOf(name) !== -1) {
|
|
125
|
+
var obj = this._processField(o, requireds, model);
|
|
126
|
+
pm.push(obj);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return pm;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 处理单个字段
|
|
134
|
+
* @param {object} field 字段对象
|
|
135
|
+
* @param {Array} requireds 必填字段数组
|
|
136
|
+
* @param {object} model 模型
|
|
137
|
+
* @returns {object} 处理后的字段对象
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
Model.prototype._processField = function(field, requireds, model) {
|
|
141
|
+
var obj = { ...field};
|
|
142
|
+
var format_info = this._getFieldFormat(obj.name, model);
|
|
143
|
+
|
|
144
|
+
if (format_info.format) {
|
|
145
|
+
obj.title = format_info.format.title;
|
|
146
|
+
obj.format = format_info.format;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (requireds.indexOf(obj.name) !== -1) {
|
|
150
|
+
obj.required = true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
obj.show = this._getFieldShow(obj.description, format_info.has_format);
|
|
154
|
+
return obj;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 获取字段格式
|
|
159
|
+
* @param {string} fieldName 字段名
|
|
160
|
+
* @param {object} model 模型
|
|
161
|
+
* @returns {object} 格式信息
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
164
|
+
Model.prototype._getFieldFormat = function(fieldName, model) {
|
|
165
|
+
var format = model.sql.format.getObj({ key: fieldName });
|
|
166
|
+
return {
|
|
167
|
+
format: format,
|
|
168
|
+
has_format: !!format
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 获取字段显示配置
|
|
174
|
+
* @param {string} description 字段描述
|
|
175
|
+
* @param {boolean} has_format 是否有格式
|
|
176
|
+
* @returns {object} 显示配置
|
|
177
|
+
* @private
|
|
178
|
+
*/
|
|
179
|
+
Model.prototype._getFieldShow = function(description, has_format) {
|
|
180
|
+
if (description.indexOf('##') === -1) {
|
|
181
|
+
return this._getDefaultShowConfig(has_format);
|
|
182
|
+
}
|
|
183
|
+
return this._getCustomShowConfig(description, has_format);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 获取默认显示配置
|
|
188
|
+
* @param {boolean} has_format 是否有格式
|
|
189
|
+
* @returns {object} 默认显示配置
|
|
190
|
+
* @private
|
|
191
|
+
*/
|
|
192
|
+
Model.prototype._getDefaultShowConfig = function(has_format) {
|
|
193
|
+
return {
|
|
194
|
+
form: has_format ? 'select' : 'input',
|
|
195
|
+
view: 'text',
|
|
196
|
+
search: has_format ? 'select' : '',
|
|
197
|
+
table: has_format ? 'select' : 'text',
|
|
198
|
+
list: 'text',
|
|
199
|
+
edit: has_format ? 'select' : 'input',
|
|
200
|
+
details: 'text',
|
|
201
|
+
batch: has_format ? 'select' : '',
|
|
202
|
+
filter: has_format ? 'select' : ''
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 获取自定义显示配置
|
|
208
|
+
* @param {string} description 字段描述
|
|
209
|
+
* @param {boolean} has_format 是否有格式
|
|
210
|
+
* @returns {object} 自定义显示配置
|
|
211
|
+
* @private
|
|
212
|
+
*/
|
|
213
|
+
Model.prototype._getCustomShowConfig = function(description, has_format) {
|
|
214
|
+
var desc = description.between('##', '##');
|
|
215
|
+
var ar = desc.trim().split(' ');
|
|
216
|
+
|
|
217
|
+
if (desc.indexOf('none') !== -1) {
|
|
218
|
+
return this._getEmptyShowConfig();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return this._buildShowConfig(ar, has_format);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 获取空显示配置
|
|
226
|
+
* @returns {object} 空显示配置
|
|
227
|
+
* @private
|
|
228
|
+
*/
|
|
229
|
+
Model.prototype._getEmptyShowConfig = function() {
|
|
230
|
+
return {
|
|
231
|
+
form: '',
|
|
232
|
+
view: '',
|
|
233
|
+
search: '',
|
|
234
|
+
table: '',
|
|
235
|
+
list: '',
|
|
236
|
+
edit: '',
|
|
237
|
+
details: '',
|
|
238
|
+
batch: '',
|
|
239
|
+
filter: ''
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 构建显示配置
|
|
245
|
+
* @param {Array} configArray 配置数组
|
|
246
|
+
* @param {boolean} has_format 是否有格式
|
|
247
|
+
* @returns {object} 显示配置
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
250
|
+
Model.prototype._buildShowConfig = function(configArray, has_format) {
|
|
251
|
+
return {
|
|
252
|
+
search: this.getShow(configArray, 'search', has_format),
|
|
253
|
+
table: this.getShow(configArray, 'table', has_format),
|
|
254
|
+
form: this.getShow(configArray, 'form', has_format),
|
|
255
|
+
view: this.getShow(configArray, 'view', has_format),
|
|
256
|
+
batch: this.getShow(configArray, 'batch', has_format),
|
|
257
|
+
list: this.getShow(configArray, 'list', has_format),
|
|
258
|
+
details: this.getShow(configArray, 'details', has_format),
|
|
259
|
+
filter: this.getShow(configArray, 'filter', has_format),
|
|
260
|
+
edit: this.getShow(configArray, 'edit', has_format)
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 运算视图模型(css)
|
|
266
|
+
* @param {object} model 模型
|
|
267
|
+
* @returns {object} 返回视图所用模型
|
|
268
|
+
*/
|
|
269
|
+
Model.prototype.css = async function(model) {
|
|
270
|
+
var css = {};
|
|
271
|
+
return css;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* 运算视图模型(html)
|
|
276
|
+
* @param {object} model 模型
|
|
277
|
+
* @returns {object} 返回视图所用模型
|
|
278
|
+
*/
|
|
279
|
+
Model.prototype.html = async function(model) {
|
|
280
|
+
var html = {};
|
|
281
|
+
if (!model.sql) {
|
|
282
|
+
return html;
|
|
283
|
+
}
|
|
284
|
+
return html;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 运算视图模型(js)
|
|
289
|
+
* @param {object} model 模型
|
|
290
|
+
* @returns {object} 返回视图所用模型
|
|
291
|
+
*/
|
|
292
|
+
Model.prototype.js = async function(model) {
|
|
293
|
+
var js = {
|
|
294
|
+
data: [],
|
|
295
|
+
query: []
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
var field = model.field;
|
|
299
|
+
var path_start = model.file.indexOf('admin') !== -1 ? '/apis/' : '/api/';
|
|
300
|
+
|
|
301
|
+
this._processField(js, field, path_start);
|
|
302
|
+
this._processQuery(js, model.param);
|
|
303
|
+
|
|
304
|
+
return js;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* 处理字段
|
|
309
|
+
* @param {object} js js对象
|
|
310
|
+
* @param {Array} field 字段列表
|
|
311
|
+
* @param {string} path_start 路径前缀
|
|
312
|
+
* @private
|
|
313
|
+
*/
|
|
314
|
+
Model.prototype._processField = function(js, field, path_start) {
|
|
315
|
+
for (var i = 0; i < field.length; i++) {
|
|
316
|
+
var o = field[i];
|
|
317
|
+
var format = o.format;
|
|
318
|
+
if (format) {
|
|
319
|
+
var obj = this._createFormatObj(o, format, path_start);
|
|
320
|
+
if (obj) {
|
|
321
|
+
js.data.push(obj);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 创建格式对象
|
|
329
|
+
* @param {object} field 字段对象
|
|
330
|
+
* @param {object} format 格式对象
|
|
331
|
+
* @param {string} path_start 路径前缀
|
|
332
|
+
* @returns {object} 格式对象
|
|
333
|
+
* @private
|
|
334
|
+
*/
|
|
335
|
+
Model.prototype._createFormatObj = function(field, format, path_start) {
|
|
336
|
+
if (format.table) {
|
|
337
|
+
return this._createTableFormatObj(field, format, path_start);
|
|
338
|
+
} else {
|
|
339
|
+
return this._createListFormatObj(field, format);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 创建表格格式对象
|
|
345
|
+
* @param {object} field 字段对象
|
|
346
|
+
* @param {object} format 格式对象
|
|
347
|
+
* @param {string} path_start 路径前缀
|
|
348
|
+
* @returns {object} 表格格式对象
|
|
349
|
+
* @private
|
|
350
|
+
*/
|
|
351
|
+
Model.prototype._createTableFormatObj = function(field, format, path_start) {
|
|
352
|
+
var basename = format.table.split('_').splice(1).join('_');
|
|
353
|
+
var name = 'list_' + basename;
|
|
354
|
+
var id = format.nav_id || format.key;
|
|
355
|
+
var path = path_start + format.table.replace('_', '/') + '?size=0';
|
|
356
|
+
|
|
357
|
+
var obj = {
|
|
358
|
+
basename,
|
|
359
|
+
title: format.title,
|
|
360
|
+
id,
|
|
361
|
+
name,
|
|
362
|
+
field: format.name,
|
|
363
|
+
value: [],
|
|
364
|
+
path
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
return this._addSpecialFields(obj, field.name, name);
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* 添加特殊字段
|
|
372
|
+
* @param {object} obj 对象
|
|
373
|
+
* @param {string} field_name 字段名
|
|
374
|
+
* @param {string} label 标签
|
|
375
|
+
* @returns {object} 新对象
|
|
376
|
+
* @private
|
|
377
|
+
*/
|
|
378
|
+
Model.prototype._addSpecialFields = function(obj, field_name, label) {
|
|
379
|
+
var new_obj = { ...obj };
|
|
380
|
+
|
|
381
|
+
if (field_name === 'father_id' || field_name === 'fid') {
|
|
382
|
+
new_obj.father_id = field_name;
|
|
383
|
+
}
|
|
384
|
+
if (field_name === 'title') {
|
|
385
|
+
new_obj.title_name = 'title';
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return new_obj;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* 创建列表格式对象
|
|
393
|
+
* @param {object} field 字段对象
|
|
394
|
+
* @param {object} format 格式对象
|
|
395
|
+
* @returns {object} 列表格式对象
|
|
396
|
+
* @private
|
|
397
|
+
*/
|
|
398
|
+
Model.prototype._createListFormatObj = function(field, format) {
|
|
399
|
+
var basename = format.key;
|
|
400
|
+
var name = 'arr_' + basename;
|
|
401
|
+
|
|
402
|
+
return {
|
|
403
|
+
title: format.title,
|
|
404
|
+
name,
|
|
405
|
+
value: format.list
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 处理查询
|
|
411
|
+
* @param {object} js js对象
|
|
412
|
+
* @param {object} param 参数对象
|
|
413
|
+
* @private
|
|
414
|
+
*/
|
|
415
|
+
Model.prototype._processQuery = function(js, param) {
|
|
416
|
+
if (param && param.get) {
|
|
417
|
+
var arr = param.get.query_required.concat(param.get.query);
|
|
418
|
+
var lt = param.list;
|
|
419
|
+
for (var i = 0; i < arr.length; i++) {
|
|
420
|
+
var o = lt.getObj({ name: arr[i] });
|
|
421
|
+
if (o) {
|
|
422
|
+
js.query.push({
|
|
423
|
+
title: o.title,
|
|
424
|
+
name: o.name,
|
|
425
|
+
type: o.type,
|
|
426
|
+
select: o.description ? (o.description.indexOf('(') !== -1) : false
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* 运算视图模型
|
|
435
|
+
* @param {object} model 模型
|
|
436
|
+
* @returns {object} 返回视图所用模型
|
|
437
|
+
*/
|
|
438
|
+
Model.prototype.run = async function(model) {
|
|
439
|
+
model.field = await this.field(model);
|
|
440
|
+
model.js = await this.js(model);
|
|
441
|
+
model.html = await this.html(model);
|
|
442
|
+
model.css = await this.css(model);
|
|
443
|
+
return model;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
module.exports = Model;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
+
// 参数配置名
|
|
3
|
+
"name": "${name}",
|
|
4
|
+
// 参数标题
|
|
5
|
+
"title": "${title || '参数配置'}",
|
|
6
|
+
// 参数描述
|
|
7
|
+
"description": "${description || '描述参数配置使用方法'}",
|
|
2
8
|
// 是否启用过滤, 启用过滤后, 不符合的参数会被过滤掉
|
|
3
9
|
"filter": true,
|
|
4
10
|
// 校验脚本文件, 可以使用脚本的方式加一步进行校验, 让传参更加安全
|
|
5
|
-
"
|
|
11
|
+
"main": "",
|
|
6
12
|
// get请求
|
|
7
13
|
"get": {
|
|
8
14
|
// 查询参数校验项
|