mm_os 4.2.6 → 4.2.8
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 +1 -1
- package/README_EN.md +2 -2
- package/adapter/adapter.js +105 -52
- package/adapter/custom_persistence.js +32 -31
- package/adapter/mqtt.js +59 -79
- package/adapter/socket.js +188 -58
- package/adapter/web.js +92 -68
- package/adapter/websocket.js +43 -146
- package/com/api/drive.js +732 -708
- package/com/api/index.js +196 -198
- package/com/cmd/config.tpl.json +48 -122
- package/com/cmd/drive.js +176 -1548
- package/com/cmd/index.js +287 -1066
- package/com/cmd/job/config.json +66 -0
- package/com/cmd/job/index.js +241 -0
- package/com/cmd/job/test.js +188 -0
- package/com/cmd/script.tpl.js +12 -33
- package/com/db/drive.js +2206 -2019
- package/com/db/index.js +241 -242
- package/com/event/config.tpl.json +3 -1
- package/com/event/drive.js +3 -1
- package/com/event/index.js +73 -49
- package/com/event/script.tpl.js +1 -1
- package/com/mqtt/config.tpl.json +16 -8
- package/com/mqtt/drive.js +696 -676
- package/com/mqtt/index.js +1012 -822
- package/com/mqtt/index.test.js +503 -0
- package/com/mqtt/mm_mqtt.js +446 -420
- package/com/mqtt/script.tpl.js +3 -7
- package/com/nav/drive.js +7 -7
- package/com/nav/index.js +228 -231
- package/com/param/index.js +19 -17
- package/com/pendant/index.js +467 -441
- package/com/socket/drive.js +679 -616
- package/com/socket/index.js +94 -48
- package/com/sql/drive.js +1283 -1259
- package/com/sql/index.js +152 -150
- package/com/static/drive.js +1 -1
- package/com/static/index.js +232 -226
- package/com/task/drive.js +428 -405
- package/com/task/index.js +154 -148
- package/com/template/drive.js +1 -1
- package/com/template/index.js +141 -138
- package/com.js +87 -6
- package/common/middleware/web_after/index.js +4 -10
- package/common/middleware/web_base/index.js +1 -1
- package/common/middleware/web_cors/index.js +1 -1
- package/common/middleware/web_error/index.js +131 -119
- package/common/middleware/web_error/middleware.json +2 -1
- package/common/middleware/web_logger/index.js +1 -1
- package/common/middleware/web_main/index.js +2 -0
- package/common/middleware/web_static/index.js +2 -2
- package/common/middleware/web_waf/index.js +1 -1
- package/core/app/config.tpl.json +4 -4
- package/core/app/index.js +710 -534
- package/core/middleware/index.js +1 -9
- package/core/mod/config.tpl.json +1 -1
- package/core/model/config.tpl.json +1 -1
- package/core/plugin/config.tpl.json +15 -3
- package/core/plugin/index.js +31 -0
- package/core/pusher/index.js +158 -161
- package/core/scene/loop.js +1306 -1255
- package/core/store/index.js +1794 -1755
- package/core/store/sql.js +1488 -1464
- package/core/zone/bat/index.js +744 -728
- package/core/zone/config.tpl.json +3 -3
- package/core/zone/index.js +655 -616
- package/os.js +0 -4
- package/package.json +16 -16
- package/server.js +583 -427
- package/com/cmd/nlp.js +0 -525
- package/core/app/index copy.js +0 -611
- package/software.js +0 -194
- package/tcp.js +0 -279
package/com/pendant/index.js
CHANGED
|
@@ -1,441 +1,467 @@
|
|
|
1
|
-
const Manager = require(
|
|
2
|
-
const Drive = require(
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Pendant 挂件类
|
|
6
|
-
* @augments {Manager}
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class Pendant 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:
|
|
35
|
-
/**
|
|
36
|
-
* 模板目录
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
|
-
tpl_dir: __dirname,
|
|
40
|
-
/**
|
|
41
|
-
* 基础目录
|
|
42
|
-
* @type {string}
|
|
43
|
-
*/
|
|
44
|
-
base_dir:
|
|
45
|
-
/**
|
|
46
|
-
* 自定义目录,加载项目自定义资源
|
|
47
|
-
* @type {string}
|
|
48
|
-
*/
|
|
49
|
-
dir:
|
|
50
|
-
/**
|
|
51
|
-
* 搜索模式 dir按目录搜索 | file按文件名搜索
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
|
-
search_way:
|
|
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: 3
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 构造函数
|
|
74
|
-
* @param {object} config 配置参数
|
|
75
|
-
* @param {object} parent 父级模块
|
|
76
|
-
*/
|
|
77
|
-
constructor(config, parent) {
|
|
78
|
-
super({ ...Pendant.config, ...config }, parent);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 挂件驱动类
|
|
84
|
-
* @type {Drive}
|
|
85
|
-
*/
|
|
86
|
-
Pendant.prototype.Drive = Drive;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 加载列表
|
|
90
|
-
* @param {Array} list 文件列表
|
|
91
|
-
*/
|
|
92
|
-
Pendant.prototype.loadList = async function (list) {
|
|
93
|
-
var _this = this;
|
|
94
|
-
|
|
95
|
-
// 遍历文件路径
|
|
96
|
-
for (var i = 0; i < list.length; i++) {
|
|
97
|
-
var file = list[i];
|
|
98
|
-
var dir = file.dirname();
|
|
99
|
-
// 载入文件
|
|
100
|
-
var obj = file.loadJson(dir);
|
|
101
|
-
if (obj) {
|
|
102
|
-
if (obj.constructor == Array) {
|
|
103
|
-
for (var n = 0; n < obj.length; n++) {
|
|
104
|
-
var o = obj[n];
|
|
105
|
-
// 实例化一个驱动
|
|
106
|
-
await _this.load(dir, o, file);
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
await _this.load(dir, obj, file);
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
var fl = _this.dir_base +
|
|
113
|
-
if (fl.hasFile()) {
|
|
114
|
-
var text = fl.loadText();
|
|
115
|
-
if (text) {
|
|
116
|
-
var l = $.slash;
|
|
117
|
-
var name = file.between(
|
|
118
|
-
text = text.replaceAll(
|
|
119
|
-
var app = file.between(
|
|
120
|
-
text = text.replaceAll(
|
|
121
|
-
file.saveText(text);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 生成字体样式
|
|
130
|
-
* @param {object} o 样式对象
|
|
131
|
-
* @returns {string} 字体样式
|
|
132
|
-
*/
|
|
133
|
-
Pendant.prototype._generateFontStyle = function (o) {
|
|
134
|
-
var style =
|
|
135
|
-
if (o.font_size) {
|
|
136
|
-
style += `\n font-size: ${o.font_size};`;
|
|
137
|
-
}
|
|
138
|
-
if (o.font_color) {
|
|
139
|
-
style += `\n color: ${o.font_color};`;
|
|
140
|
-
}
|
|
141
|
-
return style;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* 生成边框样式
|
|
146
|
-
* @param {object} o 样式对象
|
|
147
|
-
* @returns {string} 边框样式
|
|
148
|
-
*/
|
|
149
|
-
Pendant.prototype._generateBorderStyle = function (o) {
|
|
150
|
-
var borders = [
|
|
151
|
-
{
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
*
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
*
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
style += `\n
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
*
|
|
254
|
-
* @
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
*
|
|
273
|
-
* @param {
|
|
274
|
-
* @
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
*
|
|
293
|
-
* @
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if (
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
if (
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
*
|
|
377
|
-
* @
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
*
|
|
438
|
-
*/
|
|
439
|
-
if (
|
|
440
|
-
$.
|
|
441
|
-
}
|
|
1
|
+
const Manager = require("mm_machine").Manager;
|
|
2
|
+
const Drive = require("./drive");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pendant 挂件类
|
|
6
|
+
* @augments {Manager}
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class Pendant 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: "pendant.json",
|
|
35
|
+
/**
|
|
36
|
+
* 模板目录
|
|
37
|
+
* @type {string}
|
|
38
|
+
*/
|
|
39
|
+
tpl_dir: __dirname,
|
|
40
|
+
/**
|
|
41
|
+
* 基础目录
|
|
42
|
+
* @type {string}
|
|
43
|
+
*/
|
|
44
|
+
base_dir: "../common/pendant".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({ ...Pendant.config, ...config }, parent);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 挂件驱动类
|
|
84
|
+
* @type {Drive}
|
|
85
|
+
*/
|
|
86
|
+
Pendant.prototype.Drive = Drive;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 加载列表
|
|
90
|
+
* @param {Array} list 文件列表
|
|
91
|
+
*/
|
|
92
|
+
Pendant.prototype.loadList = async function (list) {
|
|
93
|
+
var _this = this;
|
|
94
|
+
|
|
95
|
+
// 遍历文件路径
|
|
96
|
+
for (var i = 0; i < list.length; i++) {
|
|
97
|
+
var file = list[i];
|
|
98
|
+
var dir = file.dirname();
|
|
99
|
+
// 载入文件
|
|
100
|
+
var obj = file.loadJson(dir);
|
|
101
|
+
if (obj) {
|
|
102
|
+
if (obj.constructor == Array) {
|
|
103
|
+
for (var n = 0; n < obj.length; n++) {
|
|
104
|
+
var o = obj[n];
|
|
105
|
+
// 实例化一个驱动
|
|
106
|
+
await _this.load(dir, o, file);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
await _this.load(dir, obj, file);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
var fl = _this.dir_base + "/config.tpl.json";
|
|
113
|
+
if (fl.hasFile()) {
|
|
114
|
+
var text = fl.loadText();
|
|
115
|
+
if (text) {
|
|
116
|
+
var l = $.slash;
|
|
117
|
+
var name = file.between("Pendant" + l, l);
|
|
118
|
+
text = text.replaceAll("{0}", name);
|
|
119
|
+
var app = file.between("app" + l, l);
|
|
120
|
+
text = text.replaceAll("{1}", app);
|
|
121
|
+
file.saveText(text);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 生成字体样式
|
|
130
|
+
* @param {object} o 样式对象
|
|
131
|
+
* @returns {string} 字体样式
|
|
132
|
+
*/
|
|
133
|
+
Pendant.prototype._generateFontStyle = function (o) {
|
|
134
|
+
var style = "";
|
|
135
|
+
if (o.font_size) {
|
|
136
|
+
style += `\n font-size: ${o.font_size};`;
|
|
137
|
+
}
|
|
138
|
+
if (o.font_color) {
|
|
139
|
+
style += `\n color: ${o.font_color};`;
|
|
140
|
+
}
|
|
141
|
+
return style;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 生成边框样式
|
|
146
|
+
* @param {object} o 样式对象
|
|
147
|
+
* @returns {string} 边框样式
|
|
148
|
+
*/
|
|
149
|
+
Pendant.prototype._generateBorderStyle = function (o) {
|
|
150
|
+
var borders = [
|
|
151
|
+
{
|
|
152
|
+
pos: "top",
|
|
153
|
+
style: o.border_top_style,
|
|
154
|
+
size: o.border_top_size,
|
|
155
|
+
color: o.border_top_color,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
pos: "right",
|
|
159
|
+
style: o.border_right_style,
|
|
160
|
+
size: o.border_right_size,
|
|
161
|
+
color: o.border_right_color,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
pos: "bottom",
|
|
165
|
+
style: o.border_bottom_style,
|
|
166
|
+
size: o.border_bottom_size,
|
|
167
|
+
color: o.border_bottom_color,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
pos: "left",
|
|
171
|
+
style: o.border_left_style,
|
|
172
|
+
size: o.border_left_size,
|
|
173
|
+
color: o.border_left_color,
|
|
174
|
+
},
|
|
175
|
+
];
|
|
176
|
+
var style = "";
|
|
177
|
+
for (var i = 0; i < borders.length; i++) {
|
|
178
|
+
var b = borders[i];
|
|
179
|
+
if (b.style !== "none") {
|
|
180
|
+
style += `\n border-${b.pos}: ${b.size || 0} ${b.style || "solid"} ${b.color || "#dbdbdb"};`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return style;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 生成边距样式
|
|
188
|
+
* @param {object} o 样式对象
|
|
189
|
+
* @returns {string} 边距样式
|
|
190
|
+
*/
|
|
191
|
+
Pendant.prototype._generateMarginStyle = function (o) {
|
|
192
|
+
var style = "";
|
|
193
|
+
if (o.margin_top) {
|
|
194
|
+
style += `\n margin-top: ${o.margin_top};`;
|
|
195
|
+
}
|
|
196
|
+
if (o.margin_right) {
|
|
197
|
+
style += `\n margin-right: ${o.margin_right};`;
|
|
198
|
+
}
|
|
199
|
+
if (o.margin_bottom) {
|
|
200
|
+
style += `\n margin-bottom: ${o.margin_bottom};`;
|
|
201
|
+
}
|
|
202
|
+
if (o.margin_left) {
|
|
203
|
+
style += `\n margin-left: ${o.margin_left};`;
|
|
204
|
+
}
|
|
205
|
+
return style;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* 生成填充样式
|
|
210
|
+
* @param {object} o 样式对象
|
|
211
|
+
* @returns {string} 填充样式
|
|
212
|
+
*/
|
|
213
|
+
Pendant.prototype._generatePaddingStyle = function (o) {
|
|
214
|
+
var style = "";
|
|
215
|
+
if (o.padding_top) {
|
|
216
|
+
style += `\n padding-top: ${o.padding_top};`;
|
|
217
|
+
}
|
|
218
|
+
if (o.padding_right) {
|
|
219
|
+
style += `\n padding-right: ${o.padding_right};`;
|
|
220
|
+
}
|
|
221
|
+
if (o.padding_bottom) {
|
|
222
|
+
style += `\n padding-bottom: ${o.padding_bottom};`;
|
|
223
|
+
}
|
|
224
|
+
if (o.padding_left) {
|
|
225
|
+
style += `\n padding-left: ${o.padding_left};`;
|
|
226
|
+
}
|
|
227
|
+
return style;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 生成圆角样式
|
|
232
|
+
* @param {object} o 样式对象
|
|
233
|
+
* @returns {string} 圆角样式
|
|
234
|
+
*/
|
|
235
|
+
Pendant.prototype._generateRadiusStyle = function (o) {
|
|
236
|
+
var style = "";
|
|
237
|
+
if (o.radius_top_right) {
|
|
238
|
+
style += `\n border-top-right-radius: ${o.radius_top_right};`;
|
|
239
|
+
}
|
|
240
|
+
if (o.radius_top_left) {
|
|
241
|
+
style += `\n border-top-left-radius: ${o.radius_top_left};`;
|
|
242
|
+
}
|
|
243
|
+
if (o.radius_bottom_right) {
|
|
244
|
+
style += `\n border-bottom-right-radius: ${o.radius_bottom_right};`;
|
|
245
|
+
}
|
|
246
|
+
if (o.radius_bottom_left) {
|
|
247
|
+
style += `\n border-bottom-left-radius: ${o.radius_bottom_left};`;
|
|
248
|
+
}
|
|
249
|
+
return style;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 生成背景样式
|
|
254
|
+
* @param {object} o 样式对象
|
|
255
|
+
* @returns {string} 背景样式
|
|
256
|
+
*/
|
|
257
|
+
Pendant.prototype._generateBgStyle = function (o) {
|
|
258
|
+
var style = "";
|
|
259
|
+
if (o.bg_url) {
|
|
260
|
+
style += `\n background-image: url(${o.bg_url});`;
|
|
261
|
+
style += `\n background-size: 100% auto;`;
|
|
262
|
+
style += `\n background-repeat: ${o.bg_repeat || "no-repeat"};`;
|
|
263
|
+
}
|
|
264
|
+
if (o.bg_color) {
|
|
265
|
+
style += `\n background-color: ${o.bg_color || ""};`;
|
|
266
|
+
}
|
|
267
|
+
return style;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* 生成链接样式
|
|
272
|
+
* @param {string} id 元素ID
|
|
273
|
+
* @param {object} o 样式对象
|
|
274
|
+
* @returns {string} 链接样式
|
|
275
|
+
*/
|
|
276
|
+
Pendant.prototype._generateLinkStyle = function (id, o) {
|
|
277
|
+
var style = "";
|
|
278
|
+
if (o.a_size || o.a_color) {
|
|
279
|
+
style += `\n#${id} a {`;
|
|
280
|
+
if (o.a_size) {
|
|
281
|
+
style += `\n font-size: ${o.a_size};`;
|
|
282
|
+
}
|
|
283
|
+
if (o.a_color) {
|
|
284
|
+
style += `\n color: ${o.a_color};`;
|
|
285
|
+
}
|
|
286
|
+
style += `\n}`;
|
|
287
|
+
}
|
|
288
|
+
return style;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 生成样式
|
|
293
|
+
* @param {string} id 元素ID
|
|
294
|
+
* @param {object} o 样式对象
|
|
295
|
+
* @returns {string} 样式
|
|
296
|
+
*/
|
|
297
|
+
Pendant.prototype._generateStyle = function (id, o) {
|
|
298
|
+
var style = `#${id} {`;
|
|
299
|
+
style += this._generateFontStyle(o);
|
|
300
|
+
style += this._generateBorderStyle(o);
|
|
301
|
+
style += this._generateMarginStyle(o);
|
|
302
|
+
style += this._generatePaddingStyle(o);
|
|
303
|
+
style += this._generateRadiusStyle(o);
|
|
304
|
+
style += this._generateBgStyle(o);
|
|
305
|
+
style += `\n}`;
|
|
306
|
+
style += this._generateLinkStyle(id, o);
|
|
307
|
+
return style;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* 生成分类样式
|
|
312
|
+
* @param {object} o 布局对象
|
|
313
|
+
* @returns {string} 分类样式
|
|
314
|
+
*/
|
|
315
|
+
Pendant.prototype._generateLayout = function (o) {
|
|
316
|
+
var layout = "";
|
|
317
|
+
if (o.default) {
|
|
318
|
+
layout += " col-" + o.default;
|
|
319
|
+
}
|
|
320
|
+
if (o.pc) {
|
|
321
|
+
layout += " col-xxl-" + o.pc;
|
|
322
|
+
}
|
|
323
|
+
if (o.note) {
|
|
324
|
+
layout += " col-xl-" + o.note;
|
|
325
|
+
}
|
|
326
|
+
if (o.pad) {
|
|
327
|
+
layout += " col-lg-" + o.pad;
|
|
328
|
+
}
|
|
329
|
+
if (o.pad_mini) {
|
|
330
|
+
layout += " col-sm-" + o.pad_mini;
|
|
331
|
+
}
|
|
332
|
+
if (o.phone) {
|
|
333
|
+
layout += " col-xs-" + o.phone;
|
|
334
|
+
}
|
|
335
|
+
return layout.trim();
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 配置模型
|
|
340
|
+
* @param {object} block 配置块
|
|
341
|
+
* @returns {string} 返回html代码
|
|
342
|
+
*/
|
|
343
|
+
Pendant.prototype.optionModel = function (block) {
|
|
344
|
+
var id = block.id || block.name;
|
|
345
|
+
var style = "";
|
|
346
|
+
if (block.style) {
|
|
347
|
+
var o = block.style.toJson();
|
|
348
|
+
style = this._generateStyle(id, o);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
var layout = "";
|
|
352
|
+
if (block.layout) {
|
|
353
|
+
var o = block.layout.toJson();
|
|
354
|
+
layout = this._generateLayout(o);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
var data = (block.data || "[]").toJson();
|
|
358
|
+
var attr = (block.attr || "{}").toJson();
|
|
359
|
+
var options = (block.options || "{}").toJson();
|
|
360
|
+
|
|
361
|
+
return {
|
|
362
|
+
id,
|
|
363
|
+
class: block.class,
|
|
364
|
+
style,
|
|
365
|
+
data,
|
|
366
|
+
attr,
|
|
367
|
+
layout,
|
|
368
|
+
options,
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 渲染模块
|
|
374
|
+
* @param {object} ctx 请求上下文
|
|
375
|
+
* @param {object} db 数据管理器,如: { next: async function{}, ret: {} }
|
|
376
|
+
* @param {Array} blocks 模块数组
|
|
377
|
+
* @returns {string} 返回html代码
|
|
378
|
+
*/
|
|
379
|
+
Pendant.prototype.renderBlock = async function (ctx, db, blocks) {
|
|
380
|
+
var html = "";
|
|
381
|
+
for (var i = 0; i < blocks.length; i++) {
|
|
382
|
+
var block = blocks[i];
|
|
383
|
+
var o = this.getMod(block.pendant);
|
|
384
|
+
if (o) {
|
|
385
|
+
if (!o.isLoaded()) {
|
|
386
|
+
await o.do("load");
|
|
387
|
+
}
|
|
388
|
+
var option = this.optionModel(block);
|
|
389
|
+
var ret = await o.call("main", ctx, db, option);
|
|
390
|
+
if (ret) {
|
|
391
|
+
html += "\n" + ret;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return html;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* 执行渲染
|
|
400
|
+
* @param {object} ctx 请求上下文
|
|
401
|
+
* @param {object} db 数据管理器,如: { next: async function{}, ret: {} }
|
|
402
|
+
* @param {string} path 页面
|
|
403
|
+
* @param {string} position 位置
|
|
404
|
+
* @returns {string} 返回html代码
|
|
405
|
+
*/
|
|
406
|
+
Pendant.prototype.render = async function (ctx, db, path, position) {
|
|
407
|
+
var html = "";
|
|
408
|
+
var infos = this.getInfos();
|
|
409
|
+
for (var k in infos) {
|
|
410
|
+
var info = infos[k];
|
|
411
|
+
if (info.state) {
|
|
412
|
+
let mod = this.getMod(info.name);
|
|
413
|
+
if (mod) {
|
|
414
|
+
var obj = mod.config.location.getObj({
|
|
415
|
+
path,
|
|
416
|
+
position,
|
|
417
|
+
});
|
|
418
|
+
if (obj && obj.available) {
|
|
419
|
+
if (!mod.isLoaded()) {
|
|
420
|
+
await mod.do("load");
|
|
421
|
+
}
|
|
422
|
+
var ret = await mod.call("main", ctx, db);
|
|
423
|
+
if (ret) {
|
|
424
|
+
html += "\n" + ret;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return html;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
/* 导出指令 */
|
|
434
|
+
exports.Pendant = Pendant;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Pendant组件池
|
|
438
|
+
*/
|
|
439
|
+
if (!$.pool.pendant) {
|
|
440
|
+
$.pool.pendant = {};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Pendant管理器,用于创建缓存
|
|
445
|
+
* @param {string} scope 作用域
|
|
446
|
+
* @param {string} title 标题
|
|
447
|
+
* @returns {object} 返回一个缓存类
|
|
448
|
+
*/
|
|
449
|
+
function pendantAdmin(scope, title) {
|
|
450
|
+
var sc = scope || $.val.scope + "";
|
|
451
|
+
var obj = $.pool.pendant[sc];
|
|
452
|
+
if (!obj) {
|
|
453
|
+
$.pool.pendant[sc] = new Pendant({
|
|
454
|
+
name: sc,
|
|
455
|
+
title: title,
|
|
456
|
+
});
|
|
457
|
+
obj = $.pool.pendant[sc];
|
|
458
|
+
}
|
|
459
|
+
return obj;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @module 导出Pendant管理器
|
|
464
|
+
*/
|
|
465
|
+
if ($.admin) {
|
|
466
|
+
$.admin.pendant = pendantAdmin;
|
|
467
|
+
}
|