mm_os 2.7.3 → 2.7.5
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
|
|
2
|
-
<div class="component_demo">
|
|
3
|
-
<div class="title"
|
|
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>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const compressing = require('compressing');
|
|
1
2
|
const Item = require('mm_machine').Item;
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -75,9 +76,9 @@ Drive.prototype.model = function() {
|
|
|
75
76
|
"options": [],
|
|
76
77
|
// 定位 由后台指定的展示位置
|
|
77
78
|
"location": [{
|
|
78
|
-
"
|
|
79
|
+
"path": "/admin/index",
|
|
79
80
|
"position": "main",
|
|
80
|
-
"
|
|
81
|
+
"available": 1
|
|
81
82
|
}]
|
|
82
83
|
}
|
|
83
84
|
};
|
|
@@ -109,6 +110,40 @@ Drive.prototype.new_script = function(file) {
|
|
|
109
110
|
}
|
|
110
111
|
};
|
|
111
112
|
|
|
113
|
+
/**
|
|
114
|
+
* 获取配置参数
|
|
115
|
+
* @param {Object} 设置配置
|
|
116
|
+
* @return {Object} 返回配置参数
|
|
117
|
+
*/
|
|
118
|
+
Drive.prototype.design_option = function(body) {
|
|
119
|
+
var cg = this.config;
|
|
120
|
+
if (Array.isArray(body)) {
|
|
121
|
+
cg.options = body;
|
|
122
|
+
} else {
|
|
123
|
+
var options = cg.options || [];
|
|
124
|
+
var option = options.getObj({
|
|
125
|
+
name: body.name
|
|
126
|
+
});
|
|
127
|
+
if (option) {
|
|
128
|
+
Object.assign(option, body);
|
|
129
|
+
} else {
|
|
130
|
+
options.push(body);
|
|
131
|
+
}
|
|
132
|
+
cg.options = options;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
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
|
+
|
|
112
147
|
/**
|
|
113
148
|
* 组件主函数
|
|
114
149
|
* @param {Object} ctx 请求上下文
|
|
@@ -121,4 +156,20 @@ Drive.prototype.main = async function(ctx, db) {
|
|
|
121
156
|
return db.tpl.view(html_file.fullname(this.dir), model);
|
|
122
157
|
};
|
|
123
158
|
|
|
159
|
+
/**
|
|
160
|
+
* 压缩主题模板
|
|
161
|
+
* @param {String} 要压缩的目录
|
|
162
|
+
* @returns {String} 打包成功返回压缩包文件地址
|
|
163
|
+
*/
|
|
164
|
+
Drive.prototype.zip = async function(zip_dir = "/static/file/zip/") {
|
|
165
|
+
var dir = this.filename.dirname();
|
|
166
|
+
var file = ("./" + this.config.name + '.zip').fullname(zip_dir);
|
|
167
|
+
file.addDir();
|
|
168
|
+
var done = await compressing.zip.compressDir(dir, file);
|
|
169
|
+
if (file.hasFile()) {
|
|
170
|
+
return file;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
124
175
|
module.exports = Drive;
|
|
@@ -71,16 +71,142 @@ 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
|
+
style +=
|
|
116
|
+
`\n margin-top: ${o.margin_top || 0};`;
|
|
117
|
+
style +=
|
|
118
|
+
`\n margin-right: ${o.margin_right || 0};`;
|
|
119
|
+
style +=
|
|
120
|
+
`\n margin-bottom: ${o.margin_bottom || 0};`;
|
|
121
|
+
style +=
|
|
122
|
+
`\n margin-left: ${o.margin_left || 0};`;
|
|
123
|
+
|
|
124
|
+
// 填充
|
|
125
|
+
style +=
|
|
126
|
+
`\n padding-top: ${o.padding_top || 0};`;
|
|
127
|
+
style +=
|
|
128
|
+
`\n padding-right: ${o.padding_right || 0};`;
|
|
129
|
+
style +=
|
|
130
|
+
`\n padding-bottom: ${o.padding_bottom || 0};`;
|
|
131
|
+
style +=
|
|
132
|
+
`\n padding-left: ${o.padding_left || 0};`;
|
|
133
|
+
|
|
134
|
+
// 背景
|
|
135
|
+
if (o.bg_url) {
|
|
136
|
+
style += `\n background-image: url(${o.bg_url});`;
|
|
137
|
+
style += `\n background-size: 100% auto;`;
|
|
138
|
+
style += `\n background-repeat: ${o.bg_repeat || 'no-repeat'};`;
|
|
139
|
+
}
|
|
140
|
+
if (o.bg_color) {
|
|
141
|
+
style +=
|
|
142
|
+
`\n background-color: ${o.bg_color || ''};`;
|
|
143
|
+
}
|
|
144
|
+
style += `\n}`;
|
|
145
|
+
|
|
146
|
+
// 设置A样式
|
|
147
|
+
if (o.a_size || o.a_color) {
|
|
148
|
+
style += `\n#${id} a {`;
|
|
149
|
+
if (o.a_size) {
|
|
150
|
+
style += `\n font-size: ${o.a_size};`;
|
|
151
|
+
}
|
|
152
|
+
if (o.a_color) {
|
|
153
|
+
style += `\n color: ${o.a_color};`;
|
|
154
|
+
}
|
|
155
|
+
style += `\n}`;
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
style = "";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
var layout = "";
|
|
162
|
+
|
|
163
|
+
var data = (block.data || '[]').toJson();
|
|
164
|
+
var attr = (block.attr || '{}').toJson();
|
|
165
|
+
var options = (block.options || '{}').toJson();
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
id,
|
|
169
|
+
class: block.class,
|
|
170
|
+
style,
|
|
171
|
+
data,
|
|
172
|
+
attr,
|
|
173
|
+
layout,
|
|
174
|
+
options
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 渲染模块
|
|
180
|
+
* @param {Object} ctx 请求上下文
|
|
181
|
+
* @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
|
|
182
|
+
* @param {Array} blocks 模块
|
|
183
|
+
*/
|
|
184
|
+
Component.prototype.render_block = async function(ctx, db, blocks) {
|
|
185
|
+
var html = "";
|
|
186
|
+
for (var i = 0; i < blocks.length; i++) {
|
|
187
|
+
var block = blocks[i];
|
|
188
|
+
var o = this.get(block.component);
|
|
189
|
+
if (o) {
|
|
190
|
+
var option = this.option_model(block);
|
|
191
|
+
var ret = await o.run('main', ctx, db, option);
|
|
192
|
+
if (ret) {
|
|
193
|
+
html += "\n" + ret;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return html;
|
|
198
|
+
}
|
|
199
|
+
|
|
74
200
|
/**
|
|
75
201
|
* 执行渲染
|
|
76
|
-
* @param {String} page 页面
|
|
77
|
-
* @param {String} position 位置
|
|
78
|
-
* @param {String} position position
|
|
79
202
|
* @param {Object} ctx 请求上下文
|
|
80
203
|
* @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
|
|
81
|
-
* @
|
|
204
|
+
* @param {String} path 页面
|
|
205
|
+
* @param {String} position 位置
|
|
206
|
+
* @param {String} position position
|
|
207
|
+
* @return {String} 返回html代码
|
|
82
208
|
*/
|
|
83
|
-
Component.prototype.render = async function(
|
|
209
|
+
Component.prototype.render = async function(ctx, db, path, position) {
|
|
84
210
|
var html = "";
|
|
85
211
|
var list = this.list;
|
|
86
212
|
for (var i = 0; i < list.length; i++) {
|
|
@@ -88,10 +214,10 @@ Component.prototype.render = async function(page, position, ctx, db) {
|
|
|
88
214
|
var cg = o.config;
|
|
89
215
|
if (cg.state) {
|
|
90
216
|
var obj = cg.location.getObj({
|
|
91
|
-
|
|
217
|
+
path,
|
|
92
218
|
position
|
|
93
219
|
});
|
|
94
|
-
if (obj && obj.
|
|
220
|
+
if (obj && obj.available) {
|
|
95
221
|
var ret = await o.run('main', ctx, db);
|
|
96
222
|
if (ret) {
|
|
97
223
|
html += "\n" + ret;
|
|
@@ -3,10 +3,13 @@ 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
|
+
};
|
|
10
13
|
return db.tpl.view("./component.html".fullname(__dirname), model);
|
|
11
14
|
}
|
|
12
15
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_os",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.5",
|
|
4
4
|
"description": "这是超级美眉服务端框架,用于快速构建应用程序。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"mm_mongodb": "^1.4.2",
|
|
46
46
|
"mm_mqtt": "^1.0.6",
|
|
47
47
|
"mm_mysql": "^1.8.9",
|
|
48
|
-
"mm_os": "^2.6.4",
|
|
49
48
|
"mm_redis": "^1.4.2",
|
|
50
49
|
"mm_ret": "^1.3.9",
|
|
51
50
|
"mm_session": "^1.4.8",
|