mm_os 2.7.4 → 2.7.6

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,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>
1
+ <div class="mm_col ${' ' + config.layout}">
2
+ <div id="${config.id}" class="component_demo ${' ' + config.class}">
3
+ <div class="title">${@config.options.xxx}</div>
4
4
  <div class="description">示例组件描述</div>
5
5
  </div>
6
6
  </div>
7
7
 
8
8
  <style scoped>
9
+ /*[config.style]*/
10
+
9
11
  .component_demo {}
10
12
 
11
13
  .component_demo .title {}
12
14
 
13
- .component_demo .description {
14
-
15
- }
15
+ .component_demo .description {}
16
16
  </style>
@@ -12,7 +12,7 @@
12
12
  // 分组, 可以将特有的分一个组, 方便用户查询
13
13
  "group": "default",
14
14
  // 分类, 例如: 查询生活类、监测类、便民类
15
- "type": "监测",
15
+ "type": "默认",
16
16
  // 脚本文件, 非必传,可和渲染文件二选一传
17
17
  "func_file": "./component.js",
18
18
  // 渲染, 非必传,可和脚本文件二选一传
@@ -23,8 +23,8 @@
23
23
  "options": [],
24
24
  // 定位 由后台指定的展示位置
25
25
  "location": [{
26
- "page": "/admin/index",
26
+ "path": "/admin/index",
27
27
  "position": "main",
28
- "onoff": true
28
+ "available": 1
29
29
  }]
30
30
  }
@@ -32,7 +32,7 @@ class Drive extends Item {
32
32
  // 分组, 可以将特有的分一个组, 方便用户查询
33
33
  "group": "default",
34
34
  // 分类, 例如: 查询生活类、监测类、便民类
35
- "type": "监测",
35
+ "type": "默认",
36
36
  // 脚本文件
37
37
  "func_file": "./component.js",
38
38
  // 渲染
@@ -76,9 +76,9 @@ Drive.prototype.model = function() {
76
76
  "options": [],
77
77
  // 定位 由后台指定的展示位置
78
78
  "location": [{
79
- "page": "/admin/index",
79
+ "path": "/admin/index",
80
80
  "position": "main",
81
- "onoff": true
81
+ "available": 1
82
82
  }]
83
83
  }
84
84
  };
@@ -133,6 +133,17 @@ Drive.prototype.design_option = function(body) {
133
133
  }
134
134
  }
135
135
 
136
+ /**
137
+ * 挂件模板
138
+ * @param {Object} ctx 请求上下文
139
+ * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
140
+ * @return {Object} 执行结果
141
+ */
142
+ Drive.prototype.tpl = async function(ctx, db) {
143
+ var html_file = this.config.template || "./component.html";
144
+ return html_file.fullname(this.dir).loadText();
145
+ };
146
+
136
147
  /**
137
148
  * 组件主函数
138
149
  * @param {Object} ctx 请求上下文
@@ -71,16 +71,186 @@ Component.prototype.sort = function() {
71
71
  });
72
72
  };
73
73
 
74
+ /**
75
+ * 配置模型
76
+ * @param {Object} option 配置
77
+ * @param {Object} ctx 请求上下文
78
+ * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
79
+ * @return {String} 返回html代码
80
+ */
81
+ Component.prototype.option_model = function(block) {
82
+ var id = block.id || block.name;
83
+ var style = "";
84
+ if (block.style) {
85
+ var o = block.style.toJson();
86
+ style += `#${id} {`;
87
+
88
+ // 字体
89
+ if (o.font_size) {
90
+ style += `\n font-size: ${o.font_size};`;
91
+ }
92
+ if (o.font_color) {
93
+ style += `\n color: ${o.font_color};`;
94
+ }
95
+
96
+ // 边框
97
+ if (o.border_top_style !== 'none') {
98
+ style +=
99
+ `\n border-top: ${o.border_top_size || 0} ${o.border_top_style || 'solid'} ${o.border_top_color || '#dbdbdb'};`;
100
+ }
101
+ if (o.border_right_style !== 'none') {
102
+ style +=
103
+ `\n border-right: ${o.border_right_size || 0} ${o.border_right_style || 'solid'} ${o.border_right_color || '#dbdbdb'};`;
104
+ }
105
+ if (o.border_bottom_style !== 'none') {
106
+ style +=
107
+ `\n border-bottom: ${o.border_bottom_size || 0} ${o.border_bottom_style || 'solid'} ${o.border_bottom_color || '#dbdbdb'};`;
108
+ }
109
+ if (o.border_left_style !== 'none') {
110
+ style +=
111
+ `\n border-left: ${o.border_left_size || 0} ${o.border_left_style || 'solid'} ${o.border_left_color || '#dbdbdb'};`;
112
+ }
113
+
114
+ // 边距
115
+ if (o.margin_top) {
116
+ style += `\n margin-top: ${o.margin_top};`;
117
+ }
118
+ if (o.margin_right) {
119
+ style += `\n margin-right: ${o.margin_right};`;
120
+ }
121
+ if (o.margin_bottom) {
122
+ style += `\n margin-bottom: ${o.margin_bottom};`;
123
+ }
124
+ if (o.margin_left) {
125
+ style += `\n margin-left: ${o.margin_left};`;
126
+ }
127
+
128
+ // 填充
129
+ if (o.padding_top) {
130
+ style += `\n padding-top: ${o.padding_top};`;
131
+ }
132
+ if (o.padding_right) {
133
+ style += `\n padding-right: ${o.padding_right};`;
134
+ }
135
+ if (o.padding_bottom) {
136
+ style += `\n padding-bottom: ${o.padding_bottom};`;
137
+ }
138
+ if (o.padding_left) {
139
+ style += `\n padding-left: ${o.padding_left};`;
140
+ }
141
+
142
+ // 圆角
143
+ if (o.radius_top_right) {
144
+ style += `\n border-top-right-radius: ${o.radius_top_right};`;
145
+ }
146
+ if (o.radius_top_left) {
147
+ style += `\n border-top-left-radius: ${o.radius_top_left};`;
148
+ }
149
+ if (o.radius_bottom_right) {
150
+ style += `\n border-bottom-right-radius: ${o.radius_bottom_right};`;
151
+ }
152
+ if (o.radius_bottom_left) {
153
+ style += `\n border-bottom-left-radius: ${o.radius_bottom_left};`;
154
+ }
155
+
156
+ // 背景
157
+ if (o.bg_url) {
158
+ style += `\n background-image: url(${o.bg_url});`;
159
+ style += `\n background-size: 100% auto;`;
160
+ style += `\n background-repeat: ${o.bg_repeat || 'no-repeat'};`;
161
+ }
162
+ if (o.bg_color) {
163
+ style +=
164
+ `\n background-color: ${o.bg_color || ''};`;
165
+ }
166
+ style += `\n}`;
167
+
168
+ // 设置A样式
169
+ if (o.a_size || o.a_color) {
170
+ style += `\n#${id} a {`;
171
+ if (o.a_size) {
172
+ style += `\n font-size: ${o.a_size};`;
173
+ }
174
+ if (o.a_color) {
175
+ style += `\n color: ${o.a_color};`;
176
+ }
177
+ style += `\n}`;
178
+ }
179
+ } else {
180
+ style = "";
181
+ }
182
+
183
+ var layout = "";
184
+ if (block.layout) {
185
+ var o = block.layout.toJson();
186
+ if (o.default) {
187
+ layout += " col-" + o.default;
188
+ }
189
+ if (o.pc) {
190
+ layout += " col-xxl-" + o.pc;
191
+ }
192
+ if (o.note) {
193
+ layout += " col-xl-" + o.note;
194
+ }
195
+ if (o.pad) {
196
+ layout += " col-lg-" + o.pad;
197
+ }
198
+ if (o.pad_mini) {
199
+ layout += " col-sm-" + o.pad_mini;
200
+ }
201
+ if (o.phone) {
202
+ layout += " col-xs-" + o.phone;
203
+ }
204
+ layout = layout.trim();
205
+ }
206
+
207
+ var data = (block.data || '[]').toJson();
208
+ var attr = (block.attr || '{}').toJson();
209
+ var options = (block.options || '{}').toJson();
210
+
211
+ return {
212
+ id,
213
+ class: block.class,
214
+ style,
215
+ data,
216
+ attr,
217
+ layout,
218
+ options
219
+ };
220
+ }
221
+
222
+ /**
223
+ * 渲染模块
224
+ * @param {Object} ctx 请求上下文
225
+ * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
226
+ * @param {Array} blocks 模块
227
+ */
228
+ Component.prototype.render_block = async function(ctx, db, blocks) {
229
+ var html = "";
230
+ for (var i = 0; i < blocks.length; i++) {
231
+ var block = blocks[i];
232
+ var o = this.get(block.component);
233
+ if (o) {
234
+ var option = this.option_model(block);
235
+ var ret = await o.run('main', ctx, db, option);
236
+ if (ret) {
237
+ html += "\n" + ret;
238
+ }
239
+ }
240
+ }
241
+ return html;
242
+ }
243
+
74
244
  /**
75
245
  * 执行渲染
76
- * @param {String} page 页面
77
- * @param {String} position 位置
78
- * @param {String} position position
79
246
  * @param {Object} ctx 请求上下文
80
247
  * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
81
- * @return {String}
248
+ * @param {String} path 页面
249
+ * @param {String} position 位置
250
+ * @param {String} position position
251
+ * @return {String} 返回html代码
82
252
  */
83
- Component.prototype.render = async function(page, position, ctx, db) {
253
+ Component.prototype.render = async function(ctx, db, path, position) {
84
254
  var html = "";
85
255
  var list = this.list;
86
256
  for (var i = 0; i < list.length; i++) {
@@ -88,10 +258,10 @@ Component.prototype.render = async function(page, position, ctx, db) {
88
258
  var cg = o.config;
89
259
  if (cg.state) {
90
260
  var obj = cg.location.getObj({
91
- page,
261
+ path,
92
262
  position
93
263
  });
94
- if (obj && obj.onoff) {
264
+ if (obj && obj.available) {
95
265
  var ret = await o.run('main', ctx, db);
96
266
  if (ret) {
97
267
  html += "\n" + ret;
@@ -3,10 +3,16 @@ module.exports = {
3
3
  * 组件主函数
4
4
  * @param {Object} ctx 请求上下文
5
5
  * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
6
+ * @param {Object} config 模块配置
6
7
  * @return {Object} 执行结果
7
8
  */
8
- async main(ctx, db) {
9
- var model = {};
9
+ async main(ctx, db, config) {
10
+ var model = {
11
+ config
12
+ };
13
+ if (config.diy) {
14
+ return db.tpl.render(config.diy, model);
15
+ }
10
16
  return db.tpl.view("./component.html".fullname(__dirname), model);
11
17
  }
12
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.7.4",
3
+ "version": "2.7.6",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {