mm_os 2.4.5 → 2.4.7

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.
@@ -3,7 +3,7 @@
3
3
  "name": "demo",
4
4
  // 标题, 用于查询指令时
5
5
  "title": "指令标题",
6
- // 标题, 用于介绍该指令的作用
6
+ // 描述, 用于介绍该指令的作用
7
7
  "description": "暂无描述",
8
8
  // 时态, 分before之前、main主要、after之后三个时态,
9
9
  "tense": "main",
@@ -25,7 +25,7 @@ class Cmd extends Index {
25
25
  }
26
26
 
27
27
  /**
28
- * 执行导航
28
+ * 执行指令
29
29
  * @param {Object} msg 消息
30
30
  * @param {Object} db 数据管理器
31
31
  * @param {String} table 表名
@@ -0,0 +1,3 @@
1
+ ## 指令框架
2
+ 用于以聊天的方式操作程序。
3
+ 前端发送字符串,后端通过字符串判断是否为指令进而执行程序。提高工作效率。
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "组件管理器",
3
+ "script": "./index.js"
4
+ }
@@ -0,0 +1,16 @@
1
+ <div class="mm_col col-12 col-sm-6 col-md-3 col-lg-2">
2
+ <div class="component_demo">
3
+ <div class="title">示例组件标题</div>
4
+ <div class="description">示例组件描述</div>
5
+ </div>
6
+ </div>
7
+
8
+ <style scoped>
9
+ .component_demo {}
10
+
11
+ .component_demo .title {}
12
+
13
+ .component_demo .description {
14
+
15
+ }
16
+ </style>
@@ -0,0 +1,28 @@
1
+ {
2
+ // 应用于,根据应用而判断使用
3
+ "app": "admin",
4
+ // 名称, 用于动态增删改配置
5
+ "name": "{0}",
6
+ // 页面位置
7
+ "pages": ["/admin/index"],
8
+ // 位置 side侧边栏、main主体、float浮动栏、header头部、footer尾部
9
+ "position": "main",
10
+ // 标题, 用于查询时
11
+ "title": "示例组件(挂件)",
12
+ // 描述, 用于介绍该组件的作用
13
+ "description": "暂无描述",
14
+ // 时态, 分before之前、main主要、after之后三个时态,
15
+ "tense": "main",
16
+ // 执行顺序, 数值越小的越优先显示
17
+ "sort": 100,
18
+ // 分组, 可以将特有的分一个组, 方便用户查询
19
+ "group": "default",
20
+ // 分类, 例如: 查询生活类、监测类、便民类
21
+ "type": "监测",
22
+ // 脚本文件, 非必传,可和渲染文件二选一传
23
+ "func_file": "./component.js",
24
+ // 渲染, 非必传,可和脚本文件二选一传
25
+ "template": "./component.html",
26
+ // 状态, 0为未开启 1为开启
27
+ "state": 1
28
+ }
@@ -0,0 +1,97 @@
1
+ const Item = require('mm_machine').Item;
2
+
3
+ /**
4
+ * 指令驱动类
5
+ * @extends {Item}
6
+ * @class
7
+ */
8
+ class Drive extends Item {
9
+ /**
10
+ * 构造函数
11
+ * @param {String} dir 当前目录
12
+ * @constructor
13
+ */
14
+ constructor(dir) {
15
+ super(dir, __dirname);
16
+ this.default_file = "./component.json";
17
+
18
+ /* 通用项 */
19
+ // 配置参数
20
+ this.config = {
21
+ // 应用于,根据应用而判断使用
22
+ "app": "admin",
23
+ // 名称, 用于动态增删改配置
24
+ "name": "demo",
25
+ // 页面位置
26
+ "pages": ["/admin/index"],
27
+ // 位置 side侧边栏、main主体、float浮动栏、header头部、footer尾部
28
+ "position": "main",
29
+ // 标题, 用于查询时
30
+ "title": "示例组件",
31
+ // 描述, 用于介绍该组件的作用
32
+ "description": "暂无描述",
33
+ // 时态, 分before之前、main主要、after之后三个时态,
34
+ "tense": "main",
35
+ // 执行顺序, 数值越小的越优先显示
36
+ "sort": 100,
37
+ // 分组, 可以将特有的分一个组, 方便用户查询
38
+ "group": "default",
39
+ // 分类, 例如: 查询生活类、监测类、便民类
40
+ "type": "监测",
41
+ // 脚本文件
42
+ "func_file": "./component.js",
43
+ // 渲染
44
+ "template": "./component.html",
45
+ // 状态, 0为未开启 1为开启
46
+ "state": 1
47
+ }
48
+ }
49
+ };
50
+
51
+ /**
52
+ * 创建一个参数模型
53
+ */
54
+ Drive.prototype.model = function() {
55
+ return {
56
+ // 应用于,根据应用而判断使用
57
+ "app": "admin",
58
+ // 名称, 用于动态增删改配置
59
+ "name": "demo",
60
+ // 页面位置
61
+ "pages": ["/admin/index"],
62
+ // 位置 side侧边栏、main主体、float浮动栏、header头部、footer尾部
63
+ "position": "main",
64
+ // 标题, 用于查询时
65
+ "title": "示例组件",
66
+ // 描述, 用于介绍该组件的作用
67
+ "description": "暂无描述",
68
+ // 时态, 分before之前、main主要、after之后三个时态,
69
+ "tense": "main",
70
+ // 执行顺序, 数值越小的越优先显示
71
+ "sort": 100,
72
+ // 分组, 可以将特有的分一个组, 方便用户查询
73
+ "group": "default",
74
+ // 分类, 例如: 查询生活类、监测类、便民类
75
+ "type": "监测",
76
+ // 脚本文件, 非必传,可和渲染文件二选一传
77
+ "func_file": "./component.js",
78
+ // 渲染, 非必传,可和脚本文件二选一传
79
+ "template": "./component.html",
80
+ // 状态, 0为未开启 1为开启
81
+ "state": 1
82
+ }
83
+ };
84
+
85
+ /**
86
+ * 组件主函数
87
+ * @param {Object} ctx 请求上下文
88
+ * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
89
+ * @return {Object} 执行结果
90
+ */
91
+ Drive.prototype.main = async function(ctx, db) {
92
+ var model = {};
93
+ var html_file = this.config.template || "./component.html";
94
+ return db.tpl.view(html_file.fullname(this.dir), model);
95
+ };
96
+
97
+ module.exports = Drive;
@@ -0,0 +1,145 @@
1
+ const Index = require('mm_machine').Index;
2
+ const Drive = require('./drive');
3
+
4
+ /**
5
+ * Component组件
6
+ * @extends {Index}
7
+ * @class
8
+ */
9
+ class Component extends Index {
10
+ /**
11
+ * 构造函数
12
+ * @param {Object} scope 作用域
13
+ * @param {String} title 标题
14
+ * @constructor
15
+ */
16
+ constructor(scope, title) {
17
+ super(scope, __dirname);
18
+ this.Drive = Drive;
19
+ this.type = "component";
20
+ this.title = title;
21
+ this.list = [];
22
+ }
23
+ }
24
+
25
+ /**
26
+ * 新建脚本
27
+ * @param {String} file 文件
28
+ */
29
+ Component.prototype.new_script = function(file) {
30
+ var fl = __dirname + "/script.js";
31
+ if (fl.hasFile()) {
32
+ var text = fl.loadText();
33
+ if (text) {
34
+ var l = $.slash;
35
+ var arr = file.split(l);
36
+ var name = arr[arr.length - 2];
37
+ text = text.replaceAll('{0}', name);
38
+ file.saveText(text);
39
+ }
40
+ }
41
+
42
+ var file_html = "./component.html".fullname(file.dirname());
43
+ if (!file_html.hasFile()) {
44
+ var flh = __dirname + "/component.html";
45
+ if (flh.hasFile()) {
46
+ var html = flh.loadText();
47
+ file_html.saveText(html);
48
+ }
49
+ }
50
+ };
51
+
52
+
53
+ /**
54
+ * 加载列表
55
+ * @param {Array} list 文件列表
56
+ */
57
+ Component.prototype.load_list = function(list) {
58
+ var _this = this;
59
+ // 遍历文件路径
60
+ list.map(function(file) {
61
+ var dir = file.dirname();
62
+ // 载入文件
63
+ var obj = file.loadJson(dir);
64
+ if (obj) {
65
+ if (obj.constructor == Array) {
66
+ obj.map(function(o) {
67
+ // 实例化一个驱动
68
+ _this.load_item(dir, o, file);
69
+ });
70
+ } else {
71
+ _this.load_item(dir, obj, file);
72
+ }
73
+ } else {
74
+ var fl = _this.dir_base + "/config.tpl.json";
75
+ if (fl.hasFile()) {
76
+ fl.copyFile(file);
77
+ }
78
+ }
79
+ });
80
+ };
81
+
82
+ /**
83
+ * 执行渲染
84
+ * @param {String} page 页面
85
+ * @param {String} position 位置
86
+ * @param {String} position position
87
+ * @param {Object} ctx 请求上下文
88
+ * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
89
+ * @return {String}
90
+ */
91
+ Component.prototype.render = async function(page, position, ctx, db) {
92
+ var html = "";
93
+ var list = this.list;
94
+ for (var i = 0; i < list.length; i++) {
95
+ var o = list[i];
96
+ var cg = o.config;
97
+ if (cg.state && cg.position == position) {
98
+ if(cg.pages && cg.pages.indexOf(page) !== -1){
99
+ var ret;
100
+ try {
101
+ ret = await o.run('main', ctx, db);
102
+ } catch (error) {
103
+ $.log.error("组件渲染失败", o.config.name, error);
104
+ }
105
+ if (ret) {
106
+ html += "\n" + ret;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ return html;
112
+ };
113
+
114
+ /* 导出指令 */
115
+ exports.Component = Component;
116
+
117
+ /**
118
+ * Component组件池
119
+ */
120
+ if (!$.pool.component) {
121
+ $.pool.component = {};
122
+ }
123
+
124
+ /**
125
+ * Component管理器,用于创建缓存
126
+ * @param {String} scope 作用域
127
+ * @param {string} title 标题
128
+ * @return {Object} 返回一个缓存类
129
+ */
130
+ function component_admin(scope, title) {
131
+ if (!scope) {
132
+ scope = $.val.scope + '';
133
+ }
134
+ var obj = $.pool.component[scope];
135
+ if (!obj) {
136
+ $.pool.component[scope] = new Component(scope, title);
137
+ obj = $.pool.component[scope];
138
+ }
139
+ return obj;
140
+ }
141
+
142
+ /**
143
+ * @module 导出Component管理器
144
+ */
145
+ $.component_admin = component_admin;
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ /**
3
+ * 组件主函数
4
+ * @param {Object} ctx 请求上下文
5
+ * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
6
+ * @return {Object} 执行结果
7
+ */
8
+ async main(ctx, db) {
9
+ var model = {};
10
+ return db.tpl.view("./component.html".fullname(__dirname), model);
11
+ }
12
+ };
@@ -59,7 +59,7 @@ Task.prototype.load_item = function(dir, cg, file) {
59
59
  var drive = new this.Drive(dir);
60
60
  drive.loadObj(cg);
61
61
  drive.filename = file;
62
- drive.task_adminr = this;
62
+ drive.task_admin = this;
63
63
  this.list.push(drive);
64
64
  };
65
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.4.5",
3
+ "version": "2.4.7",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {