mm_os 4.3.6 → 5.0.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/README.md +101 -504
- package/index.js +26 -19
- package/lib/loader.js +787 -0
- package/lib/os.js +369 -0
- package/package.json +55 -80
- 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 -696
- package/com/mqtt/index.js +0 -1017
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/mm_mqtt.js +0 -446
- 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 -1283
- 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 -385
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -710
- 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 -297
- 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/store/sql.js +0 -1488
- 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 -595
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// 名称
|
|
3
|
-
"name": "${name}",
|
|
4
|
-
// 标题
|
|
5
|
-
"title": "角色信息",
|
|
6
|
-
// 描述
|
|
7
|
-
"description": "定义角色信息的组件",
|
|
8
|
-
// 状态 0:禁用 1:启用
|
|
9
|
-
"state": 1,
|
|
10
|
-
// 排序,越小越靠前
|
|
11
|
-
"sort": 10,
|
|
12
|
-
// 组件包含字段
|
|
13
|
-
"fields": {
|
|
14
|
-
"id": {
|
|
15
|
-
"type": "string",
|
|
16
|
-
"title": "角色ID",
|
|
17
|
-
"description": "角色的唯一标识符",
|
|
18
|
-
"min": 1,
|
|
19
|
-
"max": 10000000,
|
|
20
|
-
"default": "role_10000000"
|
|
21
|
-
},
|
|
22
|
-
"name": {
|
|
23
|
-
"type": "string",
|
|
24
|
-
"title": "角色名称",
|
|
25
|
-
"description": "角色的显示名称",
|
|
26
|
-
"min": 1,
|
|
27
|
-
"max": 24,
|
|
28
|
-
"default": "张三"
|
|
29
|
-
},
|
|
30
|
-
"description": {
|
|
31
|
-
"type": "string",
|
|
32
|
-
"title": "角色描述",
|
|
33
|
-
"description": "角色的详细说明",
|
|
34
|
-
"min": 1,
|
|
35
|
-
"max": 255,
|
|
36
|
-
"default": "一个普通的角色"
|
|
37
|
-
},
|
|
38
|
-
"type_id": {
|
|
39
|
-
"type": "number",
|
|
40
|
-
"title": "类型ID",
|
|
41
|
-
"description": "角色的类型ID",
|
|
42
|
-
"min": 1,
|
|
43
|
-
"max": 10000000,
|
|
44
|
-
"default": 1
|
|
45
|
-
},
|
|
46
|
-
"race": {
|
|
47
|
-
"type": "string",
|
|
48
|
-
"title": "种族",
|
|
49
|
-
"description": "角色的种族",
|
|
50
|
-
"min": 1,
|
|
51
|
-
"max": 10000000,
|
|
52
|
-
"default": "人族"
|
|
53
|
-
},
|
|
54
|
-
"age": {
|
|
55
|
-
"type": "number",
|
|
56
|
-
"title": "年龄",
|
|
57
|
-
"description": "角色的年龄",
|
|
58
|
-
"min": 1,
|
|
59
|
-
"max": 10000,
|
|
60
|
-
"default": 16
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
package/core/component/index.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
const { Drive } = require('mm_machine');
|
|
2
|
-
const Comp = require('./component.js');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 组件基类
|
|
6
|
-
* 纯粹的组件数据容器,不包含任何业务逻辑
|
|
7
|
-
* 只负责定义组件的数据结构和验证规则
|
|
8
|
-
*/
|
|
9
|
-
class Component extends Drive {
|
|
10
|
-
static config = {
|
|
11
|
-
'name': 'default',
|
|
12
|
-
'title': '组件',
|
|
13
|
-
'main': '',
|
|
14
|
-
'sort': 10
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 构造函数
|
|
19
|
-
* @param {object} config 配置参数
|
|
20
|
-
* @param {object} parent 父对象
|
|
21
|
-
*/
|
|
22
|
-
constructor(config, parent) {
|
|
23
|
-
super({ ...Component.config, ...config || {} }, parent);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 获取模板目录
|
|
29
|
-
* @returns {string} 模板目录
|
|
30
|
-
*/
|
|
31
|
-
Component.prototype.getTplDir = function() {
|
|
32
|
-
return __dirname;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 获取组件字段定义
|
|
37
|
-
* @returns {object} 组件字段定义
|
|
38
|
-
*/
|
|
39
|
-
Component.prototype.getFields = function () {
|
|
40
|
-
return this.config.fields || {};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 创建组件数据实例
|
|
45
|
-
* @param {object} data 组件数据
|
|
46
|
-
* @returns {object} 组件数据实例
|
|
47
|
-
*/
|
|
48
|
-
Component.prototype.create = function (data = {}) {
|
|
49
|
-
if (typeof data !== 'object' || Array.isArray(data)) {
|
|
50
|
-
throw new TypeError('组件数据必须是对象');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let component = new Comp();
|
|
54
|
-
let fields = this.getFields();
|
|
55
|
-
|
|
56
|
-
for (let field_name in fields) {
|
|
57
|
-
let rule = fields[field_name];
|
|
58
|
-
let field_value = data[field_name];
|
|
59
|
-
component[field_name] = this._getDefaultValue(field_value, rule);
|
|
60
|
-
}
|
|
61
|
-
component.isDirty(false);
|
|
62
|
-
return component;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 获取字段默认值
|
|
67
|
-
* @param {*} field_value 字段值
|
|
68
|
-
* @param {object} rule 规则
|
|
69
|
-
* @returns {*} 默认值
|
|
70
|
-
*/
|
|
71
|
-
Component.prototype._getDefaultValue = function(field_value, rule) {
|
|
72
|
-
if (field_value !== undefined) {
|
|
73
|
-
return field_value;
|
|
74
|
-
}
|
|
75
|
-
if (rule.default !== undefined) {
|
|
76
|
-
return rule.default;
|
|
77
|
-
}
|
|
78
|
-
return this._getTypeDefault(rule.type);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 根据类型获取默认值
|
|
83
|
-
* @param {string} type 类型
|
|
84
|
-
* @returns {*} 默认值
|
|
85
|
-
*/
|
|
86
|
-
Component.prototype._getTypeDefault = function(type) {
|
|
87
|
-
const defaults = {
|
|
88
|
-
'number': 0,
|
|
89
|
-
'string': '',
|
|
90
|
-
'boolean': false,
|
|
91
|
-
'object': {},
|
|
92
|
-
'array': []
|
|
93
|
-
};
|
|
94
|
-
return defaults[type] !== undefined ? defaults[type] : null;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 验证必填字段
|
|
99
|
-
* @param {string} field_name 字段名
|
|
100
|
-
* @param {*} field_value 字段值
|
|
101
|
-
* @param {object} rule 验证规则
|
|
102
|
-
* @returns {string|undefined} 错误信息
|
|
103
|
-
*/
|
|
104
|
-
Component.prototype._validateRequired = function (field_name, field_value, rule) {
|
|
105
|
-
if (rule.required && (field_value === undefined || field_value === null || field_value === '')) {
|
|
106
|
-
return `${field_name} 是必填字段`;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 验证字段类型
|
|
112
|
-
* @param {string} field_name 字段名
|
|
113
|
-
* @param {*} field_value 字段值
|
|
114
|
-
* @param {object} rule 验证规则
|
|
115
|
-
* @returns {string|undefined} 错误信息
|
|
116
|
-
*/
|
|
117
|
-
Component.prototype._validateType = function (field_name, field_value, rule) {
|
|
118
|
-
if (rule.type && typeof field_value !== rule.type) {
|
|
119
|
-
return `${field_name} 必须是 ${rule.type} 类型`;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 验证字段范围
|
|
125
|
-
* @param {string} field_name 字段名
|
|
126
|
-
* @param {*} field_value 字段值
|
|
127
|
-
* @param {object} rule 验证规则
|
|
128
|
-
* @returns {string|undefined} 错误信息
|
|
129
|
-
*/
|
|
130
|
-
Component.prototype._validateRange = function (field_name, field_value, rule) {
|
|
131
|
-
if (rule.min !== undefined && field_value < rule.min) {
|
|
132
|
-
return `${field_name} 不能小于 ${rule.min}`;
|
|
133
|
-
}
|
|
134
|
-
if (rule.max !== undefined && field_value > rule.max) {
|
|
135
|
-
return `${field_name} 不能大于 ${rule.max}`;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* 验证字段长度
|
|
141
|
-
* @param {string} field_name 字段名
|
|
142
|
-
* @param {*} field_value 字段值
|
|
143
|
-
* @param {object} rule 验证规则
|
|
144
|
-
* @returns {string|undefined} 错误信息
|
|
145
|
-
*/
|
|
146
|
-
Component.prototype._validateLength = function (field_name, field_value, rule) {
|
|
147
|
-
if (rule.min_length !== undefined && field_value.length < rule.min_length) {
|
|
148
|
-
return `${field_name} 长度不能小于 ${rule.min_length}`;
|
|
149
|
-
}
|
|
150
|
-
if (rule.max_length !== undefined && field_value.length > rule.max_length) {
|
|
151
|
-
return `${field_name} 长度不能大于 ${rule.max_length}`;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 验证字段格式
|
|
157
|
-
* @param {string} field_name 字段名
|
|
158
|
-
* @param {*} field_value 字段值
|
|
159
|
-
* @param {object} rule 验证规则
|
|
160
|
-
* @returns {string|undefined} 错误信息
|
|
161
|
-
*/
|
|
162
|
-
Component.prototype._validateFormat = function (field_name, field_value, rule) {
|
|
163
|
-
if (rule.pattern && !rule.pattern.test(field_value)) {
|
|
164
|
-
return `${field_name} 格式不正确`;
|
|
165
|
-
}
|
|
166
|
-
if (rule.enum && !rule.enum.includes(field_value)) {
|
|
167
|
-
return `${field_name} 的值必须是 ${rule.enum.join('、')}`;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* 验证单个字段
|
|
173
|
-
* @param {string} field_name 字段名
|
|
174
|
-
* @param {*} field_value 字段值
|
|
175
|
-
* @param {object} rule 验证规则
|
|
176
|
-
* @returns {string|undefined} 错误信息
|
|
177
|
-
*/
|
|
178
|
-
Component.prototype._validateField = function (field_name, field_value, rule) {
|
|
179
|
-
var error = this._validateRequired(field_name, field_value, rule);
|
|
180
|
-
if (error) return error;
|
|
181
|
-
if (field_value === undefined || field_value === null) return;
|
|
182
|
-
error = this._validateType(field_name, field_value, rule);
|
|
183
|
-
if (error) return error;
|
|
184
|
-
error = this._validateRange(field_name, field_value, rule);
|
|
185
|
-
if (error) return error;
|
|
186
|
-
error = this._validateLength(field_name, field_value, rule);
|
|
187
|
-
if (error) return error;
|
|
188
|
-
return this._validateFormat(field_name, field_value, rule);
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 验证组件数据
|
|
193
|
-
* @param {object} data 组件数据
|
|
194
|
-
* @returns {object} 验证结果
|
|
195
|
-
*/
|
|
196
|
-
Component.prototype.validate = function (data) {
|
|
197
|
-
if (typeof data !== 'object' || Array.isArray(data)) {
|
|
198
|
-
throw new TypeError('验证数据必须是对象');
|
|
199
|
-
}
|
|
200
|
-
const errors = {};
|
|
201
|
-
let fields = this.getFields();
|
|
202
|
-
for (let field_name in fields) {
|
|
203
|
-
let error = this._validateField(field_name, data[field_name], fields[field_name]);
|
|
204
|
-
if (error) errors[field_name] = error;
|
|
205
|
-
}
|
|
206
|
-
return { valid: Object.keys(errors).length === 0, errors };
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* 获取组件类型
|
|
211
|
-
* @returns {string} 组件类型
|
|
212
|
-
*/
|
|
213
|
-
Component.prototype.getType = function () {
|
|
214
|
-
return this.config.name;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* 获取组件标题
|
|
219
|
-
* @returns {string} 组件标题
|
|
220
|
-
*/
|
|
221
|
-
Component.prototype.getTitle = function () {
|
|
222
|
-
return this.config.title;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* 获取组件描述
|
|
227
|
-
* @returns {string} 组件描述
|
|
228
|
-
*/
|
|
229
|
-
Component.prototype.getDescription = function () {
|
|
230
|
-
return this.config.description || '';
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* 转换为JSON字符串
|
|
235
|
-
* @param {object} component 组件数据
|
|
236
|
-
* @returns {string} JSON字符串
|
|
237
|
-
*/
|
|
238
|
-
Component.prototype.toJson = function (component) {
|
|
239
|
-
// 参数校验
|
|
240
|
-
if (typeof component !== 'object' || Array.isArray(component)) {
|
|
241
|
-
throw new TypeError('组件数据必须是对象');
|
|
242
|
-
}
|
|
243
|
-
return JSON.stringify(component);
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* 从JSON字符串创建组件数据
|
|
248
|
-
* @param {string} json_str JSON字符串
|
|
249
|
-
* @returns {object} 组件数据
|
|
250
|
-
*/
|
|
251
|
-
Component.prototype.fromJson = function (json_str) {
|
|
252
|
-
// 参数校验
|
|
253
|
-
if (typeof json_str !== 'string') {
|
|
254
|
-
throw new TypeError('JSON字符串必须是字符串');
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
let data = JSON.parse(json_str);
|
|
258
|
-
return this.create(data);
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 初始化组件核心
|
|
263
|
-
* @param {object} logger 日志对象
|
|
264
|
-
*/
|
|
265
|
-
Component.prototype._initCore = async function (logger) {
|
|
266
|
-
// 日志对象
|
|
267
|
-
if (logger) {
|
|
268
|
-
this.setLogger(logger);
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
// 导出模块
|
|
273
|
-
exports.Component = Component;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 组件,主要用于游戏
|
|
3
|
-
*/
|
|
4
|
-
module.exports = {
|
|
5
|
-
/**
|
|
6
|
-
* 初始化
|
|
7
|
-
*/
|
|
8
|
-
async _init() {
|
|
9
|
-
// this.log('debug', `初始化!`);
|
|
10
|
-
},
|
|
11
|
-
/**
|
|
12
|
-
* 主要逻辑
|
|
13
|
-
* @param {...any} args 逻辑参数
|
|
14
|
-
*/
|
|
15
|
-
async main(...args) {
|
|
16
|
-
this.log('debug', `主要逻辑被调用`, { args });
|
|
17
|
-
// 主要代码写在这
|
|
18
|
-
}
|
|
19
|
-
};
|