@nasl/cli 0.1.1 → 0.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,23 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <title>NASL Preview</title>
7
+ <!-- <script src="https://ide-sandbox.lcap.codewave-test.163yun.com/dependency/lodash@4.17.21/lodash.js"></script> -->
8
+ <script src="https://ide-sandbox.lcap.codewave-test.163yun.com/dependency/vue@3.5.13/umd/vue.global.js"></script>
9
+ <script src="https://ide-sandbox.lcap.codewave-test.163yun.com/dependency/vue-router@4.5.0/umd/vue-router.global.js"></script>
10
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/pc-template-vue3@2.1.0/cloudAdminDesigner.umd.min.js"></script>
11
+ <link rel="stylesheet" type="text/css" href="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/element-plus@1.0.0/dist-theme/index.css" />
12
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/element-plus@1.0.0/dist-theme/index.js"></script>
13
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/element-plus@1.0.0/dist-theme/nasl.ui.json"></script>
14
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/element-plus@1.0.0/dist-theme/i18n.json"></script>
15
+ <link rel="stylesheet" type="text/css" href="//minio-api.codewave-test.163yun.com/lowcode-static/packages/extension/cw_chart_js@0.2.2/dist-theme/index.css" />
16
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/extension/cw_chart_js@0.2.2/dist-theme/index.js"></script>
17
+ <script src="./nasl.bundle.js"></script>
18
+ <!-- webpack will inject bundle.js here -->
19
+ </head>
20
+ <body>
21
+ <div id="app"></div>
22
+ </body>
23
+ </html>
package/build/index.js ADDED
@@ -0,0 +1,109 @@
1
+ import { platformConfig } from './platformConfig';
2
+ import { get, pick } from 'lodash';
3
+
4
+ // 加载应用所需的文件
5
+ import '@/backendMock';
6
+ import { routes, metaData } from '@/router';
7
+ import '@/index.css';
8
+
9
+ // 应用初始化
10
+ class AppHandler {
11
+ constructor() {}
12
+
13
+ // 处理路由相关
14
+ handleRouter() {
15
+ messager.sendCommand('getRoutes', [JSON.stringify(routes)]);
16
+ window.afterRouter = async (to, from) => {
17
+ try {
18
+ // 获取 messager 实例
19
+ const messager = window.messager;
20
+ if (messager && typeof messager.sendCommand === 'function') {
21
+ await messager.sendCommand('routeChanged', to.path);
22
+ }
23
+ } catch (err) {
24
+ console.error('路由变化处理失败:', err);
25
+ }
26
+ };
27
+ }
28
+
29
+ initLogic(options = {}, Basic) {
30
+ const { logicsMap, backendApp } = options;
31
+ const logics = {};
32
+ const context = {
33
+ app: backendApp
34
+ };
35
+
36
+ const entityRE = /entities\.(\w+?)\.logics/;
37
+
38
+ Object.keys(logicsMap).forEach((path) => {
39
+ const isEntity = entityRE.test(path);
40
+ const backendPath = path.replace(entityRE, 'entities.$1Entity');
41
+ const prevPath = backendPath.split('.').slice(0, -1).join('.');
42
+
43
+ logics[path] = async function ({ query, body }) {
44
+ const func = get(context, backendPath);
45
+ const obj = get(context, prevPath);
46
+ body = body === undefined ? undefined : JSON.parse(JSON.stringify(body));
47
+
48
+ let result;
49
+ if (isEntity) {
50
+ if (path.endsWith('.get') || path.endsWith('.delete')) {
51
+ query = query === undefined ? undefined : JSON.parse(JSON.stringify(query));
52
+ result = func.call(obj, Object.values(query)[0]);
53
+ } else if (path.endsWith('.update')) {
54
+ if (body.properties) {
55
+ if (body.entity) body.entity = pick(body.entity, body.properties);
56
+ if (body.entities) body.entities = body.entities.map((entity) => pick(entity, body.properties));
57
+ }
58
+ result = func.call(obj, body.entity);
59
+ } else {
60
+ result = func.call(obj, body);
61
+ }
62
+ } else {
63
+ const argNames =
64
+ func
65
+ .toString()
66
+ .match(/function\s*\w*\((.*?)\)/)?.[1]
67
+ ?.split(',')
68
+ .map((name) => name.replace(/=.*$/, '').trim()) || [];
69
+ const args = argNames.map((name) => body[name]);
70
+ result = func.call(obj, ...args);
71
+ }
72
+
73
+ return result === undefined ? undefined : JSON.parse(JSON.stringify(result));
74
+ };
75
+ });
76
+
77
+ Basic.Config.globalProperties.set('$logics', logics);
78
+
79
+ return {
80
+ logics
81
+ };
82
+ }
83
+
84
+ async initialize() {
85
+ window.lcapStandardUI = window.ElementPlus;
86
+ try {
87
+ // this.handleRouter();
88
+ const override = {
89
+ enabled: true,
90
+ initLogic: this.initLogic,
91
+ };
92
+ window.LcapVueRouterConfig = {
93
+ mode: 'abstract'
94
+ };
95
+ let app = await window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, routes, { ...metaData, backendApp: window.backendApp, override });
96
+ app.use(window.Cw_chart_js);
97
+ app.use(window.ElementPlus);
98
+ } catch (error) {
99
+ console.error('Failed to initialize: sandbox:\n', error);
100
+ }
101
+ console.log('应用初始化完成');
102
+ }
103
+ }
104
+
105
+ // 启动应用
106
+ const appHandler = new AppHandler();
107
+ appHandler.initialize().catch((error) => {
108
+ console.error('应用初始化失败:', error);
109
+ });