@lcap/nasl 0.3.10 → 0.3.11

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.
Files changed (194) hide show
  1. package/out/service/app/api.d.ts +1 -15
  2. package/out/service/app/api.js +7 -17
  3. package/out/service/app/api.js.map +1 -1
  4. package/out/service/create/errHandles.js +19 -2
  5. package/out/service/create/errHandles.js.map +1 -1
  6. package/out/service/create/index.js +5 -0
  7. package/out/service/create/index.js.map +1 -1
  8. package/out/service/logic/logic.d.ts +50 -14
  9. package/out/service/logic/logic.js +26 -0
  10. package/out/service/logic/logic.js.map +1 -1
  11. package/out/service/page/element.d.ts +9 -0
  12. package/out/service/page/element.js +6 -0
  13. package/out/service/page/element.js.map +1 -1
  14. package/out/service/permission/api.d.ts +57 -0
  15. package/out/service/permission/api.js +41 -0
  16. package/out/service/permission/api.js.map +1 -0
  17. package/out/service/permission/index.d.ts +2 -0
  18. package/out/service/permission/index.js +17 -0
  19. package/out/service/permission/index.js.map +1 -0
  20. package/out/service/webFile/index.js +5 -0
  21. package/out/service/webFile/index.js.map +1 -1
  22. package/out/types/app/App.d.ts +13 -0
  23. package/out/types/app/App.js +55 -1
  24. package/out/types/app/App.js.map +1 -1
  25. package/out/types/app/History.js +3 -2
  26. package/out/types/app/History.js.map +1 -1
  27. package/out/types/app/Service.d.ts +5 -2
  28. package/out/types/app/Service.js +42 -9
  29. package/out/types/app/Service.js.map +1 -1
  30. package/out/types/cache.d.ts +6 -0
  31. package/out/types/cache.js +54 -0
  32. package/out/types/cache.js.map +1 -0
  33. package/out/types/cacheData.js.map +1 -1
  34. package/out/types/common/Vertex.d.ts +25 -0
  35. package/out/types/common/Vertex.js +42 -1
  36. package/out/types/common/Vertex.js.map +1 -1
  37. package/out/types/data/Entity.d.ts +4 -0
  38. package/out/types/data/Entity.js +9 -0
  39. package/out/types/data/Entity.js.map +1 -1
  40. package/out/types/data/EntityProperty.d.ts +5 -0
  41. package/out/types/data/EntityProperty.js +16 -0
  42. package/out/types/data/EntityProperty.js.map +1 -1
  43. package/out/types/data/Enum.d.ts +5 -0
  44. package/out/types/data/Enum.js +5 -0
  45. package/out/types/data/Enum.js.map +1 -1
  46. package/out/types/data/GlobalLogicNode.js +8 -1
  47. package/out/types/data/GlobalLogicNode.js.map +1 -1
  48. package/out/types/data/Interface.js +5 -3
  49. package/out/types/data/Interface.js.map +1 -1
  50. package/out/types/data/dataTypes.js +1 -1
  51. package/out/types/data/dataTypes.js.map +1 -1
  52. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  53. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  54. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  55. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  56. package/out/types/data/genBlock/genCurdEditTableBlock.d.ts +3 -0
  57. package/out/types/data/genBlock/genCurdEditTableBlock.js +578 -0
  58. package/out/types/data/genBlock/genCurdEditTableBlock.js.map +1 -0
  59. package/out/types/data/genBlock/genEditTableBlock.d.ts +234 -0
  60. package/out/types/data/genBlock/genEditTableBlock.js +419 -0
  61. package/out/types/data/genBlock/genEditTableBlock.js.map +1 -0
  62. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  63. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  64. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  65. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  66. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  67. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  68. package/out/types/data/genBlock/genQueryComponent.d.ts +20 -0
  69. package/out/types/data/genBlock/genQueryComponent.js +57 -1
  70. package/out/types/data/genBlock/genQueryComponent.js.map +1 -1
  71. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  72. package/out/types/data/genBlock/genTableBlock.js +23 -8
  73. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  74. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  75. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  76. package/out/types/data/genBlock/index.d.ts +2 -0
  77. package/out/types/data/genBlock/index.js +2 -0
  78. package/out/types/data/genBlock/index.js.map +1 -1
  79. package/out/types/data/genBlock/utils.d.ts +7 -0
  80. package/out/types/data/genBlock/utils.js +38 -1
  81. package/out/types/data/genBlock/utils.js.map +1 -1
  82. package/out/types/data/systemTypes.js +47 -0
  83. package/out/types/data/systemTypes.js.map +1 -1
  84. package/out/types/enum.d.ts +6 -0
  85. package/out/types/enum.js +11 -0
  86. package/out/types/enum.js.map +1 -0
  87. package/out/types/generator/hotReload.d.ts +2 -0
  88. package/out/types/generator/hotReload.js +12 -1
  89. package/out/types/generator/hotReload.js.map +1 -1
  90. package/out/types/index.d.ts +5 -1
  91. package/out/types/index.js +8 -2
  92. package/out/types/index.js.map +1 -1
  93. package/out/types/logic/Logic.d.ts +32 -0
  94. package/out/types/logic/Logic.js +151 -41
  95. package/out/types/logic/Logic.js.map +1 -1
  96. package/out/types/logic/LogicItem.d.ts +1 -0
  97. package/out/types/logic/LogicItem.js +49 -32
  98. package/out/types/logic/LogicItem.js.map +1 -1
  99. package/out/types/logic/Param.d.ts +1 -0
  100. package/out/types/logic/Param.js +43 -33
  101. package/out/types/logic/Param.js.map +1 -1
  102. package/out/types/logic/Return.js +17 -30
  103. package/out/types/logic/Return.js.map +1 -1
  104. package/out/types/logic/Variable.js +17 -25
  105. package/out/types/logic/Variable.js.map +1 -1
  106. package/out/types/logic/translator.js +39 -10
  107. package/out/types/logic/translator.js.map +1 -1
  108. package/out/types/nuims/Nuims.d.ts +1 -1
  109. package/out/types/nuims/Nuims.js +11 -4
  110. package/out/types/nuims/Nuims.js.map +1 -1
  111. package/out/types/page/Element.d.ts +24 -0
  112. package/out/types/page/Element.js +198 -134
  113. package/out/types/page/Element.js.map +1 -1
  114. package/out/types/page/Event.js.map +1 -1
  115. package/out/types/page/Page.d.ts +5 -0
  116. package/out/types/page/Page.js +66 -27
  117. package/out/types/page/Page.js.map +1 -1
  118. package/out/types/page/View.d.ts +19 -1
  119. package/out/types/page/View.js +150 -40
  120. package/out/types/page/View.js.map +1 -1
  121. package/out/types/page/ViewParam.d.ts +1 -0
  122. package/out/types/page/ViewParam.js +23 -4
  123. package/out/types/page/ViewParam.js.map +1 -1
  124. package/out/types/page/ViewVariable.js +13 -24
  125. package/out/types/page/ViewVariable.js.map +1 -1
  126. package/out/types/permission/Permission.d.ts +41 -0
  127. package/out/types/permission/Permission.js +122 -0
  128. package/out/types/permission/Permission.js.map +1 -0
  129. package/out/types/process/ProcessParam.js +3 -1
  130. package/out/types/process/ProcessParam.js.map +1 -1
  131. package/out/types/utils/index.d.ts +1 -0
  132. package/out/types/utils/index.js +16 -7
  133. package/out/types/utils/index.js.map +1 -1
  134. package/package.json +1 -2
  135. package/src/service/app/api.js +8 -17
  136. package/src/service/create/errHandles.js +18 -2
  137. package/src/service/create/index.js +6 -0
  138. package/src/service/developPermission/api.js +37 -0
  139. package/src/service/developPermission/index.js +13 -0
  140. package/src/service/logic/logic.js +26 -0
  141. package/src/service/page/element.js +6 -0
  142. package/src/service/permission/api.js +38 -0
  143. package/src/service/permission/index.js +13 -0
  144. package/src/service/webFile/index.js +6 -1
  145. package/src/types/app/App.ts +58 -2
  146. package/src/types/app/History.ts +3 -2
  147. package/src/types/app/Service.ts +48 -10
  148. package/src/types/cache.ts +50 -0
  149. package/src/types/cacheData.ts +7 -7
  150. package/src/types/common/Vertex.ts +32 -1
  151. package/src/types/data/Entity.ts +8 -0
  152. package/src/types/data/EntityProperty.ts +12 -0
  153. package/src/types/data/Enum.ts +5 -0
  154. package/src/types/data/GlobalLogicNode.ts +8 -1
  155. package/src/types/data/Interface.ts +4 -3
  156. package/src/types/data/dataTypes.ts +1 -1
  157. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  158. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  159. package/src/types/data/genBlock/genCurdEditTableBlock.ts +581 -0
  160. package/src/types/data/genBlock/genEditTableBlock.ts +470 -0
  161. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  162. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  163. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  164. package/src/types/data/genBlock/genQueryComponent.ts +56 -0
  165. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  166. package/src/types/data/genBlock/genTableBlock.ts +28 -13
  167. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  168. package/src/types/data/genBlock/index.ts +2 -0
  169. package/src/types/data/genBlock/utils.ts +38 -0
  170. package/src/types/data/systemTypes.ts +47 -0
  171. package/src/types/enum.ts +6 -0
  172. package/src/types/generator/hotReload.ts +10 -0
  173. package/src/types/index.ts +5 -1
  174. package/src/types/logic/Logic.ts +148 -39
  175. package/src/types/logic/LogicItem.ts +55 -38
  176. package/src/types/logic/Param.ts +43 -35
  177. package/src/types/logic/Return.ts +21 -34
  178. package/src/types/logic/Variable.ts +21 -27
  179. package/src/types/logic/translator.js +41 -14
  180. package/src/types/logic/translator_backup.js +5 -16
  181. package/src/types/nuims/Nuims.ts +11 -5
  182. package/src/types/page/Element.ts +212 -138
  183. package/src/types/page/Event.ts +0 -3
  184. package/src/types/page/Page.ts +80 -40
  185. package/src/types/page/View.ts +154 -39
  186. package/src/types/page/ViewParam.ts +22 -3
  187. package/src/types/page/ViewVariable.ts +16 -26
  188. package/src/types/page/dist/View.js +727 -0
  189. package/src/types/permission/Permission.ts +112 -0
  190. package/src/types/process/ProcessParam.ts +4 -1
  191. package/src/types/utils/index.ts +16 -7
  192. package/out/test/units/config.spec.d.ts +0 -1
  193. package/out/test/units/config.spec.js +0 -12
  194. package/out/test/units/config.spec.js.map +0 -1
@@ -0,0 +1,727 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
16
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
18
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
19
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __generator = (this && this.__generator) || function (thisArg, body) {
31
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
+ function verb(n) { return function (v) { return step([n, v]); }; }
34
+ function step(op) {
35
+ if (f) throw new TypeError("Generator is already executing.");
36
+ while (_) try {
37
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
+ if (y = 0, t) op = [op[0] & 2, t.value];
39
+ switch (op[0]) {
40
+ case 0: case 1: t = op; break;
41
+ case 4: _.label++; return { value: op[1], done: false };
42
+ case 5: _.label++; y = op[1]; op = [0]; continue;
43
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
+ default:
45
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
+ if (t[2]) _.ops.pop();
50
+ _.trys.pop(); continue;
51
+ }
52
+ op = body.call(thisArg, _);
53
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
+ }
56
+ };
57
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
58
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
59
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
60
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
61
+ r[k] = a[j];
62
+ return r;
63
+ };
64
+ exports.__esModule = true;
65
+ exports.View = void 0;
66
+ var decorators_1 = require("../decorators");
67
+ var __1 = require("..");
68
+ var Block_1 = require("./Block");
69
+ var page_1 = require("../../service/page");
70
+ var Logic_1 = require("../logic/Logic");
71
+ var logic_1 = require("../../service/logic");
72
+ var templates_1 = require("../../service/page/templates");
73
+ var translator_1 = require("../logic/translator");
74
+ var lodash_1 = require("lodash");
75
+ /**
76
+ * 子页面类,前端路由控制
77
+ */
78
+ var View = /** @class */ (function (_super) {
79
+ __extends(View, _super);
80
+ /**
81
+ * @param source 需要合并的部分参数
82
+ */
83
+ function View(source) {
84
+ var _this = _super.call(this) || this;
85
+ /**
86
+ * 概念类型
87
+ */
88
+ _this.level = __1.LEVEL_ENUM.view;
89
+ /**
90
+ * 子页面 Id
91
+ */
92
+ _this.id = undefined;
93
+ /**
94
+ * 子页面名称
95
+ */
96
+ _this.name = undefined;
97
+ /**
98
+ * 前端路径,不带 page 名
99
+ */
100
+ _this.path = undefined;
101
+ /**
102
+ * 前后端路径
103
+ * 由于 name 会改的关系,尽量不要用
104
+ * @deprecated
105
+ */
106
+ _this.tempPath = undefined;
107
+ /**
108
+ * 唯一标识码
109
+ */
110
+ _this.code = undefined;
111
+ /**
112
+ * 标题
113
+ */
114
+ _this.title = undefined;
115
+ /**
116
+ * 面包屑
117
+ */
118
+ _this.crumb = undefined;
119
+ /**
120
+ * 是否为默认跳转页
121
+ */
122
+ _this.first = undefined;
123
+ /**
124
+ * 子页面 Id
125
+ */
126
+ _this.parentId = undefined;
127
+ /**
128
+ * 附加的 script
129
+ */
130
+ _this.script = undefined;
131
+ /**
132
+ * 所属页面
133
+ */
134
+ _this.page = undefined;
135
+ /**
136
+ * 父级子页面
137
+ */
138
+ _this.parent = undefined;
139
+ /**
140
+ * 子页面
141
+ */
142
+ _this.children = [];
143
+ /**
144
+ * 输入参数
145
+ */
146
+ // @immutable()
147
+ // public readonly params: Array<Param> = [];
148
+ /**
149
+ * 逻辑列表
150
+ */
151
+ // @immutable()
152
+ // public readonly logics: Array<Logic> = [];
153
+ // vueFile: VueFile;
154
+ /**
155
+ * 树组件的子节点字段
156
+ */
157
+ _this.moreChildrenFields = ['$def.params', '$def.variables', '$def.logics'];
158
+ source && _this.assign(source);
159
+ _this.on('change', lodash_1.throttle(_this._onChange.bind(_this), __1.config.throttleWait, { leading: true, trailing: false }));
160
+ return _this;
161
+ }
162
+ View.prototype._onChange = function () {
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ return __generator(this, function (_a) {
165
+ switch (_a.label) {
166
+ case 0:
167
+ if (!__1.config.webFileCache) return [3 /*break*/, 3];
168
+ if (!!this.$html) return [3 /*break*/, 2];
169
+ return [4 /*yield*/, this.load()];
170
+ case 1:
171
+ _a.sent();
172
+ _a.label = 2;
173
+ case 2:
174
+ __1.generator.saveViewCache(this);
175
+ _a.label = 3;
176
+ case 3: return [2 /*return*/];
177
+ }
178
+ });
179
+ });
180
+ };
181
+ View.prototype.load = function () {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ var result, temp;
184
+ return __generator(this, function (_a) {
185
+ switch (_a.label) {
186
+ case 0: return [4 /*yield*/, page_1.viewService.load({
187
+ path: {
188
+ id: this.id
189
+ }
190
+ })];
191
+ case 1:
192
+ result = _a.sent();
193
+ temp = View.from(result, this.parent, this.page, this);
194
+ delete temp._events;
195
+ delete temp.children;
196
+ this.assign(temp);
197
+ this.attachNodePath();
198
+ return [2 /*return*/, this];
199
+ }
200
+ });
201
+ });
202
+ };
203
+ /**
204
+ * 后续改为根据 id 查找 Element
205
+ * @deprecated
206
+ */
207
+ View.prototype.attachNodePath = function () {
208
+ if (!this.$html)
209
+ return;
210
+ __1.utils.traverse(function (current) {
211
+ current.node.nodePath = current.nodePath;
212
+ }, { node: this.$html });
213
+ };
214
+ /**
215
+ * 根据路径查找子节点
216
+ * @param nodePath 节点路径,/1/2 表示根节点的第1个子节点的第2个子节点
217
+ * @param node 查找的起始节点
218
+ * @examples
219
+ * - findElementByNodePath('', root) 指根节点本身
220
+ * - findElementByNodePath('/', root) 指根节点本身
221
+ * - findElementByNodePath('/0', root) 指第0个子节点
222
+ * - findElementByNodePath('/2/1', root) 指第2个子节点的第1个子节点
223
+ */
224
+ View.prototype.findElementByNodePath = function (nodePath, node) {
225
+ if (node === void 0) { node = this.$html; }
226
+ if (nodePath[0] === '/') // 这个里边相对和绝对是一样的
227
+ nodePath = nodePath.slice(1);
228
+ var arr = nodePath.split('/');
229
+ if (!nodePath || !arr.length)
230
+ return node;
231
+ else {
232
+ var parent = node;
233
+ return this.findElementByNodePath(arr.slice(1).join('/'), parent.children[+arr[0]]);
234
+ }
235
+ };
236
+ /**
237
+ * 根据标签查找元素
238
+ * @param tag
239
+ */
240
+ View.prototype.findElementByTag = function (tag) {
241
+ return this.$html.findElementByTag(tag);
242
+ };
243
+ /**
244
+ * 根据属性查找元素
245
+ * @param name
246
+ * @param value
247
+ */
248
+ View.prototype.findElementByAttr = function (name, value) {
249
+ return this.$html.findElementByAttr(name, value);
250
+ };
251
+ /**
252
+ * 添加子页面
253
+ */
254
+ View.prototype.create = function () {
255
+ return __awaiter(this, void 0, void 0, function () {
256
+ var body, result;
257
+ return __generator(this, function (_a) {
258
+ switch (_a.label) {
259
+ case 0:
260
+ body = this.toJSON();
261
+ __1.utils.logger.debug('添加子页面', body);
262
+ return [4 /*yield*/, page_1.viewService.create({
263
+ body: body
264
+ })];
265
+ case 1:
266
+ result = _a.sent();
267
+ this.deepPick(result, ['id']);
268
+ this.assign({
269
+ tempPath: this.parent ? this.parent.tempPath + "/" + this.name : "/" + this.page.name,
270
+ code: this.parent ? this.parent.code + "/ID_" + this.id + "/" : "/ID_" + this.page.id
271
+ });
272
+ // 在子页面修改时生成缓存,注意不需要 await
273
+ __1.config.webFileCache && __1.generator.saveViewCache(this);
274
+ __1.history.push("\u6DFB\u52A0\u5B50\u9875\u9762\"" + this.name + (this.title ? "(" + this.title + ")" : '') + "\"");
275
+ return [2 /*return*/, this];
276
+ }
277
+ });
278
+ });
279
+ };
280
+ /**
281
+ * 删除子页面
282
+ */
283
+ View.prototype["delete"] = function () {
284
+ return __awaiter(this, void 0, void 0, function () {
285
+ var index;
286
+ return __generator(this, function (_a) {
287
+ switch (_a.label) {
288
+ case 0:
289
+ if (!this.parent)
290
+ throw Error('该子页面为根节点!');
291
+ return [4 /*yield*/, page_1.viewService["delete"]({
292
+ path: {
293
+ id: this.id
294
+ }
295
+ })];
296
+ case 1:
297
+ _a.sent();
298
+ index = this.parent.children.indexOf(this);
299
+ ~index && this.parent.children.splice(index, 1);
300
+ __1.history.push("\u5220\u9664\u5B50\u9875\u9762\"" + this.name + (this.title ? "(" + this.title + ")" : '') + "\"");
301
+ return [2 /*return*/];
302
+ }
303
+ });
304
+ });
305
+ };
306
+ /**
307
+ * 修改子页面
308
+ */
309
+ View.prototype.update = function () {
310
+ return __awaiter(this, void 0, void 0, function () {
311
+ var body, result;
312
+ return __generator(this, function (_a) {
313
+ switch (_a.label) {
314
+ case 0:
315
+ body = this.toPlainJSON();
316
+ __1.utils.logger.debug('修改页面', body);
317
+ return [4 /*yield*/, page_1.viewService.update({
318
+ body: body
319
+ })];
320
+ case 1:
321
+ result = _a.sent();
322
+ return [2 /*return*/, this];
323
+ }
324
+ });
325
+ });
326
+ };
327
+ /**
328
+ * 设置子页面名称
329
+ * 如果为顶级子页面,会同时设置 Page 的属性
330
+ * @param name 名称
331
+ */
332
+ View.prototype.setName = function (name) {
333
+ return __awaiter(this, void 0, void 0, function () {
334
+ var oldName;
335
+ return __generator(this, function (_a) {
336
+ switch (_a.label) {
337
+ case 0:
338
+ oldName = this.name;
339
+ this.assign({ name: name });
340
+ return [4 /*yield*/, this.update()];
341
+ case 1:
342
+ _a.sent();
343
+ if (!(this.page.rootView === this)) return [3 /*break*/, 3];
344
+ this.page.assign({ name: name });
345
+ return [4 /*yield*/, this.page.update()];
346
+ case 2:
347
+ _a.sent();
348
+ _a.label = 3;
349
+ case 3:
350
+ __1.history.push("\u8BBE\u7F6E\u9875\u9762\"" + oldName + "\"\u7684\u540D\u79F0\u4E3A\"" + name + "\"");
351
+ return [2 /*return*/];
352
+ }
353
+ });
354
+ });
355
+ };
356
+ /**
357
+ * 设置子页面标题
358
+ * 如果为顶级子页面,会同时设置 Page 的属性
359
+ * @param title 标题
360
+ */
361
+ View.prototype.setTitle = function (title) {
362
+ return __awaiter(this, void 0, void 0, function () {
363
+ var oldTitle;
364
+ return __generator(this, function (_a) {
365
+ switch (_a.label) {
366
+ case 0:
367
+ oldTitle = this.title;
368
+ this.assign({ title: title });
369
+ return [4 /*yield*/, this.update()];
370
+ case 1:
371
+ _a.sent();
372
+ if (!(this.page.rootView === this)) return [3 /*break*/, 3];
373
+ this.page.assign({ title: title });
374
+ return [4 /*yield*/, this.page.update()];
375
+ case 2:
376
+ _a.sent();
377
+ _a.label = 3;
378
+ case 3:
379
+ __1.history.push("\u8BBE\u7F6E\u9875\u9762\"" + oldTitle + "\"\u7684\u6807\u9898\u4E3A\"" + title + "\"");
380
+ return [2 /*return*/];
381
+ }
382
+ });
383
+ });
384
+ };
385
+ /**
386
+ * 设置面包屑
387
+ * @param crumb 面包屑
388
+ */
389
+ View.prototype.setCrumb = function (crumb) {
390
+ return __awaiter(this, void 0, void 0, function () {
391
+ var oldCrumb;
392
+ return __generator(this, function (_a) {
393
+ switch (_a.label) {
394
+ case 0:
395
+ oldCrumb = this.crumb;
396
+ this.assign({ crumb: crumb });
397
+ return [4 /*yield*/, this.update()];
398
+ case 1:
399
+ _a.sent();
400
+ __1.history.push("\u8BBE\u7F6E\u9875\u9762\"" + oldCrumb + "\"\u7684\u9762\u5305\u5C51\u4E3A\"" + crumb + "\"");
401
+ return [2 /*return*/];
402
+ }
403
+ });
404
+ });
405
+ };
406
+ /**
407
+ * 设为默认跳转页
408
+ */
409
+ View.prototype.setAsFirst = function () {
410
+ return __awaiter(this, void 0, void 0, function () {
411
+ return __generator(this, function (_a) {
412
+ switch (_a.label) {
413
+ case 0:
414
+ if (!this.parent)
415
+ return [2 /*return*/];
416
+ this.parent.assign({ first: this.name });
417
+ return [4 /*yield*/, this.parent.update()];
418
+ case 1:
419
+ _a.sent();
420
+ // 重新生成父页面缓存
421
+ __1.config.webFileCache && __1.generator.saveViewCache(this.parent);
422
+ __1.history.push("\u8BBE\u7F6E\u5B50\u9875\u9762\"" + this.name + "\"\u4E3A\u9ED8\u8BA4\u8DF3\u8F6C\u9875");
423
+ return [2 /*return*/];
424
+ }
425
+ });
426
+ });
427
+ };
428
+ /**
429
+ * 添加子页面
430
+ * @param view
431
+ */
432
+ View.prototype.addView = function (view) {
433
+ return __awaiter(this, void 0, void 0, function () {
434
+ return __generator(this, function (_a) {
435
+ switch (_a.label) {
436
+ case 0:
437
+ view.assign({
438
+ pageId: 'test',
439
+ parentId: this.id,
440
+ parent: this
441
+ });
442
+ return [4 /*yield*/, view.create()];
443
+ case 1:
444
+ _a.sent();
445
+ this.children.unshift(view);
446
+ return [2 /*return*/, view];
447
+ }
448
+ });
449
+ });
450
+ };
451
+ View.prototype.addParam = function (paramOptions) {
452
+ return __awaiter(this, void 0, void 0, function () {
453
+ return __generator(this, function (_a) {
454
+ return [2 /*return*/];
455
+ });
456
+ });
457
+ };
458
+ View.prototype.addLogic = function (logicOptions) {
459
+ return __awaiter(this, void 0, void 0, function () {
460
+ var result, logic;
461
+ return __generator(this, function (_a) {
462
+ switch (_a.label) {
463
+ case 0: return [4 /*yield*/, logic_1.logicService.add({
464
+ body: Object.assign(logicOptions, {
465
+ name: 'logic1',
466
+ description: '',
467
+ params: [],
468
+ returns: [],
469
+ variables: []
470
+ })
471
+ })];
472
+ case 1:
473
+ result = _a.sent();
474
+ logic = new Logic_1["default"](result);
475
+ logic.assign({ view: this, editing: true });
476
+ this.$def.logics.push(logic);
477
+ return [2 /*return*/, logic];
478
+ }
479
+ });
480
+ });
481
+ };
482
+ /**
483
+ * 转换成 Vue 中需要的 JS 代码
484
+ * @TODO 这一版先做成 componentOptions 式的,后面再美化
485
+ */
486
+ View.prototype.toScript = function (options) {
487
+ var componentOptions = 'const componentOptions = {};';
488
+ if (this.script)
489
+ componentOptions = this.script.trim().replace(/export default |module\.exports +=/, 'const componentOptions = ');
490
+ var $def = JSON.parse(JSON.stringify(this.$def));
491
+ $def.title = this.title;
492
+ $def.crumb = this.crumb;
493
+ $def.first = this.first;
494
+ var finalCode = options.finalCode;
495
+ return componentOptions + "\n " + __1.genFinalCode(translator_1["default"]($def), finalCode) + "\n export default componentOptions;\n";
496
+ };
497
+ /**
498
+ * 转换成 Vue 文件
499
+ */
500
+ View.prototype.toVue = function (options) {
501
+ var result = '';
502
+ if (this.$html)
503
+ result += "<template>\n" + this.$html.toVue(options) + "\n</template>\n";
504
+ if (this.script)
505
+ result += "<script>\n" + this.toScript(options) + "\n</script>\n";
506
+ if (this.$def)
507
+ result += ''; // `<script>\n${this.$html.toVue()}\n</script>\n`;
508
+ return result;
509
+ };
510
+ /**
511
+ * 转换成设计器中使用的 Vue 文件
512
+ * @param options
513
+ */
514
+ View.prototype.toDesignerVue = function (options) {
515
+ var result = '';
516
+ if (this.$html)
517
+ result += "<template>\n" + this.$html.toDesignerVue(options) + "\n</template>\n";
518
+ // if (this.script)
519
+ // result += `<script>\n${this.script}\n</script>\n`;
520
+ if (this.$def)
521
+ result += ''; // `<script>\n${this.$html.toVue()}\n</script>\n`;
522
+ return result;
523
+ };
524
+ /**
525
+ * 转换成 VueOptions
526
+ * @TODO 后面 template 可以优化成 render 函数
527
+ */
528
+ View.prototype.toVueOptions = function (options) {
529
+ return {
530
+ template: this.$html.toVue(options),
531
+ script: this.toScript(options)
532
+ };
533
+ };
534
+ /**
535
+ * 合并代码
536
+ */
537
+ View.prototype.mergeCode = function (code, nodePath) {
538
+ return __awaiter(this, void 0, void 0, function () {
539
+ var thisNameSets, replacements, template, body, parentNode, viewId, parentId, definition, $def, newNode, res;
540
+ return __generator(this, function (_a) {
541
+ switch (_a.label) {
542
+ case 0:
543
+ thisNameSets = {
544
+ baseVariables: new Set(),
545
+ logics: new Set(),
546
+ elements: new Set()
547
+ };
548
+ replacements = {
549
+ baseVariables: {},
550
+ logics: {},
551
+ elements: {}
552
+ };
553
+ this.$def.params.forEach(function (param) { return thisNameSets.baseVariables.add(param.name); });
554
+ this.$def.variables.forEach(function (param) { return thisNameSets.baseVariables.add(param.name); });
555
+ this.$def.logics.forEach(function (logic) { return thisNameSets.logics.add(logic.name); });
556
+ __1.utils.traverse(function (current) {
557
+ if (current.node.name)
558
+ thisNameSets.elements.add(current.node.name);
559
+ }, { node: this.$html });
560
+ template = __1.utils.sliceTagContent(code, 'template');
561
+ body = {};
562
+ parentNode = this.findElementByNodePath(nodePath);
563
+ viewId = parentNode.view.id;
564
+ parentId = parentNode.id;
565
+ definition = __1.utils.sliceTagContent(code, 'definition');
566
+ if (definition) {
567
+ $def = JSON.parse(definition);
568
+ __spreadArrays($def.params, $def.variables).forEach(function (param) {
569
+ param.viewId = viewId;
570
+ // name 去重
571
+ var newName = __1.utils.unique(param.name, thisNameSets.baseVariables);
572
+ if (newName !== param.name)
573
+ replacements.baseVariables[param.name] = newName;
574
+ });
575
+ $def.lifecycles.forEach(function (lifecycle) {
576
+ lifecycle.viewId = viewId;
577
+ });
578
+ $def.logics.forEach(function (logic) {
579
+ logic.moduleType = 'view';
580
+ logic.moduleId = viewId;
581
+ // name 去重
582
+ var newName = __1.utils.unique(logic.name, thisNameSets.logics);
583
+ if (newName !== logic.name)
584
+ replacements.baseVariables[logic.name] = newName;
585
+ });
586
+ body.$def = $def;
587
+ }
588
+ if (template) {
589
+ newNode = __1.Element.parse(template, body.$def);
590
+ newNode.assign({
591
+ viewId: viewId,
592
+ parentId: parentId
593
+ });
594
+ body.$html = newNode;
595
+ }
596
+ return [4 /*yield*/, page_1.viewService.mergeBlock({
597
+ body: body
598
+ })];
599
+ case 1:
600
+ res = _a.sent();
601
+ return [4 /*yield*/, this.load()];
602
+ case 2:
603
+ _a.sent();
604
+ this.emit('change');
605
+ this.page.service.emit('vertexIdToNameChange');
606
+ return [2 /*return*/];
607
+ }
608
+ });
609
+ });
610
+ };
611
+ /**
612
+ * 从后端 JSON 生成规范的 View 对象
613
+ * @param currentView 方便构建子对象时关联,主要在 load 中使用
614
+ */
615
+ View.from = function (source, parent, page, currentView) {
616
+ var view = new View(source);
617
+ currentView = currentView || view;
618
+ if (page) {
619
+ view.assign({
620
+ tempPath: parent ? parent.tempPath + "/" + view.name : "/" + page.name,
621
+ code: parent ? parent.code + "/ID_" + view.id + "/" : "/ID_" + page.id
622
+ });
623
+ }
624
+ view.assign({
625
+ parent: parent,
626
+ page: page,
627
+ children: view.children.map(function (child) { return View.from(child, currentView, page); })
628
+ });
629
+ view.$html && view.assign({ $html: __1.Element.from(view.$html, null, currentView) });
630
+ view.$def.params = view.$def.params.map(function (param) { return __1.ViewParam.from(param, currentView); });
631
+ view.$def.variables = view.$def.variables.map(function (param) { return __1.ViewVariable.from(param, currentView); });
632
+ view.$def.lifecycles = view.$def.lifecycles.map(function (lifecycle) { return __1.Lifecycle.from(lifecycle, currentView); });
633
+ view.$def.logics = view.$def.logics.map(function (param) { return Logic_1["default"].from(param, currentView); });
634
+ return view;
635
+ };
636
+ /**
637
+ * 按照模板创建
638
+ */
639
+ View.fromTemplate = function (templateName, source, parent, page) {
640
+ var template = templates_1.TEMPLATE_MAP[templateName];
641
+ var html = __1.utils.sliceTagContent(template.content, 'template');
642
+ var script = __1.utils.sliceTagContent(template.content, 'script');
643
+ var view = this.from(source, parent, page);
644
+ view.assign({
645
+ $html: __1.Element.fromHTML(html, null, view),
646
+ script: script
647
+ });
648
+ return view;
649
+ };
650
+ __decorate([
651
+ decorators_1.immutable()
652
+ ], View.prototype, "level");
653
+ __decorate([
654
+ decorators_1.immutable()
655
+ ], View.prototype, "id");
656
+ __decorate([
657
+ decorators_1.immutable()
658
+ ], View.prototype, "name");
659
+ __decorate([
660
+ decorators_1.immutable()
661
+ ], View.prototype, "path");
662
+ __decorate([
663
+ decorators_1.immutable()
664
+ ], View.prototype, "tempPath");
665
+ __decorate([
666
+ decorators_1.immutable()
667
+ ], View.prototype, "code");
668
+ __decorate([
669
+ decorators_1.immutable()
670
+ ], View.prototype, "title");
671
+ __decorate([
672
+ decorators_1.immutable()
673
+ ], View.prototype, "crumb");
674
+ __decorate([
675
+ decorators_1.immutable()
676
+ ], View.prototype, "first");
677
+ __decorate([
678
+ decorators_1.immutable()
679
+ ], View.prototype, "parentId");
680
+ __decorate([
681
+ decorators_1.immutable()
682
+ ], View.prototype, "script");
683
+ __decorate([
684
+ decorators_1.circular(),
685
+ decorators_1.immutable()
686
+ ], View.prototype, "page");
687
+ __decorate([
688
+ decorators_1.circular(),
689
+ decorators_1.immutable()
690
+ ], View.prototype, "parent");
691
+ __decorate([
692
+ decorators_1.immutable()
693
+ ], View.prototype, "children");
694
+ __decorate([
695
+ decorators_1.immutable()
696
+ ], View.prototype, "moreChildrenFields");
697
+ __decorate([
698
+ decorators_1.action('添加子页面')
699
+ ], View.prototype, "create");
700
+ __decorate([
701
+ decorators_1.action('删除子页面')
702
+ ], View.prototype, "delete");
703
+ __decorate([
704
+ decorators_1.action('设置页面名称')
705
+ ], View.prototype, "setName");
706
+ __decorate([
707
+ decorators_1.action('设置页面标题')
708
+ ], View.prototype, "setTitle");
709
+ __decorate([
710
+ decorators_1.action('设置面包屑')
711
+ ], View.prototype, "setCrumb");
712
+ __decorate([
713
+ decorators_1.action('设为默认跳转页')
714
+ ], View.prototype, "setAsFirst");
715
+ __decorate([
716
+ decorators_1.action('添加子页面')
717
+ ], View.prototype, "addView");
718
+ __decorate([
719
+ decorators_1.action('添加输入参数')
720
+ ], View.prototype, "addParam");
721
+ __decorate([
722
+ decorators_1.action('添加逻辑')
723
+ ], View.prototype, "addLogic");
724
+ return View;
725
+ }(Block_1["default"]));
726
+ exports.View = View;
727
+ exports["default"] = View;