mm_nav 1.1.0 → 1.1.2

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.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * mm_nav 最小可运行示例
3
+ * @description 演示 Nav 导航类的路由/导航项构建与 Manager 管理器(纯内存操作,无外部服务)
4
+ */
5
+ const { Nav, Manager, navAdmin } = require('../index.js');
6
+
7
+ /**
8
+ * 主函数
9
+ */
10
+ function main() {
11
+ console.log('== mm_nav 示例开始 ==');
12
+
13
+ // 实例化导航驱动
14
+ const nav = new Nav({ name: 'example' });
15
+
16
+ // 构建导航项与路由
17
+ const mainNav = nav.newNav('首页', 'home', '/home', 1);
18
+ const route = nav.newRoutes('example', 'pc', 'example_index', 0);
19
+ console.log('导航项:', JSON.stringify(mainNav));
20
+ console.log('路由项:', JSON.stringify(route));
21
+
22
+ // 追加到配置并输出
23
+ nav.config.main_nav.push(mainNav);
24
+ nav.config.routes.push(route);
25
+ const result = nav.run('main_nav');
26
+ console.log('run("main_nav") 输出条目数:', result.main_nav.length);
27
+
28
+ // 通过工厂函数获取管理器实例
29
+ const manager = navAdmin('example');
30
+ console.log('navAdmin 获取实例:', manager instanceof Manager);
31
+
32
+ console.log('== mm_nav 示例结束 ==');
33
+ }
34
+
35
+ main();
package/index.js CHANGED
@@ -5,13 +5,13 @@ let admin = new Admin();
5
5
  admin.setClass(Manager);
6
6
 
7
7
  module.exports = {
8
- Drive: require('./lib/drive'),
8
+ Nav: require('./lib/nav'),
9
9
  Manager,
10
10
  admin,
11
11
  navAdmin(scope, config) {
12
12
  if (!scope) {
13
13
  scope = 'os';
14
14
  }
15
- return admin.get(scope, { name: scope, ...config });
15
+ return admin.get(scope, config);
16
16
  }
17
17
  };
package/lib/manager.js CHANGED
@@ -1,12 +1,12 @@
1
- const Manager = require("mm_corejs").Manager;
2
- const Drive = require("./drive");
1
+ const Manager = require("mm_mod").Manager;
2
+ const Nav = require("./nav");
3
3
 
4
4
  /**
5
- * Nav导航类
5
+ * NavManager导航类
6
6
  * @augments {Manager}
7
7
  * @class
8
8
  */
9
- class Nav extends Manager {
9
+ class NavManager extends Manager {
10
10
  /**
11
11
  * 配置参数
12
12
  * @type {object}
@@ -40,9 +40,7 @@ class Nav extends Manager {
40
40
  * @param {object} parent 父级模块(仅作兼容传入,不使用)
41
41
  */
42
42
  constructor(config, parent) {
43
- super({ ...Nav.config, ...config }, parent);
44
- // 插件注册表(方案B:手动注册)
45
- this.plugins = {};
43
+ super({ ...NavManager.config, ...config }, parent);
46
44
  }
47
45
  }
48
46
 
@@ -50,15 +48,15 @@ class Nav extends Manager {
50
48
  * 导航驱动类
51
49
  * @type {Drive}
52
50
  */
53
- Nav.prototype.Drive = Drive;
51
+ NavManager.prototype.Drive = Nav;
54
52
 
55
53
  /**
56
54
  * 注册一个导航配置(方案B:手动注册,不扫描目录)
57
55
  * @param {object} config 驱动配置(必须包含 name)
58
56
  * @returns {object} 驱动实例
59
57
  */
60
- Nav.prototype.add = function (config) {
61
- var drive = new Drive({ ...config }, this);
58
+ NavManager.prototype.add = function (config) {
59
+ var drive = new this.Drive(config, this);
62
60
  this.set(drive.config.name, drive);
63
61
  return drive;
64
62
  };
@@ -68,7 +66,7 @@ Nav.prototype.add = function (config) {
68
66
  * @param {string} name 导航名称
69
67
  * @returns {Promise<boolean>} 是否删除成功
70
68
  */
71
- Nav.prototype.del = async function (name) {
69
+ NavManager.prototype.del = async function (name) {
72
70
  return Manager.prototype.del.call(this, name);
73
71
  };
74
72
 
@@ -77,7 +75,7 @@ Nav.prototype.del = async function (name) {
77
75
  * @param {string} name 导航名称
78
76
  * @returns {Promise<boolean>} 是否执行成功
79
77
  */
80
- Nav.prototype.reload = async function (name) {
78
+ NavManager.prototype.reload = async function (name) {
81
79
  var drive = this.get(name);
82
80
  if (!drive) {
83
81
  this.log("warn", "导航配置不存在,无法重载", name);
@@ -89,24 +87,13 @@ Nav.prototype.reload = async function (name) {
89
87
  return true;
90
88
  };
91
89
 
92
- /**
93
- * 注册插件集合(供驱动 plugin() 查找,替代原全局插件池)
94
- * @param {string} name 插件作用域名称(app 名)
95
- * @param {object} obj 插件集合对象(需含 get 方法)
96
- * @returns {object} 当前管理器实例
97
- */
98
- Nav.prototype.usePlugin = function (name, obj) {
99
- this.plugins[name] = obj;
100
- return this;
101
- };
102
-
103
90
  /**
104
91
  * 执行导航
105
92
  * @param {string} name 导航名称
106
93
  * @param {string} type 导航类型
107
94
  * @returns {object | string} 导航配置
108
95
  */
109
- Nav.prototype.run = async function (name, type) {
96
+ NavManager.prototype.run = async function (name, type) {
110
97
  var obj = new Drive();
111
98
  if (name) {
112
99
  var mod = this.get(name);
@@ -136,12 +123,12 @@ Nav.prototype.run = async function (name, type) {
136
123
  * 排序所有导航配置
137
124
  * @returns {Promise<Array>} 按sort降序排列的配置列表
138
125
  */
139
- Nav.prototype._sort = async function () {
126
+ NavManager.prototype._sort = async function () {
140
127
  var mods = this.values();
141
128
  for (var i = 0; i < mods.length; i++) {
142
129
  await mods[i].sort();
143
130
  }
144
- var infos = this._getInfos();
131
+ var infos = this.configs;
145
132
  infos.sort((o1, o2) => {
146
133
  var p1 = o1.sort || 100;
147
134
  var p2 = o2.sort || 100;
@@ -159,7 +146,7 @@ Nav.prototype._sort = async function () {
159
146
  * @property {string} param.path 路由路径
160
147
  * @returns {string} 更新成功返回null, 失败返回错误提示
161
148
  */
162
- Nav.prototype.updateVue = async function (param) {
149
+ NavManager.prototype.updateVue = async function (param) {
163
150
  var { name, cover, route_name, path } = param;
164
151
 
165
152
  if (name) {
@@ -170,7 +157,7 @@ Nav.prototype.updateVue = async function (param) {
170
157
  return "该配置不存在";
171
158
  }
172
159
  } else {
173
- var infos = this._getInfos();
160
+ var infos = this.configs;
174
161
  for (var i = 0; i < infos.length; i++) {
175
162
  var info = infos[i];
176
163
  if (route_name && info.name !== route_name) {
@@ -190,11 +177,11 @@ Nav.prototype.updateVue = async function (param) {
190
177
  * @returns {Array} 配置数组
191
178
  * @private
192
179
  */
193
- Nav.prototype._getInfos = function () {
180
+ NavManager.prototype._getInfos = function () {
194
181
  return this.values().map((d) => d.config);
195
182
  };
196
183
 
197
184
  /**
198
185
  * @module 导出导航管理器类
199
186
  */
200
- module.exports = Nav;
187
+ module.exports = NavManager;
@@ -1,8 +1,8 @@
1
1
  const fs = require("fs");
2
2
  const os = require("os");
3
3
  const path = require("path");
4
- const Item = require("mm_corejs").Base;
5
- const { string, array, file } = require("mm_helper");
4
+ const Item = require("mm_mod").Base;
5
+ const { string, array, object, file } = require("mm_helper");
6
6
  const Model = require("./viewmodel.js");
7
7
 
8
8
  /** 视图模型实例 */
@@ -32,135 +32,12 @@ function _getTpl() {
32
32
  return tpl_instance || null;
33
33
  }
34
34
 
35
- /**
36
- * 补全文件路径(等价复刻 mm_expand 的 fullname)
37
- * @param {string} file 文件路径
38
- * @param {string} dir 相对路径的基准目录,默认当前执行目录
39
- * @returns {string} 完整路径
40
- */
41
- function _fullname(file, dir) {
42
- var str = file + "";
43
- if (!str) {
44
- return process.cwd();
45
- }
46
- if (str.startsWith("/") && !str.startsWith("//") && str !== "/") {
47
- return path.resolve(process.cwd(), str.substring(1));
48
- }
49
- if (str.startsWith("~/")) {
50
- return path.resolve(os.homedir(), str.substring(2));
51
- }
52
- if (
53
- str.startsWith("./") ||
54
- str.startsWith("../") ||
55
- (!path.isAbsolute(str) && !str.startsWith("/"))
56
- ) {
57
- return path.resolve(dir || process.cwd(), str);
58
- }
59
- return str;
60
- }
61
-
62
- /**
63
- * 递归搜索目录下所有以指定后缀结尾的文件(替代原全局 file.getAll 的 "*xxx" 关键词匹配)
64
- * @param {string} dir 目录地址
65
- * @param {string} suffix 文件名结尾匹配串
66
- * @returns {Array} 文件路径数组
67
- */
68
- function _listFilesBySuffix(dir, suffix) {
69
- var files = [];
70
- _walkDir(_fullname(dir), suffix, files);
71
- return files;
72
- }
73
-
74
- /**
75
- * 递归遍历目录收集匹配文件
76
- * @param {string} dir 目录地址
77
- * @param {string} suffix 文件名结尾匹配串
78
- * @param {Array} files 结果数组
79
- * @private
80
- */
81
- function _walkDir(dir, suffix, files) {
82
- var items;
83
- try {
84
- items = fs.readdirSync(dir, { withFileTypes: true });
85
- } catch {
86
- return;
87
- }
88
- for (var i = 0; i < items.length; i++) {
89
- var item = items[i];
90
- var f = path.join(dir, item.name);
91
- if (item.isFile()) {
92
- if (!suffix || item.name.endsWith(suffix)) {
93
- files.push(f);
94
- }
95
- } else if (item.isDirectory()) {
96
- _walkDir(f, suffix, files);
97
- }
98
- }
99
- }
100
-
101
- /**
102
- * 转换值类型(等价复刻 mm_expand 的 convertValue)
103
- * @param {any} target_val 目标值
104
- * @param {any} source_val 源值
105
- * @returns {any} 转换后的值
106
- */
107
- function _convertValue(target_val, source_val) {
108
- var target_type = typeof target_val;
109
- if (target_type === "number") {
110
- var num = Number(source_val);
111
- return isNaN(num) ? 0 : num;
112
- } else if (target_type === "boolean") {
113
- if (source_val === "0" || source_val === "false" || source_val === "False") {
114
- return false;
115
- } else if (source_val === "1" || source_val === "true" || source_val === "True") {
116
- return true;
117
- } else {
118
- return Boolean(source_val);
119
- }
120
- } else if (target_type === "string") {
121
- return String(source_val);
122
- } else {
123
- return source_val;
124
- }
125
- }
126
-
127
- /**
128
- * 深合并对象属性并补充缺失项(等价复刻原全局 push 的 supplement=true 行为)
129
- * @param {object} target 被添加的对象
130
- * @param {object} source 用作添加的对象
131
- * @returns {object} 修改后的目标对象
132
- */
133
- function _pushObj(target, source) {
134
- if (!target || !source || typeof target !== "object" || typeof source !== "object") {
135
- return target;
136
- }
137
- for (var key in source) {
138
- if (Object.prototype.hasOwnProperty.call(target, key)) {
139
- var target_val = target[key];
140
- var source_val = source[key];
141
- if (
142
- target_val &&
143
- typeof target_val === "object" &&
144
- source_val &&
145
- typeof source_val === "object"
146
- ) {
147
- _pushObj(target_val, source_val);
148
- } else if (typeof target_val === typeof source_val) {
149
- target[key] = _convertValue(target_val, source_val);
150
- }
151
- } else {
152
- target[key] = source[key];
153
- }
154
- }
155
- return target;
156
- }
157
-
158
35
  /**
159
36
  * 导航驱动类
160
37
  * @augments {Item}
161
38
  * @class
162
39
  */
163
- class Drive extends Item {
40
+ class Nav extends Item {
164
41
  static config = {
165
42
  // 路由
166
43
  "routes": [
@@ -242,7 +119,7 @@ class Drive extends Item {
242
119
  * @class
243
120
  */
244
121
  constructor(config, parent) {
245
- super({ ...Drive.config, ...config });
122
+ super({ ...Nav.config, ...config });
246
123
 
247
124
  // 父级管理器引用(用于跨模块服务注入回退)
248
125
  this.parent = parent || null;
@@ -260,7 +137,7 @@ class Drive extends Item {
260
137
  * @param {object} type 导航类型
261
138
  * @returns {object} 执行结果
262
139
  */
263
- Drive.prototype.run = function (type) {
140
+ Nav.prototype.run = function (type) {
264
141
  var cg = {
265
142
  routes: this.config.routes,
266
143
  };
@@ -273,7 +150,7 @@ Drive.prototype.run = function (type) {
273
150
  * @param {object[]} arr 目标数组
274
151
  * @param {object[]} lt 导航项
275
152
  */
276
- Drive.prototype.mergeSub = function (arr, lt) {
153
+ Nav.prototype.mergeSub = function (arr, lt) {
277
154
  if (lt) {
278
155
  var len = lt.length;
279
156
  for (var i = 0; i < len; i++) {
@@ -281,7 +158,7 @@ Drive.prototype.mergeSub = function (arr, lt) {
281
158
  if (o.name) {
282
159
  var item = array.getMatch(arr, o.name, "name");
283
160
  if (item) {
284
- _pushObj(item, o);
161
+ object.push(item, o, true);
285
162
  } else {
286
163
  arr.push(o);
287
164
  }
@@ -295,7 +172,7 @@ Drive.prototype.mergeSub = function (arr, lt) {
295
172
  * @param {string} type 导航类型
296
173
  * @returns {object|string} 执行结果
297
174
  */
298
- Drive.prototype.exec = function (type) {
175
+ Nav.prototype.exec = function (type) {
299
176
  var cg = this.config;
300
177
  if (cg[type]) {
301
178
  return this.run(type);
@@ -306,7 +183,7 @@ Drive.prototype.exec = function (type) {
306
183
  /**
307
184
  * 排序
308
185
  */
309
- Drive.prototype.sort = async function () {
186
+ Nav.prototype.sort = async function () {
310
187
  var cg = this.config;
311
188
  if (cg.top_nav) array.sortBy(cg.top_nav, "asc", "display");
312
189
  if (cg.left_nav) array.sortBy(cg.left_nav, "asc", "display");
@@ -321,7 +198,7 @@ Drive.prototype.sort = async function () {
321
198
  * 合并配置
322
199
  * @param {object} o 配置
323
200
  */
324
- Drive.prototype.merge = function (o) {
201
+ Nav.prototype.merge = function (o) {
325
202
  var cg = this.config;
326
203
  cg.name = o.name;
327
204
  cg.sort = o.sort;
@@ -343,7 +220,7 @@ Drive.prototype.merge = function (o) {
343
220
  * @param {number} display 显示顺序
344
221
  * @returns {object} 导航对象
345
222
  */
346
- Drive.prototype.newNav = function (title, name, url, display = 100) {
223
+ Nav.prototype.newNav = function (title, name, url, display = 100) {
347
224
  var obj = {
348
225
  title: title,
349
226
  // 在没有权限下是否显示
@@ -364,7 +241,7 @@ Drive.prototype.newNav = function (title, name, url, display = 100) {
364
241
  * @param {object} oauth 身份验证
365
242
  * @returns {object} 路由对象
366
243
  */
367
- Drive.prototype.newRoutes = function (app, plugin, name, group, oauth) {
244
+ Nav.prototype.newRoutes = function (app, plugin, name, group, oauth) {
368
245
  var pn = plugin === "pc" ? "" : plugin;
369
246
  var n = name.replace(app + "_", "");
370
247
  var obj = {
@@ -407,7 +284,7 @@ Drive.prototype.newRoutes = function (app, plugin, name, group, oauth) {
407
284
  * @param {Array} nav 导航数组
408
285
  * @param {object} cg 配置对象
409
286
  */
410
- Drive.prototype._processManageApis = function (dir, app, plugin, nav, cg) {
287
+ Nav.prototype._processManageApis = function (dir, app, plugin, nav, cg) {
411
288
  var d = dir + "api_manage";
412
289
  if (!file.hasDir(d)) {
413
290
  d = dir + `api_${app}_manage`;
@@ -416,7 +293,7 @@ Drive.prototype._processManageApis = function (dir, app, plugin, nav, cg) {
416
293
  return;
417
294
  }
418
295
 
419
- var list = _listFilesBySuffix(d, "api.json");
296
+ var list = file.getAllFile(d, "*api.json");
420
297
  for (var i = 0; i < list.length; i++) {
421
298
  var o = file.loadJson(list[i]);
422
299
  if (o) {
@@ -445,7 +322,7 @@ Drive.prototype._processManageApis = function (dir, app, plugin, nav, cg) {
445
322
  * @param {Array} nav 导航数组
446
323
  * @param {object} cg 配置对象
447
324
  */
448
- Drive.prototype._processClientApis = function (dir, app, plugin, nav, cg) {
325
+ Nav.prototype._processClientApis = function (dir, app, plugin, nav, cg) {
449
326
  var d = dir + "api_client";
450
327
  if (!file.hasDir(d)) {
451
328
  d = dir + `api_${app}_client`;
@@ -454,7 +331,7 @@ Drive.prototype._processClientApis = function (dir, app, plugin, nav, cg) {
454
331
  return;
455
332
  }
456
333
 
457
- var list = _listFilesBySuffix(d, "api.json");
334
+ var list = file.getAllFile(d, "*api.json");
458
335
  for (var i = 0; i < list.length; i++) {
459
336
  var o = file.loadJson(list[i]);
460
337
  if (o && !Array.isArray(o)) {
@@ -488,9 +365,9 @@ Drive.prototype._processClientApis = function (dir, app, plugin, nav, cg) {
488
365
  * @param {string} file 文件路径
489
366
  * @returns {string} 应用标题
490
367
  */
491
- Drive.prototype._getAppTitle = function (app, file) {
368
+ Nav.prototype._getAppTitle = function (app, file) {
492
369
  var title = "未命名";
493
- var app_file = _fullname("/app/" + app + "/app.json");
370
+ var app_file = file.fullname("/app/" + app + "/app.json");
494
371
  if (file.hasFile(app_file)) {
495
372
  var jobj = file.loadJson(app_file);
496
373
  if (jobj) {
@@ -510,7 +387,7 @@ Drive.prototype._getAppTitle = function (app, file) {
510
387
  * @param {object} cg 配置对象
511
388
  * @param {string} app 应用名
512
389
  */
513
- Drive.prototype._setDefaultRoute = function (cg, app) {
390
+ Nav.prototype._setDefaultRoute = function (cg, app) {
514
391
  if (cg.routes.length > 0) {
515
392
  cg.routes.splice(0, 0, {
516
393
  name: app,
@@ -524,7 +401,7 @@ Drive.prototype._setDefaultRoute = function (cg, app) {
524
401
  * 新建配置
525
402
  * @param {string} file 文件路径
526
403
  */
527
- Drive.prototype.newConfig = function (file) {
404
+ Nav.prototype.newConfig = function (file) {
528
405
  var cg = this.config;
529
406
  var l = path.sep;
530
407
  var plugin = string.left(string.right(file + "", "plugin" + l), l, true);
@@ -563,7 +440,7 @@ Drive.prototype.newConfig = function (file) {
563
440
  * @param {object} route 路由配置
564
441
  * @returns {object} 返回作用域和路由
565
442
  */
566
- Drive.prototype._getApiScope = function (app, route) {
443
+ Nav.prototype._getApiScope = function (app, route) {
567
444
  var { path: route_path, component } = route;
568
445
  var scope = app;
569
446
  var p = route_path
@@ -588,7 +465,7 @@ Drive.prototype._getApiScope = function (app, route) {
588
465
  * @returns {object|null} API集合;未配置注入函数时告警并返回null
589
466
  * @private
590
467
  */
591
- Drive.prototype._getApiByScope = function (scope) {
468
+ Nav.prototype._getApiByScope = function (scope) {
592
469
  var getter = this.parent && this.parent.config ? this.parent.config.get_api : null;
593
470
  if (typeof getter !== "function") {
594
471
  this._warnNoApi();
@@ -602,7 +479,7 @@ Drive.prototype._getApiByScope = function (scope) {
602
479
  * @returns {void}
603
480
  * @private
604
481
  */
605
- Drive.prototype._warnNoApi = function () {
482
+ Nav.prototype._warnNoApi = function () {
606
483
  if (this._api_warned) {
607
484
  return;
608
485
  }
@@ -616,7 +493,7 @@ Drive.prototype._warnNoApi = function () {
616
493
  * @param {object} route 路由配置
617
494
  * @returns {object} 返回api配置
618
495
  */
619
- Drive.prototype.getApi = function (app, route) {
496
+ Nav.prototype.getApi = function (app, route) {
620
497
  var { scope, api_route } = this._getApiScope(app, route);
621
498
  var api = this._getApiByScope(scope);
622
499
  if (!api) {
@@ -636,7 +513,7 @@ Drive.prototype.getApi = function (app, route) {
636
513
  * @param {string} api_route API路由
637
514
  * @returns {object} 返回api配置
638
515
  */
639
- Drive.prototype._findApiConfig = function (list, scope, api_route) {
516
+ Nav.prototype._findApiConfig = function (list, scope, api_route) {
640
517
  var config = { api: {}, param: {}, sql: {} };
641
518
  for (var i = 0; i < list.length; i++) {
642
519
  var o = list[i];
@@ -659,14 +536,14 @@ Drive.prototype._findApiConfig = function (list, scope, api_route) {
659
536
  * @param {string} file 文件路径
660
537
  * @returns {string} 模板文件路径
661
538
  */
662
- Drive.prototype._getTplPath = function (name, plugin, file) {
539
+ Nav.prototype._getTplPath = function (name, plugin, file) {
663
540
  var f = this.tpl_path;
664
541
  var l = path.sep;
665
542
 
666
543
  f += this._getSubDir(plugin, file, l);
667
544
  f += this._getPageFile(name);
668
545
 
669
- return _fullname(f, __dirname);
546
+ return file.fullname(f, __dirname);
670
547
  };
671
548
 
672
549
  /**
@@ -677,7 +554,7 @@ Drive.prototype._getTplPath = function (name, plugin, file) {
677
554
  * @returns {string} 子目录
678
555
  * @private
679
556
  */
680
- Drive.prototype._getSubDir = function (plugin, file, l) {
557
+ Nav.prototype._getSubDir = function (plugin, file, l) {
681
558
  if (plugin) {
682
559
  return plugin + "/";
683
560
  }
@@ -700,7 +577,7 @@ Drive.prototype._getSubDir = function (plugin, file, l) {
700
577
  * @returns {string} 页面文件名
701
578
  * @private
702
579
  */
703
- Drive.prototype._getPageFile = function (name) {
580
+ Nav.prototype._getPageFile = function (name) {
704
581
  var pageMap = [
705
582
  { suffix: "_config_form", file: "page_config_form.vue" },
706
583
  { suffix: "_form", file: "page_form.vue" },
@@ -731,7 +608,7 @@ Drive.prototype._getPageFile = function (name) {
731
608
  * @param {object} route 路由配置
732
609
  * @returns {object} 视图模型
733
610
  */
734
- Drive.prototype._createViewModel = function (name, app, plugin, file, arr, route) {
611
+ Nav.prototype._createViewModel = function (name, app, plugin, file, arr, route) {
735
612
  var model = {
736
613
  id: app + "_" + name,
737
614
  name: name,
@@ -755,7 +632,7 @@ Drive.prototype._createViewModel = function (name, app, plugin, file, arr, route
755
632
  * @param {object} vm 视图模型
756
633
  * @param {string} file 目标文件路径
757
634
  */
758
- Drive.prototype._renderAndSaveVue = function (tpl_file, vm, file) {
635
+ Nav.prototype._renderAndSaveVue = function (tpl_file, vm, file) {
759
636
  var tpl = _getTpl();
760
637
  if (!tpl) {
761
638
  this.log("error", "模板引擎不可用,跳过vue渲染", tpl_file);
@@ -778,7 +655,7 @@ Drive.prototype._renderAndSaveVue = function (tpl_file, vm, file) {
778
655
  * @param {string} filename 文件保存路径
779
656
  * @param {object} route 路由配置
780
657
  */
781
- Drive.prototype.createVue = async function (filename, route) {
658
+ Nav.prototype.createVue = async function (filename, route) {
782
659
  var file = filename;
783
660
  var l = path.sep;
784
661
  file = file.replace(process.cwd(), "/");
@@ -806,7 +683,7 @@ Drive.prototype.createVue = async function (filename, route) {
806
683
  * 创建路径
807
684
  * @param {string} filepath 文件路径
808
685
  */
809
- Drive.prototype.mkdir = function (filepath) {
686
+ Nav.prototype.mkdir = function (filepath) {
810
687
  var l = path.sep;
811
688
  var arr = filepath.split(l);
812
689
  var dir = arr[0];
@@ -823,13 +700,13 @@ Drive.prototype.mkdir = function (filepath) {
823
700
  * @param {Array} routes 路由列表
824
701
  * @returns {object} 返回路径信息
825
702
  */
826
- Drive.prototype._getVueDirInfo = function (routes) {
703
+ Nav.prototype._getVueDirInfo = function (routes) {
827
704
  for (var i = 0; i < routes.length; i++) {
828
705
  var f = routes[i].component;
829
706
  if (f) {
830
707
  var p = path.dirname(f).replace(/\\/g, "/");
831
708
  var fl = f.replace("/", "").replace("/", "\\plugin\\").replace("/", "\\static\\");
832
- var dir = path.dirname(_fullname("./app/" + fl));
709
+ var dir = path.dirname(file.fullname("./app/" + fl));
833
710
  return { p, dir };
834
711
  }
835
712
  }
@@ -843,10 +720,10 @@ Drive.prototype._getVueDirInfo = function (routes) {
843
720
  * @param {string} dir 目标目录
844
721
  * @param {boolean} cover 是否覆盖
845
722
  */
846
- Drive.prototype._createVueFile = async function (route, p, dir, cover) {
723
+ Nav.prototype._createVueFile = async function (route, p, dir, cover) {
847
724
  var f = route.component;
848
725
  if (!f) return;
849
- var file = _fullname(f.replace(p, dir));
726
+ var file = f.replace(p, dir).fullname();
850
727
  if (cover || !file.hasFile(file)) {
851
728
  this.mkdir(file);
852
729
  await this.createVue(file, route);
@@ -858,7 +735,7 @@ Drive.prototype._createVueFile = async function (route, p, dir, cover) {
858
735
  * @param {string} route_path 路由路径
859
736
  * @param {boolean} cover 是否覆盖文件
860
737
  */
861
- Drive.prototype.updateVue = async function (route_path, cover) {
738
+ Nav.prototype.updateVue = async function (route_path, cover) {
862
739
  var lt = this.config.routes;
863
740
  var { p, dir } = this._getVueDirInfo(lt);
864
741
  if (!dir) return;
@@ -874,7 +751,7 @@ Drive.prototype.updateVue = async function (route_path, cover) {
874
751
  * @param {string} type 模型类型
875
752
  * @returns {object} 返回获取到的模型
876
753
  */
877
- Drive.prototype.getModel = function (type) {
754
+ Nav.prototype.getModel = function (type) {
878
755
  let model = { ...this.config };
879
756
  let dir = this.config.dir || "";
880
757
  let l = path.sep;
@@ -887,4 +764,4 @@ Drive.prototype.getModel = function (type) {
887
764
  return model;
888
765
  };
889
766
 
890
- module.exports = Drive;
767
+ module.exports = Nav;
package/package.json CHANGED
@@ -1,28 +1,33 @@
1
1
  {
2
- "name": "mm_nav",
3
- "version": "1.1.0",
4
- "description": "导航框架,用于生成前端所需的路由导航,配合vue路由使用,可以实现动态添加页面(基于 mm_corejs,内置管理器池,无全局/原型扩展依赖)",
5
- "main": "index.js",
6
- "keywords": [
7
- "mm_mod",
8
- "mm_adapter",
9
- "mm_in_adapter",
10
- "nav",
11
- "navigation",
12
- "vue",
13
- "router",
14
- "导航管理器"
15
- ],
16
- "layer": "adapter",
17
- "group": "in_adapter",
18
- "author": "邱文武",
19
- "license": "ISC",
20
- "dependencies": {
21
- "mm_corejs": "^1.1.4",
22
- "mm_tpl": "^2.7.2",
23
- "mm_helper": "^1.0.0"
24
- },
25
- "scripts": {
26
- "test": "node test.js"
27
- }
2
+ "name": "mm_nav",
3
+ "version": "1.1.2",
4
+ "description": "导航框架,用于生成前端所需的路由导航,配合vue路由使用,可以实现动态添加页面(基于 mm_corejs,内置管理器池,无全局/原型扩展依赖)",
5
+ "main": "index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://gitee.com/qiuwenwu91/mm_nav.git"
9
+ },
10
+ "keywords": [
11
+ "mm_mod",
12
+ "mm_adapter",
13
+ "mm_in_adapter",
14
+ "nav",
15
+ "navigation",
16
+ "vue",
17
+ "router",
18
+ "导航管理器"
19
+ ],
20
+ "layer": "crosscut",
21
+ "group": "in_adapter",
22
+ "author": "邱文武",
23
+ "license": "ISC",
24
+ "dependencies": {
25
+ "mm_corejs": "^1.1.5",
26
+ "mm_mod": "^1.0.6",
27
+ "mm_tpl": "^2.7.3",
28
+ "mm_helper": "^1.0.3"
29
+ },
30
+ "scripts": {
31
+ "test": "node test.js"
32
+ }
28
33
  }