@dckj-npm/lowcode-plugin-code-generator 1.2.6 → 1.2.8

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.
@@ -6,8 +6,8 @@ import React, { useState } from 'react';
6
6
  import * as CodeGenerator from '@dckj-npm/lowcode-code-generator/standalone-loader';
7
7
  import { Button, Drawer, Loading, Message } from '@alifd/next';
8
8
  import coerce from 'semver/functions/coerce';
9
- import { project } from '@alilc/lowcode-engine';
10
9
  import { CodeGenResult } from '../CodeGenResult';
10
+ import { getAllSchemaByResourceList, getProjectId, getResourceListFromLocalStorage } from "../../utils/utils";
11
11
  export function CodeGenActionBtn(_ref) {
12
12
  var ctx = _ref.ctx;
13
13
  var _useState = useState({
@@ -23,7 +23,7 @@ export function CodeGenActionBtn(_ref) {
23
23
  setState = _useState[1];
24
24
  var handleClick = /*#__PURE__*/function () {
25
25
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
26
- var originalSchema, schema, result;
26
+ var name, resourceList, allSchema, result;
27
27
  return _regeneratorRuntime.wrap(function _callee$(_context) {
28
28
  while (1) switch (_context.prev = _context.next) {
29
29
  case 0:
@@ -38,38 +38,45 @@ export function CodeGenActionBtn(_ref) {
38
38
  });
39
39
 
40
40
  // 获取 schema,并修正
41
- _context.next = 4;
42
- return project.exportSchema();
43
- case 4:
44
- originalSchema = _context.sent;
45
- console.log('ctx ', ctx);
41
+ // const originalSchema = await project.exportSchema();
42
+ name = getProjectId();
43
+ _context.next = 5;
44
+ return getResourceListFromLocalStorage(name);
45
+ case 5:
46
+ resourceList = _context.sent;
47
+ _context.next = 8;
48
+ return getAllSchemaByResourceList(name, resourceList);
49
+ case 8:
50
+ allSchema = _context.sent;
51
+ _context.next = 11;
52
+ return Promise.all(allSchema.map(function (item) {
53
+ return fixSchema(item);
54
+ }));
55
+ case 11:
56
+ allSchema = _context.sent;
57
+ // console.log('ctx ', ctx)
46
58
  // console.log('isActive ', ctx.workspace.isActive)
47
59
  // console.log('window.exportSchema ', ctx.workspace.window.exportSchema())
48
60
  // console.log('skeleton ', ctx.workspace.skeleton)
49
61
  // console.log('windows ', ctx.workspace.windows)
50
62
  // const originalSchema2 = await ctx.project.exportSchema();
51
- _context.next = 8;
52
- return fixSchema(originalSchema);
53
- case 8:
54
- schema = _context.sent;
63
+ // const schema = await fixSchema(originalSchema);
55
64
  console.log('got schema:222222 ', schema);
56
65
  // console.log('got schema:33333333 ', originalSchema2);
57
66
 
58
67
  setState(function (prev) {
59
- return _extends({}, prev, {
60
- schema: schema,
61
- originalSchema: originalSchema
62
- });
68
+ return _extends({}, prev);
63
69
  });
64
70
 
65
71
  // 出码...
66
- _context.next = 13;
72
+ _context.next = 16;
67
73
  return CodeGenerator.generateCode({
68
74
  solution: 'vuejs3',
69
- schema: schema,
70
- flattenResult: true
75
+ schema: allSchema,
76
+ flattenResult: true,
77
+ resourceList: resourceList
71
78
  });
72
- case 13:
79
+ case 16:
73
80
  result = _context.sent;
74
81
  console.log('generated: ', result);
75
82
  setState(function (prev) {
@@ -78,10 +85,10 @@ export function CodeGenActionBtn(_ref) {
78
85
  result: result
79
86
  });
80
87
  });
81
- _context.next = 22;
88
+ _context.next = 25;
82
89
  break;
83
- case 18:
84
- _context.prev = 18;
90
+ case 21:
91
+ _context.prev = 21;
85
92
  _context.t0 = _context["catch"](0);
86
93
  console.error('failed to run code generator: ', _context.t0);
87
94
  setState(function (prev) {
@@ -90,11 +97,11 @@ export function CodeGenActionBtn(_ref) {
90
97
  error: _context.t0 instanceof Error ? _context.t0 : new Error("" + ((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0))
91
98
  });
92
99
  });
93
- case 22:
100
+ case 25:
94
101
  case "end":
95
102
  return _context.stop();
96
103
  }
97
- }, _callee, null, [[0, 18]]);
104
+ }, _callee, null, [[0, 21]]);
98
105
  }));
99
106
  return function handleClick() {
100
107
  return _ref2.apply(this, arguments);
@@ -5,3 +5,12 @@ export declare type SyncCodeGenResult = {
5
5
  content: string;
6
6
  }>;
7
7
  };
8
+ /**
9
+ * 页面参数
10
+ */
11
+ export interface ResourceListType {
12
+ title: string;
13
+ slug: string;
14
+ id: string;
15
+ firstPage: 'true' | 'false';
16
+ }
@@ -0,0 +1,26 @@
1
+ import { ResourceListType } from "../types";
2
+ import { IPublicTypeProjectSchema } from "@alilc/lowcode-types";
3
+ /**
4
+ * 从缓存获取ResourceList
5
+ * @param scenarioName
6
+ */
7
+ export declare const getResourceListFromLocalStorage: (scenarioName: string) => Promise<ResourceListType[]>;
8
+ /**
9
+ * 根据ResourceList获取所有schema
10
+ * @param scenarioName
11
+ * @param ResourceList
12
+ */
13
+ export declare const getAllSchemaByResourceList: (scenarioName: string, ResourceList: ResourceListType[]) => Promise<IPublicTypeProjectSchema[]>;
14
+ export declare const getResourceName: (scenarioName: string, ns?: string) => string;
15
+ /**
16
+ * 获取项目id
17
+ */
18
+ export declare function getProjectId(): string;
19
+ /**
20
+ * 获取地址栏参数值
21
+ * @param queryName
22
+ * @param defaultValue
23
+ * @returns {string}
24
+ */
25
+ export declare function getValueFromQueryByName(queryName: string, defaultValue?: string): string;
26
+ export declare const getLSName: (scenarioName: string, id?: string, ns?: string) => string;
@@ -0,0 +1,95 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ /**
4
+ * 从缓存获取ResourceList
5
+ * @param scenarioName
6
+ */
7
+ export var getResourceListFromLocalStorage = /*#__PURE__*/function () {
8
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(scenarioName) {
9
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
10
+ while (1) switch (_context.prev = _context.next) {
11
+ case 0:
12
+ if (scenarioName) {
13
+ _context.next = 3;
14
+ break;
15
+ }
16
+ console.error('scenarioName is required!');
17
+ return _context.abrupt("return");
18
+ case 3:
19
+ return _context.abrupt("return", JSON.parse(window.localStorage.getItem(getResourceName(scenarioName)) || '[{"title":"首页","slug":"index","id": "index"}]'));
20
+ case 4:
21
+ case "end":
22
+ return _context.stop();
23
+ }
24
+ }, _callee);
25
+ }));
26
+ return function getResourceListFromLocalStorage(_x) {
27
+ return _ref.apply(this, arguments);
28
+ };
29
+ }();
30
+
31
+ /**
32
+ * 根据ResourceList获取所有schema
33
+ * @param scenarioName
34
+ * @param ResourceList
35
+ */
36
+ export var getAllSchemaByResourceList = /*#__PURE__*/function () {
37
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(scenarioName, ResourceList) {
38
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
39
+ while (1) switch (_context2.prev = _context2.next) {
40
+ case 0:
41
+ if (ResourceList) {
42
+ _context2.next = 3;
43
+ break;
44
+ }
45
+ console.error('ResourceList is required!');
46
+ return _context2.abrupt("return");
47
+ case 3:
48
+ return _context2.abrupt("return", ResourceList.map(function (item) {
49
+ return JSON.parse(window.localStorage.getItem(getLSName(scenarioName, item.id)) || '{}');
50
+ }));
51
+ case 4:
52
+ case "end":
53
+ return _context2.stop();
54
+ }
55
+ }, _callee2);
56
+ }));
57
+ return function getAllSchemaByResourceList(_x2, _x3) {
58
+ return _ref2.apply(this, arguments);
59
+ };
60
+ }();
61
+ export var getResourceName = function getResourceName(scenarioName, ns) {
62
+ if (ns === void 0) {
63
+ ns = 'resourceList';
64
+ }
65
+ return scenarioName + ":" + ns;
66
+ };
67
+
68
+ /**
69
+ * 获取项目id
70
+ */
71
+ export function getProjectId() {
72
+ return getValueFromQueryByName('projectId', 'general');
73
+ }
74
+
75
+ /**
76
+ * 获取地址栏参数值
77
+ * @param queryName
78
+ * @param defaultValue
79
+ * @returns {string}
80
+ */
81
+ export function getValueFromQueryByName(queryName, defaultValue) {
82
+ if (defaultValue === void 0) {
83
+ defaultValue = '';
84
+ }
85
+ if (location.search) {
86
+ return new URLSearchParams(location.search.slice(1)).get(queryName) || defaultValue;
87
+ }
88
+ return defaultValue;
89
+ }
90
+ export var getLSName = function getLSName(scenarioName, id, ns) {
91
+ if (ns === void 0) {
92
+ ns = 'projectSchema';
93
+ }
94
+ return scenarioName + ":" + id + ":" + ns;
95
+ };
@@ -12,8 +12,8 @@ var _react = _interopRequireWildcard(require("react"));
12
12
  var CodeGenerator = _interopRequireWildcard(require("@dckj-npm/lowcode-code-generator/standalone-loader"));
13
13
  var _next = require("@alifd/next");
14
14
  var _coerce = _interopRequireDefault(require("semver/functions/coerce"));
15
- var _lowcodeEngine = require("@alilc/lowcode-engine");
16
15
  var _CodeGenResult = require("../CodeGenResult");
16
+ var _utils = require("../../utils/utils");
17
17
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
18
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
19
19
  function CodeGenActionBtn(_ref) {
@@ -31,7 +31,7 @@ function CodeGenActionBtn(_ref) {
31
31
  setState = _useState[1];
32
32
  var handleClick = /*#__PURE__*/function () {
33
33
  var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
34
- var originalSchema, schema, result;
34
+ var name, resourceList, allSchema, result;
35
35
  return _regenerator["default"].wrap(function _callee$(_context) {
36
36
  while (1) switch (_context.prev = _context.next) {
37
37
  case 0:
@@ -46,38 +46,45 @@ function CodeGenActionBtn(_ref) {
46
46
  });
47
47
 
48
48
  // 获取 schema,并修正
49
- _context.next = 4;
50
- return _lowcodeEngine.project.exportSchema();
51
- case 4:
52
- originalSchema = _context.sent;
53
- console.log('ctx ', ctx);
49
+ // const originalSchema = await project.exportSchema();
50
+ name = (0, _utils.getProjectId)();
51
+ _context.next = 5;
52
+ return (0, _utils.getResourceListFromLocalStorage)(name);
53
+ case 5:
54
+ resourceList = _context.sent;
55
+ _context.next = 8;
56
+ return (0, _utils.getAllSchemaByResourceList)(name, resourceList);
57
+ case 8:
58
+ allSchema = _context.sent;
59
+ _context.next = 11;
60
+ return Promise.all(allSchema.map(function (item) {
61
+ return fixSchema(item);
62
+ }));
63
+ case 11:
64
+ allSchema = _context.sent;
65
+ // console.log('ctx ', ctx)
54
66
  // console.log('isActive ', ctx.workspace.isActive)
55
67
  // console.log('window.exportSchema ', ctx.workspace.window.exportSchema())
56
68
  // console.log('skeleton ', ctx.workspace.skeleton)
57
69
  // console.log('windows ', ctx.workspace.windows)
58
70
  // const originalSchema2 = await ctx.project.exportSchema();
59
- _context.next = 8;
60
- return fixSchema(originalSchema);
61
- case 8:
62
- schema = _context.sent;
71
+ // const schema = await fixSchema(originalSchema);
63
72
  console.log('got schema:222222 ', schema);
64
73
  // console.log('got schema:33333333 ', originalSchema2);
65
74
 
66
75
  setState(function (prev) {
67
- return (0, _extends2["default"])({}, prev, {
68
- schema: schema,
69
- originalSchema: originalSchema
70
- });
76
+ return (0, _extends2["default"])({}, prev);
71
77
  });
72
78
 
73
79
  // 出码...
74
- _context.next = 13;
80
+ _context.next = 16;
75
81
  return CodeGenerator.generateCode({
76
82
  solution: 'vuejs3',
77
- schema: schema,
78
- flattenResult: true
83
+ schema: allSchema,
84
+ flattenResult: true,
85
+ resourceList: resourceList
79
86
  });
80
- case 13:
87
+ case 16:
81
88
  result = _context.sent;
82
89
  console.log('generated: ', result);
83
90
  setState(function (prev) {
@@ -86,10 +93,10 @@ function CodeGenActionBtn(_ref) {
86
93
  result: result
87
94
  });
88
95
  });
89
- _context.next = 22;
96
+ _context.next = 25;
90
97
  break;
91
- case 18:
92
- _context.prev = 18;
98
+ case 21:
99
+ _context.prev = 21;
93
100
  _context.t0 = _context["catch"](0);
94
101
  console.error('failed to run code generator: ', _context.t0);
95
102
  setState(function (prev) {
@@ -98,11 +105,11 @@ function CodeGenActionBtn(_ref) {
98
105
  error: _context.t0 instanceof Error ? _context.t0 : new Error("" + ((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0))
99
106
  });
100
107
  });
101
- case 22:
108
+ case 25:
102
109
  case "end":
103
110
  return _context.stop();
104
111
  }
105
- }, _callee, null, [[0, 18]]);
112
+ }, _callee, null, [[0, 21]]);
106
113
  }));
107
114
  return function handleClick() {
108
115
  return _ref2.apply(this, arguments);
@@ -5,3 +5,12 @@ export declare type SyncCodeGenResult = {
5
5
  content: string;
6
6
  }>;
7
7
  };
8
+ /**
9
+ * 页面参数
10
+ */
11
+ export interface ResourceListType {
12
+ title: string;
13
+ slug: string;
14
+ id: string;
15
+ firstPage: 'true' | 'false';
16
+ }
@@ -0,0 +1,26 @@
1
+ import { ResourceListType } from "../types";
2
+ import { IPublicTypeProjectSchema } from "@alilc/lowcode-types";
3
+ /**
4
+ * 从缓存获取ResourceList
5
+ * @param scenarioName
6
+ */
7
+ export declare const getResourceListFromLocalStorage: (scenarioName: string) => Promise<ResourceListType[]>;
8
+ /**
9
+ * 根据ResourceList获取所有schema
10
+ * @param scenarioName
11
+ * @param ResourceList
12
+ */
13
+ export declare const getAllSchemaByResourceList: (scenarioName: string, ResourceList: ResourceListType[]) => Promise<IPublicTypeProjectSchema[]>;
14
+ export declare const getResourceName: (scenarioName: string, ns?: string) => string;
15
+ /**
16
+ * 获取项目id
17
+ */
18
+ export declare function getProjectId(): string;
19
+ /**
20
+ * 获取地址栏参数值
21
+ * @param queryName
22
+ * @param defaultValue
23
+ * @returns {string}
24
+ */
25
+ export declare function getValueFromQueryByName(queryName: string, defaultValue?: string): string;
26
+ export declare const getLSName: (scenarioName: string, id?: string, ns?: string) => string;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.getLSName = exports.getAllSchemaByResourceList = void 0;
6
+ exports.getProjectId = getProjectId;
7
+ exports.getResourceName = exports.getResourceListFromLocalStorage = void 0;
8
+ exports.getValueFromQueryByName = getValueFromQueryByName;
9
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ /**
12
+ * 从缓存获取ResourceList
13
+ * @param scenarioName
14
+ */
15
+ var getResourceListFromLocalStorage = exports.getResourceListFromLocalStorage = /*#__PURE__*/function () {
16
+ var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(scenarioName) {
17
+ return _regenerator["default"].wrap(function _callee$(_context) {
18
+ while (1) switch (_context.prev = _context.next) {
19
+ case 0:
20
+ if (scenarioName) {
21
+ _context.next = 3;
22
+ break;
23
+ }
24
+ console.error('scenarioName is required!');
25
+ return _context.abrupt("return");
26
+ case 3:
27
+ return _context.abrupt("return", JSON.parse(window.localStorage.getItem(getResourceName(scenarioName)) || '[{"title":"首页","slug":"index","id": "index"}]'));
28
+ case 4:
29
+ case "end":
30
+ return _context.stop();
31
+ }
32
+ }, _callee);
33
+ }));
34
+ return function getResourceListFromLocalStorage(_x) {
35
+ return _ref.apply(this, arguments);
36
+ };
37
+ }();
38
+
39
+ /**
40
+ * 根据ResourceList获取所有schema
41
+ * @param scenarioName
42
+ * @param ResourceList
43
+ */
44
+ var getAllSchemaByResourceList = exports.getAllSchemaByResourceList = /*#__PURE__*/function () {
45
+ var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(scenarioName, ResourceList) {
46
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
47
+ while (1) switch (_context2.prev = _context2.next) {
48
+ case 0:
49
+ if (ResourceList) {
50
+ _context2.next = 3;
51
+ break;
52
+ }
53
+ console.error('ResourceList is required!');
54
+ return _context2.abrupt("return");
55
+ case 3:
56
+ return _context2.abrupt("return", ResourceList.map(function (item) {
57
+ return JSON.parse(window.localStorage.getItem(getLSName(scenarioName, item.id)) || '{}');
58
+ }));
59
+ case 4:
60
+ case "end":
61
+ return _context2.stop();
62
+ }
63
+ }, _callee2);
64
+ }));
65
+ return function getAllSchemaByResourceList(_x2, _x3) {
66
+ return _ref2.apply(this, arguments);
67
+ };
68
+ }();
69
+ var getResourceName = exports.getResourceName = function getResourceName(scenarioName, ns) {
70
+ if (ns === void 0) {
71
+ ns = 'resourceList';
72
+ }
73
+ return scenarioName + ":" + ns;
74
+ };
75
+
76
+ /**
77
+ * 获取项目id
78
+ */
79
+ function getProjectId() {
80
+ return getValueFromQueryByName('projectId', 'general');
81
+ }
82
+
83
+ /**
84
+ * 获取地址栏参数值
85
+ * @param queryName
86
+ * @param defaultValue
87
+ * @returns {string}
88
+ */
89
+ function getValueFromQueryByName(queryName, defaultValue) {
90
+ if (defaultValue === void 0) {
91
+ defaultValue = '';
92
+ }
93
+ if (location.search) {
94
+ return new URLSearchParams(location.search.slice(1)).get(queryName) || defaultValue;
95
+ }
96
+ return defaultValue;
97
+ }
98
+ var getLSName = exports.getLSName = function getLSName(scenarioName, id, ns) {
99
+ if (ns === void 0) {
100
+ ns = 'projectSchema';
101
+ }
102
+ return scenarioName + ":" + id + ":" + ns;
103
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dckj-npm/lowcode-plugin-code-generator",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "集团低代码引擎 - 浏览器出码插件",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -35,7 +35,7 @@
35
35
  "@alilc/lowcode-code-generator": "^1.0.4",
36
36
  "@alilc/lowcode-plugin-base-monaco-editor": "^1.0.0",
37
37
  "@alilc/lowcode-types": "^1.0.0",
38
- "@dckj-npm/lowcode-code-generator": "^1.2.11",
38
+ "@dckj-npm/lowcode-code-generator": "^1.2.13",
39
39
  "@types/file-saver": "^2.0.4",
40
40
  "@types/js-base64": "^3.3.1",
41
41
  "@types/string-natural-compare": "^3.0.2",