@yibozhang/pro-table 0.0.3 → 0.0.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/README.md +55 -55
- package/bundles/yibozhang-pro-table.umd.js +420 -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 +340 -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 +374 -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 +96 -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,385 @@
|
|
|
3076
2742
|
{ type: i1.FormBuilder }
|
|
3077
2743
|
]; };
|
|
3078
2744
|
|
|
2745
|
+
/** 数组型数据收集基础服务 */
|
|
2746
|
+
var ArrayFormService = /** @class */ (function () {
|
|
2747
|
+
function ArrayFormService() {
|
|
2748
|
+
this.formStore = {};
|
|
2749
|
+
}
|
|
2750
|
+
/** 深度克隆值 */
|
|
2751
|
+
ArrayFormService.prototype.cloneValue = function (value) {
|
|
2752
|
+
var e_1, _c;
|
|
2753
|
+
var _this = this;
|
|
2754
|
+
if (value === null || value === undefined) {
|
|
2755
|
+
return value;
|
|
2756
|
+
}
|
|
2757
|
+
if (Array.isArray(value)) {
|
|
2758
|
+
return value.map(function (item) { return _this.cloneValue(item); });
|
|
2759
|
+
}
|
|
2760
|
+
if (typeof value === "object") {
|
|
2761
|
+
var cloned = {};
|
|
2762
|
+
try {
|
|
2763
|
+
for (var _d = __values(Object.keys(value)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2764
|
+
var key = _e.value;
|
|
2765
|
+
cloned[key] = this.cloneValue(value[key]);
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2769
|
+
finally {
|
|
2770
|
+
try {
|
|
2771
|
+
if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
|
|
2772
|
+
}
|
|
2773
|
+
finally { if (e_1) throw e_1.error; }
|
|
2774
|
+
}
|
|
2775
|
+
return cloned;
|
|
2776
|
+
}
|
|
2777
|
+
return value;
|
|
2778
|
+
};
|
|
2779
|
+
/** 比较两个值是否相等 */
|
|
2780
|
+
ArrayFormService.prototype.isEqual = function (a, b) {
|
|
2781
|
+
var _this = this;
|
|
2782
|
+
if (a === b)
|
|
2783
|
+
return true;
|
|
2784
|
+
if (a === null || b === null)
|
|
2785
|
+
return a === b;
|
|
2786
|
+
if (a === undefined || b === undefined)
|
|
2787
|
+
return a === b;
|
|
2788
|
+
if (typeof a !== typeof b)
|
|
2789
|
+
return false;
|
|
2790
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
2791
|
+
if (a.length !== b.length)
|
|
2792
|
+
return false;
|
|
2793
|
+
return a.every(function (item, index) { return _this.isEqual(item, b[index]); });
|
|
2794
|
+
}
|
|
2795
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
2796
|
+
var keysA = Object.keys(a);
|
|
2797
|
+
var keysB = Object.keys(b);
|
|
2798
|
+
if (keysA.length !== keysB.length)
|
|
2799
|
+
return false;
|
|
2800
|
+
return keysA.every(function (key) { return _this.isEqual(a[key], b[key]); });
|
|
2801
|
+
}
|
|
2802
|
+
return false;
|
|
2803
|
+
};
|
|
2804
|
+
/** 创建行的初始值快照 */
|
|
2805
|
+
ArrayFormService.prototype.createRowSnapshot = function (row, fields) {
|
|
2806
|
+
var _this = this;
|
|
2807
|
+
var snapshot = {};
|
|
2808
|
+
fields.forEach(function (field) {
|
|
2809
|
+
snapshot[field.name] = _this.cloneValue(row[field.name]);
|
|
2810
|
+
});
|
|
2811
|
+
return snapshot;
|
|
2812
|
+
};
|
|
2813
|
+
/** 初始化数组数据,添加 uid 和 isEdit 字段 */
|
|
2814
|
+
ArrayFormService.prototype.initializeData = function (data) {
|
|
2815
|
+
var _this = this;
|
|
2816
|
+
return data.map(function (item) { return _this.enrichRow(item); });
|
|
2817
|
+
};
|
|
2818
|
+
/** 为单行数据添加 uid 和 isEdit 字段 */
|
|
2819
|
+
ArrayFormService.prototype.enrichRow = function (row) {
|
|
2820
|
+
return Object.assign(Object.assign({}, row), { uid: row.uid || uuid.v4(), isEdit: row.isEdit !== undefined ? row.isEdit : false, disabled: row.disabled !== undefined ? row.disabled : false });
|
|
2821
|
+
};
|
|
2822
|
+
/** 新增一行数据 */
|
|
2823
|
+
ArrayFormService.prototype.addRow = function (data, defaultValues) {
|
|
2824
|
+
var newRow = Object.assign(Object.assign({}, defaultValues), { uid: uuid.v4(), isEdit: true, isAdd: true, disabled: false });
|
|
2825
|
+
data.push(newRow);
|
|
2826
|
+
return newRow;
|
|
2827
|
+
};
|
|
2828
|
+
/** 校验单个字段 */
|
|
2829
|
+
ArrayFormService.prototype.validateField = function (row, fieldName, config) {
|
|
2830
|
+
var fieldConfig = config.fields.find(function (f) { return f.name === fieldName; });
|
|
2831
|
+
if (!fieldConfig) {
|
|
2832
|
+
return "";
|
|
2833
|
+
}
|
|
2834
|
+
if (fieldConfig.validator) {
|
|
2835
|
+
return fieldConfig.validator(row[fieldName], row, fieldName);
|
|
2836
|
+
}
|
|
2837
|
+
return "";
|
|
2838
|
+
};
|
|
2839
|
+
/** 校验整行数据 */
|
|
2840
|
+
ArrayFormService.prototype.validateRow = function (row, config) {
|
|
2841
|
+
var _this = this;
|
|
2842
|
+
var results = {};
|
|
2843
|
+
config.fields.forEach(function (fieldConfig) {
|
|
2844
|
+
results[fieldConfig.name] = _this.validateField(row, fieldConfig.name, config);
|
|
2845
|
+
});
|
|
2846
|
+
return results;
|
|
2847
|
+
};
|
|
2848
|
+
/** 校验整个数组 */
|
|
2849
|
+
ArrayFormService.prototype.validateData = function (data, config) {
|
|
2850
|
+
var _this = this;
|
|
2851
|
+
var results = {};
|
|
2852
|
+
data.forEach(function (row) {
|
|
2853
|
+
results[row.uid] = _this.validateRow(row, config);
|
|
2854
|
+
});
|
|
2855
|
+
return results;
|
|
2856
|
+
};
|
|
2857
|
+
/** 注册表单到存储 */
|
|
2858
|
+
ArrayFormService.prototype.registerForm = function (formName, data, config) {
|
|
2859
|
+
var _this = this;
|
|
2860
|
+
var initializedData = this.initializeData(data);
|
|
2861
|
+
// 记录初始值快照
|
|
2862
|
+
var initialSnapshot = {};
|
|
2863
|
+
initializedData.forEach(function (row) {
|
|
2864
|
+
initialSnapshot[row.uid] = _this.createRowSnapshot(row, config.fields);
|
|
2865
|
+
});
|
|
2866
|
+
this.formStore[formName] = {
|
|
2867
|
+
data: initializedData,
|
|
2868
|
+
config: config,
|
|
2869
|
+
validationResults: {},
|
|
2870
|
+
initialSnapshot: initialSnapshot,
|
|
2871
|
+
editingSnapshot: {},
|
|
2872
|
+
allTouched: false,
|
|
2873
|
+
rowTouched: {},
|
|
2874
|
+
};
|
|
2875
|
+
// 如果配置了自动更新,立即更新一次
|
|
2876
|
+
this.autoUpdateArrayReference(formName);
|
|
2877
|
+
};
|
|
2878
|
+
/** 从存储中获取表单 */
|
|
2879
|
+
ArrayFormService.prototype.getForm = function (formName) {
|
|
2880
|
+
return this.formStore[formName];
|
|
2881
|
+
};
|
|
2882
|
+
/** 从存储中获取表单数据 */
|
|
2883
|
+
ArrayFormService.prototype.getFormData = function (formName) {
|
|
2884
|
+
var form = this.formStore[formName];
|
|
2885
|
+
if (!form) {
|
|
2886
|
+
return undefined;
|
|
2887
|
+
}
|
|
2888
|
+
return form.data.map(function (item) {
|
|
2889
|
+
delete item.isEdit;
|
|
2890
|
+
delete item.isAdd;
|
|
2891
|
+
delete item.uid;
|
|
2892
|
+
return item;
|
|
2893
|
+
});
|
|
2894
|
+
};
|
|
2895
|
+
/** 向表单添加行 */
|
|
2896
|
+
ArrayFormService.prototype.addRowToForm = function (formName, defaultValues) {
|
|
2897
|
+
var form = this.formStore[formName];
|
|
2898
|
+
if (!form) {
|
|
2899
|
+
return undefined;
|
|
2900
|
+
}
|
|
2901
|
+
var newRow = this.addRow(form.data, defaultValues);
|
|
2902
|
+
// 为新行记录初始值快照
|
|
2903
|
+
form.initialSnapshot[newRow.uid] = this.createRowSnapshot(newRow, form.config.fields);
|
|
2904
|
+
// 自动更新外部数组引用
|
|
2905
|
+
this.autoUpdateArrayReference(formName);
|
|
2906
|
+
return newRow;
|
|
2907
|
+
};
|
|
2908
|
+
/** 校验表单,自动标记所有字段为已触碰 */
|
|
2909
|
+
ArrayFormService.prototype.validateForm = function (formName) {
|
|
2910
|
+
var e_2, _c, e_3, _d;
|
|
2911
|
+
var form = this.formStore[formName];
|
|
2912
|
+
if (!form) {
|
|
2913
|
+
return true;
|
|
2914
|
+
}
|
|
2915
|
+
// 标记所有字段为已触碰
|
|
2916
|
+
form.allTouched = true;
|
|
2917
|
+
var results = this.validateData(form.data, form.config);
|
|
2918
|
+
form.validationResults = results;
|
|
2919
|
+
try {
|
|
2920
|
+
// 检查是否有任何错误
|
|
2921
|
+
for (var _e = __values(Object.keys(results)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
2922
|
+
var uid = _f.value;
|
|
2923
|
+
try {
|
|
2924
|
+
for (var _g = (e_3 = void 0, __values(Object.keys(results[uid]))), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2925
|
+
var fieldName = _h.value;
|
|
2926
|
+
if (results[uid][fieldName]) {
|
|
2927
|
+
return false;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2932
|
+
finally {
|
|
2933
|
+
try {
|
|
2934
|
+
if (_h && !_h.done && (_d = _g.return)) _d.call(_g);
|
|
2935
|
+
}
|
|
2936
|
+
finally { if (e_3) throw e_3.error; }
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2941
|
+
finally {
|
|
2942
|
+
try {
|
|
2943
|
+
if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
|
|
2944
|
+
}
|
|
2945
|
+
finally { if (e_2) throw e_2.error; }
|
|
2946
|
+
}
|
|
2947
|
+
return true;
|
|
2948
|
+
};
|
|
2949
|
+
/** 开启编辑模式,保存快照用于取消恢复 */
|
|
2950
|
+
ArrayFormService.prototype.enableEdit = function (formName, row) {
|
|
2951
|
+
var form = this.formStore[formName];
|
|
2952
|
+
if (form && row.uid) {
|
|
2953
|
+
// 保存编辑前的快照
|
|
2954
|
+
form.editingSnapshot[row.uid] = this.createRowSnapshot(row, form.config.fields);
|
|
2955
|
+
}
|
|
2956
|
+
row.isEdit = true;
|
|
2957
|
+
};
|
|
2958
|
+
/** 取消编辑,恢复到编辑前的数据 */
|
|
2959
|
+
ArrayFormService.prototype.disableEdit = function (formName, row) {
|
|
2960
|
+
var _this = this;
|
|
2961
|
+
var form = this.formStore[formName];
|
|
2962
|
+
if (form && row.uid && form.editingSnapshot[row.uid]) {
|
|
2963
|
+
// 恢复编辑前的数据
|
|
2964
|
+
var snapshot_1 = form.editingSnapshot[row.uid];
|
|
2965
|
+
form.config.fields.forEach(function (field) {
|
|
2966
|
+
row[field.name] = _this.cloneValue(snapshot_1[field.name]);
|
|
2967
|
+
});
|
|
2968
|
+
// 更新初始快照为恢复后的值,消除 touched 状态
|
|
2969
|
+
form.initialSnapshot[row.uid] = this.cloneValue(snapshot_1);
|
|
2970
|
+
// 清理编辑快照和 touched 状态
|
|
2971
|
+
delete form.editingSnapshot[row.uid];
|
|
2972
|
+
delete form.rowTouched[row.uid];
|
|
2973
|
+
// 清理该行的校验结果
|
|
2974
|
+
if (form.validationResults) {
|
|
2975
|
+
delete form.validationResults[row.uid];
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
row.isEdit = false;
|
|
2979
|
+
};
|
|
2980
|
+
/** 确认编辑,保留修改后的数据 */
|
|
2981
|
+
ArrayFormService.prototype.confirmEdit = function (formName, row) {
|
|
2982
|
+
var form = this.formStore[formName];
|
|
2983
|
+
if (form && row.uid) {
|
|
2984
|
+
// 清理编辑快照(保留当前数据)
|
|
2985
|
+
if (form.editingSnapshot[row.uid]) {
|
|
2986
|
+
delete form.editingSnapshot[row.uid];
|
|
2987
|
+
}
|
|
2988
|
+
// 更新初始快照为当前值(用于后续 touched 检测)
|
|
2989
|
+
form.initialSnapshot[row.uid] = this.createRowSnapshot(row, form.config.fields);
|
|
2990
|
+
// 清除 touched 状态,基于新的 initialSnapshot 重新判断
|
|
2991
|
+
delete form.rowTouched[row.uid];
|
|
2992
|
+
}
|
|
2993
|
+
row.isEdit = false;
|
|
2994
|
+
row.isAdd = false;
|
|
2995
|
+
};
|
|
2996
|
+
/** 从表单中删除指定行 */
|
|
2997
|
+
ArrayFormService.prototype.deleteRowFromForm = function (formName, row) {
|
|
2998
|
+
var form = this.formStore[formName];
|
|
2999
|
+
if (!form || !row.uid) {
|
|
3000
|
+
return false;
|
|
3001
|
+
}
|
|
3002
|
+
var index = form.data.findIndex(function (item) { return item.uid === row.uid; });
|
|
3003
|
+
if (index === -1) {
|
|
3004
|
+
return false;
|
|
3005
|
+
}
|
|
3006
|
+
form.data.splice(index, 1);
|
|
3007
|
+
// 清理该行的所有快照、touched 状态和校验结果
|
|
3008
|
+
delete form.initialSnapshot[row.uid];
|
|
3009
|
+
delete form.editingSnapshot[row.uid];
|
|
3010
|
+
delete form.rowTouched[row.uid];
|
|
3011
|
+
if (form.validationResults) {
|
|
3012
|
+
delete form.validationResults[row.uid];
|
|
3013
|
+
}
|
|
3014
|
+
// 自动更新外部数组引用
|
|
3015
|
+
this.autoUpdateArrayReference(formName);
|
|
3016
|
+
return true;
|
|
3017
|
+
};
|
|
3018
|
+
/** 检测字段是否已被触碰 */
|
|
3019
|
+
ArrayFormService.prototype.isFieldTouched = function (form, row, fieldName) {
|
|
3020
|
+
var _a;
|
|
3021
|
+
// 整个表单已 touched(整个表单提交时)
|
|
3022
|
+
if (form.allTouched) {
|
|
3023
|
+
return true;
|
|
3024
|
+
}
|
|
3025
|
+
// 当前行已 touched(单行保存时)
|
|
3026
|
+
if (form.rowTouched[row.uid]) {
|
|
3027
|
+
return true;
|
|
3028
|
+
}
|
|
3029
|
+
// 检测当前值与初始值是否不同
|
|
3030
|
+
var initialValue = (_a = form.initialSnapshot[row.uid]) === null || _a === void 0 ? void 0 : _a[fieldName];
|
|
3031
|
+
var currentValue = row[fieldName];
|
|
3032
|
+
return !this.isEqual(initialValue, currentValue);
|
|
3033
|
+
};
|
|
3034
|
+
/** 校验指定行的指定字段,未修改时不显示校验状态 */
|
|
3035
|
+
ArrayFormService.prototype.validateFieldInRow = function (formName, row, fieldName) {
|
|
3036
|
+
var form = this.formStore[formName];
|
|
3037
|
+
if (!form) {
|
|
3038
|
+
return "";
|
|
3039
|
+
}
|
|
3040
|
+
var fieldConfig = form.config.fields.find(function (f) { return f.name === fieldName; });
|
|
3041
|
+
if (!fieldConfig) {
|
|
3042
|
+
return "";
|
|
3043
|
+
}
|
|
3044
|
+
// 执行校验
|
|
3045
|
+
var result = "";
|
|
3046
|
+
if (fieldConfig.validator) {
|
|
3047
|
+
result = fieldConfig.validator(row[fieldName], row, fieldName);
|
|
3048
|
+
}
|
|
3049
|
+
// 更新校验结果存储
|
|
3050
|
+
if (!form.validationResults) {
|
|
3051
|
+
form.validationResults = {};
|
|
3052
|
+
}
|
|
3053
|
+
if (!form.validationResults[row.uid]) {
|
|
3054
|
+
form.validationResults[row.uid] = {};
|
|
3055
|
+
}
|
|
3056
|
+
form.validationResults[row.uid][fieldName] = result;
|
|
3057
|
+
// 如果字段未被触碰,不显示校验状态
|
|
3058
|
+
if (!this.isFieldTouched(form, row, fieldName)) {
|
|
3059
|
+
return "";
|
|
3060
|
+
}
|
|
3061
|
+
return result ? "error" : "success";
|
|
3062
|
+
};
|
|
3063
|
+
/** 获取指定行指定字段的校验错误信息 */
|
|
3064
|
+
ArrayFormService.prototype.getFieldErrorMessage = function (formName, row, fieldName) {
|
|
3065
|
+
var _a, _b;
|
|
3066
|
+
var form = this.formStore[formName];
|
|
3067
|
+
if (!form || !row.uid) {
|
|
3068
|
+
return "";
|
|
3069
|
+
}
|
|
3070
|
+
// 如果字段未被触碰,不显示错误信息
|
|
3071
|
+
if (!this.isFieldTouched(form, row, fieldName)) {
|
|
3072
|
+
return "";
|
|
3073
|
+
}
|
|
3074
|
+
return ((_b = (_a = form.validationResults) === null || _a === void 0 ? void 0 : _a[row.uid]) === null || _b === void 0 ? void 0 : _b[fieldName]) || "";
|
|
3075
|
+
};
|
|
3076
|
+
/** 校验指定行的所有字段 */
|
|
3077
|
+
ArrayFormService.prototype.validateRowAllFields = function (formName, row) {
|
|
3078
|
+
var _this = this;
|
|
3079
|
+
var form = this.formStore[formName];
|
|
3080
|
+
if (!form || !row.uid) {
|
|
3081
|
+
return true;
|
|
3082
|
+
}
|
|
3083
|
+
// 更新初始快照为当前值
|
|
3084
|
+
form.initialSnapshot[row.uid] = this.createRowSnapshot(row, form.config.fields);
|
|
3085
|
+
// 标记当前行为 touched(只影响当前行,不影响其他行)
|
|
3086
|
+
form.rowTouched[row.uid] = true;
|
|
3087
|
+
var hasError = false;
|
|
3088
|
+
form.config.fields.forEach(function (fieldConfig) {
|
|
3089
|
+
var result = _this.validateFieldInRow(formName, row, fieldConfig.name);
|
|
3090
|
+
if (result === "error") {
|
|
3091
|
+
hasError = true;
|
|
3092
|
+
}
|
|
3093
|
+
});
|
|
3094
|
+
return !hasError;
|
|
3095
|
+
};
|
|
3096
|
+
/** 自动更新外部数组引用 */
|
|
3097
|
+
ArrayFormService.prototype.autoUpdateArrayReference = function (formName) {
|
|
3098
|
+
var form = this.formStore[formName];
|
|
3099
|
+
if (!form || !form.config.targetObject || !form.config.arrayPropertyName) {
|
|
3100
|
+
return;
|
|
3101
|
+
}
|
|
3102
|
+
var newArray = form.data ? __spread(form.data) : [];
|
|
3103
|
+
// 更新目标对象的数组属性为新数组引用
|
|
3104
|
+
form.config.targetObject[form.config.arrayPropertyName] = newArray;
|
|
3105
|
+
};
|
|
3106
|
+
/** 是否有正在编辑的行 */
|
|
3107
|
+
ArrayFormService.prototype.hasEditingRow = function (formName) {
|
|
3108
|
+
var form = this.formStore[formName];
|
|
3109
|
+
if (!form) {
|
|
3110
|
+
return false;
|
|
3111
|
+
}
|
|
3112
|
+
return form.data.some(function (item) { return item.isEdit; });
|
|
3113
|
+
};
|
|
3114
|
+
return ArrayFormService;
|
|
3115
|
+
}());
|
|
3116
|
+
ArrayFormService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ArrayFormService_Factory() { return new ArrayFormService(); }, token: ArrayFormService, providedIn: "root" });
|
|
3117
|
+
ArrayFormService.decorators = [
|
|
3118
|
+
{ type: i0.Injectable, args: [{
|
|
3119
|
+
providedIn: "root",
|
|
3120
|
+
},] }
|
|
3121
|
+
];
|
|
3122
|
+
ArrayFormService.ctorParameters = function () { return []; };
|
|
3123
|
+
|
|
3079
3124
|
/*
|
|
3080
3125
|
* Public API Surface of pro-table
|
|
3081
3126
|
*/
|
|
@@ -3085,6 +3130,7 @@
|
|
|
3085
3130
|
*/
|
|
3086
3131
|
|
|
3087
3132
|
exports.AntdFormService = AntdFormService;
|
|
3133
|
+
exports.ArrayFormService = ArrayFormService;
|
|
3088
3134
|
exports.DefaultPlatePrefixLoadService = DefaultPlatePrefixLoadService;
|
|
3089
3135
|
exports.PLATE_PREFIX_LOAD_SERVICE = PLATE_PREFIX_LOAD_SERVICE;
|
|
3090
3136
|
exports.PRO_TABLE_COLUMN_REMOTE = PRO_TABLE_COLUMN_REMOTE;
|