vap1 0.1.3 → 0.1.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.
- package/components/Box/Box.js +5 -0
- package/components/Tables/VTable.js +7 -5
- package/components/UForm/UForm.js +6 -8
- package/components/_adapt/Col.js +3 -1
- package/components/_adapt/Row.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/uform/FormEditor.d.ts +21 -0
- package/uform/FormEditor.js +101 -0
- package/uform/FormViewer.d.ts +12 -0
- package/uform/FormViewer.js +71 -0
- package/uform/hooks/useEditor.d.ts +28 -0
- package/uform/hooks/useEditor.js +144 -0
- package/uform/hooks/useForm.d.ts +4 -0
- package/uform/hooks/useForm.js +7 -0
- package/uform/index.d.ts +5 -0
- package/uform/index.js +35 -0
- package/uform/inputs/_advance.d.ts +2 -0
- package/uform/inputs/_advance.js +57 -0
- package/uform/inputs/_date.d.ts +2 -0
- package/uform/inputs/_date.js +178 -0
- package/uform/inputs/_input.d.ts +6 -0
- package/uform/inputs/_input.js +139 -0
- package/uform/inputs/_select.d.ts +2 -0
- package/uform/inputs/_select.js +241 -0
- package/uform/inputs/_specific.d.ts +2 -0
- package/uform/inputs/_specific.js +107 -0
- package/uform/inputs/index.d.ts +6 -0
- package/uform/inputs/index.js +18 -0
- package/uform/inputs/register.d.ts +25 -0
- package/uform/inputs/register.js +47 -0
- package/uform/panel/Editor/GroupEditor.d.ts +7 -0
- package/uform/panel/Editor/GroupEditor.js +126 -0
- package/uform/panel/Editor/ListEditor.d.ts +4 -0
- package/uform/panel/Editor/ListEditor.js +77 -0
- package/uform/panel/Editor/_FieldItems.d.ts +5 -0
- package/uform/panel/Editor/_FieldItems.js +45 -0
- package/uform/panel/Editor/_GroupCollapse.d.ts +3 -0
- package/uform/panel/Editor/_GroupCollapse.js +24 -0
- package/uform/panel/Editor/_GroupDefault.d.ts +3 -0
- package/uform/panel/Editor/_GroupDefault.js +24 -0
- package/uform/panel/Editor/_GroupStep.d.ts +3 -0
- package/uform/panel/Editor/_GroupStep.js +49 -0
- package/uform/panel/Editor/_GroupTab.d.ts +3 -0
- package/uform/panel/Editor/_GroupTab.js +41 -0
- package/uform/panel/Editor/index.d.ts +3 -0
- package/uform/panel/Editor/index.js +83 -0
- package/uform/panel/Items/index.d.ts +3 -0
- package/uform/panel/Items/index.js +23 -0
- package/uform/panel/Propreties/CanvasProperties.d.ts +3 -0
- package/uform/panel/Propreties/CanvasProperties.js +42 -0
- package/uform/panel/Propreties/Component/FieldPlugin.d.ts +12 -0
- package/uform/panel/Propreties/Component/FieldPlugin.js +39 -0
- package/uform/panel/Propreties/Component/LinkAsyncFunction.d.ts +8 -0
- package/uform/panel/Propreties/Component/LinkAsyncFunction.js +171 -0
- package/uform/panel/Propreties/Component/LinkSyncFunction.d.ts +8 -0
- package/uform/panel/Propreties/Component/LinkSyncFunction.js +149 -0
- package/uform/panel/Propreties/Component/Links.d.ts +3 -0
- package/uform/panel/Propreties/Component/Links.js +114 -0
- package/uform/panel/Propreties/Component/OptionTable.d.ts +3 -0
- package/uform/panel/Propreties/Component/OptionTable.js +144 -0
- package/uform/panel/Propreties/Component/RegexpModal.d.ts +5 -0
- package/uform/panel/Propreties/Component/RegexpModal.js +74 -0
- package/uform/panel/Propreties/Component/Validate.d.ts +3 -0
- package/uform/panel/Propreties/Component/Validate.js +93 -0
- package/uform/panel/Propreties/Component/ValidateAsyncFunction.d.ts +3 -0
- package/uform/panel/Propreties/Component/ValidateAsyncFunction.js +83 -0
- package/uform/panel/Propreties/Component/ValidateSyncFunction.d.ts +3 -0
- package/uform/panel/Propreties/Component/ValidateSyncFunction.js +77 -0
- package/uform/panel/Propreties/FieldOptions.d.ts +6 -0
- package/uform/panel/Propreties/FieldOptions.js +131 -0
- package/uform/panel/Propreties/FieldProperties.d.ts +3 -0
- package/uform/panel/Propreties/FieldProperties.js +60 -0
- package/uform/panel/Propreties/GroupProperties.d.ts +3 -0
- package/uform/panel/Propreties/GroupProperties.js +17 -0
- package/uform/panel/Propreties/_ItemAdvance.d.ts +4 -0
- package/uform/panel/Propreties/_ItemAdvance.js +140 -0
- package/uform/panel/Propreties/_ItemBase.d.ts +4 -0
- package/uform/panel/Propreties/_ItemBase.js +34 -0
- package/uform/panel/Propreties/_ItemLink.d.ts +4 -0
- package/uform/panel/Propreties/_ItemLink.js +15 -0
- package/uform/panel/Propreties/_ItemValidate.d.ts +4 -0
- package/uform/panel/Propreties/_ItemValidate.js +67 -0
- package/uform/panel/Propreties/_util.d.ts +9 -0
- package/uform/panel/Propreties/_util.js +2 -0
- package/uform/plugins/index.d.ts +15 -0
- package/uform/plugins/index.js +47 -0
- package/uform/schema.d.ts +155 -0
- package/uform/schema.js +2 -0
- package/uform/utils/Const.d.ts +20 -0
- package/uform/utils/Const.js +24 -0
- package/uform/utils/Convert.d.ts +3 -0
- package/uform/utils/Convert.js +274 -0
- package/uform/utils/SchemaConvert.d.ts +6 -0
- package/uform/utils/SchemaConvert.js +169 -0
- package/uform/utils/arr.d.ts +12 -0
- package/uform/utils/arr.js +175 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.schemaToForm = void 0;
|
|
16
|
+
const react_1 = __importDefault(require("react"));
|
|
17
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
18
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
19
|
+
const index_1 = require("../../index");
|
|
20
|
+
const utils_1 = require("../../utils");
|
|
21
|
+
const Const_1 = require("./Const");
|
|
22
|
+
const converUrl = (url, data) => {
|
|
23
|
+
const fn = lodash_1.default.template(url, { imports: { _: lodash_1.default, dayjs: dayjs_1.default } });
|
|
24
|
+
return fn(data);
|
|
25
|
+
};
|
|
26
|
+
const convertParam = (param, data) => {
|
|
27
|
+
const fn = lodash_1.default.template(param, { imports: { _: lodash_1.default, dayjs: dayjs_1.default } });
|
|
28
|
+
return JSON.parse(fn(data));
|
|
29
|
+
};
|
|
30
|
+
const syncValidator = (rule) => {
|
|
31
|
+
var fn = lodash_1.default.template(`<%
|
|
32
|
+
${rule.code}
|
|
33
|
+
%>`, { imports: { _: lodash_1.default, dayjs: dayjs_1.default } });
|
|
34
|
+
return {
|
|
35
|
+
message: rule.message,
|
|
36
|
+
validator: (r, value, callback) => {
|
|
37
|
+
try {
|
|
38
|
+
let result = fn({ value });
|
|
39
|
+
if (!Const_1.BOOLEAN_VALUE.has(result)) {
|
|
40
|
+
console.error('代码执行有误,请检查,:必须print(true/false)');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (utils_1.StringUtil.getBoolean(result)) {
|
|
44
|
+
callback();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
callback('error');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
console.error('代码配置有误,请检查');
|
|
52
|
+
callback();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const asyncValidator = (rule) => {
|
|
58
|
+
var fn = lodash_1.default.template(`<%
|
|
59
|
+
${rule.code}
|
|
60
|
+
%>`, { imports: { _: lodash_1.default, dayjs: dayjs_1.default } });
|
|
61
|
+
return {
|
|
62
|
+
message: null,
|
|
63
|
+
validator: (r, value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
let response;
|
|
65
|
+
const url = converUrl(rule.url, { value });
|
|
66
|
+
if (rule.method == 'POST') {
|
|
67
|
+
try {
|
|
68
|
+
const param = convertParam(rule.param, { value });
|
|
69
|
+
response = yield utils_1.Ajax.POST(url, param);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error(e);
|
|
73
|
+
throw '验证失败';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
response = yield utils_1.Ajax.GET(url);
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
fn({ response, value });
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const syncLink = (link) => {
|
|
89
|
+
var fn = lodash_1.default.template(`<%
|
|
90
|
+
${link.code}
|
|
91
|
+
%>`, { imports: { _: lodash_1.default, dayjs: dayjs_1.default } });
|
|
92
|
+
return {
|
|
93
|
+
field: link.field,
|
|
94
|
+
call: (value, form, extra) => {
|
|
95
|
+
const result = fn({ value, form, extra });
|
|
96
|
+
if (result == '')
|
|
97
|
+
return result;
|
|
98
|
+
try {
|
|
99
|
+
let json = JSON.parse(result);
|
|
100
|
+
if (lodash_1.default.isPlainObject(json))
|
|
101
|
+
return json;
|
|
102
|
+
throw (new Error());
|
|
103
|
+
}
|
|
104
|
+
catch (_a) {
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const asyncLink = (link) => {
|
|
111
|
+
var fn = lodash_1.default.template(`<%
|
|
112
|
+
${link.code}
|
|
113
|
+
%>`, { imports: { _: lodash_1.default, dayjs: dayjs_1.default } });
|
|
114
|
+
return {
|
|
115
|
+
field: link.field,
|
|
116
|
+
call: (value, form, extra) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
let response;
|
|
118
|
+
const url = converUrl(link.url, { value, form, extra });
|
|
119
|
+
if (link.method == 'POST') {
|
|
120
|
+
try {
|
|
121
|
+
const param = convertParam(link.param, { value, form, extra });
|
|
122
|
+
response = yield utils_1.Ajax.POST(url, param);
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.error(e);
|
|
126
|
+
// throw '验证失败';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
response = yield utils_1.Ajax.GET(url);
|
|
131
|
+
}
|
|
132
|
+
const result = fn({ value, form, extra, response });
|
|
133
|
+
if (result == '')
|
|
134
|
+
return result;
|
|
135
|
+
try {
|
|
136
|
+
let json = JSON.parse(result);
|
|
137
|
+
if (lodash_1.default.isPlainObject(json))
|
|
138
|
+
return json;
|
|
139
|
+
throw (new Error());
|
|
140
|
+
}
|
|
141
|
+
catch (_a) {
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const convertFields = (fields, def) => fields.map(item => {
|
|
148
|
+
let field = { field: item.field, title: item.title, type: item.type };
|
|
149
|
+
if (lodash_1.default.has(item, '_default')) {
|
|
150
|
+
if (Const_1.NUMBER.has(item.type) || item._isNumber) {
|
|
151
|
+
if (!isNaN(item._default)) {
|
|
152
|
+
def[item.field] = parseInt(item._default);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
def[item.field] = item._default;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
field.config = item.config || {};
|
|
160
|
+
field.rules = [];
|
|
161
|
+
if (item.ik)
|
|
162
|
+
field.ik = item.ik;
|
|
163
|
+
if (item.options)
|
|
164
|
+
field.options = item.options;
|
|
165
|
+
if (item.span)
|
|
166
|
+
field.span = item.span;
|
|
167
|
+
if (item.extra)
|
|
168
|
+
field.extra = item.extra;
|
|
169
|
+
if (item.placeholder)
|
|
170
|
+
field.placeholder = item.placeholder;
|
|
171
|
+
if (item.roleCode)
|
|
172
|
+
field.roleCode = item.roleCode;
|
|
173
|
+
if (item.required)
|
|
174
|
+
field.required = true;
|
|
175
|
+
if (item.tip)
|
|
176
|
+
field.tip = item.tip;
|
|
177
|
+
if (lodash_1.default.has(item, 'show'))
|
|
178
|
+
field.show = item.show;
|
|
179
|
+
if (lodash_1.default.has(item, 'disabled'))
|
|
180
|
+
field.disabled = item.disabled;
|
|
181
|
+
if (item.help)
|
|
182
|
+
field.help = item.help;
|
|
183
|
+
if (item.ignore)
|
|
184
|
+
field.ignore = true;
|
|
185
|
+
field.rules = [];
|
|
186
|
+
if (item._pattern && Const_1.TEXT.has(item.type)) {
|
|
187
|
+
field.rules.push({ pattern: new RegExp(item._pattern), message: item.title + ' 格式有误' });
|
|
188
|
+
}
|
|
189
|
+
if (lodash_1.default.has(item, '_min') && lodash_1.default.isNumber(item._min)) {
|
|
190
|
+
if (Const_1.LEN.has(item.type)) {
|
|
191
|
+
field.rules.push({
|
|
192
|
+
message: `${item.title} 不得小于 ${item._min} 个字符`,
|
|
193
|
+
validator: (rule, value, callback) => {
|
|
194
|
+
if ((value + '').length < item._min) {
|
|
195
|
+
callback('error');
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
callback();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
else if (Const_1.NUMBER.has(item.type)) {
|
|
204
|
+
field.config.min = item._min;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (item._max) {
|
|
208
|
+
if (Const_1.LEN.has(item.type)) {
|
|
209
|
+
field.config.maxLength = item._max;
|
|
210
|
+
field.rules.push({
|
|
211
|
+
message: `${item.title} 不得大于 ${item._max} 个字符`,
|
|
212
|
+
validator: (rule, value, callback) => {
|
|
213
|
+
if ((value + '').length > item._max) {
|
|
214
|
+
callback('error');
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
callback();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
else if (Const_1.NUMBER.has(item.type)) {
|
|
223
|
+
field.config.max = item._max;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
(item._rules || []).map(rule => {
|
|
227
|
+
if (rule.async) {
|
|
228
|
+
field.rules.push(asyncValidator(rule));
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
field.rules.push(syncValidator(rule));
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
field.link = [];
|
|
235
|
+
(item._links || []).map(link => {
|
|
236
|
+
if (link.async) {
|
|
237
|
+
field.link.push(asyncLink(link));
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
field.link.push(syncLink(link));
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
// TODO PLUGINS
|
|
244
|
+
return field;
|
|
245
|
+
});
|
|
246
|
+
const convertGroups = (groups, def) => groups.map(group => ({ title: group.title, fields: convertFields(group.fields, def) }));
|
|
247
|
+
const schemaToForm = (schema) => {
|
|
248
|
+
const uformProps = {
|
|
249
|
+
fields: [],
|
|
250
|
+
};
|
|
251
|
+
if (schema.tip && schema.tip.text) {
|
|
252
|
+
uformProps.tip = react_1.default.createElement(index_1.Alert, { message: schema.tip.text, type: schema.tip.type || 'info' });
|
|
253
|
+
}
|
|
254
|
+
if (lodash_1.default.has(schema, 'className') && lodash_1.default.isString(schema.className)) {
|
|
255
|
+
uformProps.className = lodash_1.default.trim(schema.className);
|
|
256
|
+
}
|
|
257
|
+
if (schema.layout)
|
|
258
|
+
uformProps.layout = schema.layout;
|
|
259
|
+
let def = {};
|
|
260
|
+
if (schema.isGroup) {
|
|
261
|
+
if (schema.groupType)
|
|
262
|
+
uformProps.groupType = schema.groupType;
|
|
263
|
+
uformProps.fields = convertGroups(schema.fields, def);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
uformProps.fields = convertFields(schema.fields, def);
|
|
267
|
+
}
|
|
268
|
+
if (schema.size)
|
|
269
|
+
uformProps.size = schema.size;
|
|
270
|
+
if (lodash_1.default.keys(def).length > 0)
|
|
271
|
+
uformProps.default = def;
|
|
272
|
+
return uformProps;
|
|
273
|
+
};
|
|
274
|
+
exports.schemaToForm = schemaToForm;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FormSchema } from '../schema';
|
|
2
|
+
export declare const save: (schema: FormSchema) => void;
|
|
3
|
+
export declare const saveSchema: (schema: FormSchema) => void;
|
|
4
|
+
export declare const saveUForm: (schema: FormSchema) => void;
|
|
5
|
+
export declare const saveCEMS: (schema: FormSchema) => void;
|
|
6
|
+
export declare const loadFormJSON: (text: string) => any;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadFormJSON = exports.saveCEMS = exports.saveUForm = exports.saveSchema = exports.save = void 0;
|
|
7
|
+
// 将 schame 转换为 UForm 接收的参数
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
const antd_1 = require("antd");
|
|
12
|
+
const cleanId = (schema) => {
|
|
13
|
+
let obj = lodash_1.default.cloneDeep(schema);
|
|
14
|
+
if (obj.isGroup) {
|
|
15
|
+
obj.fields.map(group => {
|
|
16
|
+
lodash_1.default.unset(group, 'id');
|
|
17
|
+
group.fields.map(field => lodash_1.default.unset(field, 'id'));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
obj.fields.map(group => {
|
|
22
|
+
lodash_1.default.unset(group, 'id');
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
lodash_1.default.unset(obj, 'selected');
|
|
26
|
+
lodash_1.default.unset(obj, 'baseSpan');
|
|
27
|
+
lodash_1.default.unset(obj, '__idx');
|
|
28
|
+
if (obj.tip && obj.tip.text == '') {
|
|
29
|
+
lodash_1.default.unset(obj, 'tip');
|
|
30
|
+
}
|
|
31
|
+
lodash_1.default.keys(obj).map(key => {
|
|
32
|
+
if (obj[key] === '') {
|
|
33
|
+
lodash_1.default.unset(obj, key);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return obj;
|
|
37
|
+
};
|
|
38
|
+
const setId = (schema) => {
|
|
39
|
+
let obj = lodash_1.default.cloneDeep(schema);
|
|
40
|
+
obj.fields.map(group => {
|
|
41
|
+
lodash_1.default.set(group, 'id', utils_1.StringUtil.genKey());
|
|
42
|
+
if (lodash_1.default.isArray(group.fields) && group.fields.length) {
|
|
43
|
+
group.fields.map(field => lodash_1.default.set(field, 'id', utils_1.StringUtil.genKey()));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (lodash_1.default.isArray(obj.options) && obj.options.length) {
|
|
47
|
+
obj.options.map(item => lodash_1.default.set(item, 'id', utils_1.StringUtil.genKey()));
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
};
|
|
51
|
+
const save = (schema) => {
|
|
52
|
+
let obj = cleanId(schema);
|
|
53
|
+
antd_1.notification.success({ message: react_1.default.createElement("pre", { dangerouslySetInnerHTML: { __html: JSON.stringify(obj, null, 2) } }) });
|
|
54
|
+
};
|
|
55
|
+
exports.save = save;
|
|
56
|
+
const saveSchema = (schema) => {
|
|
57
|
+
if (schema.fields.length <= 0) {
|
|
58
|
+
antd_1.message.error('表单最少要有一个字段');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let obj = cleanId(schema);
|
|
62
|
+
let fileName = (schema.title ? schema.title : '表单') + ".json";
|
|
63
|
+
var file = new File([JSON.stringify(obj, null, 4)], fileName, { type: "application/json;charset=utf-8" });
|
|
64
|
+
var a = document.createElement('a');
|
|
65
|
+
a.href = URL.createObjectURL(file);
|
|
66
|
+
a.download = fileName;
|
|
67
|
+
a.click();
|
|
68
|
+
};
|
|
69
|
+
exports.saveSchema = saveSchema;
|
|
70
|
+
// var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
|
|
71
|
+
const FORMATS = {
|
|
72
|
+
_title: (title) => {
|
|
73
|
+
if (title) {
|
|
74
|
+
return `\n title="${title}"`;
|
|
75
|
+
}
|
|
76
|
+
return '';
|
|
77
|
+
},
|
|
78
|
+
_layout: (layout) => {
|
|
79
|
+
if (layout == 'common' || layout == 'simple' || layout == 'compress') {
|
|
80
|
+
return `\n layout="${layout}"`;
|
|
81
|
+
}
|
|
82
|
+
return '';
|
|
83
|
+
},
|
|
84
|
+
_tip: (tip) => {
|
|
85
|
+
if (tip && tip.text) {
|
|
86
|
+
return `\n tip={<Alert type="${tip.type}" message="${tip.text}"/>}`;
|
|
87
|
+
}
|
|
88
|
+
return '';
|
|
89
|
+
},
|
|
90
|
+
_group: (group) => {
|
|
91
|
+
return `{ title: "${group.title}", fields: [
|
|
92
|
+
${group.fields.map(item => FORMATS._field(item)).join('\n')}
|
|
93
|
+
]},`;
|
|
94
|
+
},
|
|
95
|
+
_field: (field) => {
|
|
96
|
+
var rule = '';
|
|
97
|
+
var config = '';
|
|
98
|
+
var options = '';
|
|
99
|
+
if (field.options) {
|
|
100
|
+
options = ` , options: [
|
|
101
|
+
${field.options.map(item => ` { label:"${item.label}", value: "${item.value}"}`).join(',\n')}
|
|
102
|
+
]`;
|
|
103
|
+
}
|
|
104
|
+
if (field.required) {
|
|
105
|
+
rule = ` ,rule: [
|
|
106
|
+
{ required: true, },
|
|
107
|
+
]`;
|
|
108
|
+
}
|
|
109
|
+
if (field.config) {
|
|
110
|
+
}
|
|
111
|
+
return `\n {field:"${field.field}", type: "${field.type}", label:"${field.title}"${rule}${config}${options}}`;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const UFormCode = lodash_1.default.template(`<UModal<%= _title(data.title) %><%= _layout(data.layout) %><%= _tip(data.tip) %>
|
|
115
|
+
fields={[<% _.forEach(data.fields, function(field) { %><%= data.isGroup?_group(field):_field(field) %><% }); %>
|
|
116
|
+
]}
|
|
117
|
+
/>`, { imports: FORMATS, variable: 'data' });
|
|
118
|
+
const saveUForm = (schema) => {
|
|
119
|
+
if (schema.fields.length <= 0) {
|
|
120
|
+
antd_1.message.error('表单最少要有一个字段');
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
let codeText = UFormCode(schema);
|
|
124
|
+
let fileName = (schema.title ? schema.title : '代码') + ".tsx";
|
|
125
|
+
var file = new File([codeText], fileName, { type: "text/plain;charset=utf-8" });
|
|
126
|
+
var a = document.createElement('a');
|
|
127
|
+
a.href = URL.createObjectURL(file);
|
|
128
|
+
a.download = fileName;
|
|
129
|
+
a.click();
|
|
130
|
+
};
|
|
131
|
+
exports.saveUForm = saveUForm;
|
|
132
|
+
const CEMS = `<?xml version="1.0" encoding="UTF-8"?>
|
|
133
|
+
<policy id=""
|
|
134
|
+
originalId="00010094"
|
|
135
|
+
name="防网络入侵策略"
|
|
136
|
+
type="2"
|
|
137
|
+
priority="2"
|
|
138
|
+
pid="d82b9e291e3445fdbabab18278caca35"
|
|
139
|
+
crc=""
|
|
140
|
+
level="1"
|
|
141
|
+
orgLevel=""
|
|
142
|
+
updateTime=""
|
|
143
|
+
executelogic="8"
|
|
144
|
+
description="防网络入侵策略模板"
|
|
145
|
+
version="8.1.1709.2218"
|
|
146
|
+
supportAgentType="1"
|
|
147
|
+
UseAgenttype="1"
|
|
148
|
+
></policy>`;
|
|
149
|
+
const saveCEMS = (schema) => {
|
|
150
|
+
let fileName = (schema.policy || schema.title || 'policy') + ".xml";
|
|
151
|
+
var file = new File([CEMS], ".xml", { type: "text/plain;charset=utf-8" });
|
|
152
|
+
var a = document.createElement('a');
|
|
153
|
+
a.href = URL.createObjectURL(file);
|
|
154
|
+
a.download = fileName;
|
|
155
|
+
a.click();
|
|
156
|
+
};
|
|
157
|
+
exports.saveCEMS = saveCEMS;
|
|
158
|
+
const loadFormJSON = (text) => {
|
|
159
|
+
try {
|
|
160
|
+
let info = JSON.parse(text);
|
|
161
|
+
let p = setId(info);
|
|
162
|
+
// notification.success({ message: <pre dangerouslySetInnerHTML={{ __html: JSON.stringify(p, null, 2) }}></pre> })
|
|
163
|
+
return p;
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
exports.loadFormJSON = loadFormJSON;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FormItem, FormGroup, Cursor } from "../schema";
|
|
2
|
+
import type { PlainObject } from '../../basetype';
|
|
3
|
+
export declare const insertInList: (fieldType: string, list: FormItem[], pos?: Cursor) => FormItem[];
|
|
4
|
+
export declare const insertInGroup: (fieldType: string, list: FormGroup[], groupId: string, pos?: Cursor) => FormGroup[];
|
|
5
|
+
export declare const sortList: (id: string, fields: FormItem[], pos: Cursor) => FormItem[];
|
|
6
|
+
export declare const sortListInGroup: (id: string, fields: FormGroup[], groupId: string, pos?: Cursor) => FormGroup[];
|
|
7
|
+
export declare const setProperties: (fields: FormItem[], fieldId: string, property: string | PlainObject, value: any) => any[];
|
|
8
|
+
export declare const setPropertiesInGroup: (fields: FormGroup[], groupId: string, fieldId: string, property: string, value: any) => {
|
|
9
|
+
fields: any[];
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
}[];
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setPropertiesInGroup = exports.setProperties = exports.sortListInGroup = exports.sortList = exports.insertInGroup = exports.insertInList = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const inputs_1 = require("../inputs");
|
|
9
|
+
const antd_1 = require("antd");
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
const insertFieldInList = (field, list, pos = null) => {
|
|
12
|
+
if (pos == null) {
|
|
13
|
+
return [...list, field];
|
|
14
|
+
}
|
|
15
|
+
let { id, prev } = pos;
|
|
16
|
+
let idx = lodash_1.default.findIndex(list, { id });
|
|
17
|
+
if (idx < 0) {
|
|
18
|
+
return [...list, field];
|
|
19
|
+
}
|
|
20
|
+
let inSertPos = prev ? idx : idx + 1;
|
|
21
|
+
return [...lodash_1.default.slice(list, 0, inSertPos), field, ...lodash_1.default.slice(list, inSertPos)];
|
|
22
|
+
};
|
|
23
|
+
// 插入一个字段到列表指定位置
|
|
24
|
+
const insertInList = (fieldType, list, pos = null) => {
|
|
25
|
+
const info = (0, inputs_1.getInput)(fieldType);
|
|
26
|
+
if (info == null) {
|
|
27
|
+
antd_1.message.error('无此类型');
|
|
28
|
+
return list;
|
|
29
|
+
}
|
|
30
|
+
let key = utils_1.StringUtil.genKey();
|
|
31
|
+
const field = { id: key, type: fieldType, title: info.title, field: key };
|
|
32
|
+
if (info.defaultProperties)
|
|
33
|
+
lodash_1.default.assign(field, info.defaultProperties);
|
|
34
|
+
if (info.defaultConfig)
|
|
35
|
+
field.config = lodash_1.default.assign({}, info.defaultConfig);
|
|
36
|
+
if (info.fieldCount && info.fieldCount > 1)
|
|
37
|
+
field.field = lodash_1.default.range(info.fieldCount).map(utils_1.StringUtil.genKey).join(',');
|
|
38
|
+
if (info.hasOption) {
|
|
39
|
+
field.options = [];
|
|
40
|
+
if (field.type == 'switch') {
|
|
41
|
+
field.options.push({ id: utils_1.StringUtil.genKey(), label: '开启', value: '0' });
|
|
42
|
+
field.options.push({ id: utils_1.StringUtil.genKey(), label: '关闭', value: '1' });
|
|
43
|
+
field._default = '0';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return insertFieldInList(field, list, pos);
|
|
47
|
+
};
|
|
48
|
+
exports.insertInList = insertInList;
|
|
49
|
+
// 插入一个字段到分组指定位置
|
|
50
|
+
const insertInGroup = (fieldType, list, groupId, pos = null) => {
|
|
51
|
+
let idx = lodash_1.default.findIndex(list, { id: groupId });
|
|
52
|
+
if (idx < 0) {
|
|
53
|
+
return list;
|
|
54
|
+
}
|
|
55
|
+
let group = list[idx];
|
|
56
|
+
return [
|
|
57
|
+
...lodash_1.default.slice(list, 0, idx),
|
|
58
|
+
Object.assign(Object.assign({}, group), { fields: (0, exports.insertInList)(fieldType, group.fields, pos) }),
|
|
59
|
+
...lodash_1.default.slice(list, idx + 1)
|
|
60
|
+
];
|
|
61
|
+
};
|
|
62
|
+
exports.insertInGroup = insertInGroup;
|
|
63
|
+
// 在列表内字段拖拽排序
|
|
64
|
+
const sortList = (id, fields, pos) => {
|
|
65
|
+
if (pos == null) {
|
|
66
|
+
return fields;
|
|
67
|
+
}
|
|
68
|
+
let idx = lodash_1.default.findIndex(fields, { id });
|
|
69
|
+
if (idx < 0) {
|
|
70
|
+
return fields;
|
|
71
|
+
}
|
|
72
|
+
let tdx = lodash_1.default.findIndex(fields, { id: pos.id });
|
|
73
|
+
if (tdx < 0 || tdx == idx) {
|
|
74
|
+
return fields;
|
|
75
|
+
}
|
|
76
|
+
if ((pos.prev && tdx - idx == 1) || (!pos.prev && idx - tdx == 1)) {
|
|
77
|
+
return fields;
|
|
78
|
+
}
|
|
79
|
+
let sorted = fields.filter(item => item.id != id);
|
|
80
|
+
tdx = lodash_1.default.findIndex(sorted, { id: pos.id });
|
|
81
|
+
let inSertPos = pos.prev ? tdx : tdx + 1;
|
|
82
|
+
return [...lodash_1.default.slice(sorted, 0, inSertPos), fields[idx], ...lodash_1.default.slice(sorted, inSertPos)];
|
|
83
|
+
};
|
|
84
|
+
exports.sortList = sortList;
|
|
85
|
+
// 字段排序, 在分组里面
|
|
86
|
+
const sortListInGroup = (id, fields, groupId, pos) => {
|
|
87
|
+
let [gdx, fdx] = [-1, -1];
|
|
88
|
+
let group = null;
|
|
89
|
+
for (let i = 0; i < fields.length; i++) {
|
|
90
|
+
group = fields[i];
|
|
91
|
+
let j = lodash_1.default.findIndex(group.fields, { id });
|
|
92
|
+
if (j >= 0) {
|
|
93
|
+
gdx = i;
|
|
94
|
+
fdx = j;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (gdx < 0 || fdx < 0) {
|
|
99
|
+
return fields;
|
|
100
|
+
}
|
|
101
|
+
// case 1 : 组内移动
|
|
102
|
+
if (group.id == groupId) {
|
|
103
|
+
return [
|
|
104
|
+
...lodash_1.default.slice(fields, 0, gdx),
|
|
105
|
+
Object.assign(Object.assign({}, fields[gdx]), { fields: (0, exports.sortList)(id, fields[gdx].fields, pos) }),
|
|
106
|
+
...lodash_1.default.slice(fields, gdx + 1),
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
let tdx = lodash_1.default.findIndex(fields, { id: groupId });
|
|
110
|
+
if (tdx < 0) {
|
|
111
|
+
return fields;
|
|
112
|
+
}
|
|
113
|
+
let sourceGroup = fields[gdx];
|
|
114
|
+
let targetGroup = fields[tdx];
|
|
115
|
+
if (tdx > gdx) {
|
|
116
|
+
// case 2 : 上移到下
|
|
117
|
+
return [
|
|
118
|
+
...lodash_1.default.slice(fields, 0, gdx),
|
|
119
|
+
Object.assign(Object.assign({}, sourceGroup), { fields: lodash_1.default.filter(sourceGroup.fields, item => item.id != id) }),
|
|
120
|
+
...lodash_1.default.slice(fields, gdx + 1, tdx),
|
|
121
|
+
Object.assign(Object.assign({}, targetGroup), { fields: insertFieldInList(fields[gdx].fields[fdx], targetGroup.fields, pos) }),
|
|
122
|
+
...lodash_1.default.slice(fields, tdx + 1),
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// case 3 : 下移到上
|
|
127
|
+
return [
|
|
128
|
+
...lodash_1.default.slice(fields, 0, tdx),
|
|
129
|
+
Object.assign(Object.assign({}, targetGroup), { fields: insertFieldInList(fields[gdx].fields[fdx], targetGroup.fields, pos) }),
|
|
130
|
+
...lodash_1.default.slice(fields, tdx + 1, gdx),
|
|
131
|
+
Object.assign(Object.assign({}, sourceGroup), { fields: lodash_1.default.filter(sourceGroup.fields, item => item.id != id) }),
|
|
132
|
+
...lodash_1.default.slice(fields, gdx + 1),
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
exports.sortListInGroup = sortListInGroup;
|
|
137
|
+
const setProperties = (fields, fieldId, property, value) => {
|
|
138
|
+
let idx = lodash_1.default.findIndex(fields, { id: fieldId });
|
|
139
|
+
if (idx < 0) {
|
|
140
|
+
return fields;
|
|
141
|
+
}
|
|
142
|
+
let info;
|
|
143
|
+
if (lodash_1.default.isString(property)) {
|
|
144
|
+
if (value === null) {
|
|
145
|
+
lodash_1.default.unset(info, property);
|
|
146
|
+
}
|
|
147
|
+
info = Object.assign(Object.assign({}, fields[idx]), { [property]: value });
|
|
148
|
+
}
|
|
149
|
+
else if (lodash_1.default.isPlainObject(property)) {
|
|
150
|
+
info = Object.assign(Object.assign({}, fields[idx]), property);
|
|
151
|
+
}
|
|
152
|
+
return [
|
|
153
|
+
...(lodash_1.default.slice(fields, 0, idx)),
|
|
154
|
+
info,
|
|
155
|
+
...(lodash_1.default.slice(fields, idx + 1))
|
|
156
|
+
];
|
|
157
|
+
};
|
|
158
|
+
exports.setProperties = setProperties;
|
|
159
|
+
const setPropertiesInGroup = (fields, groupId, fieldId, property, value) => {
|
|
160
|
+
let gdx = lodash_1.default.findIndex(fields, { id: groupId });
|
|
161
|
+
if (gdx < 0) {
|
|
162
|
+
return fields;
|
|
163
|
+
}
|
|
164
|
+
let group = fields[gdx];
|
|
165
|
+
let idx = lodash_1.default.findIndex(group.fields, { id: fieldId });
|
|
166
|
+
if (idx < 0) {
|
|
167
|
+
return fields;
|
|
168
|
+
}
|
|
169
|
+
return [
|
|
170
|
+
...(lodash_1.default.slice(fields, 0, gdx)),
|
|
171
|
+
Object.assign(Object.assign({}, group), { fields: (0, exports.setProperties)(group.fields, fieldId, property, value) }),
|
|
172
|
+
...(lodash_1.default.slice(fields, gdx + 1))
|
|
173
|
+
];
|
|
174
|
+
};
|
|
175
|
+
exports.setPropertiesInGroup = setPropertiesInGroup;
|