mm_os 2.4.6 → 2.4.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.
@@ -1,16 +1,12 @@
1
1
  {
2
2
  // 应用于,根据应用而判断使用
3
3
  "app": "admin",
4
- // 位置 side侧边栏、main主体、float浮动栏、header头部、footer尾部
5
- "position": "main",
6
4
  // 名称, 用于动态增删改配置
7
5
  "name": "{0}",
8
6
  // 标题, 用于查询时
9
7
  "title": "示例组件(挂件)",
10
8
  // 描述, 用于介绍该组件的作用
11
9
  "description": "暂无描述",
12
- // 时态, 分before之前、main主要、after之后三个时态,
13
- "tense": "main",
14
10
  // 执行顺序, 数值越小的越优先显示
15
11
  "sort": 100,
16
12
  // 分组, 可以将特有的分一个组, 方便用户查询
@@ -22,5 +18,11 @@
22
18
  // 渲染, 非必传,可和脚本文件二选一传
23
19
  "template": "./component.html",
24
20
  // 状态, 0为未开启 1为开启
25
- "state": 1
21
+ "state": 1,
22
+ // 定位 由后台指定的展示位置
23
+ "location": [{
24
+ "page": "/admin/index",
25
+ "position": "main",
26
+ "onoff": true
27
+ }]
26
28
  }
@@ -20,16 +20,12 @@ class Drive extends Item {
20
20
  this.config = {
21
21
  // 应用于,根据应用而判断使用
22
22
  "app": "admin",
23
- // 位置 side侧边栏、main主体、float浮动栏、header头部、footer尾部
24
- "position": "main",
25
23
  // 名称, 用于动态增删改配置
26
24
  "name": "demo",
27
25
  // 标题, 用于查询时
28
26
  "title": "示例组件",
29
27
  // 描述, 用于介绍该组件的作用
30
28
  "description": "暂无描述",
31
- // 时态, 分before之前、main主要、after之后三个时态,
32
- "tense": "main",
33
29
  // 执行顺序, 数值越小的越优先显示
34
30
  "sort": 100,
35
31
  // 分组, 可以将特有的分一个组, 方便用户查询
@@ -41,12 +37,13 @@ class Drive extends Item {
41
37
  // 渲染
42
38
  "template": "./component.html",
43
39
  // 状态, 0为未开启 1为开启
44
- "state": 1
40
+ "state": 1,
41
+ // 定位 由后台指定的展示位置
42
+ "location": []
45
43
  }
46
44
  }
47
45
  };
48
46
 
49
-
50
47
  /**
51
48
  * 创建一个参数模型
52
49
  */
@@ -54,16 +51,12 @@ Drive.prototype.model = function() {
54
51
  return {
55
52
  // 应用于,根据应用而判断使用
56
53
  "app": "admin",
57
- // 位置 side侧边栏、main主体、float浮动栏、header头部、footer尾部
58
- "position": "main",
59
54
  // 名称, 用于动态增删改配置
60
55
  "name": "demo",
61
56
  // 标题, 用于查询时
62
57
  "title": "示例组件",
63
58
  // 描述, 用于介绍该组件的作用
64
59
  "description": "暂无描述",
65
- // 时态, 分before之前、main主要、after之后三个时态,
66
- "tense": "main",
67
60
  // 执行顺序, 数值越小的越优先显示
68
61
  "sort": 100,
69
62
  // 分组, 可以将特有的分一个组, 方便用户查询
@@ -75,7 +68,40 @@ Drive.prototype.model = function() {
75
68
  // 渲染, 非必传,可和脚本文件二选一传
76
69
  "template": "./component.html",
77
70
  // 状态, 0为未开启 1为开启
78
- "state": 1
71
+ "state": 1,
72
+ // 定位 由后台指定的展示位置
73
+ "location": [{
74
+ "page": "/admin/index",
75
+ "position": "main",
76
+ "onoff": true
77
+ }]
78
+ }
79
+ };
80
+
81
+ /**
82
+ * 新建脚本
83
+ * @param {String} file 文件
84
+ */
85
+ Drive.prototype.new_script = function(file) {
86
+ var fl = __dirname + "/script.js";
87
+ if (fl.hasFile()) {
88
+ var text = fl.loadText();
89
+ if (text) {
90
+ var l = $.slash;
91
+ var arr = file.split(l);
92
+ var name = arr[arr.length - 2];
93
+ text = text.replaceAll('{0}', name);
94
+ file.saveText(text);
95
+ }
96
+ }
97
+
98
+ var file_html = "./component.html".fullname(file.dirname());
99
+ if (!file_html.hasFile()) {
100
+ var flh = __dirname + "/component.html";
101
+ if (flh.hasFile()) {
102
+ var html = flh.loadText();
103
+ file_html.saveText(html);
104
+ }
79
105
  }
80
106
  };
81
107
 
@@ -22,33 +22,6 @@ class Component extends Index {
22
22
  }
23
23
  }
24
24
 
25
- /**
26
- * 新建脚本
27
- * @param {String} file 文件
28
- */
29
- Drive.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
25
 
53
26
  /**
54
27
  * 加载列表
@@ -73,36 +46,61 @@ Component.prototype.load_list = function(list) {
73
46
  } else {
74
47
  var fl = _this.dir_base + "/config.tpl.json";
75
48
  if (fl.hasFile()) {
76
- fl.copyFile(file);
49
+ var text = fl.loadText();
50
+ if (text) {
51
+ var l = $.slash;
52
+ var arr = file.split(l);
53
+ var name = arr[arr.length - 2];
54
+ text = text.replaceAll('{0}', name);
55
+ file.saveText(text);
56
+ }
77
57
  }
78
58
  }
79
59
  });
80
60
  };
81
61
 
62
+ /**
63
+ * 排序
64
+ */
65
+ Component.prototype.sort = function() {
66
+ var _this = this;
67
+ this.list.sort(function(o1, o2) {
68
+ var p1 = o1.config[_this.sort_key];
69
+ var p2 = o2.config[_this.sort_key];
70
+ return p1 - p2;
71
+ });
72
+ };
73
+
82
74
  /**
83
75
  * 执行渲染
84
- * @param {String} app 应用
76
+ * @param {String} page 页面
85
77
  * @param {String} position 位置
86
78
  * @param {String} position position
87
79
  * @param {Object} ctx 请求上下文
88
80
  * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
89
81
  * @return {String}
90
82
  */
91
- Component.prototype.render = async function(app, position, ctx, db) {
83
+ Component.prototype.render = async function(page, position, ctx, db) {
92
84
  var html = "";
93
85
  var list = this.list;
94
86
  for (var i = 0; i < list.length; i++) {
95
87
  var o = list[i];
96
88
  var cg = o.config;
97
- if (cg.state && cg.app == app && cg.position == position) {
98
- var ret;
99
- try {
100
- ret = await o.run('main', ctx, db);
101
- } catch (error) {
102
- $.log.error("组件渲染失败", o.config.name, error);
103
- }
104
- if (ret) {
105
- html += "\n" + ret;
89
+ if (cg.state) {
90
+ var obj = cg.location.getObj({
91
+ page,
92
+ position
93
+ });
94
+ if (obj && obj.onoff) {
95
+ var ret;
96
+ try {
97
+ ret = await o.run('main', ctx, db);
98
+ } catch (error) {
99
+ $.log.error("组件渲染失败", o.config.name, error);
100
+ }
101
+ if (ret) {
102
+ html += "\n" + ret;
103
+ }
106
104
  }
107
105
  }
108
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.4.6",
3
+ "version": "2.4.8",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {