@yibozhang/pro-table 0.0.3 → 0.0.4
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/README.md +55 -55
- package/bundles/yibozhang-pro-table.umd.js +312 -374
- package/bundles/yibozhang-pro-table.umd.js.map +1 -1
- package/bundles/yibozhang-pro-table.umd.min.js +1 -1
- package/bundles/yibozhang-pro-table.umd.min.js.map +1 -1
- package/esm2015/lib/components/colmuns-setting/colmuns-setting.component.js +1 -1
- package/esm2015/lib/components/dynamic-search-field/dynamic-search-field.component.js +1 -1
- package/esm2015/lib/constants.js +1 -1
- package/esm2015/lib/page-container/page-container.component.js +1 -1
- package/esm2015/lib/page-container/page-container.module.js +1 -1
- package/esm2015/lib/page-public/antd-form.js +35 -360
- package/esm2015/lib/page-public/array-form.js +269 -0
- package/esm2015/lib/plate-input/plate-input.component.js +1 -1
- package/esm2015/lib/plate-input/plate-input.module.js +1 -1
- package/esm2015/lib/plate-input/plate-prefix-load.service.js +1 -1
- package/esm2015/lib/pro-table.component.js +1 -1
- package/esm2015/lib/pro-table.module.js +1 -1
- package/esm2015/lib/table-search-bar/table-search-bar-module.js +1 -1
- package/esm2015/lib/table-search-bar/table-search-bar.component.js +1 -1
- package/esm2015/lib/tokens.js +1 -1
- package/esm2015/lib/type.js +1 -1
- package/esm2015/public-api.js +4 -2
- package/esm2015/yibozhang-pro-table.js +1 -1
- package/fesm2015/yibozhang-pro-table.js +303 -360
- package/fesm2015/yibozhang-pro-table.js.map +1 -1
- package/lib/components/colmuns-setting/colmuns-setting.component.d.ts.map +1 -1
- package/lib/components/dynamic-search-field/dynamic-search-field.component.d.ts.map +1 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/page-container/page-container.component.d.ts.map +1 -1
- package/lib/page-container/page-container.module.d.ts.map +1 -1
- package/lib/page-public/antd-form.d.ts +1 -20
- package/lib/page-public/antd-form.d.ts.map +1 -1
- package/lib/page-public/array-form.d.ts +186 -0
- package/lib/page-public/array-form.d.ts.map +1 -0
- package/lib/plate-input/plate-input.component.d.ts.map +1 -1
- package/lib/plate-input/plate-input.module.d.ts.map +1 -1
- package/lib/plate-input/plate-prefix-load.service.d.ts.map +1 -1
- package/lib/pro-table.component.d.ts.map +1 -1
- package/lib/pro-table.module.d.ts.map +1 -1
- package/lib/table-search-bar/table-search-bar-module.d.ts.map +1 -1
- package/lib/table-search-bar/table-search-bar.component.d.ts.map +1 -1
- package/lib/tokens.d.ts.map +1 -1
- package/lib/type.d.ts.map +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +4 -2
- package/public-api.d.ts.map +1 -1
- package/yibozhang-pro-table.d.ts.map +1 -1
- package/yibozhang-pro-table.metadata.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('lodash-es'), require('rxjs'), require('@angular/cdk/drag-drop'), require('@angular/common'), require('@angular/common/http'), require('@angular/forms'), require('@angular/router'), require('ng-zorro-antd/button'), require('ng-zorro-antd/checkbox'), require('ng-zorro-antd/date-picker'), require('ng-zorro-antd/form'), require('ng-zorro-antd/grid'), require('ng-zorro-antd/icon'), require('ng-zorro-antd/input'), require('ng-zorro-antd/modal'), require('ng-zorro-antd/popover'), require('ng-zorro-antd/select'), require('ng-zorro-antd/space'), require('ng-zorro-antd/table'), require('ng-zorro-antd/typography'), require('ng-zorro-antd/card'), require('sortablejs'), require('ng-zorro-antd/auto-complete'), require('ng-zorro-antd/input-number'), require('ng-zorro-antd/tooltip'), require('rxjs/operators')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@yibozhang/pro-table', ['exports', '@angular/core', 'lodash-es', 'rxjs', '@angular/cdk/drag-drop', '@angular/common', '@angular/common/http', '@angular/forms', '@angular/router', 'ng-zorro-antd/button', 'ng-zorro-antd/checkbox', 'ng-zorro-antd/date-picker', 'ng-zorro-antd/form', 'ng-zorro-antd/grid', 'ng-zorro-antd/icon', 'ng-zorro-antd/input', 'ng-zorro-antd/modal', 'ng-zorro-antd/popover', 'ng-zorro-antd/select', 'ng-zorro-antd/space', 'ng-zorro-antd/table', 'ng-zorro-antd/typography', 'ng-zorro-antd/card', 'sortablejs', 'ng-zorro-antd/auto-complete', 'ng-zorro-antd/input-number', 'ng-zorro-antd/tooltip', 'rxjs/operators'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.yibozhang = global.yibozhang || {}, global.yibozhang['pro-table'] = {}), global.ng.core, global.lodashEs, global.rxjs, global.ng.cdk.dragDrop, global.ng.common, global.ng.common.http, global.ng.forms, global.ng.router, global.button, global.checkbox, global.datePicker, global.form, global.grid, global.icon, global.input, global.modal, global.popover, global.select, global.space, global.table, global.typography, global.card, global.Sortable, global.autoComplete, global.inputNumber, global.tooltip, global.rxjs.operators));
|
|
5
|
-
}(this, (function (exports, i0, lodashEs, rxjs, dragDrop, common, http, i1, router, button, checkbox, datePicker, form, grid, icon, input, modal, popover, select, space, table, typography, card, Sortable, autoComplete, inputNumber, tooltip, operators) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('lodash-es'), require('rxjs'), require('@angular/cdk/drag-drop'), require('@angular/common'), require('@angular/common/http'), require('@angular/forms'), require('@angular/router'), require('ng-zorro-antd/button'), require('ng-zorro-antd/checkbox'), require('ng-zorro-antd/date-picker'), require('ng-zorro-antd/form'), require('ng-zorro-antd/grid'), require('ng-zorro-antd/icon'), require('ng-zorro-antd/input'), require('ng-zorro-antd/modal'), require('ng-zorro-antd/popover'), require('ng-zorro-antd/select'), require('ng-zorro-antd/space'), require('ng-zorro-antd/table'), require('ng-zorro-antd/typography'), require('ng-zorro-antd/card'), require('sortablejs'), require('ng-zorro-antd/auto-complete'), require('ng-zorro-antd/input-number'), require('ng-zorro-antd/tooltip'), require('rxjs/operators'), require('uuid')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@yibozhang/pro-table', ['exports', '@angular/core', 'lodash-es', 'rxjs', '@angular/cdk/drag-drop', '@angular/common', '@angular/common/http', '@angular/forms', '@angular/router', 'ng-zorro-antd/button', 'ng-zorro-antd/checkbox', 'ng-zorro-antd/date-picker', 'ng-zorro-antd/form', 'ng-zorro-antd/grid', 'ng-zorro-antd/icon', 'ng-zorro-antd/input', 'ng-zorro-antd/modal', 'ng-zorro-antd/popover', 'ng-zorro-antd/select', 'ng-zorro-antd/space', 'ng-zorro-antd/table', 'ng-zorro-antd/typography', 'ng-zorro-antd/card', 'sortablejs', 'ng-zorro-antd/auto-complete', 'ng-zorro-antd/input-number', 'ng-zorro-antd/tooltip', 'rxjs/operators', 'uuid'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.yibozhang = global.yibozhang || {}, global.yibozhang['pro-table'] = {}), global.ng.core, global.lodashEs, global.rxjs, global.ng.cdk.dragDrop, global.ng.common, global.ng.common.http, global.ng.forms, global.ng.router, global.button, global.checkbox, global.datePicker, global.form, global.grid, global.icon, global.input, global.modal, global.popover, global.select, global.space, global.table, global.typography, global.card, global.Sortable, global.autoComplete, global.inputNumber, global.tooltip, global.rxjs.operators, global.uuid));
|
|
5
|
+
}(this, (function (exports, i0, lodashEs, rxjs, dragDrop, common, http, i1, router, button, checkbox, datePicker, form, grid, icon, input, modal, popover, select, space, table, typography, card, Sortable, autoComplete, inputNumber, tooltip, operators, uuid) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -2328,8 +2328,6 @@
|
|
|
2328
2328
|
this.labelAlign = "right";
|
|
2329
2329
|
this.labelObservers = {};
|
|
2330
2330
|
this.errorMessageStore = {};
|
|
2331
|
-
this.formArrayConfigStore = {};
|
|
2332
|
-
this.INTERNAL_ID_FIELD = "__formItemId";
|
|
2333
2331
|
this.classPrefix = "ant-form-";
|
|
2334
2332
|
this.defaultErrorMessages = {
|
|
2335
2333
|
required: "该字段为必填项",
|
|
@@ -2340,44 +2338,20 @@
|
|
|
2340
2338
|
};
|
|
2341
2339
|
}
|
|
2342
2340
|
// ==================== 表单创建和初始化 ====================
|
|
2343
|
-
//
|
|
2341
|
+
// 初始化表单
|
|
2344
2342
|
AntdFormService.prototype.createFormGroup = function (name, config, options) {
|
|
2345
2343
|
var _this = this;
|
|
2346
2344
|
var groupConfig = {};
|
|
2347
2345
|
this.errorMessageStore[name] = {};
|
|
2348
2346
|
Object.entries(config).forEach(function (_f) {
|
|
2349
|
-
var _g = __read(_f, 2), key = _g[0],
|
|
2347
|
+
var _g = __read(_f, 2), key = _g[0], fieldConfig = _g[1];
|
|
2350
2348
|
var _a, _b, _c;
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
_this.
|
|
2357
|
-
itemConfig: field.itemConfig,
|
|
2358
|
-
uniqueIdField: field.uniqueIdField,
|
|
2359
|
-
};
|
|
2360
|
-
var formArray = _this.createFormArrayFromConfig(name, key, field.itemConfig, field.initialItems || [], field.uniqueIdField);
|
|
2361
|
-
groupConfig[key] = formArray;
|
|
2362
|
-
// 存储 FormArray 字段的错误消息配置,格式:arrayName[].fieldName
|
|
2363
|
-
if (field.errorMessages) {
|
|
2364
|
-
Object.entries(field.errorMessages).forEach(function (_f) {
|
|
2365
|
-
var _g = __read(_f, 2), fieldName = _g[0], errorMessages = _g[1];
|
|
2366
|
-
var errorMessageKey = key + "[]." + fieldName;
|
|
2367
|
-
_this.errorMessageStore[name][errorMessageKey] = errorMessages;
|
|
2368
|
-
});
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
else {
|
|
2372
|
-
// 普通字段配置
|
|
2373
|
-
var fieldConfig = field;
|
|
2374
|
-
groupConfig[key] = [
|
|
2375
|
-
{ value: fieldConfig.value, disabled: (_a = fieldConfig.disabled) !== null && _a !== void 0 ? _a : false },
|
|
2376
|
-
(_c = (_b = fieldConfig.validators) === null || _b === void 0 ? void 0 : _b.call(fieldConfig)) !== null && _c !== void 0 ? _c : [],
|
|
2377
|
-
];
|
|
2378
|
-
if (fieldConfig.errorMessages) {
|
|
2379
|
-
_this.errorMessageStore[name][key] = fieldConfig.errorMessages;
|
|
2380
|
-
}
|
|
2349
|
+
groupConfig[key] = [
|
|
2350
|
+
{ value: fieldConfig.value, disabled: (_a = fieldConfig.disabled) !== null && _a !== void 0 ? _a : false },
|
|
2351
|
+
(_c = (_b = fieldConfig.validators) === null || _b === void 0 ? void 0 : _b.call(fieldConfig)) !== null && _c !== void 0 ? _c : [],
|
|
2352
|
+
];
|
|
2353
|
+
if (fieldConfig.errorMessages) {
|
|
2354
|
+
_this.errorMessageStore[name][key] = fieldConfig.errorMessages;
|
|
2381
2355
|
}
|
|
2382
2356
|
});
|
|
2383
2357
|
if (options === null || options === void 0 ? void 0 : options.labelWidth) {
|
|
@@ -2421,17 +2395,13 @@
|
|
|
2421
2395
|
result.success = false;
|
|
2422
2396
|
return result;
|
|
2423
2397
|
}
|
|
2424
|
-
// 2. 初始化 errorMessageStore
|
|
2398
|
+
// 2. 初始化 errorMessageStore(如果不存在)
|
|
2425
2399
|
if (!this.errorMessageStore[formName]) {
|
|
2426
2400
|
this.errorMessageStore[formName] = {};
|
|
2427
2401
|
}
|
|
2428
|
-
if (!this.formArrayConfigStore[formName]) {
|
|
2429
|
-
this.formArrayConfigStore[formName] = {};
|
|
2430
|
-
}
|
|
2431
2402
|
// 3. 批量构建控件配置
|
|
2432
2403
|
var controlsToAdd = {};
|
|
2433
2404
|
var errorMessagesToAdd = {};
|
|
2434
|
-
var formArrayConfigsToAdd = {};
|
|
2435
2405
|
// 4. 遍历所有字段配置,进行验证和构建
|
|
2436
2406
|
Object.entries(fieldsConfig).forEach(function (_f) {
|
|
2437
2407
|
var _g = __read(_f, 2), fieldName = _g[0], fieldConfig = _g[1];
|
|
@@ -2447,41 +2417,19 @@
|
|
|
2447
2417
|
(_a = options === null || options === void 0 ? void 0 : options.onFieldAdded) === null || _a === void 0 ? void 0 : _a.call(options, fieldName, false, error);
|
|
2448
2418
|
return;
|
|
2449
2419
|
}
|
|
2450
|
-
// 4.2
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
uniqueIdField: fieldConfig.uniqueIdField,
|
|
2459
|
-
};
|
|
2460
|
-
// 存储错误消息
|
|
2461
|
-
if (fieldConfig.errorMessages) {
|
|
2462
|
-
Object.entries(fieldConfig.errorMessages).forEach(function (_f) {
|
|
2463
|
-
var _g = __read(_f, 2), itemFieldName = _g[0], errorMessages = _g[1];
|
|
2464
|
-
var errorMessageKey = fieldName + "[]." + itemFieldName;
|
|
2465
|
-
errorMessagesToAdd[errorMessageKey] = errorMessages;
|
|
2466
|
-
});
|
|
2467
|
-
}
|
|
2420
|
+
// 4.2 创建控件
|
|
2421
|
+
var controlOptions = {
|
|
2422
|
+
validators: (_c = (_b = fieldConfig.validators) === null || _b === void 0 ? void 0 : _b.call(fieldConfig)) !== null && _c !== void 0 ? _c : [],
|
|
2423
|
+
};
|
|
2424
|
+
var control = _this.fb.control(fieldConfig.value, controlOptions);
|
|
2425
|
+
// 设置 disabled 状态
|
|
2426
|
+
if (fieldConfig.disabled) {
|
|
2427
|
+
control.disable();
|
|
2468
2428
|
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
validators: (_c = (_b = fieldConfigTyped.validators) === null || _b === void 0 ? void 0 : _b.call(fieldConfigTyped)) !== null && _c !== void 0 ? _c : [],
|
|
2474
|
-
};
|
|
2475
|
-
var control = _this.fb.control(fieldConfigTyped.value, controlOptions);
|
|
2476
|
-
// 设置 disabled 状态
|
|
2477
|
-
if (fieldConfigTyped.disabled) {
|
|
2478
|
-
control.disable();
|
|
2479
|
-
}
|
|
2480
|
-
controlsToAdd[fieldName] = control;
|
|
2481
|
-
// 存储错误消息
|
|
2482
|
-
if (fieldConfigTyped.errorMessages) {
|
|
2483
|
-
errorMessagesToAdd[fieldName] = fieldConfigTyped.errorMessages;
|
|
2484
|
-
}
|
|
2429
|
+
controlsToAdd[fieldName] = control;
|
|
2430
|
+
// 存储错误消息
|
|
2431
|
+
if (fieldConfig.errorMessages) {
|
|
2432
|
+
errorMessagesToAdd[fieldName] = fieldConfig.errorMessages;
|
|
2485
2433
|
}
|
|
2486
2434
|
result.added.push(fieldName);
|
|
2487
2435
|
(_d = options === null || options === void 0 ? void 0 : options.onFieldAdded) === null || _d === void 0 ? void 0 : _d.call(options, fieldName, true);
|
|
@@ -2506,12 +2454,7 @@
|
|
|
2506
2454
|
var _g = __read(_f, 2), key = _g[0], messages = _g[1];
|
|
2507
2455
|
_this.errorMessageStore[formName][key] = messages;
|
|
2508
2456
|
});
|
|
2509
|
-
// 7.
|
|
2510
|
-
Object.entries(formArrayConfigsToAdd).forEach(function (_f) {
|
|
2511
|
-
var _g = __read(_f, 2), fieldName = _g[0], config = _g[1];
|
|
2512
|
-
_this.formArrayConfigStore[formName][fieldName] = config;
|
|
2513
|
-
});
|
|
2514
|
-
// 8. 更新表单验证状态
|
|
2457
|
+
// 7. 更新表单验证状态
|
|
2515
2458
|
if (options === null || options === void 0 ? void 0 : options.updateValueAndValidity) {
|
|
2516
2459
|
formGroup.updateValueAndValidity({
|
|
2517
2460
|
emitEvent: (_a = options === null || options === void 0 ? void 0 : options.emitEvent) !== null && _a !== void 0 ? _a : true,
|
|
@@ -2548,7 +2491,6 @@
|
|
|
2548
2491
|
// 2. 批量收集需要清理的信息
|
|
2549
2492
|
var fieldsToRemove = [];
|
|
2550
2493
|
var errorMessageKeysToRemove = [];
|
|
2551
|
-
var formArrayFields = [];
|
|
2552
2494
|
// 3. 验证每个字段并收集信息
|
|
2553
2495
|
fieldNames.forEach(function (fieldName) {
|
|
2554
2496
|
var _a;
|
|
@@ -2562,22 +2504,8 @@
|
|
|
2562
2504
|
(_a = options === null || options === void 0 ? void 0 : options.onFieldRemoved) === null || _a === void 0 ? void 0 : _a.call(options, fieldName, false, error);
|
|
2563
2505
|
return;
|
|
2564
2506
|
}
|
|
2565
|
-
//
|
|
2566
|
-
|
|
2567
|
-
formArrayFields.push(fieldName);
|
|
2568
|
-
// 收集 FormArray 相关的错误消息键(格式:arrayName[].fieldName)
|
|
2569
|
-
if (_this.errorMessageStore[formName]) {
|
|
2570
|
-
Object.keys(_this.errorMessageStore[formName]).forEach(function (key) {
|
|
2571
|
-
if (key.startsWith(fieldName + "[].")) {
|
|
2572
|
-
errorMessageKeysToRemove.push(key);
|
|
2573
|
-
}
|
|
2574
|
-
});
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
else {
|
|
2578
|
-
// 普通字段的错误消息键
|
|
2579
|
-
errorMessageKeysToRemove.push(fieldName);
|
|
2580
|
-
}
|
|
2507
|
+
// 收集错误消息键
|
|
2508
|
+
errorMessageKeysToRemove.push(fieldName);
|
|
2581
2509
|
fieldsToRemove.push(fieldName);
|
|
2582
2510
|
});
|
|
2583
2511
|
// 4. 批量执行删除操作
|
|
@@ -2595,12 +2523,6 @@
|
|
|
2595
2523
|
delete _this.errorMessageStore[formName][key];
|
|
2596
2524
|
});
|
|
2597
2525
|
}
|
|
2598
|
-
// 4.3 批量删除 FormArray 配置
|
|
2599
|
-
if (this.formArrayConfigStore[formName]) {
|
|
2600
|
-
formArrayFields.forEach(function (fieldName) {
|
|
2601
|
-
delete _this.formArrayConfigStore[formName][fieldName];
|
|
2602
|
-
});
|
|
2603
|
-
}
|
|
2604
2526
|
}
|
|
2605
2527
|
catch (error) {
|
|
2606
2528
|
// 如果批量删除过程中出错,标记为失败
|
|
@@ -2620,33 +2542,17 @@
|
|
|
2620
2542
|
result.success = result.failed.length === 0;
|
|
2621
2543
|
return result;
|
|
2622
2544
|
};
|
|
2623
|
-
//
|
|
2545
|
+
// 局部赋值
|
|
2624
2546
|
AntdFormService.prototype.patchFormValues = function (name, values, options) {
|
|
2625
|
-
var _this = this;
|
|
2626
2547
|
var _a;
|
|
2627
2548
|
var formGroup = this.formStore[name];
|
|
2628
2549
|
if (!formGroup) {
|
|
2629
2550
|
console.warn("[AntdFormService] patchFormValues: form \"" + name + "\" not found.");
|
|
2630
2551
|
return;
|
|
2631
2552
|
}
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
var _g = __read(_f, 2), key = _g[0], value = _g[1];
|
|
2635
|
-
var control = formGroup.get(key);
|
|
2636
|
-
// 检测是否是 FormArray
|
|
2637
|
-
if (control instanceof i1.FormArray && Array.isArray(value)) {
|
|
2638
|
-
_this.patchFormArray(name, key, value);
|
|
2639
|
-
return;
|
|
2640
|
-
}
|
|
2641
|
-
// 普通字段,直接加入
|
|
2642
|
-
processedValues[key] = value;
|
|
2553
|
+
formGroup.patchValue(values, {
|
|
2554
|
+
emitEvent: (_a = options === null || options === void 0 ? void 0 : options.emitEvent) !== null && _a !== void 0 ? _a : true,
|
|
2643
2555
|
});
|
|
2644
|
-
// 处理普通字段
|
|
2645
|
-
if (Object.keys(processedValues).length > 0) {
|
|
2646
|
-
formGroup.patchValue(processedValues, {
|
|
2647
|
-
emitEvent: (_a = options === null || options === void 0 ? void 0 : options.emitEvent) !== null && _a !== void 0 ? _a : true,
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
2556
|
};
|
|
2651
2557
|
// 表单校验(自动过滤内部字段)
|
|
2652
2558
|
AntdFormService.prototype.validateForm = function (name, options) {
|
|
@@ -2656,12 +2562,12 @@
|
|
|
2656
2562
|
return this.excludeInternalFields(rawValue);
|
|
2657
2563
|
}
|
|
2658
2564
|
else {
|
|
2659
|
-
//
|
|
2565
|
+
// 递归校验所有控件
|
|
2660
2566
|
this.markAllControlsAsDirty(this.formStore[name], (_a = options === null || options === void 0 ? void 0 : options.emitEvent) !== null && _a !== void 0 ? _a : true, (_b = options === null || options === void 0 ? void 0 : options.onlySelf) !== null && _b !== void 0 ? _b : false);
|
|
2661
2567
|
return false;
|
|
2662
2568
|
}
|
|
2663
2569
|
};
|
|
2664
|
-
// 递归标记所有无效控件为 dirty
|
|
2570
|
+
// 递归标记所有无效控件为 dirty
|
|
2665
2571
|
AntdFormService.prototype.markAllControlsAsDirty = function (control, emitEvent, onlySelf) {
|
|
2666
2572
|
var _this = this;
|
|
2667
2573
|
if (control.invalid) {
|
|
@@ -2677,15 +2583,9 @@
|
|
|
2677
2583
|
_this.markAllControlsAsDirty(childControl, emitEvent, onlySelf);
|
|
2678
2584
|
});
|
|
2679
2585
|
}
|
|
2680
|
-
// 如果是 FormArray,递归处理数组中的每一项
|
|
2681
|
-
if (control instanceof i1.FormArray) {
|
|
2682
|
-
control.controls.forEach(function (childControl) {
|
|
2683
|
-
_this.markAllControlsAsDirty(childControl, emitEvent, onlySelf);
|
|
2684
|
-
});
|
|
2685
|
-
}
|
|
2686
2586
|
};
|
|
2687
2587
|
// ==================== 错误消息相关 ====================
|
|
2688
|
-
//
|
|
2588
|
+
// 获取字段首条错误提示
|
|
2689
2589
|
AntdFormService.prototype.getFieldErrorMessage = function (name, controlName) {
|
|
2690
2590
|
var e_1, _f;
|
|
2691
2591
|
var _a;
|
|
@@ -2702,20 +2602,12 @@
|
|
|
2702
2602
|
if (!control.errors) {
|
|
2703
2603
|
return "";
|
|
2704
2604
|
}
|
|
2705
|
-
// 解析 controlName,支持 FormArray 格式:arrayName.index.fieldName
|
|
2706
|
-
var errorMessageKey = controlName;
|
|
2707
|
-
var arrayMatch = controlName.match(/^(.+)\.(\d+)\.(.+)$/);
|
|
2708
|
-
if (arrayMatch) {
|
|
2709
|
-
// FormArray 格式:arrayName.index.fieldName -> 使用 arrayName[].fieldName 作为 key
|
|
2710
|
-
var _g = __read(arrayMatch, 4), arrayName = _g[1], fieldName = _g[3];
|
|
2711
|
-
errorMessageKey = arrayName + "[]." + fieldName;
|
|
2712
|
-
}
|
|
2713
2605
|
// 从 errorMessageStore 获取错误消息配置
|
|
2714
|
-
var errorMessages = (_a = this.errorMessageStore[name]) === null || _a === void 0 ? void 0 : _a[
|
|
2606
|
+
var errorMessages = (_a = this.errorMessageStore[name]) === null || _a === void 0 ? void 0 : _a[controlName];
|
|
2715
2607
|
var mergedMessages = Object.assign(Object.assign({}, this.defaultErrorMessages), (errorMessages !== null && errorMessages !== void 0 ? errorMessages : {}));
|
|
2716
2608
|
try {
|
|
2717
|
-
for (var
|
|
2718
|
-
var errorKey =
|
|
2609
|
+
for (var _g = __values(Object.keys(control.errors)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2610
|
+
var errorKey = _h.value;
|
|
2719
2611
|
var message = mergedMessages[errorKey];
|
|
2720
2612
|
if (message) {
|
|
2721
2613
|
// 不再支持函数形式,只返回字符串
|
|
@@ -2726,7 +2618,7 @@
|
|
|
2726
2618
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2727
2619
|
finally {
|
|
2728
2620
|
try {
|
|
2729
|
-
if (
|
|
2621
|
+
if (_h && !_h.done && (_f = _g.return)) _f.call(_g);
|
|
2730
2622
|
}
|
|
2731
2623
|
finally { if (e_1) throw e_1.error; }
|
|
2732
2624
|
}
|
|
@@ -2804,232 +2696,6 @@
|
|
|
2804
2696
|
this.labelObservers[name] = observer;
|
|
2805
2697
|
};
|
|
2806
2698
|
// ==================== 私有方法 ====================
|
|
2807
|
-
// 获取 FormArray
|
|
2808
|
-
AntdFormService.prototype.getFormArray = function (formName, arrayName) {
|
|
2809
|
-
var formGroup = this.formStore[formName];
|
|
2810
|
-
if (!formGroup) {
|
|
2811
|
-
console.warn("[AntdFormService] getFormArray: form \"" + formName + "\" not found.");
|
|
2812
|
-
return null;
|
|
2813
|
-
}
|
|
2814
|
-
var control = formGroup.get(arrayName);
|
|
2815
|
-
if (!control || !(control instanceof i1.FormArray)) {
|
|
2816
|
-
console.warn("[AntdFormService] getFormArray: array \"" + arrayName + "\" not found in form \"" + formName + "\".");
|
|
2817
|
-
return null;
|
|
2818
|
-
}
|
|
2819
|
-
return control;
|
|
2820
|
-
};
|
|
2821
|
-
// 判断是否是 FormArray 配置
|
|
2822
|
-
AntdFormService.prototype.isFormArrayConfig = function (field) {
|
|
2823
|
-
return field.type === "array";
|
|
2824
|
-
};
|
|
2825
|
-
// 从配置创建 FormArray
|
|
2826
|
-
AntdFormService.prototype.createFormArrayFromConfig = function (formName, arrayName, itemConfig, initialItems, uniqueIdField) {
|
|
2827
|
-
var _this = this;
|
|
2828
|
-
var formArray = this.fb.array([]);
|
|
2829
|
-
initialItems.forEach(function (item) {
|
|
2830
|
-
var itemGroup = _this.createItemFormGroup(itemConfig, item, uniqueIdField);
|
|
2831
|
-
formArray.push(itemGroup);
|
|
2832
|
-
});
|
|
2833
|
-
return formArray;
|
|
2834
|
-
};
|
|
2835
|
-
// 生成内部ID(使用业务唯一字段或生成临时ID)
|
|
2836
|
-
AntdFormService.prototype.generateInternalId = function (itemData, uniqueIdField) {
|
|
2837
|
-
// 优先使用业务唯一字段
|
|
2838
|
-
if (uniqueIdField && (itemData === null || itemData === void 0 ? void 0 : itemData[uniqueIdField]) !== undefined) {
|
|
2839
|
-
var businessId = itemData[uniqueIdField];
|
|
2840
|
-
if (businessId !== null &&
|
|
2841
|
-
businessId !== undefined &&
|
|
2842
|
-
businessId !== "") {
|
|
2843
|
-
return "business-" + uniqueIdField + "-" + businessId;
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
// 如果没有业务ID,生成临时ID(用于新添加的项)
|
|
2847
|
-
return "temp-" + Date.now() + "-" + Math.random().toString(36).substr(2, 9);
|
|
2848
|
-
};
|
|
2849
|
-
// 创建单个项的 FormGroup
|
|
2850
|
-
AntdFormService.prototype.createItemFormGroup = function (itemConfig, itemData, uniqueIdField) {
|
|
2851
|
-
var _this = this;
|
|
2852
|
-
var groupConfig = {};
|
|
2853
|
-
// 添加内部ID字段
|
|
2854
|
-
var itemId = this.generateInternalId(itemData, uniqueIdField);
|
|
2855
|
-
groupConfig[this.INTERNAL_ID_FIELD] = [
|
|
2856
|
-
{ value: itemId, disabled: true },
|
|
2857
|
-
[],
|
|
2858
|
-
];
|
|
2859
|
-
// 添加业务字段
|
|
2860
|
-
Object.entries(itemConfig).forEach(function (_f) {
|
|
2861
|
-
var _g = __read(_f, 2), key = _g[0], field = _g[1];
|
|
2862
|
-
var _a, _b, _c;
|
|
2863
|
-
// itemConfig 中的字段应该是 FieldConfig,不应该包含 FormArrayConfig
|
|
2864
|
-
if (_this.isFormArrayConfig(field)) {
|
|
2865
|
-
console.warn("[AntdFormService] createItemFormGroup: FormArrayConfig is not allowed in itemConfig. Skipping field \"" + key + "\".");
|
|
2866
|
-
return;
|
|
2867
|
-
}
|
|
2868
|
-
var fieldConfig = field;
|
|
2869
|
-
var value = (itemData === null || itemData === void 0 ? void 0 : itemData[key]) !== undefined ? itemData[key] : fieldConfig.value;
|
|
2870
|
-
groupConfig[key] = [
|
|
2871
|
-
{ value: value, disabled: (_a = fieldConfig.disabled) !== null && _a !== void 0 ? _a : false },
|
|
2872
|
-
(_c = (_b = fieldConfig.validators) === null || _b === void 0 ? void 0 : _b.call(fieldConfig)) !== null && _c !== void 0 ? _c : [],
|
|
2873
|
-
];
|
|
2874
|
-
});
|
|
2875
|
-
return this.fb.group(groupConfig);
|
|
2876
|
-
};
|
|
2877
|
-
// 通过业务唯一字段查找内部ID
|
|
2878
|
-
AntdFormService.prototype.findFormArrayItemIdByBusinessField = function (formName, arrayName, uniqueIdField, businessIdValue) {
|
|
2879
|
-
var formArray = this.getFormArray(formName, arrayName);
|
|
2880
|
-
if (!formArray)
|
|
2881
|
-
return null;
|
|
2882
|
-
for (var i = 0; i < formArray.length; i++) {
|
|
2883
|
-
var item = formArray.at(i);
|
|
2884
|
-
var itemValue = item.getRawValue();
|
|
2885
|
-
var internalId = itemValue[this.INTERNAL_ID_FIELD];
|
|
2886
|
-
// 检查内部ID是否匹配业务ID
|
|
2887
|
-
if (internalId && internalId.startsWith("business-" + uniqueIdField + "-")) {
|
|
2888
|
-
var idInInternalId = internalId.replace("business-" + uniqueIdField + "-", "");
|
|
2889
|
-
if (String(idInInternalId) === String(businessIdValue)) {
|
|
2890
|
-
return internalId;
|
|
2891
|
-
}
|
|
2892
|
-
}
|
|
2893
|
-
// 也检查当前业务字段值是否匹配(处理业务ID更新的情况)
|
|
2894
|
-
if (itemValue[uniqueIdField] === businessIdValue) {
|
|
2895
|
-
return internalId;
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
return null;
|
|
2899
|
-
};
|
|
2900
|
-
// 通过内部ID查找项
|
|
2901
|
-
AntdFormService.prototype.findFormArrayItemById = function (formName, arrayName, itemId) {
|
|
2902
|
-
var _a;
|
|
2903
|
-
var formArray = this.getFormArray(formName, arrayName);
|
|
2904
|
-
if (!formArray)
|
|
2905
|
-
return null;
|
|
2906
|
-
for (var i = 0; i < formArray.length; i++) {
|
|
2907
|
-
var item = formArray.at(i);
|
|
2908
|
-
var id = (_a = item.get(this.INTERNAL_ID_FIELD)) === null || _a === void 0 ? void 0 : _a.value;
|
|
2909
|
-
if (id === itemId) {
|
|
2910
|
-
return { index: i, formGroup: item };
|
|
2911
|
-
}
|
|
2912
|
-
}
|
|
2913
|
-
return null;
|
|
2914
|
-
};
|
|
2915
|
-
// 获取操作类型(必须明确指定 action 字段)
|
|
2916
|
-
AntdFormService.prototype.getOperationType = function (itemData) {
|
|
2917
|
-
if (!itemData || typeof itemData !== "object")
|
|
2918
|
-
return null;
|
|
2919
|
-
var action = itemData.action;
|
|
2920
|
-
if (action === "delete" || action === "update" || action === "create") {
|
|
2921
|
-
return action;
|
|
2922
|
-
}
|
|
2923
|
-
return null;
|
|
2924
|
-
};
|
|
2925
|
-
// 过滤操作字段(action 字段不保存到表单中)
|
|
2926
|
-
AntdFormService.prototype.filterOperationFields = function (itemData) {
|
|
2927
|
-
if (!itemData || typeof itemData !== "object")
|
|
2928
|
-
return itemData;
|
|
2929
|
-
var filtered = {};
|
|
2930
|
-
Object.entries(itemData).forEach(function (_f) {
|
|
2931
|
-
var _g = __read(_f, 2), key = _g[0], value = _g[1];
|
|
2932
|
-
if (key !== "action") {
|
|
2933
|
-
filtered[key] = value;
|
|
2934
|
-
}
|
|
2935
|
-
});
|
|
2936
|
-
return filtered;
|
|
2937
|
-
};
|
|
2938
|
-
// 处理 FormArray 的更新(统一根据 action 字段判断操作类型)
|
|
2939
|
-
AntdFormService.prototype.patchFormArray = function (formName, arrayName, newValues) {
|
|
2940
|
-
var _this = this;
|
|
2941
|
-
var _a;
|
|
2942
|
-
var formArray = this.getFormArray(formName, arrayName);
|
|
2943
|
-
if (!formArray) {
|
|
2944
|
-
console.warn("[AntdFormService] patchFormArray: array \"" + arrayName + "\" not found in form \"" + formName + "\".");
|
|
2945
|
-
return;
|
|
2946
|
-
}
|
|
2947
|
-
var config = (_a = this.formArrayConfigStore[formName]) === null || _a === void 0 ? void 0 : _a[arrayName];
|
|
2948
|
-
if (!config) {
|
|
2949
|
-
console.warn("[AntdFormService] patchFormArray: config not found for array \"" + arrayName + "\" in form \"" + formName + "\".");
|
|
2950
|
-
return;
|
|
2951
|
-
}
|
|
2952
|
-
var itemConfig = config.itemConfig, uniqueIdField = config.uniqueIdField;
|
|
2953
|
-
// 统一根据 action 字段判断操作类型
|
|
2954
|
-
var itemsToDelete = new Set();
|
|
2955
|
-
var itemsToUpdate = new Map();
|
|
2956
|
-
var itemsToAdd = [];
|
|
2957
|
-
newValues.forEach(function (itemData) {
|
|
2958
|
-
if (!itemData || typeof itemData !== "object")
|
|
2959
|
-
return;
|
|
2960
|
-
var operationType = _this.getOperationType(itemData);
|
|
2961
|
-
if (!operationType) {
|
|
2962
|
-
console.warn("[AntdFormService] patchFormArray: Item missing required \"action\" field. Skipping.", itemData);
|
|
2963
|
-
return;
|
|
2964
|
-
}
|
|
2965
|
-
// 删除操作
|
|
2966
|
-
if (operationType === "delete") {
|
|
2967
|
-
if (uniqueIdField && itemData[uniqueIdField] !== undefined) {
|
|
2968
|
-
var businessId = itemData[uniqueIdField];
|
|
2969
|
-
var internalId = _this.findFormArrayItemIdByBusinessField(formName, arrayName, uniqueIdField, businessId);
|
|
2970
|
-
if (internalId) {
|
|
2971
|
-
itemsToDelete.add(internalId);
|
|
2972
|
-
}
|
|
2973
|
-
else {
|
|
2974
|
-
console.warn("[AntdFormService] patchFormArray: Cannot delete item with " + uniqueIdField + "=" + businessId + ", item not found.");
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
else {
|
|
2978
|
-
console.warn("[AntdFormService] patchFormArray: Cannot delete item, missing required uniqueIdField \"" + uniqueIdField + "\".");
|
|
2979
|
-
}
|
|
2980
|
-
return;
|
|
2981
|
-
}
|
|
2982
|
-
// 更新操作
|
|
2983
|
-
if (operationType === "update") {
|
|
2984
|
-
if (uniqueIdField && itemData[uniqueIdField] !== undefined) {
|
|
2985
|
-
var businessId = itemData[uniqueIdField];
|
|
2986
|
-
var internalId = _this.findFormArrayItemIdByBusinessField(formName, arrayName, uniqueIdField, businessId);
|
|
2987
|
-
if (internalId) {
|
|
2988
|
-
var filteredData = _this.filterOperationFields(itemData);
|
|
2989
|
-
itemsToUpdate.set(internalId, filteredData);
|
|
2990
|
-
}
|
|
2991
|
-
else {
|
|
2992
|
-
console.warn("[AntdFormService] patchFormArray: Cannot update item with " + uniqueIdField + "=" + businessId + ", item not found. Skipping.");
|
|
2993
|
-
}
|
|
2994
|
-
}
|
|
2995
|
-
else {
|
|
2996
|
-
console.warn("[AntdFormService] patchFormArray: Cannot update item, missing required uniqueIdField \"" + uniqueIdField + "\". Skipping.");
|
|
2997
|
-
}
|
|
2998
|
-
return;
|
|
2999
|
-
}
|
|
3000
|
-
// 创建操作
|
|
3001
|
-
if (operationType === "create") {
|
|
3002
|
-
var filteredData = _this.filterOperationFields(itemData);
|
|
3003
|
-
itemsToAdd.push(filteredData);
|
|
3004
|
-
}
|
|
3005
|
-
});
|
|
3006
|
-
// 执行删除(需要从后往前删除,避免索引变化)
|
|
3007
|
-
var deleteIndices = [];
|
|
3008
|
-
itemsToDelete.forEach(function (itemId) {
|
|
3009
|
-
var found = _this.findFormArrayItemById(formName, arrayName, itemId);
|
|
3010
|
-
if (found) {
|
|
3011
|
-
deleteIndices.push(found.index);
|
|
3012
|
-
}
|
|
3013
|
-
});
|
|
3014
|
-
deleteIndices
|
|
3015
|
-
.sort(function (a, b) { return b - a; })
|
|
3016
|
-
.forEach(function (index) {
|
|
3017
|
-
formArray.removeAt(index);
|
|
3018
|
-
});
|
|
3019
|
-
// 执行更新
|
|
3020
|
-
itemsToUpdate.forEach(function (itemData, itemId) {
|
|
3021
|
-
var found = _this.findFormArrayItemById(formName, arrayName, itemId);
|
|
3022
|
-
if (found) {
|
|
3023
|
-
var _a_1 = itemData, _b = _this.INTERNAL_ID_FIELD, _ = _a_1[_b], dataToUpdate = __rest(_a_1, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
3024
|
-
found.formGroup.patchValue(dataToUpdate);
|
|
3025
|
-
}
|
|
3026
|
-
});
|
|
3027
|
-
// 执行添加
|
|
3028
|
-
itemsToAdd.forEach(function (itemData) {
|
|
3029
|
-
var newItem = _this.createItemFormGroup(itemConfig, itemData, uniqueIdField);
|
|
3030
|
-
formArray.push(newItem);
|
|
3031
|
-
});
|
|
3032
|
-
};
|
|
3033
2699
|
// 过滤内部字段(递归处理对象和数组)
|
|
3034
2700
|
AntdFormService.prototype.excludeInternalFields = function (value) {
|
|
3035
2701
|
var _this = this;
|
|
@@ -3045,8 +2711,8 @@
|
|
|
3045
2711
|
var filtered = {};
|
|
3046
2712
|
Object.entries(value).forEach(function (_f) {
|
|
3047
2713
|
var _g = __read(_f, 2), key = _g[0], val = _g[1];
|
|
3048
|
-
// 过滤以 __
|
|
3049
|
-
if (!key.startsWith("__")
|
|
2714
|
+
// 过滤以 __ 开头的内部字段
|
|
2715
|
+
if (!key.startsWith("__")) {
|
|
3050
2716
|
filtered[key] = _this.excludeInternalFields(val);
|
|
3051
2717
|
}
|
|
3052
2718
|
});
|
|
@@ -3076,6 +2742,277 @@
|
|
|
3076
2742
|
{ type: i1.FormBuilder }
|
|
3077
2743
|
]; };
|
|
3078
2744
|
|
|
2745
|
+
/**
|
|
2746
|
+
* 数组型数据收集基础服务
|
|
2747
|
+
*
|
|
2748
|
+
* 功能:
|
|
2749
|
+
* 1. 支持通过 ngModel 绑定对应行的数据源
|
|
2750
|
+
* 2. 自动为数组数据添加 isEdit 和 uid 字段
|
|
2751
|
+
* 3. 支持每个字段的自定义校验方法,返回 'success' | 'warning' | 'error'
|
|
2752
|
+
* 4. 提供公共方法支持删除、新增、编辑等操作
|
|
2753
|
+
*/
|
|
2754
|
+
var ArrayFormService = /** @class */ (function () {
|
|
2755
|
+
function ArrayFormService() {
|
|
2756
|
+
this.formStore = {};
|
|
2757
|
+
}
|
|
2758
|
+
/**
|
|
2759
|
+
* 初始化数组数据
|
|
2760
|
+
* 为现有数据添加 uid 和 isEdit 字段
|
|
2761
|
+
*
|
|
2762
|
+
* @param data 原始数据数组
|
|
2763
|
+
* @param config 表单配置
|
|
2764
|
+
* @returns 初始化后的数据数组
|
|
2765
|
+
*/
|
|
2766
|
+
ArrayFormService.prototype.initializeData = function (data) {
|
|
2767
|
+
var _this = this;
|
|
2768
|
+
return data.map(function (item) { return _this.enrichRow(item); });
|
|
2769
|
+
};
|
|
2770
|
+
/**
|
|
2771
|
+
* 为单行数据添加 uid 和 isEdit 字段
|
|
2772
|
+
*
|
|
2773
|
+
* @param row 原始行数据
|
|
2774
|
+
* @returns 增强后的行数据
|
|
2775
|
+
*/
|
|
2776
|
+
ArrayFormService.prototype.enrichRow = function (row) {
|
|
2777
|
+
return Object.assign(Object.assign({}, row), { uid: row.uid || uuid.v4(), isEdit: row.isEdit !== undefined ? row.isEdit : false });
|
|
2778
|
+
};
|
|
2779
|
+
/**
|
|
2780
|
+
* 新增一行数据
|
|
2781
|
+
*
|
|
2782
|
+
* @param data 数据数组引用
|
|
2783
|
+
* @param defaultValues 默认值
|
|
2784
|
+
* @returns 新增的行数据
|
|
2785
|
+
*/
|
|
2786
|
+
ArrayFormService.prototype.addRow = function (data, defaultValues) {
|
|
2787
|
+
var newRow = Object.assign(Object.assign({}, defaultValues), { uid: uuid.v4(), isEdit: true, isAdd: true });
|
|
2788
|
+
data.push(newRow);
|
|
2789
|
+
return newRow;
|
|
2790
|
+
};
|
|
2791
|
+
/**
|
|
2792
|
+
* 校验单个字段
|
|
2793
|
+
*
|
|
2794
|
+
* @param row 行数据
|
|
2795
|
+
* @param fieldName 字段名
|
|
2796
|
+
* @param config 表单配置
|
|
2797
|
+
* @returns 校验结果
|
|
2798
|
+
*/
|
|
2799
|
+
ArrayFormService.prototype.validateField = function (row, fieldName, config) {
|
|
2800
|
+
var fieldConfig = config.fields.find(function (f) { return f.name === fieldName; });
|
|
2801
|
+
if (!fieldConfig) {
|
|
2802
|
+
return "";
|
|
2803
|
+
}
|
|
2804
|
+
if (fieldConfig.validator) {
|
|
2805
|
+
return fieldConfig.validator(row[fieldName], row, fieldName);
|
|
2806
|
+
}
|
|
2807
|
+
return "";
|
|
2808
|
+
};
|
|
2809
|
+
/**
|
|
2810
|
+
* 校验整行数据
|
|
2811
|
+
*
|
|
2812
|
+
* @param row 行数据
|
|
2813
|
+
* @param config 表单配置
|
|
2814
|
+
* @returns 校验结果对象,key为字段名,value为校验结果
|
|
2815
|
+
*/
|
|
2816
|
+
ArrayFormService.prototype.validateRow = function (row, config) {
|
|
2817
|
+
var _this = this;
|
|
2818
|
+
var results = {};
|
|
2819
|
+
config.fields.forEach(function (fieldConfig) {
|
|
2820
|
+
results[fieldConfig.name] = _this.validateField(row, fieldConfig.name, config);
|
|
2821
|
+
});
|
|
2822
|
+
return results;
|
|
2823
|
+
};
|
|
2824
|
+
/**
|
|
2825
|
+
* 校验整个数组
|
|
2826
|
+
*
|
|
2827
|
+
* @param data 数据数组
|
|
2828
|
+
* @param config 表单配置
|
|
2829
|
+
* @returns 校验结果对象,key为行的uid,value为该行的校验结果
|
|
2830
|
+
*/
|
|
2831
|
+
ArrayFormService.prototype.validateData = function (data, config) {
|
|
2832
|
+
var _this = this;
|
|
2833
|
+
var results = {};
|
|
2834
|
+
data.forEach(function (row) {
|
|
2835
|
+
results[row.uid] = _this.validateRow(row, config);
|
|
2836
|
+
});
|
|
2837
|
+
return results;
|
|
2838
|
+
};
|
|
2839
|
+
/**
|
|
2840
|
+
* 注册表单到存储
|
|
2841
|
+
* 如果表单已存在,则更新其配置
|
|
2842
|
+
*
|
|
2843
|
+
* @param formName 表单名称
|
|
2844
|
+
* @param data 数据数组
|
|
2845
|
+
* @param config 表单配置
|
|
2846
|
+
*/
|
|
2847
|
+
ArrayFormService.prototype.registerForm = function (formName, data, config) {
|
|
2848
|
+
this.formStore[formName] = {
|
|
2849
|
+
data: this.initializeData(data),
|
|
2850
|
+
config: config,
|
|
2851
|
+
validationResults: {},
|
|
2852
|
+
};
|
|
2853
|
+
// 如果配置了自动更新,立即更新一次
|
|
2854
|
+
this.autoUpdateArrayReference(formName);
|
|
2855
|
+
};
|
|
2856
|
+
/**
|
|
2857
|
+
* 从存储中获取表单
|
|
2858
|
+
*
|
|
2859
|
+
* @param formName 表单名称
|
|
2860
|
+
* @returns 表单存储项或undefined
|
|
2861
|
+
*/
|
|
2862
|
+
ArrayFormService.prototype.getForm = function (formName) {
|
|
2863
|
+
return this.formStore[formName];
|
|
2864
|
+
};
|
|
2865
|
+
/**
|
|
2866
|
+
* 向表单添加行
|
|
2867
|
+
*
|
|
2868
|
+
* @param formName 表单名称
|
|
2869
|
+
* @param defaultValues 默认值
|
|
2870
|
+
* @returns 新增的行数据或undefined
|
|
2871
|
+
*/
|
|
2872
|
+
ArrayFormService.prototype.addRowToForm = function (formName, defaultValues) {
|
|
2873
|
+
var form = this.formStore[formName];
|
|
2874
|
+
if (!form) {
|
|
2875
|
+
return undefined;
|
|
2876
|
+
}
|
|
2877
|
+
var newRow = this.addRow(form.data, defaultValues);
|
|
2878
|
+
// 自动更新外部数组引用
|
|
2879
|
+
this.autoUpdateArrayReference(formName);
|
|
2880
|
+
return newRow;
|
|
2881
|
+
};
|
|
2882
|
+
/**
|
|
2883
|
+
* 校验表单
|
|
2884
|
+
*
|
|
2885
|
+
* @param formName 表单名称
|
|
2886
|
+
* @returns 校验结果或undefined
|
|
2887
|
+
*/
|
|
2888
|
+
ArrayFormService.prototype.validateForm = function (formName) {
|
|
2889
|
+
var form = this.formStore[formName];
|
|
2890
|
+
if (!form) {
|
|
2891
|
+
return undefined;
|
|
2892
|
+
}
|
|
2893
|
+
var results = this.validateData(form.data, form.config);
|
|
2894
|
+
form.validationResults = results;
|
|
2895
|
+
return results;
|
|
2896
|
+
};
|
|
2897
|
+
/**
|
|
2898
|
+
* 开启指定行的编辑模式
|
|
2899
|
+
*
|
|
2900
|
+
* @param row 行数据
|
|
2901
|
+
*/
|
|
2902
|
+
ArrayFormService.prototype.enableEdit = function (row) {
|
|
2903
|
+
row.isEdit = true;
|
|
2904
|
+
};
|
|
2905
|
+
/**
|
|
2906
|
+
* 关闭指定行的编辑模式
|
|
2907
|
+
*
|
|
2908
|
+
* @param row 行数据
|
|
2909
|
+
*/
|
|
2910
|
+
ArrayFormService.prototype.disableEdit = function (row) {
|
|
2911
|
+
row.isEdit = false;
|
|
2912
|
+
};
|
|
2913
|
+
/**
|
|
2914
|
+
* 从表单中删除指定行
|
|
2915
|
+
*
|
|
2916
|
+
* @param formName 表单名称
|
|
2917
|
+
* @param row 行的uid
|
|
2918
|
+
* @returns 是否删除成功
|
|
2919
|
+
*/
|
|
2920
|
+
ArrayFormService.prototype.deleteRowFromForm = function (formName, row) {
|
|
2921
|
+
var form = this.formStore[formName];
|
|
2922
|
+
if (!form) {
|
|
2923
|
+
return false;
|
|
2924
|
+
}
|
|
2925
|
+
var index = form.data.findIndex(function (item) { return item.uid === row.uid; });
|
|
2926
|
+
if (index === -1) {
|
|
2927
|
+
return false;
|
|
2928
|
+
}
|
|
2929
|
+
form.data.splice(index, 1);
|
|
2930
|
+
if (form.validationResults && form.validationResults[row.uid]) {
|
|
2931
|
+
delete form.validationResults[row.uid];
|
|
2932
|
+
}
|
|
2933
|
+
// 自动更新外部数组引用
|
|
2934
|
+
this.autoUpdateArrayReference(formName);
|
|
2935
|
+
return true;
|
|
2936
|
+
};
|
|
2937
|
+
/**
|
|
2938
|
+
* 校验指定行的指定字段并返回校验结果
|
|
2939
|
+
* 实时执行校验,用于模板中的实时校验显示
|
|
2940
|
+
*
|
|
2941
|
+
* @param formName 表单名称
|
|
2942
|
+
* @param row 行数据
|
|
2943
|
+
* @param fieldName 字段名
|
|
2944
|
+
* @returns 校验结果
|
|
2945
|
+
*/
|
|
2946
|
+
ArrayFormService.prototype.validateFieldInRow = function (formName, row, fieldName) {
|
|
2947
|
+
var form = this.formStore[formName];
|
|
2948
|
+
if (!form) {
|
|
2949
|
+
return "success";
|
|
2950
|
+
}
|
|
2951
|
+
var fieldConfig = form.config.fields.find(function (f) { return f.name === fieldName; });
|
|
2952
|
+
if (!fieldConfig) {
|
|
2953
|
+
return "success";
|
|
2954
|
+
}
|
|
2955
|
+
var result = "";
|
|
2956
|
+
if (fieldConfig.validator) {
|
|
2957
|
+
result = fieldConfig.validator(row[fieldName], row, fieldName);
|
|
2958
|
+
}
|
|
2959
|
+
// 更新校验结果存储
|
|
2960
|
+
if (!form.validationResults) {
|
|
2961
|
+
form.validationResults = {};
|
|
2962
|
+
}
|
|
2963
|
+
if (!form.validationResults[row.uid]) {
|
|
2964
|
+
form.validationResults[row.uid] = {};
|
|
2965
|
+
}
|
|
2966
|
+
form.validationResults[row.uid][fieldName] = result;
|
|
2967
|
+
return result ? "error" : "success";
|
|
2968
|
+
};
|
|
2969
|
+
/**
|
|
2970
|
+
* 校验指定行的所有字段
|
|
2971
|
+
*
|
|
2972
|
+
* @param formName 表单名称
|
|
2973
|
+
* @param row 行数据
|
|
2974
|
+
* @returns 是否所有字段都通过校验
|
|
2975
|
+
*/
|
|
2976
|
+
ArrayFormService.prototype.validateRowAllFields = function (formName, row) {
|
|
2977
|
+
var _this = this;
|
|
2978
|
+
var form = this.formStore[formName];
|
|
2979
|
+
if (!form) {
|
|
2980
|
+
return true;
|
|
2981
|
+
}
|
|
2982
|
+
var hasError = false;
|
|
2983
|
+
form.config.fields.forEach(function (fieldConfig) {
|
|
2984
|
+
var result = _this.validateFieldInRow(formName, row, fieldConfig.name);
|
|
2985
|
+
if (result === "error") {
|
|
2986
|
+
hasError = true;
|
|
2987
|
+
}
|
|
2988
|
+
});
|
|
2989
|
+
return !hasError;
|
|
2990
|
+
};
|
|
2991
|
+
/**
|
|
2992
|
+
* 自动更新外部数组引用(如果配置了)
|
|
2993
|
+
* 私有方法,在数据变化时自动调用
|
|
2994
|
+
*
|
|
2995
|
+
* @param formName 表单名称
|
|
2996
|
+
*/
|
|
2997
|
+
ArrayFormService.prototype.autoUpdateArrayReference = function (formName) {
|
|
2998
|
+
var form = this.formStore[formName];
|
|
2999
|
+
if (!form || !form.config.targetObject || !form.config.arrayPropertyName) {
|
|
3000
|
+
return;
|
|
3001
|
+
}
|
|
3002
|
+
var newArray = form.data ? __spread(form.data) : [];
|
|
3003
|
+
// 更新目标对象的数组属性为新数组引用
|
|
3004
|
+
form.config.targetObject[form.config.arrayPropertyName] = newArray;
|
|
3005
|
+
};
|
|
3006
|
+
return ArrayFormService;
|
|
3007
|
+
}());
|
|
3008
|
+
ArrayFormService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ArrayFormService_Factory() { return new ArrayFormService(); }, token: ArrayFormService, providedIn: "root" });
|
|
3009
|
+
ArrayFormService.decorators = [
|
|
3010
|
+
{ type: i0.Injectable, args: [{
|
|
3011
|
+
providedIn: "root",
|
|
3012
|
+
},] }
|
|
3013
|
+
];
|
|
3014
|
+
ArrayFormService.ctorParameters = function () { return []; };
|
|
3015
|
+
|
|
3079
3016
|
/*
|
|
3080
3017
|
* Public API Surface of pro-table
|
|
3081
3018
|
*/
|
|
@@ -3085,6 +3022,7 @@
|
|
|
3085
3022
|
*/
|
|
3086
3023
|
|
|
3087
3024
|
exports.AntdFormService = AntdFormService;
|
|
3025
|
+
exports.ArrayFormService = ArrayFormService;
|
|
3088
3026
|
exports.DefaultPlatePrefixLoadService = DefaultPlatePrefixLoadService;
|
|
3089
3027
|
exports.PLATE_PREFIX_LOAD_SERVICE = PLATE_PREFIX_LOAD_SERVICE;
|
|
3090
3028
|
exports.PRO_TABLE_COLUMN_REMOTE = PRO_TABLE_COLUMN_REMOTE;
|