@lcap/nasl 3.13.3-rc.4 → 3.13.3-rc.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.
@@ -41,6 +41,8 @@ const microApp_1 = require("./microApp");
41
41
  // @ts-ignore FIXME wudengke 类型在构建前找不到的问题
42
42
  const nasl_unified_frontend_generator_2 = require("@lcap/nasl-unified-frontend-generator");
43
43
  const axios_1 = __importDefault(require("axios"));
44
+ const runtime_1 = require("./templates/runtime");
45
+ const chunk_1 = require("./templates/chunk");
44
46
  const officalEntityMap = {
45
47
  LCAPUser: ['id', 'createdTime', 'updatedTime', 'userId', 'userName', 'password', 'phone', 'email', 'displayName', 'status', 'source'],
46
48
  LCAPLogicViewMapping: ['id', 'logicIdentifier', 'resourceName', 'resourceType', 'group', 'changeTime'],
@@ -114,8 +116,8 @@ function genComponentCode(component) {
114
116
  })()`;
115
117
  }
116
118
  // 生成导入组件代码
117
- function genImportComponetCode(componentPath) {
118
- return `() => importComponent('${componentPath}')`;
119
+ function genImportComponetCode(chunkId) {
120
+ return `() => __webpack_require__.e("${chunkId}").then(__webpack_require__.bind(__webpack_require__, "./${chunkId}.js"))`;
119
121
  }
120
122
  // 生成导出组件代码
121
123
  function genExportComponetCode(component) {
@@ -123,7 +125,7 @@ function genExportComponetCode(component) {
123
125
  Object.assign(componentOptions, {
124
126
  template: \`${component.template.replace(/[`$]/g, (m) => `\\${m}`)}\`,
125
127
  });
126
- return componentOptions;`;
128
+ `;
127
129
  }
128
130
  // 获取文件路径
129
131
  // name 或者 文件 至少有一个必填
@@ -136,27 +138,44 @@ const getCompletePath = (name, fileContent, config) => {
136
138
  fileName += `${(0, nasl_utils_1.genHash)(fileContent)}.`;
137
139
  }
138
140
  fileName += `min.js`;
139
- // if(config?.isExport && !fileName.includes('bundle')&& !fileName.includes('router')){
140
- // fileName =`${config.sysPrefixPath}/${fileName}`
141
- // }
142
141
  return fileName;
143
142
  };
144
- function genRouterFileContent(routes, defaultRoute) {
143
+ function genRouterFileContent(routes, defaultRoute, config) {
144
+ // 单页面发布
145
+ if (config.isOneFile) {
146
+ let code = config?.cacheRouters;
147
+ const changedChunks = config?.asyncChunksMap;
148
+ let newRoutesCode = 'window.lcap_routes = [\n';
149
+ routes.forEach((route) => {
150
+ newRoutesCode += `${routeToString(route)},\n`;
151
+ });
152
+ newRoutesCode += '];\n';
153
+ const [start, end] = ['// lcap_routes start', '// lcap_routes end'];
154
+ // 将start和end之间的代码替换掉
155
+ code = code.slice(0, code.indexOf(start) + start.length) + '\n' + newRoutesCode + code.slice(code.indexOf(end));
156
+ const placeholderIdx = code.indexOf('// lcap_changed_chunks placeholder');
157
+ // 前面插入代码
158
+ if (placeholderIdx !== -1) {
159
+ code = code.slice(0, placeholderIdx) + `Object.assign(lcap_changed_chunks, ${JSON.stringify(changedChunks)});\n` + code.slice(placeholderIdx);
160
+ }
161
+ return code;
162
+ }
145
163
  function routeToString(route) {
146
164
  let content = `{
147
165
  path: '${route.path}',\n`;
148
- if (route?.lazyPath) {
149
- const routeLazyPath = route.lazyPath;
150
- content += `lazyPath: '${routeLazyPath}',\n`;
151
- content += `component: ${genImportComponetCode(route.lazyPath)},\n`;
166
+ if (route?.fullPath) {
167
+ // 单页面发布时需要
168
+ content += `fullPath: '${route.fullPath}',\n`;
169
+ const chunkId = (0, nasl_utils_1.genHash)(route.fullPath);
170
+ content += `component: ${genImportComponetCode(chunkId)},\n`;
152
171
  }
153
172
  if (route?.meta) {
154
173
  content += `meta: ${stringifyMetaData(route.meta)},`;
155
174
  }
156
- if (route?.children?.length) {
175
+ if (route.children?.length) {
157
176
  content += `children: [
158
- ${route.children.map(routeToString).join(',\n')}
159
- ],\n`;
177
+ ${route.children?.map?.(routeToString)?.join(',\n')}
178
+ ],\n`;
160
179
  }
161
180
  if (route?.redirect) {
162
181
  content += `redirect: '${route?.redirect}',\n`;
@@ -164,35 +183,64 @@ function genRouterFileContent(routes, defaultRoute) {
164
183
  content += '}';
165
184
  return content;
166
185
  }
186
+ // 生成异步块映射表
187
+ const name = config?.app?.name;
188
+ let code = `window["${name}LcapChunksMap"] = ${JSON5.stringify(config?.asyncChunksMap || {})};\n`;
167
189
  // 生成路由配置
168
- let routesStr = `const routers = [`;
190
+ code += `// lcap_routes start
191
+ window.lcap_routes = [\n`;
169
192
  routes.forEach((route) => {
170
- routesStr += `${routeToString(route)},\n`;
193
+ code += `${routeToString(route)},\n`;
171
194
  });
172
195
  if (defaultRoute) {
173
- routesStr += `{
196
+ code += `{
174
197
  path: '*',
175
198
  redirect: '${defaultRoute}',
176
199
  }\n`;
177
200
  }
178
- routesStr += `];
179
- return routers;`;
180
- return routesStr;
201
+ code += `];
202
+ // lcap_routes end\n`;
203
+ // changedChunk
204
+ code += `var lcap_changed_chunks = {};
205
+
206
+ // lcap_changed_chunks placeholder
207
+
208
+ Object.keys(lcap_changed_chunks).forEach(function(chunkId) {
209
+ window["${name}LcapChunksMap"][chunkId] = lcap_changed_chunks[chunkId];
210
+ });`;
211
+ return (0, chunk_1.generate)({
212
+ name: config?.app?.name,
213
+ chunkId: 'router',
214
+ moduleId: 'router',
215
+ content: code,
216
+ exports: [],
217
+ exec: false,
218
+ });
181
219
  }
182
220
  // 生成路由文件
183
221
  function genRouteFiles(routes, defaultRoute, config) {
184
222
  // 生成路由文件列表
185
223
  const routeFiles = [];
224
+ const asyncChunksMap = {};
186
225
  function routeToFile(route) {
187
226
  if (route?.component?.script) {
188
227
  const content = genExportComponetCode(route.component);
189
- const lazyPath = getCompletePath(null, content, config);
190
- route.lazyPath = lazyPath;
191
- // let outFilePath =`${config?.sysPrefixPath? config?.sysPrefixPath +'/' :''}${lazyPath}`;
228
+ const chunkId = (0, nasl_utils_1.genHash)(route.fullPath);
229
+ const contentHash = (0, nasl_utils_1.genHash)(content);
192
230
  routeFiles.push({
193
- name: lazyPath,
194
- content,
231
+ name: chunkId + '.' + contentHash + '.js',
232
+ content: (0, chunk_1.generate)({
233
+ name: config?.app?.name,
234
+ chunkId,
235
+ moduleId: chunkId,
236
+ content,
237
+ exports: [
238
+ ['componentOptions', 'default'],
239
+ ],
240
+ exec: false,
241
+ }),
195
242
  });
243
+ asyncChunksMap[chunkId] = contentHash;
196
244
  }
197
245
  if (route?.children?.length) {
198
246
  route.children.map(routeToFile);
@@ -201,13 +249,16 @@ function genRouteFiles(routes, defaultRoute, config) {
201
249
  routes.forEach((route) => {
202
250
  routeToFile(route);
203
251
  });
204
- let routerPath = getCompletePath('router', null, config);
205
252
  routeFiles.push({
206
- name: routerPath,
253
+ name: getCompletePath('router', null, config),
207
254
  isRouterFile: true,
208
- content: genRouterFileContent(routes, defaultRoute),
255
+ content: genRouterFileContent(routes, defaultRoute, Object.assign({}, config, { asyncChunksMap })),
209
256
  });
210
- return routeFiles;
257
+ const { publicPath } = config;
258
+ return routeFiles.map(file => ({
259
+ ...file,
260
+ name: publicPath + file.name,
261
+ }));
211
262
  }
212
263
  async function genBundleFiles(app, frontend, config) {
213
264
  config.sysPrefixPath = app?.sysPrefixPath;
@@ -222,6 +273,7 @@ async function genBundleFiles(app, frontend, config) {
222
273
  const fnLowcodeDomain = config?.envLcpDomain?.[config?.env]?.lcpDomain || config?.lowcodeDomain;
223
274
  const modules = [];
224
275
  const views = [];
276
+ const isExport = !!config.isExport;
225
277
  const STATIC_URL = config.isExport ? '' : config.STATIC_URL;
226
278
  app.dependencies && modules.push(...app.dependencies);
227
279
  app.interfaceDependencies && modules.push(...app.interfaceDependencies);
@@ -289,24 +341,19 @@ async function genBundleFiles(app, frontend, config) {
289
341
  (0, nasl_log_1.clearLogs)(app);
290
342
  }
291
343
  }
292
- const getBundleFileName = () => {
293
- if (config.isPreviewFe && config.previewVersion) {
294
- return `mockBundle-${config.previewVersion}`;
295
- }
296
- else {
297
- return 'bundle';
298
- }
299
- };
300
- let baseUrl = `${config.USER_STATIC_URL}/${config.tenant}/${app.id}/${config.env}`;
301
- let { basePath } = frontend;
302
- if (config.isExport) {
303
- baseUrl = '';
304
- // basePath = '';
305
- }
306
- if (config.isPreviewFe) {
307
- baseUrl = `${config.USER_STATIC_URL}/asset-center/preview/${config.tenant}/${app.id}/${config.env}`;
344
+ // @ts-expect-error
345
+ const publicPath = (0, nasl_unified_frontend_generator_2.getPublicPath)(app, config, frontend);
346
+ /**
347
+ * 为什么要加这个呢,因为导出静态资源的场景下,所有资源都会经过一道loadJSWrap
348
+ * 这个loadJSWrap会补上统一前缀,但是不带端路径
349
+ * 所以client.js里的资源需要是:
350
+ * /packages/pc-ui/index.js
351
+ * /m/bundle.js
352
+ */
353
+ let basePath = frontend.basePath || '/';
354
+ if (!basePath.endsWith('/')) {
355
+ basePath += '/';
308
356
  }
309
- let completePath = `${baseUrl}${basePath || ''}/`;
310
357
  /**
311
358
  * vue.config.js page options
312
359
  */
@@ -346,11 +393,18 @@ async function genBundleFiles(app, frontend, config) {
346
393
  }
347
394
  }
348
395
  }
396
+ let fullPath = `/${viewName}`;
397
+ let parent = view.parentNode;
398
+ while (parent?.concept === 'View') {
399
+ fullPath = `/${parent.name}${fullPath}`;
400
+ parent = parent.parentNode;
401
+ }
349
402
  const route = {
350
403
  path: routePath,
351
404
  component: (0, compileComponent_1.compileComponent)(componentMap[view.id]),
352
405
  children: [],
353
406
  meta: view.getRouteMeta(),
407
+ fullPath,
354
408
  };
355
409
  const viewChildren = view.children;
356
410
  if (Array.isArray(viewChildren) && viewChildren.length) {
@@ -425,15 +479,7 @@ async function genBundleFiles(app, frontend, config) {
425
479
  // authResourcePathMap={}
426
480
  }
427
481
  const authResourcePaths = Object.keys(authResourcePathMap);
428
- const routerFiles = genRouteFiles(routes, defaultRoute, config);
429
- routerFiles.forEach(item => {
430
- let temp = completePath;
431
- // if(completePath=='/'){temp=''}else{temp = `${completePath}/`}
432
- if (config?.isExport && config?.sysPrefixPath?.length > 0) {
433
- temp = config?.sysPrefixPath + temp;
434
- }
435
- item.name = temp + item.name;
436
- });
482
+ const routerFiles = genRouteFiles(routes, defaultRoute, Object.assign({}, config, { app, publicPath }));
437
483
  let fileI18nInfo = {
438
484
  enabled: false,
439
485
  locale: 'zh-CN',
@@ -533,8 +579,6 @@ async function genBundleFiles(app, frontend, config) {
533
579
  }
534
580
  const assetsInfo = app.genAllAssetsInfo(STATIC_URL, frontend.type, frontendType.frameworkKind);
535
581
  const customNames = JSON5.stringify(assetsInfo.custom.names);
536
- let content1 = `(async function(){
537
- `;
538
582
  let contentScale = '';
539
583
  if (frontend.globalScaleEnabled)
540
584
  contentScale = `{
@@ -644,148 +688,6 @@ async function genBundleFiles(app, frontend, config) {
644
688
  let contentImport = `
645
689
  var platformConfig = ${platformConfig};
646
690
  var metaData = ${metaDataStr};
647
-
648
- var getCompletePath = (path) => {
649
- return '${config?.isExport ? config.sysPrefixPath : ''}${completePath}' + path;
650
- }
651
-
652
- function createErrorLayout(error) {
653
- if (!error || !error.stack) {
654
- return;
655
- }
656
- // 创建异常提示层
657
- const errorRoot = document.createElement('div');
658
- errorRoot.style.position = 'fixed';
659
- errorRoot.style.margin = '0 auto';
660
- errorRoot.style.width = '0';
661
- errorRoot.style.left = '0';
662
- errorRoot.style.right = '0';
663
- errorRoot.style.top = '10px';
664
-
665
- const errorItem = document.createElement('div');
666
- errorItem.style.width = '200px';
667
- errorItem.style.transform = 'translateX(-50%)';
668
- errorItem.style.backgroundColor = '#303030cc';
669
- errorItem.style.fontSize = '14px';
670
- errorItem.style.color = 'white';
671
- errorItem.style.borderRadius = '4px';
672
- errorItem.style.textAlign = 'center';
673
- errorItem.style.display = 'flex';
674
- errorItem.style.alignItems = 'center';
675
- errorItem.style.justifyContent = 'center';
676
-
677
- // 初始化异常文本
678
- const textDiv = document.createElement('div');
679
- textDiv.textContent = '初始化异常';
680
- textDiv.style.padding = '10px';
681
-
682
- // 复制按钮
683
- const copyDiv = document.createElement('div');
684
- copyDiv.textContent = '复制异常信息';
685
- copyDiv.style.position = 'relative';
686
- copyDiv.style.cursor = 'pointer';
687
- copyDiv.style.padding = '10px';
688
- copyDiv.onclick = function () {
689
- const message = '初始化异常提醒仅预览环境生效。出错堆栈信息如下:' + (error && error.stack);
690
- const input = document.createElement('input');
691
- input.style.position = 'fixed';
692
- input.style.top = '-10000px';
693
- input.style.zIndex = '-999';
694
- document.body.appendChild(input);
695
- input.value = message;
696
- input.focus();
697
- input.select();
698
- try {
699
- let result = document.execCommand('copy');
700
- document.body.removeChild(input);
701
- if (!result) {
702
- alert('复制失败');
703
- } else {
704
- alert('复制成功');
705
- }
706
- } catch {
707
- document.body.removeChild(input);
708
- alert('当前浏览器不支持复制功能,请检查更新或更换其他浏览器操作');
709
- }
710
- };
711
-
712
- // copy 按钮左侧竖线
713
- const before = document.createElement('span');
714
- before.style.position = 'absolute';
715
- before.style.top = '0';
716
- before.style.left = '0';
717
- before.style.width = '1px';
718
- before.style.height = '100%';
719
- before.style.opacity = '.5';
720
- before.style.background = 'currentColor';
721
- copyDiv.appendChild(before);
722
-
723
- errorItem.appendChild(textDiv);
724
- errorItem.appendChild(copyDiv);
725
- errorRoot.appendChild(errorItem);
726
-
727
- document.body.appendChild(errorRoot);
728
-
729
- // 3秒后自动隐藏
730
- setTimeout(() => {
731
- if (errorRoot.parentNode) {
732
- errorRoot.parentNode.removeChild(errorRoot);
733
- }
734
- }, 3000);
735
- }
736
-
737
- // 低版本
738
- function importXMLHttpRequestComponent (scriptUrl) {
739
- return new Promise(function(resolve, reject) {
740
- var xhr = new XMLHttpRequest();
741
- xhr.open('GET', scriptUrl, true);
742
- xhr.onreadystatechange = function() {
743
- if (xhr.readyState === 4) {
744
- if (xhr.status === 200) {
745
- var scriptContent = xhr.responseText;
746
- try {
747
- var func = new Function('importComponent', 'window', scriptContent + '\\n//# sourceURL=' + scriptUrl);
748
- var result = func(window.importComponent, window);
749
- resolve(result);
750
- } catch (error) {
751
- createErrorLayout(error);
752
- reject(error);
753
- }
754
- } else {
755
- reject(new Error('Failed to fetch script'));
756
- }
757
- }
758
- };
759
- xhr.send();
760
- });
761
- };
762
- function importFetchComponent(scriptUrl) {
763
- return fetch(scriptUrl)
764
- .then(function(response) {
765
- if (!response.ok) {
766
- throw new Error('Network response was not ok');
767
- }
768
- return response.text();
769
- }).then(function(scriptText) {
770
- var func = new Function('importComponent', 'window', scriptText + '\\n//# sourceURL=' + scriptUrl);
771
- var result = func(window.importComponent, window);
772
- return result;
773
- })
774
- .catch(error => {
775
- console.error('Error loading script:', error);
776
- createErrorLayout(error);
777
- });
778
- }
779
- window.importComponent = (scriptUrl) => {
780
- scriptUrl = getCompletePath(scriptUrl);
781
- // 浏览器支持fetch,直接使用fetch
782
- if (window.fetch) {
783
- return importFetchComponent(scriptUrl);
784
- }
785
- return importXMLHttpRequestComponent(scriptUrl);
786
- }
787
-
788
- var routes = await importComponent('${getCompletePath('router', null, config)}?t=' + Date.now());
789
691
  `;
790
692
  // 按页面维度发布先不考虑鉴权,页面维度新增的页面都算是不鉴权的数组中
791
693
  // 只有完全页面维度新增的才会进入到这个数组中
@@ -804,11 +706,11 @@ async function genBundleFiles(app, frontend, config) {
804
706
  }
805
707
  });
806
708
  }
807
- iterateRouters(routes);` : '';
709
+ iterateRouters(window.lcap_routes);` : '';
808
710
  let contentCreateLCAPApp = `
809
711
  window.createLcapApp = () => {
810
712
  ${compRegStr}
811
- appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, routes, metaData);
713
+ var appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, window.lcap_routes, metaData);
812
714
  try {
813
715
  var push = appVM.$router.history.push;
814
716
  appVM.$router.history.push = function (a, b) {
@@ -863,6 +765,8 @@ async function genBundleFiles(app, frontend, config) {
863
765
  curParentHID = incrementID;
864
766
  });
865
767
  window.addEventListener('popstate', function (e) {
768
+ // 如果有 state,但没有 HID,说明是未知跳转,不判定前进后退
769
+ if(e.state && e.state.HID === undefined) return;
866
770
  if(curHID > (e.state ? e.state.HID : undefined)){
867
771
  isBack = true;
868
772
  } else {
@@ -885,8 +789,6 @@ async function genBundleFiles(app, frontend, config) {
885
789
  if(shortcutIconLink) parent.document.head.appendChild(shortcutIconLink);
886
790
  }
887
791
  ` : '';
888
- let content10 = `
889
- })();`;
890
792
  let contentDevOnly = config.env === 'dev' ? `
891
793
  var _div = document.createElement('div');
892
794
  _div.classList = "div-load"
@@ -1002,10 +904,21 @@ async function genBundleFiles(app, frontend, config) {
1002
904
  };
1003
905
  fetchAnnoData();
1004
906
  ` : '';
1005
- let content = [content1, contentScale, contentStyleCss, contentDocIcon, contentCustomNames, contentImport,
1006
- contentLogReportCode, contentRouter, contentCreateLCAPApp, contentPCIframe, content10,
1007
- contentDevOnly, contentVueDirectives.join(''), contentViewElemAnno].join('');
1008
- content1 = null;
907
+ let content = [
908
+ `__webpack_require__('./router.js');`,
909
+ contentScale,
910
+ contentStyleCss,
911
+ contentDocIcon,
912
+ contentCustomNames,
913
+ contentImport,
914
+ contentLogReportCode,
915
+ contentRouter,
916
+ contentCreateLCAPApp,
917
+ contentPCIframe,
918
+ contentDevOnly,
919
+ contentVueDirectives.join(''),
920
+ contentViewElemAnno
921
+ ].join('');
1009
922
  contentScale = null;
1010
923
  contentStyleCss = null;
1011
924
  contentDocIcon = null;
@@ -1015,18 +928,35 @@ async function genBundleFiles(app, frontend, config) {
1015
928
  contentRouter = null;
1016
929
  contentCreateLCAPApp = null;
1017
930
  contentPCIframe = null;
1018
- content10 = null;
1019
931
  contentDevOnly = null;
1020
932
  contentVueDirectives = null;
1021
933
  contentViewElemAnno = null;
934
+ const timeStamp = Date.now();
1022
935
  utils.delay(100);
1023
- let bundleMinPath = completePath + getCompletePath(getBundleFileName(), content, config);
936
+ content = (0, chunk_1.generate)({
937
+ name: app.name,
938
+ chunkId: 'bundle',
939
+ moduleId: 'bundle',
940
+ content,
941
+ exports: [],
942
+ exec: true,
943
+ });
944
+ const routerFileName = getCompletePath('router', null, config);
945
+ const bundleFileName = getCompletePath(getBundleFileName(config), content, config);
946
+ let clientPath = publicPath + 'client.js';
947
+ let runtimePath = publicPath + 'runtime.js';
948
+ let routerPath = publicPath + routerFileName;
949
+ let bundleMinPath = publicPath + bundleFileName;
1024
950
  const otherJsList = frontend?.appletsConfig?.enable ? ['//res.wx.qq.com/open/js/jweixin-1.3.2.js'] : [];
1025
951
  const microAppIntegration = (0, microApp_1.integrateMicroApp)(frontend);
1026
952
  if (config?.debug) {
1027
953
  otherJsList.push(`${STATIC_URL}/packages/@lcap/breakpoint-client@1.0.0/dist/index.js?time=${Date.now()}`);
1028
954
  }
1029
- let jsAssetsList = assetsInfo.basic.js.concat(assetsInfo.custom.js, otherJsList).concat([bundleMinPath]);
955
+ let jsAssetsList = assetsInfo.basic.js.concat(assetsInfo.custom.js, otherJsList).concat([
956
+ isExport ? (basePath + 'runtime.js') : runtimePath,
957
+ (isExport ? (basePath + routerFileName) : routerPath) + `?t=${timeStamp}`,
958
+ isExport ? (basePath + bundleFileName) : bundleMinPath,
959
+ ]);
1030
960
  let cssAssetsList = assetsInfo.basic.css.concat(assetsInfo.custom.css);
1031
961
  if (config.isPreviewFe) {
1032
962
  const changeToRelativePath = (str) => {
@@ -1190,18 +1120,26 @@ async function genBundleFiles(app, frontend, config) {
1190
1120
  `;
1191
1121
  const outputs = [
1192
1122
  {
1193
- name: bundleMinPath,
1194
- content,
1123
+ name: clientPath,
1124
+ content: assetsContent,
1195
1125
  },
1196
1126
  {
1197
- name: basePath ? `${baseUrl}${basePath}/client.js` : `${baseUrl}/client.js`,
1198
- content: assetsContent,
1127
+ name: runtimePath,
1128
+ content: (0, runtime_1.generate)({
1129
+ name: app.name,
1130
+ publicPath: JSON.stringify(publicPath),
1131
+ }),
1132
+ },
1133
+ {
1134
+ name: bundleMinPath,
1135
+ content,
1199
1136
  },
1200
1137
  ...routerFiles,
1201
1138
  ];
1202
1139
  assetsContent = null;
1203
1140
  content = null;
1204
1141
  processAssetsInOutputs(outputs, frontend, config);
1142
+ console.info('编译结果', outputs.map((x) => x.name));
1205
1143
  return outputs;
1206
1144
  }
1207
1145
  exports.genBundleFiles = genBundleFiles;
@@ -1273,9 +1211,8 @@ async function traverseForToVueOptions(start, cb) {
1273
1211
  }
1274
1212
  utils.timeSlicingWithGenerator(__traverse(start));
1275
1213
  }
1276
- function getOneFiles(options) {
1277
- const { view, action, cacheRouters } = options;
1278
- const frontend = view.frontend;
1214
+ async function getOneFiles(options) {
1215
+ const { app, frontend, view, action, cacheRouters, config } = options;
1279
1216
  /**
1280
1217
  * 几种情况
1281
1218
  * 1.完全新增了页面从顶层到下面都是新的页面, 发顶层 (仅自己 和 )
@@ -1293,16 +1230,23 @@ function getOneFiles(options) {
1293
1230
  if (isRootView) {
1294
1231
  routePath = `${frontend.prefixPath}/${viewName}`;
1295
1232
  }
1233
+ let fullPath = `/${viewName}`;
1234
+ let parent = view.parentNode;
1235
+ while (parent?.concept === 'View') {
1236
+ fullPath = `/${parent.name}${fullPath}`;
1237
+ parent = parent.parentNode;
1238
+ }
1296
1239
  const route = {
1297
1240
  path: routePath,
1298
1241
  component: (0, compileComponent_1.compileComponent)(viewOption),
1299
1242
  children: [],
1300
1243
  meta: view.getRouteMeta(),
1244
+ fullPath,
1301
1245
  };
1302
1246
  return route;
1303
1247
  }
1304
- let currentView = view;
1305
1248
  let currentRoute = null;
1249
+ let currentView = view;
1306
1250
  while (currentView?.concept === 'View') {
1307
1251
  if (currentRoute) {
1308
1252
  const child = currentRoute;
@@ -1336,6 +1280,7 @@ function getOneFiles(options) {
1336
1280
  // 如果找到了现有路由,更新 component 和 meta
1337
1281
  existingRoute.component = newRoute.component;
1338
1282
  existingRoute.meta = newRoute.meta;
1283
+ existingRoute.fullPath = newRoute.fullPath;
1339
1284
  // 递归合并子路由
1340
1285
  if (newRoute.children) {
1341
1286
  existingRoute.children = existingRoute.children || [];
@@ -1361,13 +1306,29 @@ function getOneFiles(options) {
1361
1306
  // 直接推入新路由
1362
1307
  routes.unshift(newRoute);
1363
1308
  }
1309
+ let existingRoutes = [];
1310
+ try {
1311
+ // 获取// lcap_routes start 到 // lcap_routes end 之间的代码
1312
+ const [start, end] = ['// lcap_routes start', '// lcap_routes end'];
1313
+ const routesCode = cacheRouters
1314
+ .substring(cacheRouters.indexOf(start) + start.length, cacheRouters.indexOf(end))
1315
+ .replace('window.lcap_routes = ', 'return ');
1316
+ const fn = new Function(`${routesCode}`);
1317
+ existingRoutes = fn();
1318
+ }
1319
+ catch (error) {
1320
+ console.error('路由代码 eval 失败:', error);
1321
+ }
1364
1322
  if (action === 'all') {
1365
- coverUpdateRoute(cacheRouters, currentRoute);
1323
+ coverUpdateRoute(existingRoutes, currentRoute);
1366
1324
  }
1367
1325
  else {
1368
- addOrUpdateRoute(cacheRouters, currentRoute);
1326
+ addOrUpdateRoute(existingRoutes, currentRoute);
1369
1327
  }
1370
- const routerFiles = genRouteFiles(cacheRouters, null);
1328
+ // @ts-expect-error
1329
+ const publicPath = (0, nasl_unified_frontend_generator_2.getPublicPath)(app, config, frontend);
1330
+ const routerFiles = genRouteFiles(existingRoutes, null, Object.assign({}, config, { app, cacheRouters, isOneFile: true, publicPath }));
1331
+ console.info('编译结果', routerFiles.map((x) => x.name));
1371
1332
  return routerFiles;
1372
1333
  }
1373
1334
  exports.getOneFiles = getOneFiles;
@@ -1387,7 +1348,10 @@ function findAndReplaceStaticResources(text, callback) {
1387
1348
  protocolPositions.push(match1.index);
1388
1349
  }
1389
1350
  // 静态资源后缀
1390
- const imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'tiff', 'svg', 'ico', 'heic', 'heif', 'avif', 'mp4', 'mkv', 'mov', 'avi', 'wmv', 'flv', 'webm', 'm4v'];
1351
+ const imageExtensions = [
1352
+ 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'tiff', 'svg', 'ico', 'heic', 'heif', 'avif', 'mp4', 'mkv', 'mov', 'avi', 'wmv', 'flv', 'webm', 'm4v',
1353
+ 'xlsx', 'xls', 'csv', 'docx', 'doc', 'pdf', 'pptx', 'ppt', 'md', 'java', 'py', 'js', 'yml', 'conf', 'json', 'xml',
1354
+ ];
1391
1355
  const extensionPattern = new RegExp(`\\.(${imageExtensions.join('|')})`, 'gi');
1392
1356
  const extensionPositions = [];
1393
1357
  let match2;
@@ -1419,11 +1383,10 @@ function findAndReplaceStaticResources(text, callback) {
1419
1383
  return modifiedText;
1420
1384
  }
1421
1385
  function processAssetsInOutputs(outputs, frontend, config) {
1422
- const assets = config.assets;
1386
+ const assetsMap = config.assetsMap;
1423
1387
  // 导出源码才处理
1424
- if (config.isExport && Array.isArray(assets) && assets.length) {
1388
+ if (config.isExport && assetsMap?.size) {
1425
1389
  function replaceContentFilePath(content) {
1426
- const assetsMap = config.assetsMap;
1427
1390
  content = findAndReplaceStaticResources(content, (url) => {
1428
1391
  const asset = utils.getAssetFromAssetsMap(assetsMap, url);
1429
1392
  if (asset) {
@@ -1459,4 +1422,13 @@ function processAssetsInOutputs(outputs, frontend, config) {
1459
1422
  });
1460
1423
  }
1461
1424
  }
1425
+ function getBundleFileName(config) {
1426
+ if (config.isPreviewFe && config.previewVersion) {
1427
+ return `mockBundle-${config.previewVersion}`;
1428
+ }
1429
+ else {
1430
+ return 'bundle';
1431
+ }
1432
+ }
1433
+ ;
1462
1434
  //# sourceMappingURL=genBundleFiles.js.map