@10yun/open-sdk 0.3.89 → 0.3.95

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.
@@ -41,19 +41,17 @@ function parseDataToMenu(appFlag, oldData) {
41
41
  * 处理 - 子菜单
42
42
  */
43
43
  let newChildren = [];
44
- for (let index2 in tempChildren) {
45
- let item2 = tempChildren[index2];
44
+ tempChildren.forEach((item2, index2) => {
46
45
  if (item2.isMenu) {
47
46
  item2['parentId'] = item1.name;
48
47
  newChildren.push(item2);
49
48
  }
50
- }
49
+ });
51
50
  /**
52
51
  * 处理 - 子操作项
53
52
  */
54
53
  let newOption = [];
55
- for (let index2 in tempChildren) {
56
- let item2 = tempChildren[index2];
54
+ tempChildren.forEach((item2, index2) => {
57
55
  item2 = parseRouteItem(item2);
58
56
  if (nameOnlyArr[item2.name]) {
59
57
  item2.name = item2.name + '_' + index2;
@@ -65,7 +63,7 @@ function parseDataToMenu(appFlag, oldData) {
65
63
  item2.checked = false;
66
64
  newOption.push(item2);
67
65
  }
68
- }
66
+ });
69
67
  // 如果不存在的子操作
70
68
  if (newOption.length > 0) {
71
69
  item_new.menuOptionsList = newOption;
package/common/router.js CHANGED
@@ -70,12 +70,131 @@ function parseChildrenOption() {}
70
70
  function parseChildrenMenu() {}
71
71
  function parseRouteTree(originalArr) {
72
72
  let newArr = [];
73
- for (let index1 in originalArr) {
74
- let tempItem1 = originalArr[index1];
73
+ originalArr.forEach((tempItem1, index1) => {
75
74
  tempItem1 = parseRouteItem(tempItem1, index1);
76
75
  if (tempItem.children) {
77
76
  tempItem.children = parseRouteTree(tempItem.children);
78
77
  }
79
- }
78
+ });
79
+ }
80
+ /**
81
+ * 树形数据 向下 递归为一维数组
82
+ * @param {*} arr 数据源
83
+ * @param {*} childs 子集key
84
+ * @return {Array}
85
+ */
86
+ function treeToSubFlatten(arr = [], childs = 'children') {
87
+ return arr.reduce((flat, item) => {
88
+ return flat.concat(item, item[childs] ? treeToSubFlatten(item[childs], childs) : []);
89
+ }, []);
90
+ }
91
+ // https://www.cnblogs.com/jj123/p/12784100.html
92
+ // https://segmentfault.com/a/1190000015419713
93
+
94
+ function _import(file) {
95
+ file = file.replace(/\s/g, '');
96
+ if (file.substr(0, 1) == '/') file = file.substr(1);
97
+ if (file.substr(0, 1) == '/') file = file.substr(1);
98
+ return file;
99
+ }
100
+
101
+ /**
102
+ * 递归获取,每层级的信息,类似 $route.matched
103
+ * @param {Array} routerlist 需要递归的数据
104
+ * @param {Array} parentInfo 上级的信息向下传递
105
+ * @returns
106
+ */
107
+ function parseRouteTreeInfo(routerlist, parentInfo = []) {
108
+ routerlist = routerlist || [];
109
+ let routerInfo = [];
110
+ routerlist.forEach((item1, index1) => {
111
+ let isParam = {
112
+ isMenu: item1.isMenu || false,
113
+ isRbac: item1.isRbac || false,
114
+ isWindow: item1.isWindow || false,
115
+ isAlone: item1.isAlone || false,
116
+ isPage: item1.path ? true : false
117
+ };
118
+ let item_new = {
119
+ path: item1.path || '',
120
+ name: item1.name || '',
121
+ ...isParam,
122
+ ...item1.meta
123
+ };
124
+ if (item1.redirect) {
125
+ item_new = Object.assign({}, item_new, { redirect: item1.redirect });
126
+ }
127
+ if (item1.generatemenu == 0) {
128
+ item_new = Object.assign({}, item_new, { hidden: true });
129
+ }
130
+ let treeInfo = [];
131
+ treeInfo.push(...parentInfo);
132
+ treeInfo.push(item_new);
133
+ if (item1.children) {
134
+ let tempChildren = item1.children;
135
+ item1.children = parseRouteTreeInfo([...tempChildren], treeInfo);
136
+ }
137
+ item1.treeInfo = treeInfo;
138
+ routerInfo.push(item1);
139
+ });
140
+ return routerInfo;
141
+ }
142
+
143
+ /**
144
+ * 根据路由匹配地址
145
+ * @param {*} data 路由数据
146
+ * @param {*} base 路由前缀
147
+ * @param {*} options 粗略的配置项
148
+ */
149
+ function routeParseQiankun(baseRoute, menuArr, isFlatten = true) {
150
+ // 递归获取,各级信息
151
+ menuArr = parseRouteTreeInfo(menuArr);
152
+ if (!Array.isArray(menuArr)) return baseRoute;
153
+
154
+ /** 2级+菜单 ,将菜单数据处理为一维函数 如果有多级菜单*/
155
+ let menuRoute = treeToSubFlatten(menuArr, 'children');
156
+ // 遍历处理路由
157
+ menuRoute.forEach((item, index) => {
158
+ // menuArr.forEach((item, index) => {
159
+ if (!item['path']) return;
160
+ item = parseRouteItem(item, index);
161
+
162
+ try {
163
+ let routerItem = {
164
+ path: item.path, // 路由路径名
165
+ name: item.name, // 命名路由 用于配合菜单简洁跳转
166
+ query: item['query'] || {},
167
+ params: item['params'] || {},
168
+ props: item['props'] || true,
169
+ isMenu: item['isMenu'] || false,
170
+ meta: {
171
+ title: item['title'] || '',
172
+ isMenu: item['isMenu'] || false,
173
+ isRbac: item['isRbac'] || false,
174
+ isWindow: item['isWindow'] || false,
175
+ isAlone: item['isAlone'] || false,
176
+ treeInfo: item['treeInfo'] || [],
177
+ ...item.meta
178
+ // purview: item[options.permissions],
179
+ }
180
+ // component = () =>
181
+ };
182
+ // 路由映射真实视图路径
183
+ if (typeof item.component == 'string') {
184
+ routerItem.component_str = _import(item.component);
185
+ }
186
+ baseRoute.push(routerItem);
187
+ // 递归处理子路由
188
+ if (!isFlatten && item.children) {
189
+ routerItem.children = [];
190
+ routeParseQiankun(routerItem.children, item.children);
191
+ }
192
+ } catch (err) {
193
+ console.log('---路由注册问题');
194
+ console.log('err--', err);
195
+ // item['url'] = '/404'
196
+ }
197
+ });
198
+ return baseRoute;
80
199
  }
81
- export { parseRouteItem, parseRouteTree };
200
+ export { parseRouteItem, parseRouteTree, routeParseQiankun };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("./index-DSBKHepn.cjs"),c={},s={class:"cloud-404-wrap"};function d(r,o){return e.openBlock(),e.createElementBlock("div",s,o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-404-box"},[e.createElementVNode("div",{class:"cloud-404-code"},"404"),e.createElementVNode("div",{class:"cloud-404-message"},"Not Found")],-1)]))}const n=t._export_sfc(c,[["render",d]]);exports.default=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("./index-CZXYqbhI.cjs"),c={},s={class:"cloud-404-wrap"};function d(r,o){return e.openBlock(),e.createElementBlock("div",s,o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-404-box"},[e.createElementVNode("div",{class:"cloud-404-code"},"404"),e.createElementVNode("div",{class:"cloud-404-message"},"Not Found")],-1)]))}const n=t._export_sfc(c,[["render",d]]);exports.default=n;
@@ -1,5 +1,5 @@
1
1
  import { createElementBlock as c, openBlock as s, createElementVNode as o } from "vue";
2
- import { _ as t } from "./index-CYEmAMQY.js";
2
+ import { _ as t } from "./index-BqgMek3a.js";
3
3
  const d = {}, r = { class: "cloud-404-wrap" };
4
4
  function l(n, e) {
5
5
  return s(), c("div", r, e[0] || (e[0] = [
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("./index-DSBKHepn.cjs"),c={},t={class:"cloud-none-wrap",style:{"background-color":"none"}};function r(s,o){return e.openBlock(),e.createElementBlock("div",t,o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-none-box"},[e.createElementVNode("div",{class:"cloud-none-code"},"不建议,子应用单独运行~"),e.createElementVNode("div",{class:"cloud-none-message"},"Not Alone")],-1)]))}const l=n._export_sfc(c,[["render",r]]);exports.default=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("./index-CZXYqbhI.cjs"),c={},t={class:"cloud-none-wrap",style:{"background-color":"none"}};function r(s,o){return e.openBlock(),e.createElementBlock("div",t,o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-none-box"},[e.createElementVNode("div",{class:"cloud-none-code"},"不建议,子应用单独运行~"),e.createElementVNode("div",{class:"cloud-none-message"},"Not Alone")],-1)]))}const l=n._export_sfc(c,[["render",r]]);exports.default=l;
@@ -1,5 +1,5 @@
1
1
  import { createElementBlock as n, openBlock as c, createElementVNode as o } from "vue";
2
- import { _ as s } from "./index-CYEmAMQY.js";
2
+ import { _ as s } from "./index-BqgMek3a.js";
3
3
  const r = {}, t = {
4
4
  class: "cloud-none-wrap",
5
5
  style: { "background-color": "none" }