mm_os 4.3.7 → 5.0.1

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.
Files changed (231) hide show
  1. package/README.md +102 -504
  2. package/index.js +26 -19
  3. package/lib/os.js +536 -0
  4. package/package.json +60 -84
  5. package/LICENSE +0 -21
  6. package/README_EN.md +0 -505
  7. package/adapter/adapter.js +0 -484
  8. package/adapter/custom_persistence.js +0 -661
  9. package/adapter/mqtt.js +0 -254
  10. package/adapter/socket.js +0 -244
  11. package/adapter/web.js +0 -92
  12. package/adapter/websocket.js +0 -43
  13. package/ai.js +0 -130
  14. package/com/api/README.md +0 -3
  15. package/com/api/com.json +0 -5
  16. package/com/api/config.tpl.json +0 -41
  17. package/com/api/drive.js +0 -732
  18. package/com/api/index.js +0 -201
  19. package/com/api/oauth.js +0 -200
  20. package/com/api/script.tpl.js +0 -32
  21. package/com/cmd/README.md +0 -11
  22. package/com/cmd/com.json +0 -5
  23. package/com/cmd/config.tpl.json +0 -48
  24. package/com/cmd/drive.js +0 -176
  25. package/com/cmd/index.js +0 -287
  26. package/com/cmd/job/config.json +0 -66
  27. package/com/cmd/job/index.js +0 -241
  28. package/com/cmd/job/test.js +0 -188
  29. package/com/cmd/msg.json +0 -48
  30. package/com/cmd/script.tpl.js +0 -12
  31. package/com/db/README.md +0 -3
  32. package/com/db/com.json +0 -5
  33. package/com/db/drive.js +0 -2206
  34. package/com/db/index.js +0 -241
  35. package/com/event/README.md +0 -4
  36. package/com/event/com.json +0 -5
  37. package/com/event/config.tpl.json +0 -20
  38. package/com/event/drive.js +0 -61
  39. package/com/event/index.js +0 -438
  40. package/com/event/script.tpl.js +0 -23
  41. package/com/mqtt/README.md +0 -47
  42. package/com/mqtt/com.json +0 -5
  43. package/com/mqtt/config.tpl.json +0 -42
  44. package/com/mqtt/drive.js +0 -704
  45. package/com/mqtt/index.js +0 -1052
  46. package/com/mqtt/index.test.js +0 -503
  47. package/com/mqtt/script.tpl.js +0 -719
  48. package/com/nav/README.md +0 -2
  49. package/com/nav/com.json +0 -5
  50. package/com/nav/config.tpl.json +0 -84
  51. package/com/nav/drive.js +0 -702
  52. package/com/nav/index.js +0 -228
  53. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  54. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  55. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  56. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  57. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  58. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  59. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  60. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  61. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  62. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  63. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  64. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  65. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  66. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  67. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  68. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  69. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  70. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  71. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  72. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  73. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  74. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  75. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  76. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  77. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  78. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  79. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  80. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  81. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  82. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  83. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  84. package/com/nav/viewmodel.js +0 -446
  85. package/com/param/README.md +0 -2
  86. package/com/param/com.json +0 -5
  87. package/com/param/config.tpl.json +0 -136
  88. package/com/param/drive.js +0 -502
  89. package/com/param/index.js +0 -158
  90. package/com/param/script.tpl.js +0 -12
  91. package/com/pendant/README.md +0 -3
  92. package/com/pendant/com.json +0 -5
  93. package/com/pendant/config.tpl.json +0 -32
  94. package/com/pendant/drive.js +0 -204
  95. package/com/pendant/index.js +0 -467
  96. package/com/pendant/pendant.html +0 -16
  97. package/com/pendant/script.tpl.js +0 -18
  98. package/com/socket/README.md +0 -47
  99. package/com/socket/com.json +0 -5
  100. package/com/socket/config.tpl.json +0 -12
  101. package/com/socket/drive.js +0 -679
  102. package/com/socket/index.js +0 -402
  103. package/com/socket/script.tpl.js +0 -41
  104. package/com/sql/README.md +0 -3
  105. package/com/sql/com.json +0 -5
  106. package/com/sql/config.tpl.json +0 -74
  107. package/com/sql/drive.js +0 -1328
  108. package/com/sql/index.js +0 -152
  109. package/com/sql/script.tpl.js +0 -47
  110. package/com/static/README.md +0 -2
  111. package/com/static/com.json +0 -5
  112. package/com/static/config.tpl.json +0 -24
  113. package/com/static/drive.js +0 -194
  114. package/com/static/index.js +0 -237
  115. package/com/static/script.tpl.js +0 -28
  116. package/com/task/README.md +0 -3
  117. package/com/task/com.json +0 -5
  118. package/com/task/config.tpl.json +0 -24
  119. package/com/task/drive.js +0 -428
  120. package/com/task/index.js +0 -159
  121. package/com/task/script.tpl.js +0 -40
  122. package/com/template/com.json +0 -5
  123. package/com/template/config.tpl.json +0 -16
  124. package/com/template/drive.js +0 -81
  125. package/com/template/index.js +0 -141
  126. package/com.js +0 -237
  127. package/common/README.md +0 -2
  128. package/common/middleware/web_after/index.js +0 -26
  129. package/common/middleware/web_after/middleware.json +0 -9
  130. package/common/middleware/web_base/index.js +0 -113
  131. package/common/middleware/web_base/middleware.json +0 -19
  132. package/common/middleware/web_before/index.js +0 -33
  133. package/common/middleware/web_before/middleware.json +0 -9
  134. package/common/middleware/web_cors/index.js +0 -87
  135. package/common/middleware/web_cors/middleware.json +0 -24
  136. package/common/middleware/web_error/index.js +0 -131
  137. package/common/middleware/web_error/middleware.json +0 -19
  138. package/common/middleware/web_ip/index.js +0 -15
  139. package/common/middleware/web_ip/middleware.json +0 -14
  140. package/common/middleware/web_logger/index.js +0 -156
  141. package/common/middleware/web_logger/middleware.json +0 -14
  142. package/common/middleware/web_main/index.js +0 -26
  143. package/common/middleware/web_main/middleware.json +0 -9
  144. package/common/middleware/web_static/index.js +0 -73
  145. package/common/middleware/web_static/middleware.json +0 -54
  146. package/common/middleware/web_waf/index.js +0 -395
  147. package/common/middleware/web_waf/middleware.json +0 -13
  148. package/core/app/config.tpl.json +0 -67
  149. package/core/app/index.js +0 -711
  150. package/core/app/script.tpl.js +0 -52
  151. package/core/channel/index.js +0 -899
  152. package/core/channel/matcher.js +0 -585
  153. package/core/com/config.tpl.json +0 -16
  154. package/core/com/index.js +0 -77
  155. package/core/com/script.tpl.js +0 -5
  156. package/core/component/component.js +0 -42
  157. package/core/component/config.tpl.json +0 -63
  158. package/core/component/index.js +0 -273
  159. package/core/component/script.tpl.js +0 -19
  160. package/core/controller/config.tpl.json +0 -14
  161. package/core/controller/index.js +0 -371
  162. package/core/controller/script.tpl.js +0 -27
  163. package/core/factory/config.tpl.json +0 -14
  164. package/core/factory/entity.js +0 -275
  165. package/core/factory/index.js +0 -241
  166. package/core/factory/script.tpl.js +0 -16
  167. package/core/game/bat/index.js +0 -137
  168. package/core/game/bat/world.js +0 -622
  169. package/core/game/config.tpl.json +0 -16
  170. package/core/game/entity_admin.js +0 -230
  171. package/core/game/index.js +0 -186
  172. package/core/handler/config.tpl.json +0 -22
  173. package/core/handler/index.js +0 -181
  174. package/core/handler/script.tpl.js +0 -23
  175. package/core/logic/config.tpl.json +0 -14
  176. package/core/logic/index.js +0 -59
  177. package/core/logic/script.tpl.js +0 -19
  178. package/core/middleware/config.tpl.json +0 -16
  179. package/core/middleware/index.js +0 -117
  180. package/core/middleware/script.tpl.js +0 -37
  181. package/core/mod/config.tpl.json +0 -22
  182. package/core/mod/index.js +0 -136
  183. package/core/mod/script.tpl.js +0 -34
  184. package/core/model/config.tpl.json +0 -219
  185. package/core/model/index.js +0 -272
  186. package/core/model/model.js +0 -27
  187. package/core/model/script.tpl.js +0 -20
  188. package/core/notifier/config.tpl.json +0 -14
  189. package/core/notifier/index.js +0 -77
  190. package/core/notifier/script.tpl.js +0 -20
  191. package/core/plugin/config.tpl.json +0 -36
  192. package/core/plugin/index.js +0 -267
  193. package/core/plugin/script.tpl.js +0 -51
  194. package/core/pusher/config.tpl.json +0 -14
  195. package/core/pusher/index.js +0 -158
  196. package/core/pusher/script.tpl.js +0 -20
  197. package/core/room/bat/index.js +0 -170
  198. package/core/room/bat/room.js +0 -524
  199. package/core/room/config.tpl.json +0 -20
  200. package/core/room/index.js +0 -249
  201. package/core/room/room.js +0 -61
  202. package/core/scene/config.tpl.json +0 -14
  203. package/core/scene/index.js +0 -467
  204. package/core/scene/loop.js +0 -1306
  205. package/core/scene/map.js +0 -28
  206. package/core/scene/script.tpl.js +0 -22
  207. package/core/sender/config.tpl.json +0 -14
  208. package/core/sender/index.js +0 -79
  209. package/core/sender/script.tpl.js +0 -20
  210. package/core/service/config.tpl.json +0 -14
  211. package/core/service/index.js +0 -100
  212. package/core/service/script.tpl.js +0 -25
  213. package/core/store/config.tpl.json +0 -26
  214. package/core/store/index.js +0 -1794
  215. package/core/store/script.tpl.js +0 -22
  216. package/core/system/config.tpl.json +0 -18
  217. package/core/system/index.js +0 -312
  218. package/core/system/script.tpl.js +0 -77
  219. package/core/view/config.tpl.json +0 -14
  220. package/core/view/index.js +0 -91
  221. package/core/view/script.tpl.js +0 -20
  222. package/core/zone/bat/index.js +0 -744
  223. package/core/zone/config.tpl.json +0 -54
  224. package/core/zone/index.js +0 -655
  225. package/core/zone/script.tpl.js +0 -10
  226. package/core/zone/zone_bat.js +0 -136
  227. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  228. package/os.js +0 -53
  229. package/server.js +0 -602
  230. package/ulits/id_gen.js +0 -134
  231. package/ulits/word.js +0 -206
package/com/nav/drive.js DELETED
@@ -1,702 +0,0 @@
1
- const fs = require('fs');
2
- const { Tpl } = require('mm_tpl');
3
- const Item = require('mm_machine').Drive;
4
- const Model = require('./viewmodel.js');
5
-
6
- let tpl = new Tpl({
7
- extname: '.vue',
8
- chache_extname: '.cache.vue'
9
- });
10
- tpl.dir = __dirname;
11
-
12
- const viewModel = new Model();
13
-
14
- /**
15
- * 导航驱动类
16
- * @augments {Item}
17
- * @class
18
- */
19
- class Drive extends Item {
20
- static config = {
21
- // 路由
22
- 'routes': [
23
- /*
24
- {
25
- // 名称
26
- "name": "root",
27
- // 路由路径
28
- "path": "/",
29
- // 组件文件路径
30
- "component": "",
31
- // 页面显示级别
32
- "level": "",
33
- // 身份验证
34
- "oauth": {
35
- // 是否登录
36
- "sign_in": false,
37
- // 要求会员级别
38
- "vip": 0,
39
- // 要求管理级别
40
- "gm": 0,
41
- // 要求商户级别
42
- "mc": 0,
43
- // 要求用户组
44
- "user_group": [],
45
- // 要求管理组
46
- "user_admin": []
47
- }
48
- }
49
- */
50
- ],
51
- // 顶部导航
52
- 'top_nav': [],
53
- // 左侧导航
54
- 'left_nav': [],
55
- // 底部导航
56
- 'bottom_nav': [],
57
- // 右侧导航
58
- 'right_nav': [],
59
- // 桌面导航
60
- 'desktop_nav': [],
61
- // 快捷导航
62
- 'quick_nav': [],
63
- // 主导航
64
- 'main_nav': [
65
- /*
66
- {
67
- // 标题
68
- "title": "",
69
- // 路径
70
- "url": "",
71
- // 在没有权限下是否显示
72
- "show": false,
73
- // 显示顺序
74
- "display": 3,
75
- // 子导航
76
- "sub": [
77
- {
78
- // 标题
79
- "title": "",
80
- // 路径
81
- "url": "",
82
- // 在没有权限下是否显示
83
- "show": false
84
- }
85
- ]
86
- }
87
- */
88
- ],
89
- // 主程序文件 - 默认为空
90
- 'main': ''
91
- };
92
- /**
93
- * 构造函数
94
- * @param {object} config 配置参数
95
- * @param {object} parent 父对象
96
- * @class
97
- */
98
- constructor(config, parent) {
99
- super({ ...Drive.config, ...config }, parent);
100
- // 模板路径
101
- this.tpl_path = './tpl/';
102
- // 默认启用热更新
103
- this.mode = 3;
104
- }
105
- };
106
-
107
- /**
108
- * 调用函数
109
- * @param {object} type 导航类型
110
- * @returns {object} 执行结果
111
- */
112
- Drive.prototype.run = function (type) {
113
- var cg = {
114
- routes: this.config.routes
115
- };
116
- cg[type] = this.config[type];
117
- return cg;
118
- };
119
-
120
- /**
121
- * 合并项
122
- * @param {object[]} arr 目标数组
123
- * @param {object[]} lt 导航项
124
- */
125
- Drive.prototype.mergeSub = function (arr, lt) {
126
- if (lt) {
127
- var len = lt.length;
128
- for (var i = 0; i < len; i++) {
129
- var o = lt[i];
130
- if (o.name) {
131
- var item = arr.getMatch(o.name, 'name');
132
- if (item) {
133
- $.push(item, o, true);
134
- } else {
135
- arr.push(o);
136
- }
137
- }
138
- }
139
- }
140
- };
141
-
142
- /**
143
- * 执行导航
144
- * @param {string} type 导航类型
145
- * @returns {object|string} 执行结果
146
- */
147
- Drive.prototype.exec = function (type) {
148
- var cg = this.config;
149
- if (cg[type]) {
150
- return this.run(type);
151
- }
152
- return '';
153
- };
154
-
155
- /**
156
- * 排序
157
- */
158
- Drive.prototype.sort = async function () {
159
- var cg = this.config;
160
- if (cg.top_nav) cg.top_nav.sortBy('asc', 'display');
161
- if (cg.left_nav) cg.left_nav.sortBy('asc', 'display');
162
- if (cg.bottom_nav) cg.bottom_nav.sortBy('asc', 'display');
163
- if (cg.right_nav) cg.right_nav.sortBy('asc', 'display');
164
- if (cg.desktop_nav) cg.desktop_nav.sortBy('asc', 'display');
165
- if (cg.quick_nav) cg.quick_nav.sortBy('asc', 'display');
166
- if (cg.main_nav) cg.main_nav.sortBy('asc', 'display');
167
- };
168
-
169
- /**
170
- * 合并配置
171
- * @param {object} o 配置
172
- */
173
- Drive.prototype.merge = function (o) {
174
- var cg = this.config;
175
- cg.name = o.name;
176
- cg.sort = o.sort;
177
- this.mergeSub(cg.routes, o.routes);
178
- this.mergeSub(cg.top, o.top);
179
- this.mergeSub(cg.left, o.left);
180
- this.mergeSub(cg.bottom, o.bottom);
181
- this.mergeSub(cg.right, o.right);
182
- this.mergeSub(cg.desktop, o.desktop);
183
- this.mergeSub(cg.quick, o.quick);
184
- this.mergeSub(cg.main, o.main);
185
- };
186
-
187
- /**
188
- * 新建导航
189
- * @param {string} title 标题
190
- * @param {string} name 名称
191
- * @param {string} url 路径
192
- * @param {number} display 显示顺序
193
- * @returns {object} 导航对象
194
- */
195
- Drive.prototype.newNav = function (title, name, url, display = 100) {
196
- var obj = {
197
- 'title': title,
198
- // 在没有权限下是否显示
199
- 'show': false,
200
- 'name': name,
201
- 'url': url,
202
- 'display': display
203
- };
204
- return obj;
205
- };
206
-
207
- /**
208
- * 新建路由
209
- * @param {string} app 应用名
210
- * @param {string} plugin 插件名
211
- * @param {string} name 接口名
212
- * @param {number} group 权限组
213
- * @param {object} oauth 身份验证
214
- * @returns {object} 路由对象
215
- */
216
- Drive.prototype.newRoutes = function (app, plugin, name, group, oauth) {
217
- var pn = plugin === 'pc' ? '' : plugin;
218
- var n = name.replace(app + '_', '');
219
- var obj = {
220
- 'name': name,
221
- 'path': '/' + app + '/' + n,
222
- 'component': '/' + app + (pn ? '/' + pn : '') + '/src/pages/' + n + '.vue',
223
- 'level': n.replace('_form', '').replace('_view', '').indexOf('_') === -1 ? 3 : 2,
224
- 'oauth': oauth
225
- };
226
- if (!oauth) {
227
- if (!group) {
228
- // 不验证身份
229
- obj.oauth = {
230
- 'sign_in': false
231
- };
232
- } else if (group === 1) {
233
- // 验证身份为管理员
234
- obj.oauth = {
235
- 'sign_in': true,
236
- 'gm': 2,
237
- 'user_admin': []
238
- };
239
- } else {
240
- // 验证身份为商户
241
- obj.oauth = {
242
- 'sign_in': true,
243
- 'mc': 1,
244
- 'user_group': []
245
- };
246
- }
247
- }
248
- return obj;
249
- };
250
-
251
- /**
252
- * 处理管理端API配置
253
- * @param {string} dir 目录路径
254
- * @param {string} app 应用名
255
- * @param {string} plugin 插件名
256
- * @param {Array} nav 导航数组
257
- * @param {object} cg 配置对象
258
- * @param {object} _this 当前对象
259
- */
260
- Drive.prototype._processManageApis = function (dir, app, plugin, nav, cg, _this) {
261
- var d = dir + 'api_manage';
262
- if (!d.hasDir()) {
263
- d = dir + `api_${app}_manage`;
264
- }
265
- if (!d.hasDir()) {
266
- return;
267
- }
268
-
269
- var list = $.file.getAll(d, '*api.json');
270
- list.map((f) => {
271
- var o = f.loadJson();
272
- if (o) {
273
- delete o.oauth.scope;
274
- var name = o.name.replace('_manage', '');
275
- // 添加一个列表页
276
- var obj = _this.newRoutes(app, plugin, name, 1, o.oauth);
277
-
278
- //添加一个详情页
279
- var obj2 = _this.newRoutes(app, plugin, name + '_form', 1, o.oauth);
280
- obj2.level += 1;
281
-
282
- cg.routes.push(obj);
283
- cg.routes.push(obj2);
284
-
285
- nav.push(_this.newNav(o.title, name, obj.path));
286
- }
287
- });
288
- };
289
-
290
- /**
291
- * 处理客户端API配置
292
- * @param {string} dir 目录路径
293
- * @param {string} app 应用名
294
- * @param {string} plugin 插件名
295
- * @param {Array} nav 导航数组
296
- * @param {object} cg 配置对象
297
- * @param {object} _this 当前对象
298
- */
299
- Drive.prototype._processClientApis = function (dir, app, plugin, nav, cg, _this) {
300
- var d = dir + 'api_client';
301
- if (!d.hasDir()) {
302
- d = dir + `api_${app}_client`;
303
- }
304
- if (!d.hasDir()) {
305
- return;
306
- }
307
-
308
- var list = $.file.getAll(d, '*api.json');
309
- list.map((f) => {
310
- var o = f.loadJson();
311
- if (o && !Array.isArray(o)) {
312
- if (o.oauth) {
313
- delete o.oauth.scope;
314
- }
315
-
316
- var name = o.name;
317
- // 添加一个列表页
318
- var obj = _this.newRoutes(app, plugin, name, 0, o.oauth);
319
-
320
- //添加一个详情页
321
- var obj2 = _this.newRoutes(app, plugin, name + '_view', 0, o.oauth);
322
- obj2.level += 1;
323
-
324
- if (name.indexOf('_') === -1) {
325
- obj.level += 1;
326
- obj2.level += 1;
327
- }
328
- cg.routes.push(obj);
329
- cg.routes.push(obj2);
330
-
331
- nav.push(_this.newNav(o.title, name, obj.path));
332
- }
333
- });
334
- };
335
-
336
- /**
337
- * 获取应用标题
338
- * @param {string} app 应用名
339
- * @param {string} file 文件路径
340
- * @returns {string} 应用标题
341
- */
342
- Drive.prototype._getAppTitle = function (app, file) {
343
- var title = '未命名';
344
- var app_file = ('/app/' + app + '/app.json').fullname();
345
- if (app_file.hasFile()) {
346
- var jobj = app_file.loadJson();
347
- if (jobj) {
348
- title = jobj.title;
349
- }
350
- }
351
- var app_config = (file + '').left('plugin') + 'app.json';
352
- if (app_config.hasFile()) {
353
- var oj = app_config.loadJson();
354
- title = oj.title;
355
- }
356
- return title;
357
- };
358
-
359
- /**
360
- * 设置默认路由
361
- * @param {object} cg 配置对象
362
- * @param {string} app 应用名
363
- */
364
- Drive.prototype._setDefaultRoute = function (cg, app) {
365
- if (cg.routes.length > 0) {
366
- cg.routes.splice(0, 0, {
367
- name: app,
368
- path: '/' + app,
369
- redirect: cg.routes[0].path
370
- });
371
- }
372
- };
373
-
374
- /**
375
- * 新建配置
376
- * @param {string} file 文件路径
377
- */
378
- Drive.prototype.newConfig = function (file) {
379
- var cg = this.config;
380
- var plugin = (file + '').right('plugin' + $.slash).left($.slash, true);
381
- var dir = (file + '').left(plugin) + 'server' + $.slash;
382
- var _this = this;
383
-
384
- var app = (file + '').right('app' + $.slash).left($.slash, true);
385
- var nav = [];
386
-
387
- if (plugin.indexOf('admin') !== -1) {
388
- this._processManageApis(dir, app, plugin, nav, cg, _this);
389
- } else {
390
- this._processClientApis(dir, app, plugin, nav, cg, _this);
391
- }
392
-
393
- cg.name = app + '_' + plugin;
394
- var title = this._getAppTitle(app, file);
395
-
396
- this._setDefaultRoute(cg, app);
397
-
398
- cg.main = [{
399
- 'title': title,
400
- 'name': app,
401
- 'icon': '<i class="fa-cog"></i>',
402
- 'url': '/' + app,
403
- 'display': 0,
404
- 'sub': nav
405
- }];
406
- file.saveText(JSON.stringify(cg, null, 4));
407
- };
408
-
409
- /**
410
- * 获取API作用域和路由
411
- * @param {string} app 应用域名
412
- * @param {object} route 路由配置
413
- * @returns {object} 返回作用域和路由
414
- */
415
- Drive.prototype._getApiScope = function (app, route) {
416
- var { path, component } = route;
417
- var scope = app;
418
- var p = path.replace('_table', '').replace('_list', '').replace('_view', '').replace('_form', '');
419
- var api_route;
420
- if (component.indexOf('/admin') !== -1) {
421
- scope += '_manage';
422
- api_route = '/apis' + p;
423
- } else {
424
- scope += '_client';
425
- api_route = '/api' + p;
426
- }
427
- return { scope, api_route };
428
- };
429
-
430
- /**
431
- * 获取API配置
432
- * @param {string} app 应用域名
433
- * @param {object} route 路由配置
434
- * @returns {object} 返回api配置
435
- */
436
- Drive.prototype.getApi = function (app, route) {
437
- var { scope, api_route } = this._getApiScope(app, route);
438
- var api = $.pool.api[scope];
439
- if (!api) {
440
- scope = scope.replace(app + '_', '');
441
- api = $.pool.api[scope];
442
- }
443
- if (!api) {
444
- return null;
445
- }
446
- return this._findApiConfig(api.list, scope, api_route);
447
- };
448
-
449
- /**
450
- * 查找API配置
451
- * @param {Array} list API列表
452
- * @param {string} scope 作用域
453
- * @param {string} api_route API路由
454
- * @returns {object} 返回api配置
455
- */
456
- Drive.prototype._findApiConfig = function (list, scope, api_route) {
457
- var config = { api: {}, param: {}, sql: {} };
458
- for (var i = 0; i < list.length; i++) {
459
- var o = list[i];
460
- if (o.config.path === api_route) {
461
- return {
462
- scope,
463
- api: o.config,
464
- param: o.param.config,
465
- sql: o.sql.config
466
- };
467
- }
468
- }
469
- return config;
470
- };
471
-
472
- /**
473
- * 获取模板文件路径
474
- * @param {string} name 文件名
475
- * @param {string} plugin 插件名
476
- * @param {string} file 文件路径
477
- * @returns {string} 模板文件路径
478
- */
479
- Drive.prototype._getTplPath = function (name, plugin, file) {
480
- var f = this.tpl_path;
481
- var l = $.slash;
482
-
483
- f += this._getSubDir(plugin, file, l);
484
- f += this._getPageFile(name);
485
-
486
- return f.fullname(__dirname);
487
- };
488
-
489
- /**
490
- * 获取子目录
491
- * @param {string} plugin 插件名
492
- * @param {string} file 文件路径
493
- * @param {string} l 分隔符
494
- * @returns {string} 子目录
495
- * @private
496
- */
497
- Drive.prototype._getSubDir = function (plugin, file, l) {
498
- if (plugin) {
499
- return plugin + '/';
500
- }
501
- var subDirs = {
502
- 'mobile': 'mobile/',
503
- 'admin': 'admin/',
504
- 'pc': 'pc/'
505
- };
506
- for (var k in subDirs) {
507
- if (file.indexOf(k + l) !== -1) {
508
- return subDirs[k];
509
- }
510
- }
511
- return '';
512
- };
513
-
514
- /**
515
- * 获取页面文件名
516
- * @param {string} name 文件名
517
- * @returns {string} 页面文件名
518
- * @private
519
- */
520
- Drive.prototype._getPageFile = function (name) {
521
- var pageMap = [
522
- { suffix: '_config_form', file: 'page_config_form.vue' },
523
- { suffix: '_form', file: 'page_form.vue' },
524
- { suffix: '_view', file: 'page_view.vue' },
525
- { suffix: '_table', file: 'page_table.vue' },
526
- { suffix: '_list', file: 'page_list.vue' },
527
- { suffix: 'channel', file: 'page_channel.vue' },
528
- { suffix: 'type', file: 'page_type.vue' },
529
- { suffix: 'nav', file: 'page_nav.vue' },
530
- { suffix: 'lang', file: 'page_lang.vue' },
531
- { suffix: 'config', file: 'page_config.vue' }
532
- ];
533
- for (var i = 0; i < pageMap.length; i++) {
534
- if (name.ends(pageMap[i].suffix)) {
535
- return pageMap[i].file;
536
- }
537
- }
538
- return 'page_default.vue';
539
- };
540
-
541
- /**
542
- * 创建视图模型
543
- * @param {string} name 文件名
544
- * @param {string} app 应用名
545
- * @param {string} plugin 插件名
546
- * @param {string} file 文件路径
547
- * @param {Array} arr 路径数组
548
- * @param {object} route 路由配置
549
- * @returns {object} 视图模型
550
- */
551
- Drive.prototype._createViewModel = function (name, app, plugin, file, arr, route) {
552
- var model = {
553
- id: app + '_' + name,
554
- name: name,
555
- app,
556
- plugin,
557
- file,
558
- group: arr[arr.length - 2],
559
- nav_config: this.config,
560
- route,
561
- scope: '',
562
- api: {},
563
- param: {},
564
- sql: {}
565
- };
566
- return Object.assign(model, this.getApi(app, route));
567
- };
568
-
569
- /**
570
- * 渲染并保存vue文件
571
- * @param {string} tpl_file 模板文件路径
572
- * @param {object} vm 视图模型
573
- * @param {string} file 目标文件路径
574
- */
575
- Drive.prototype._renderAndSaveVue = function (tpl_file, vm, file) {
576
- try {
577
- var vue = tpl.view(tpl_file, vm);
578
- if (vue) {
579
- file.saveText(vue);
580
- } else {
581
- this.log('error', '更新模板失败', tpl.error);
582
- }
583
- } catch (err) {
584
- this.log('error', '更新模板失败', err);
585
- }
586
- };
587
-
588
- /**
589
- * 创建vue文件
590
- * @param {string} filename 文件保存路径
591
- * @param {object} route 路由配置
592
- */
593
- Drive.prototype.createVue = async function (filename, route) {
594
- var file = filename;
595
- var l = $.slash;
596
- file = file.replace($.run_path, '/');
597
- var arr = file.substring(file.indexOf('app')).split(l);
598
-
599
- var name = arr[arr.length - 1].replace('.vue', '');
600
- var plugin = '';
601
- var app = '';
602
-
603
- if (arr.length > 3) {
604
- plugin = arr[3];
605
- app = arr[1];
606
- }
607
-
608
- var tpl_file = this._getTplPath(name, plugin, file);
609
- var model = this._createViewModel(name, app, plugin, file, arr, route);
610
-
611
- var vm = await viewModel.run(model);
612
- vm.JSON = JSON;
613
-
614
- this._renderAndSaveVue(tpl_file, vm, file);
615
- };
616
-
617
- /**
618
- * 创建路径
619
- * @param {string} filepath 文件路径
620
- */
621
- Drive.prototype.mkdir = function (filepath) {
622
- var l = $.slash;
623
- var arr = filepath.split(l);
624
- var dir = arr[0];
625
- for (var i = 1; i < arr.length; i++) {
626
- if (!fs.existsSync(dir)) {
627
- fs.mkdirSync(dir);
628
- }
629
- dir = dir + l + arr[i];
630
- }
631
- };
632
-
633
- /**
634
- * 获取Vue文件目录
635
- * @param {Array} routes 路由列表
636
- * @returns {object} 返回路径信息
637
- */
638
- Drive.prototype._getVueDirInfo = function (routes) {
639
- for (var i = 0; i < routes.length; i++) {
640
- var f = routes[i].component;
641
- if (f) {
642
- var p = f.dirname().replace(/\\/g, '/');
643
- var fl = f.replace('/', '').replace('/', '\\plugin\\').replace('/', '\\static\\');
644
- var dir = ('./app/' + fl).fullname().dirname();
645
- return { p, dir };
646
- }
647
- }
648
- return { p: '', dir: '' };
649
- };
650
-
651
- /**
652
- * 创建Vue文件
653
- * @param {object} route 路由配置
654
- * @param {string} p 原始路径
655
- * @param {string} dir 目标目录
656
- * @param {boolean} cover 是否覆盖
657
- */
658
- Drive.prototype._createVueFile = async function (route, p, dir, cover) {
659
- var f = route.component;
660
- if (!f) return;
661
- var file = f.replace(p, dir).fullname();
662
- if (cover || !file.hasFile()) {
663
- this.mkdir(file);
664
- await this.createVue(file, route);
665
- }
666
- };
667
-
668
- /**
669
- * 更新路由vue文件
670
- * @param {string} route_path 路由路径
671
- * @param {boolean} cover 是否覆盖文件
672
- */
673
- Drive.prototype.updateVue = async function (route_path, cover) {
674
- var lt = this.config.routes;
675
- var { p, dir } = this._getVueDirInfo(lt);
676
- if (!dir) return;
677
-
678
- for (var i = 0; i < lt.length; i++) {
679
- if (route_path && lt[i].path.indexOf(route_path) === -1) continue;
680
- await this._createVueFile(lt[i], p, dir, cover);
681
- }
682
- };
683
-
684
- /**
685
- * 获取模型
686
- * @param {string} type 模型类型
687
- * @returns {object} 返回获取到的模型
688
- */
689
- Drive.prototype.getModel = function (type) {
690
- let model = { ...this.config };
691
- let dir = this.getDir();
692
- let l = $.slash;
693
- let app_name = dir.between('app' + l, l);
694
- let plugin_name = dir.between('plugin' + l, l);
695
- let name = dir.basename();
696
- model.app = app_name;
697
- model.plugin = plugin_name;
698
- model.name = model.name || name;
699
- return model;
700
- };
701
-
702
- module.exports = Drive;