@10yun/cv-mobile-ui 0.5.26 → 0.5.27
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.
- package/build/parse-pages.js +26 -10
- package/build/parse-pages2.js +280 -0
- package/package.json +1 -1
- package/plugins/request.js +4 -4
package/build/parse-pages.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
const fs = require('/usr/local/lib/node_modules/fs-extra');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const glob = require('/usr/local/lib/node_modules/glob');
|
|
4
|
-
const exec = require('child_process').exec;
|
|
5
|
-
|
|
1
|
+
// const fs = require('/usr/local/lib/node_modules/fs-extra');
|
|
2
|
+
// const path = require('path');
|
|
3
|
+
// const glob = require('/usr/local/lib/node_modules/glob');
|
|
4
|
+
// const exec = require('child_process').exec;
|
|
5
|
+
/**
|
|
6
|
+
* https://www.cnblogs.com/Megasu/p/16635566.html
|
|
7
|
+
*/
|
|
8
|
+
// import fs from "fs-extra";
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { dirname } from 'node:path';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import glob from 'glob';
|
|
14
|
+
// 获取 __filename 的 ESM 写法
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
// 获取 __dirname 的 ESM 写法
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
18
|
|
|
19
|
+
import { exec } from 'child_process';
|
|
20
|
+
const argv = process.argv.splice(2)[0];
|
|
21
|
+
console.log('---', argv);
|
|
7
22
|
/* pages.json
|
|
8
23
|
* 用户 pages 分布式配置,分别为三类配置 mian、sub、common
|
|
9
24
|
* *-main 为主包所有路径配置
|
|
@@ -98,7 +113,7 @@ function getSubData() {
|
|
|
98
113
|
}
|
|
99
114
|
function sortoutPages() {
|
|
100
115
|
//以tabBar第一条为首页
|
|
101
|
-
for (key in pages_main_data) {
|
|
116
|
+
for (let key in pages_main_data) {
|
|
102
117
|
if (pages_main_data[key].path == pages_common_data.tabBar.list[0].pagePath) {
|
|
103
118
|
let temp = { ...pages_main_data[key] };
|
|
104
119
|
pages_main_data.splice(key, 1);
|
|
@@ -113,10 +128,11 @@ function sortoutPages() {
|
|
|
113
128
|
pages['preloadRule'] = pages_common_data.preloadRule; //分包预载配置。
|
|
114
129
|
pages['condition'] = pages_common_data.condition; //启动模式配置,仅开发期间生效,用于模拟直达页面的场景,如:小程序转发后,用户点击所打开的页面。
|
|
115
130
|
pages = pages_diy(pages);
|
|
116
|
-
fs.
|
|
131
|
+
fs.writeFileSync(projectSrc + '/pages.json', JSON.stringify(pages, '', 2));
|
|
117
132
|
console.log('【更新完毕】');
|
|
118
133
|
}
|
|
119
|
-
|
|
134
|
+
/**
|
|
135
|
+
* 遍历拼接文件地址
|
|
120
136
|
* root 分包根目录
|
|
121
137
|
*/
|
|
122
138
|
|
|
@@ -131,7 +147,7 @@ function new_file(dir) {
|
|
|
131
147
|
fs.access(projectSrc + '/' + dir + '.vue', function (flag) {
|
|
132
148
|
if (flag) {
|
|
133
149
|
console.log('【新建文件】 ' + projectSrc + '/' + dir + '.vue');
|
|
134
|
-
fs.
|
|
150
|
+
fs.writeFileSync(projectSrc + '/' + dir + '.vue', libTemplData.replace(/\<!-- path --\>/g, '<text>' + dir + '</text>'));
|
|
135
151
|
}
|
|
136
152
|
});
|
|
137
153
|
}
|
|
@@ -176,7 +192,7 @@ function pages_diy(pages) {
|
|
|
176
192
|
if (diyPlus) {
|
|
177
193
|
diyPlus = 'export default ' + JSON.stringify(diyPlus);
|
|
178
194
|
console.log('【更新文件】' + projectSrc + '/pages-diy-plus.js');
|
|
179
|
-
fs.
|
|
195
|
+
fs.writeFileSync(projectSrc + '/pages-diy-plus.js', diyPlus);
|
|
180
196
|
}
|
|
181
197
|
return pages;
|
|
182
198
|
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// const fs = require('/usr/local/lib/node_modules/fs-extra');
|
|
2
|
+
// const path = require('path');
|
|
3
|
+
// const glob = require('/usr/local/lib/node_modules/glob');
|
|
4
|
+
// const exec = require('child_process').exec;
|
|
5
|
+
/**
|
|
6
|
+
* https://www.cnblogs.com/Megasu/p/16635566.html
|
|
7
|
+
*/
|
|
8
|
+
// import fs from "fs-extra";
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { dirname } from 'node:path';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import glob from 'glob';
|
|
14
|
+
// 获取 __filename 的 ESM 写法
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
// 获取 __dirname 的 ESM 写法
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
|
|
19
|
+
import { exec } from 'child_process';
|
|
20
|
+
const argv = process.argv.splice(2)[0];
|
|
21
|
+
console.log('---', argv);
|
|
22
|
+
/* pages.json
|
|
23
|
+
* 用户 pages 分布式配置,分别为三类配置 mian、sub、common
|
|
24
|
+
* *-main 为主包所有路径配置
|
|
25
|
+
* *-sub 为当前分包所有路径配置
|
|
26
|
+
* *-common 为globalStyle、tabBar和easycom的配置
|
|
27
|
+
* 已实现空路径自动创建vue文件,模板文件:./themp.vue
|
|
28
|
+
* 内置命令 npm run pages
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/* 初始化vue模板文件 */
|
|
32
|
+
const libTemplPath = path.join(__dirname, './themp.vue');
|
|
33
|
+
let libTemplData = '';
|
|
34
|
+
fs.access(libTemplPath, function (flag) {
|
|
35
|
+
if (!flag) {
|
|
36
|
+
libTemplData = fs.readFileSync(path.join(libTemplPath), 'utf-8');
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* ---------- ----------
|
|
41
|
+
* 处理项目
|
|
42
|
+
* ---------- ----------
|
|
43
|
+
*/
|
|
44
|
+
const projectPath = process.cwd();
|
|
45
|
+
const projectSrc = path.join(projectPath, '/src');
|
|
46
|
+
|
|
47
|
+
// 用于存放pages所有配置
|
|
48
|
+
var pages = {};
|
|
49
|
+
// 获取所有
|
|
50
|
+
const pages_main = glob.sync(projectSrc + '/pages/**/*-main.json');
|
|
51
|
+
const pages_sub = glob.sync(projectSrc + '/pages/**/*-sub.json');
|
|
52
|
+
const pages_common = glob.sync(projectSrc + '/pages/**/*-common.json');
|
|
53
|
+
|
|
54
|
+
var pages_common_data = {};
|
|
55
|
+
var pages_main_data = [];
|
|
56
|
+
var pages_sub_data = [];
|
|
57
|
+
var pages_already = {};
|
|
58
|
+
// 用于存放 rbac 配置
|
|
59
|
+
var rbacAll = [];
|
|
60
|
+
|
|
61
|
+
getCommonData();
|
|
62
|
+
|
|
63
|
+
function parseCommonMenu(menuArr, root) {
|
|
64
|
+
root = root || '';
|
|
65
|
+
let newArr = [];
|
|
66
|
+
for (let i in menuArr) {
|
|
67
|
+
let menuItem = menuArr[i];
|
|
68
|
+
if (menuItem.path) {
|
|
69
|
+
if (root) {
|
|
70
|
+
// 是否重复注册
|
|
71
|
+
if (pages_already[root + menuItem.path]) {
|
|
72
|
+
continue;
|
|
73
|
+
} else {
|
|
74
|
+
pages_already[root + menuItem.path] = 1;
|
|
75
|
+
}
|
|
76
|
+
// console.log(pages_already[root + menuItem.path]);
|
|
77
|
+
}
|
|
78
|
+
delete menuArr[i].isMenu;
|
|
79
|
+
delete menuArr[i].isRbac;
|
|
80
|
+
delete menuArr[i].meta;
|
|
81
|
+
|
|
82
|
+
if (menuItem.children) {
|
|
83
|
+
let childrenArr = menuItem.children;
|
|
84
|
+
delete menuArr[i].children;
|
|
85
|
+
newArr.push(menuItem);
|
|
86
|
+
let newArr2 = parseCommonMenu(childrenArr, root);
|
|
87
|
+
newArr.push(...newArr2);
|
|
88
|
+
} else {
|
|
89
|
+
newArr.push(menuItem);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return newArr;
|
|
94
|
+
}
|
|
95
|
+
function parseRbacMenu(menuArr, root) {
|
|
96
|
+
root = root || '';
|
|
97
|
+
let newArr = [];
|
|
98
|
+
for (let i in menuArr) {
|
|
99
|
+
let menuItem = menuArr[i];
|
|
100
|
+
if (menuItem.path) {
|
|
101
|
+
let newPath = root + menuItem.path;
|
|
102
|
+
newPath = newPath.replace(/pages/g, '');
|
|
103
|
+
if (menuItem.children) {
|
|
104
|
+
let childrenArr = menuItem.children;
|
|
105
|
+
|
|
106
|
+
let newArr2 = parseRbacMenu(childrenArr, root);
|
|
107
|
+
let newItem = {
|
|
108
|
+
...menuItem,
|
|
109
|
+
path: newPath,
|
|
110
|
+
children: newArr2
|
|
111
|
+
};
|
|
112
|
+
delete newItem.style;
|
|
113
|
+
newArr.push(newItem);
|
|
114
|
+
} else {
|
|
115
|
+
let newItem = {
|
|
116
|
+
...menuItem,
|
|
117
|
+
path: newPath
|
|
118
|
+
};
|
|
119
|
+
delete newItem.style;
|
|
120
|
+
newArr.push(newItem);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return newArr;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getCommonData() {
|
|
128
|
+
pages_common
|
|
129
|
+
.reduce((promise, fileName) => {
|
|
130
|
+
return promise.then(() => {
|
|
131
|
+
console.log('【主要配置】' + fileName);
|
|
132
|
+
var temp = JSON.parse(filter_comments(fs.readFileSync(path.join(fileName), 'utf-8')));
|
|
133
|
+
Object.assign(pages_common_data, temp);
|
|
134
|
+
});
|
|
135
|
+
}, Promise.resolve([]))
|
|
136
|
+
.then(() => {
|
|
137
|
+
if (!pages_common_data.tabBar) {
|
|
138
|
+
console.log('【error】主要配置文件不正确(tabBar配置不存在),请检查修改配置后重试');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
console.log('【主要配置】 - 读取完毕');
|
|
142
|
+
ergodic(pages_common_data.tabBar.list);
|
|
143
|
+
getMainData();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function getMainData() {
|
|
147
|
+
pages_main
|
|
148
|
+
.reduce((promise, fileName) => {
|
|
149
|
+
return promise.then(() => {
|
|
150
|
+
console.log('【主包配置】 ' + fileName);
|
|
151
|
+
let temp = JSON.parse(filter_comments(fs.readFileSync(path.join(fileName), 'utf-8')));
|
|
152
|
+
|
|
153
|
+
let temp_rbac = parseRbacMenu(temp);
|
|
154
|
+
rbacAll.push(...temp_rbac);
|
|
155
|
+
|
|
156
|
+
let temp_parse = parseCommonMenu(temp);
|
|
157
|
+
pages_main_data = pages_main_data.concat(temp_parse);
|
|
158
|
+
});
|
|
159
|
+
}, Promise.resolve([]))
|
|
160
|
+
.then(() => {
|
|
161
|
+
console.log('【主包配置】 - 读取完毕');
|
|
162
|
+
ergodic(pages_main_data, 'path');
|
|
163
|
+
getSubData();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function getSubData() {
|
|
167
|
+
pages_sub
|
|
168
|
+
.reduce((promise, fileName) => {
|
|
169
|
+
return promise.then(() => {
|
|
170
|
+
console.log('【分包配置】 ' + fileName);
|
|
171
|
+
let root = fileName.match(/pages\/(\S*)\//)[0];
|
|
172
|
+
var temp = JSON.parse(filter_comments(fs.readFileSync(path.join(fileName), 'utf-8')));
|
|
173
|
+
|
|
174
|
+
let temp_rbac = parseRbacMenu(temp, root);
|
|
175
|
+
rbacAll.push(...temp_rbac);
|
|
176
|
+
|
|
177
|
+
let temp_parse = parseCommonMenu(temp, root);
|
|
178
|
+
ergodic(temp_parse, 'path', root);
|
|
179
|
+
temp_parse = {
|
|
180
|
+
root: root,
|
|
181
|
+
pages: temp_parse
|
|
182
|
+
};
|
|
183
|
+
pages_sub_data = pages_sub_data.concat(temp_parse);
|
|
184
|
+
});
|
|
185
|
+
}, Promise.resolve([]))
|
|
186
|
+
.then(() => {
|
|
187
|
+
console.log('【分包配置】 读取完毕');
|
|
188
|
+
sortoutPages();
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function sortoutPages() {
|
|
192
|
+
//以tabBar第一条为首页
|
|
193
|
+
for (let key in pages_main_data) {
|
|
194
|
+
if (pages_main_data[key].path == pages_common_data.tabBar.list[0].pagePath) {
|
|
195
|
+
let temp = { ...pages_main_data[key] };
|
|
196
|
+
pages_main_data.splice(key, 1);
|
|
197
|
+
pages_main_data.unshift(temp);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
pages['pages'] = pages_main_data;
|
|
201
|
+
pages['subPackages'] = pages_sub_data;
|
|
202
|
+
pages['globalStyle'] = pages_common_data.globalStyle; //用于设置应用的状态栏、导航条、标题、窗口背景色等。
|
|
203
|
+
pages['tabBar'] = pages_common_data.tabBar;
|
|
204
|
+
pages['easycom'] = pages_common_data.easycom;
|
|
205
|
+
pages['preloadRule'] = pages_common_data.preloadRule; //分包预载配置。
|
|
206
|
+
pages['condition'] = pages_common_data.condition; //启动模式配置,仅开发期间生效,用于模拟直达页面的场景,如:小程序转发后,用户点击所打开的页面。
|
|
207
|
+
pages = pages_diy(pages);
|
|
208
|
+
fs.writeFileSync(projectSrc + '/pages.json', JSON.stringify(pages, '', 2));
|
|
209
|
+
|
|
210
|
+
let menuDiyPlus = 'export default ' + JSON.stringify(rbacAll);
|
|
211
|
+
fs.writeFileSync(projectSrc + '/router/menu.js', menuDiyPlus);
|
|
212
|
+
|
|
213
|
+
// fs.writeFileSync(projectPath + '/public/rbac.json', JSON.stringify(rbacAll, '', 2));
|
|
214
|
+
console.log('【更新完毕】');
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 遍历拼接文件地址
|
|
218
|
+
* root 分包根目录
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
function ergodic(data, page = 'pagePath', root = '') {
|
|
222
|
+
for (const key in data) {
|
|
223
|
+
new_file(root + data[key][page], data[key][page]);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* 新建文件 */
|
|
228
|
+
function new_file(dir) {
|
|
229
|
+
fs.access(projectSrc + '/' + dir + '.vue', function (flag) {
|
|
230
|
+
if (flag) {
|
|
231
|
+
console.log('【新建文件】 ' + projectSrc + '/' + dir + '.vue');
|
|
232
|
+
fs.writeFileSync(projectSrc + '/' + dir + '.vue', libTemplData.replace(/\<!-- path --\>/g, '<text>' + dir + '</text>'));
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* 过滤注释 */
|
|
238
|
+
function filter_comments(string) {
|
|
239
|
+
string = string.replace(/\/\/[\s\S]*?(\r\n|\n)|\/\*[\s\S]*?\*\//g, ''); //过滤多行注释
|
|
240
|
+
return string;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* 抽取自定义配置diy-plus到 pages-diy-plus.js */
|
|
244
|
+
function pages_diy(pages) {
|
|
245
|
+
if (argv !== 'plus') {
|
|
246
|
+
return pages;
|
|
247
|
+
}
|
|
248
|
+
console.log('plus');
|
|
249
|
+
let diyPlus = {};
|
|
250
|
+
// 遍历主包配置
|
|
251
|
+
|
|
252
|
+
for (const key in pages.pages) {
|
|
253
|
+
if (pages.pages[key]['diy-plus']) {
|
|
254
|
+
let k = pages.pages[key].path.replace(/\//g, '_');
|
|
255
|
+
console.log('【抽取diy-plus】 ' + pages.pages[key].path, ' -> ', k);
|
|
256
|
+
diyPlus[k] = pages.pages[key]['diy-plus'];
|
|
257
|
+
delete pages.pages[key]['diy-plus'];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
//遍历分包
|
|
262
|
+
for (const key in pages.subPackages) {
|
|
263
|
+
for (const index in pages.subPackages[key].pages) {
|
|
264
|
+
let root = pages.subPackages[key].root;
|
|
265
|
+
if (pages.subPackages[key].pages[index]['diy-plus']) {
|
|
266
|
+
let full_path = root + pages.subPackages[key].pages[index].path;
|
|
267
|
+
let k = full_path.replace(/\//g, '_');
|
|
268
|
+
console.log('【抽取diy-plus】 ' + full_path, ' -> ', k);
|
|
269
|
+
diyPlus[k] = pages.subPackages[key].pages[index]['diy-plus'];
|
|
270
|
+
delete pages.subPackages[key].pages[index]['diy-plus'];
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (diyPlus) {
|
|
275
|
+
diyPlus = 'export default ' + JSON.stringify(diyPlus);
|
|
276
|
+
console.log('【更新文件】' + projectSrc + '/pages-diy-plus.js');
|
|
277
|
+
fs.writeFileSync(projectSrc + '/pages-diy-plus.js', diyPlus);
|
|
278
|
+
}
|
|
279
|
+
return pages;
|
|
280
|
+
}
|
package/package.json
CHANGED
package/plugins/request.js
CHANGED
|
@@ -120,11 +120,11 @@ class RequestClass {
|
|
|
120
120
|
/**
|
|
121
121
|
* 设置flag参数
|
|
122
122
|
*/
|
|
123
|
-
setFlag(
|
|
124
|
-
this.flagMap = Object.assign({}, this.flagMap,
|
|
123
|
+
setFlag(newFlagMap) {
|
|
124
|
+
this.flagMap = Object.assign({}, this.flagMap, newFlagMap || {});
|
|
125
125
|
return this;
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
parseFlag(oldFlag) {
|
|
128
128
|
// 类型对
|
|
129
129
|
// 不存在
|
|
130
130
|
// 重新获取flag方法存在
|
|
@@ -490,7 +490,7 @@ class RequestClass {
|
|
|
490
490
|
let apiUrl = '';
|
|
491
491
|
let apiUrlNoMsg = '';
|
|
492
492
|
if (flagOrUrl == 'flag') {
|
|
493
|
-
let apiFlag = this.
|
|
493
|
+
let apiFlag = this.parseFlag(argumentsArr[0]);
|
|
494
494
|
if (typeof apiFlag === 'string') {
|
|
495
495
|
apiFlag = apiFlag || '';
|
|
496
496
|
apiUrl = apiFlag == '' ? '' : this.flagMap[apiFlag] || '';
|