cmat 0.0.86 → 0.0.88
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/fesm2022/cmat-components-adapter.mjs +9 -9
- package/fesm2022/cmat-components-adapter.mjs.map +1 -1
- package/fesm2022/cmat-components-breadcrumb.mjs +98 -80
- package/fesm2022/cmat-components-breadcrumb.mjs.map +1 -1
- package/fesm2022/cmat-components-card.mjs +26 -34
- package/fesm2022/cmat-components-card.mjs.map +1 -1
- package/fesm2022/cmat-components-carousel.mjs +467 -556
- package/fesm2022/cmat-components-carousel.mjs.map +1 -1
- package/fesm2022/cmat-components-cascade.mjs +270 -259
- package/fesm2022/cmat-components-cascade.mjs.map +1 -1
- package/fesm2022/cmat-components-chip-input.mjs +200 -116
- package/fesm2022/cmat-components-chip-input.mjs.map +1 -1
- package/fesm2022/cmat-components-code-editor.mjs +85 -38
- package/fesm2022/cmat-components-code-editor.mjs.map +1 -1
- package/fesm2022/cmat-components-color-picker.mjs +841 -0
- package/fesm2022/cmat-components-color-picker.mjs.map +1 -0
- package/fesm2022/cmat-components-custom-formly.mjs +1395 -838
- package/fesm2022/cmat-components-custom-formly.mjs.map +1 -1
- package/fesm2022/cmat-components-data-picker.mjs +996 -0
- package/fesm2022/cmat-components-data-picker.mjs.map +1 -0
- package/fesm2022/cmat-components-date-range.mjs +310 -264
- package/fesm2022/cmat-components-date-range.mjs.map +1 -1
- package/fesm2022/cmat-components-date-time-display.mjs +16 -20
- package/fesm2022/cmat-components-date-time-display.mjs.map +1 -1
- package/fesm2022/cmat-components-drawer.mjs +120 -137
- package/fesm2022/cmat-components-drawer.mjs.map +1 -1
- package/fesm2022/cmat-components-empty-state.mjs +17 -24
- package/fesm2022/cmat-components-empty-state.mjs.map +1 -1
- package/fesm2022/cmat-components-file-preview.mjs +18 -24
- package/fesm2022/cmat-components-file-preview.mjs.map +1 -1
- package/fesm2022/cmat-components-filter-toolbar.mjs +30 -39
- package/fesm2022/cmat-components-filter-toolbar.mjs.map +1 -1
- package/fesm2022/cmat-components-form-actions.mjs +12 -12
- package/fesm2022/cmat-components-form-actions.mjs.map +1 -1
- package/fesm2022/cmat-components-fullscreen.mjs +10 -10
- package/fesm2022/cmat-components-fullscreen.mjs.map +1 -1
- package/fesm2022/cmat-components-highlight.mjs +48 -41
- package/fesm2022/cmat-components-highlight.mjs.map +1 -1
- package/fesm2022/cmat-components-image-viewer.mjs +104 -107
- package/fesm2022/cmat-components-image-viewer.mjs.map +1 -1
- package/fesm2022/cmat-components-inline-loading.mjs +12 -15
- package/fesm2022/cmat-components-inline-loading.mjs.map +1 -1
- package/fesm2022/cmat-components-json-editor.mjs +118 -75
- package/fesm2022/cmat-components-json-editor.mjs.map +1 -1
- package/fesm2022/cmat-components-knob-input.mjs +196 -178
- package/fesm2022/cmat-components-knob-input.mjs.map +1 -1
- package/fesm2022/cmat-components-masonry.mjs +26 -41
- package/fesm2022/cmat-components-masonry.mjs.map +1 -1
- package/fesm2022/cmat-components-material-color-picker.mjs +81 -80
- package/fesm2022/cmat-components-material-color-picker.mjs.map +1 -1
- package/fesm2022/cmat-components-material-datetimepicker.mjs +1212 -1287
- package/fesm2022/cmat-components-material-datetimepicker.mjs.map +1 -1
- package/fesm2022/cmat-components-navigation.mjs +467 -450
- package/fesm2022/cmat-components-navigation.mjs.map +1 -1
- package/fesm2022/cmat-components-opt-input.mjs +143 -132
- package/fesm2022/cmat-components-opt-input.mjs.map +1 -1
- package/fesm2022/cmat-components-org-chart.mjs +68 -83
- package/fesm2022/cmat-components-org-chart.mjs.map +1 -1
- package/fesm2022/cmat-components-page-header.mjs +18 -24
- package/fesm2022/cmat-components-page-header.mjs.map +1 -1
- package/fesm2022/cmat-components-pagination.mjs +220 -136
- package/fesm2022/cmat-components-pagination.mjs.map +1 -1
- package/fesm2022/cmat-components-password-strength.mjs +262 -215
- package/fesm2022/cmat-components-password-strength.mjs.map +1 -1
- package/fesm2022/cmat-components-popover.mjs +227 -195
- package/fesm2022/cmat-components-popover.mjs.map +1 -1
- package/fesm2022/cmat-components-progress-bar.mjs +15 -34
- package/fesm2022/cmat-components-progress-bar.mjs.map +1 -1
- package/fesm2022/cmat-components-qrcode.mjs +95 -88
- package/fesm2022/cmat-components-qrcode.mjs.map +1 -1
- package/fesm2022/cmat-components-rating.mjs +70 -67
- package/fesm2022/cmat-components-rating.mjs.map +1 -1
- package/fesm2022/cmat-components-rich-text-editor.mjs +23 -26
- package/fesm2022/cmat-components-rich-text-editor.mjs.map +1 -1
- package/fesm2022/cmat-components-select-search.mjs +190 -159
- package/fesm2022/cmat-components-select-search.mjs.map +1 -1
- package/fesm2022/cmat-components-select-table.mjs +276 -213
- package/fesm2022/cmat-components-select-table.mjs.map +1 -1
- package/fesm2022/cmat-components-select-tree.mjs +178 -128
- package/fesm2022/cmat-components-select-tree.mjs.map +1 -1
- package/fesm2022/cmat-components-skeleton.mjs +44 -28
- package/fesm2022/cmat-components-skeleton.mjs.map +1 -1
- package/fesm2022/cmat-components-speed-dial.mjs +107 -163
- package/fesm2022/cmat-components-speed-dial.mjs.map +1 -1
- package/fesm2022/cmat-components-status-tag.mjs +29 -36
- package/fesm2022/cmat-components-status-tag.mjs.map +1 -1
- package/fesm2022/cmat-components-table-toolbar.mjs +14 -18
- package/fesm2022/cmat-components-table-toolbar.mjs.map +1 -1
- package/fesm2022/cmat-components-timeline.mjs +111 -118
- package/fesm2022/cmat-components-timeline.mjs.map +1 -1
- package/fesm2022/cmat-components-toast.mjs +65 -66
- package/fesm2022/cmat-components-toast.mjs.map +1 -1
- package/fesm2022/cmat-components-transfer-picker.mjs +130 -160
- package/fesm2022/cmat-components-transfer-picker.mjs.map +1 -1
- package/fesm2022/cmat-components-treetable.mjs +32 -39
- package/fesm2022/cmat-components-treetable.mjs.map +1 -1
- package/fesm2022/cmat-components-upload.mjs +186 -176
- package/fesm2022/cmat-components-upload.mjs.map +1 -1
- package/fesm2022/cmat-directives-animate-on-scroll.mjs +25 -28
- package/fesm2022/cmat-directives-animate-on-scroll.mjs.map +1 -1
- package/fesm2022/cmat-directives-arrow-cursor.mjs +85 -92
- package/fesm2022/cmat-directives-arrow-cursor.mjs.map +1 -1
- package/fesm2022/cmat-directives-autofocus.mjs +3 -3
- package/fesm2022/cmat-directives-autofocus.mjs.map +1 -1
- package/fesm2022/cmat-directives-data-exporter.mjs +49 -50
- package/fesm2022/cmat-directives-data-exporter.mjs.map +1 -1
- package/fesm2022/cmat-directives-debounce.mjs +16 -19
- package/fesm2022/cmat-directives-debounce.mjs.map +1 -1
- package/fesm2022/cmat-directives-digit-only.mjs +60 -69
- package/fesm2022/cmat-directives-digit-only.mjs.map +1 -1
- package/fesm2022/cmat-directives-equal-validator.mjs +3 -3
- package/fesm2022/cmat-directives-equal-validator.mjs.map +1 -1
- package/fesm2022/cmat-directives-seamless-auto-scroll.mjs +31 -30
- package/fesm2022/cmat-directives-seamless-auto-scroll.mjs.map +1 -1
- package/fesm2022/cmat-lib-mock-api.mjs +6 -6
- package/fesm2022/cmat-lib-mock-api.mjs.map +1 -1
- package/fesm2022/cmat-pipes-bytes.mjs +3 -3
- package/fesm2022/cmat-pipes-bytes.mjs.map +1 -1
- package/fesm2022/cmat-pipes-date-format.mjs +3 -3
- package/fesm2022/cmat-pipes-date-format.mjs.map +1 -1
- package/fesm2022/cmat-pipes-find-by-key.mjs +3 -3
- package/fesm2022/cmat-pipes-find-by-key.mjs.map +1 -1
- package/fesm2022/cmat-pipes-group-by.mjs +3 -3
- package/fesm2022/cmat-pipes-group-by.mjs.map +1 -1
- package/fesm2022/cmat-pipes-keys.mjs +3 -3
- package/fesm2022/cmat-pipes-keys.mjs.map +1 -1
- package/fesm2022/cmat-pipes-secure.mjs +7 -13
- package/fesm2022/cmat-pipes-secure.mjs.map +1 -1
- package/fesm2022/cmat-pipes-uppercase.mjs +3 -3
- package/fesm2022/cmat-pipes-uppercase.mjs.map +1 -1
- package/fesm2022/cmat-services-alert.mjs +26 -27
- package/fesm2022/cmat-services-alert.mjs.map +1 -1
- package/fesm2022/cmat-services-config.mjs +14 -23
- package/fesm2022/cmat-services-config.mjs.map +1 -1
- package/fesm2022/cmat-services-confirmation.mjs +8 -8
- package/fesm2022/cmat-services-confirmation.mjs.map +1 -1
- package/fesm2022/cmat-services-data.mjs +6 -10
- package/fesm2022/cmat-services-data.mjs.map +1 -1
- package/fesm2022/cmat-services-export-as.mjs +3 -3
- package/fesm2022/cmat-services-export-as.mjs.map +1 -1
- package/fesm2022/cmat-services-loading.mjs +30 -47
- package/fesm2022/cmat-services-loading.mjs.map +1 -1
- package/fesm2022/cmat-services-local-storage.mjs +3 -3
- package/fesm2022/cmat-services-local-storage.mjs.map +1 -1
- package/fesm2022/cmat-services-media-watcher.mjs +43 -34
- package/fesm2022/cmat-services-media-watcher.mjs.map +1 -1
- package/fesm2022/cmat-services-platform.mjs +3 -3
- package/fesm2022/cmat-services-platform.mjs.map +1 -1
- package/fesm2022/cmat-services-splash-screen.mjs +3 -3
- package/fesm2022/cmat-services-splash-screen.mjs.map +1 -1
- package/fesm2022/cmat-services-title.mjs +3 -3
- package/fesm2022/cmat-services-title.mjs.map +1 -1
- package/fesm2022/cmat-services-translation.mjs +11 -11
- package/fesm2022/cmat-services-translation.mjs.map +1 -1
- package/fesm2022/cmat-services-utils.mjs +4 -4
- package/fesm2022/cmat-services-utils.mjs.map +1 -1
- package/fesm2022/cmat.mjs +9229 -7508
- package/fesm2022/cmat.mjs.map +1 -1
- package/icons/material-icons/heroicons-outline.svg +3 -0
- package/icons/material-icons/heroicons-solid.svg +3 -0
- package/package.json +10 -1
- package/styles/components/bundle.scss +21 -0
- package/styles/overrides/angular-material.scss +22 -1
- package/tailwind/plugins/theming.js +183 -183
- package/types/cmat-components-breadcrumb.d.ts +40 -37
- package/types/cmat-components-card.d.ts +11 -13
- package/types/cmat-components-carousel.d.ts +87 -113
- package/types/cmat-components-cascade.d.ts +84 -65
- package/types/cmat-components-chip-input.d.ts +29 -24
- package/types/cmat-components-code-editor.d.ts +28 -12
- package/types/cmat-components-color-picker.d.ts +236 -0
- package/types/cmat-components-custom-formly.d.ts +316 -184
- package/types/cmat-components-data-picker.d.ts +372 -0
- package/types/cmat-components-date-range.d.ts +31 -36
- package/types/cmat-components-date-time-display.d.ts +8 -8
- package/types/cmat-components-drawer.d.ts +30 -32
- package/types/cmat-components-empty-state.d.ts +9 -10
- package/types/cmat-components-file-preview.d.ts +9 -9
- package/types/cmat-components-filter-toolbar.d.ts +15 -15
- package/types/cmat-components-form-actions.d.ts +5 -5
- package/types/cmat-components-fullscreen.d.ts +5 -5
- package/types/cmat-components-highlight.d.ts +13 -14
- package/types/cmat-components-image-viewer.d.ts +29 -33
- package/types/cmat-components-inline-loading.d.ts +6 -6
- package/types/cmat-components-json-editor.d.ts +15 -17
- package/types/cmat-components-knob-input.d.ts +58 -55
- package/types/cmat-components-masonry.d.ts +9 -12
- package/types/cmat-components-material-color-picker.d.ts +16 -21
- package/types/cmat-components-material-datetimepicker.d.ts +174 -216
- package/types/cmat-components-navigation.d.ts +34 -39
- package/types/cmat-components-opt-input.d.ts +35 -33
- package/types/cmat-components-org-chart.d.ts +8 -9
- package/types/cmat-components-page-header.d.ts +9 -9
- package/types/cmat-components-pagination.d.ts +36 -40
- package/types/cmat-components-password-strength.d.ts +58 -64
- package/types/cmat-components-popover.d.ts +22 -32
- package/types/cmat-components-progress-bar.d.ts +7 -10
- package/types/cmat-components-qrcode.d.ts +22 -22
- package/types/cmat-components-rating.d.ts +17 -19
- package/types/cmat-components-rich-text-editor.d.ts +11 -12
- package/types/cmat-components-select-search.d.ts +48 -36
- package/types/cmat-components-select-table.d.ts +38 -34
- package/types/cmat-components-select-tree.d.ts +17 -15
- package/types/cmat-components-skeleton.d.ts +27 -10
- package/types/cmat-components-speed-dial.d.ts +24 -33
- package/types/cmat-components-status-tag.d.ts +19 -9
- package/types/cmat-components-table-toolbar.d.ts +7 -7
- package/types/cmat-components-timeline.d.ts +33 -34
- package/types/cmat-components-toast.d.ts +26 -30
- package/types/cmat-components-transfer-picker.d.ts +51 -56
- package/types/cmat-components-treetable.d.ts +12 -13
- package/types/cmat-components-upload.d.ts +33 -38
- package/types/cmat-components-x6-angular-shape.d.ts +1 -1
- package/types/cmat-directives-animate-on-scroll.d.ts +7 -7
- package/types/cmat-directives-arrow-cursor.d.ts +18 -20
- package/types/cmat-directives-data-exporter.d.ts +10 -10
- package/types/cmat-directives-debounce.d.ts +5 -5
- package/types/cmat-directives-digit-only.d.ts +13 -13
- package/types/cmat-directives-seamless-auto-scroll.d.ts +7 -7
- package/types/cmat-pipes-secure.d.ts +1 -3
- package/types/cmat-services-alert.d.ts +11 -12
- package/types/cmat-services-config.d.ts +2 -7
- package/types/cmat-services-confirmation.d.ts +2 -2
- package/types/cmat-services-data.d.ts +0 -1
- package/types/cmat-services-loading.d.ts +14 -22
- package/types/cmat-services-media-watcher.d.ts +5 -5
- package/types/cmat-services-translation.d.ts +4 -5
- package/types/cmat.d.ts +2167 -1746
|
@@ -0,0 +1,996 @@
|
|
|
1
|
+
import { map, startWith, debounceTime, distinctUntilChanged, tap, switchMap, catchError } from 'rxjs/operators';
|
|
2
|
+
import * as i1 from '@angular/common';
|
|
3
|
+
import { CommonModule } from '@angular/common';
|
|
4
|
+
import * as i0 from '@angular/core';
|
|
5
|
+
import { input, output, signal, computed, inject, DestroyRef, effect, untracked, ViewEncapsulation, ChangeDetectionStrategy, Component, viewChild, ElementRef, Input } from '@angular/core';
|
|
6
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
7
|
+
import * as i2 from '@angular/forms';
|
|
8
|
+
import { FormControl, ReactiveFormsModule, NgControl } from '@angular/forms';
|
|
9
|
+
import * as i1$1 from '@angular/material/button';
|
|
10
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
11
|
+
import * as i3 from '@angular/material/checkbox';
|
|
12
|
+
import { MatCheckboxModule } from '@angular/material/checkbox';
|
|
13
|
+
import * as i2$1 from '@angular/material/icon';
|
|
14
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
15
|
+
import * as i5 from '@angular/material/input';
|
|
16
|
+
import { MatInputModule } from '@angular/material/input';
|
|
17
|
+
import * as i6 from '@angular/material/progress-spinner';
|
|
18
|
+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
19
|
+
import * as i7 from '@angular/material/radio';
|
|
20
|
+
import { MatRadioModule } from '@angular/material/radio';
|
|
21
|
+
import * as i8 from '@angular/material/sort';
|
|
22
|
+
import { MatSortModule } from '@angular/material/sort';
|
|
23
|
+
import * as i9 from '@angular/material/table';
|
|
24
|
+
import { MatTableModule } from '@angular/material/table';
|
|
25
|
+
import { CmatPaginationComponent, CmatPaginatePipe } from 'cmat/components/pagination';
|
|
26
|
+
import { EMPTY, Subject } from 'rxjs';
|
|
27
|
+
import { MAT_BOTTOM_SHEET_DATA, MatBottomSheetRef, MatBottomSheet } from '@angular/material/bottom-sheet';
|
|
28
|
+
import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material/dialog';
|
|
29
|
+
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
|
30
|
+
import { Overlay } from '@angular/cdk/overlay';
|
|
31
|
+
import { ComponentPortal } from '@angular/cdk/portal';
|
|
32
|
+
import * as i1$2 from '@angular/material/chips';
|
|
33
|
+
import { MatChipsModule } from '@angular/material/chips';
|
|
34
|
+
import { MatFormField, MatFormFieldControl } from '@angular/material/form-field';
|
|
35
|
+
import { CmatMediaWatcherService } from 'cmat/services/media-watcher';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* HTTP数据提供者实现
|
|
39
|
+
*/
|
|
40
|
+
class HttpDataPickerProvider {
|
|
41
|
+
constructor(_dataService, _config) {
|
|
42
|
+
this._dataService = _dataService;
|
|
43
|
+
this._config = _config;
|
|
44
|
+
}
|
|
45
|
+
loadPage(query) {
|
|
46
|
+
const { url, method = 'post', params = {}, searchParam = 'search', orderByField = 'orderBy', descField = 'desc', responseMapper } = this._config;
|
|
47
|
+
// 构建请求参数
|
|
48
|
+
const requestParams = { ...params };
|
|
49
|
+
// 添加分页参数(使用后端期望的字段名)
|
|
50
|
+
requestParams.pageIndex = query.page;
|
|
51
|
+
requestParams.pageSize = query.size;
|
|
52
|
+
// 添加搜索参数(支持自定义字段名)
|
|
53
|
+
if (query.search) {
|
|
54
|
+
requestParams[searchParam] = query.search;
|
|
55
|
+
}
|
|
56
|
+
// 添加排序参数(固定使用 orderBy 和 desc,但字段名可配置)
|
|
57
|
+
if (query.orderBy) {
|
|
58
|
+
requestParams[orderByField] = query.orderBy;
|
|
59
|
+
requestParams[descField] = query.desc ?? false;
|
|
60
|
+
}
|
|
61
|
+
// 根据请求方法调用不同的服务
|
|
62
|
+
const request$ = method.toLowerCase() === 'get'
|
|
63
|
+
? this._dataService.get(url, requestParams)
|
|
64
|
+
: this._dataService.post(url, requestParams);
|
|
65
|
+
return request$.pipe(map((res) => {
|
|
66
|
+
// 如果提供了自定义映射函数,优先使用
|
|
67
|
+
if (responseMapper) {
|
|
68
|
+
return responseMapper(res);
|
|
69
|
+
}
|
|
70
|
+
// 默认映射:支持多种常见的响应格式
|
|
71
|
+
const record = res;
|
|
72
|
+
// 尝试常见的数据字段名
|
|
73
|
+
const data = (record['data'] ?? record['detail'] ?? record['items'] ?? record['list'] ?? []);
|
|
74
|
+
// 尝试常见的总数字段名
|
|
75
|
+
const total = (record['total'] ?? record['totalCount'] ?? record['count'] ?? record['totalItems'] ?? 0);
|
|
76
|
+
return {
|
|
77
|
+
data,
|
|
78
|
+
total
|
|
79
|
+
};
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 创建HTTP数据提供者的工厂函数
|
|
85
|
+
* @param config 数据源配置
|
|
86
|
+
* @param dataService CmatDataService 实例
|
|
87
|
+
*/
|
|
88
|
+
function createHttpDataProvider(config, dataService) {
|
|
89
|
+
return new HttpDataPickerProvider(dataService, config);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
class CmatDataPickerListComponent {
|
|
93
|
+
constructor() {
|
|
94
|
+
// === 输入 ===
|
|
95
|
+
this.dataProvider = input.required(/* @ts-ignore */
|
|
96
|
+
...(ngDevMode ? [{ debugName: "dataProvider" }] : /* istanbul ignore next */ []));
|
|
97
|
+
this.columns = input.required(/* @ts-ignore */
|
|
98
|
+
...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
99
|
+
this.keyField = input('id', /* @ts-ignore */
|
|
100
|
+
...(ngDevMode ? [{ debugName: "keyField" }] : /* istanbul ignore next */ []));
|
|
101
|
+
this.multiple = input(false, /* @ts-ignore */
|
|
102
|
+
...(ngDevMode ? [{ debugName: "multiple" }] : /* istanbul ignore next */ []));
|
|
103
|
+
this.searchable = input(true, /* @ts-ignore */
|
|
104
|
+
...(ngDevMode ? [{ debugName: "searchable" }] : /* istanbul ignore next */ []));
|
|
105
|
+
this.pageSize = input(20, /* @ts-ignore */
|
|
106
|
+
...(ngDevMode ? [{ debugName: "pageSize" }] : /* istanbul ignore next */ []));
|
|
107
|
+
this.searchPlaceholder = input('搜索...', /* @ts-ignore */
|
|
108
|
+
...(ngDevMode ? [{ debugName: "searchPlaceholder" }] : /* istanbul ignore next */ []));
|
|
109
|
+
this.emptyText = input('暂无数据', /* @ts-ignore */
|
|
110
|
+
...(ngDevMode ? [{ debugName: "emptyText" }] : /* istanbul ignore next */ []));
|
|
111
|
+
this.paginationId = input('data-picker-pagination', /* @ts-ignore */
|
|
112
|
+
...(ngDevMode ? [{ debugName: "paginationId" }] : /* istanbul ignore next */ []));
|
|
113
|
+
// === 输出 ===
|
|
114
|
+
this.selectionChange = output();
|
|
115
|
+
// === 内部状态 ===
|
|
116
|
+
this.items = signal([], /* @ts-ignore */
|
|
117
|
+
...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
118
|
+
this.loading = signal(false, /* @ts-ignore */
|
|
119
|
+
...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
|
|
120
|
+
this.selectedItems = signal(new Map(), /* @ts-ignore */
|
|
121
|
+
...(ngDevMode ? [{ debugName: "selectedItems" }] : /* istanbul ignore next */ []));
|
|
122
|
+
// === 分页状态(统一管理) ===
|
|
123
|
+
this.pagination = signal({
|
|
124
|
+
currentPage: 1,
|
|
125
|
+
itemsPerPage: 20,
|
|
126
|
+
totalItems: 0
|
|
127
|
+
}, /* @ts-ignore */
|
|
128
|
+
...(ngDevMode ? [{ debugName: "pagination" }] : /* istanbul ignore next */ []));
|
|
129
|
+
// === 排序状态 ===
|
|
130
|
+
this.sortState = signal({}, /* @ts-ignore */
|
|
131
|
+
...(ngDevMode ? [{ debugName: "sortState" }] : /* istanbul ignore next */ []));
|
|
132
|
+
// === 搜索控制 ===
|
|
133
|
+
this.searchControl = new FormControl('');
|
|
134
|
+
// === 计算属性 ===
|
|
135
|
+
this.displayedColumns = computed(() => {
|
|
136
|
+
const cols = this.columns().map(c => c.key);
|
|
137
|
+
return ['_selection', ...cols];
|
|
138
|
+
}, /* @ts-ignore */
|
|
139
|
+
...(ngDevMode ? [{ debugName: "displayedColumns" }] : /* istanbul ignore next */ []));
|
|
140
|
+
this.selectedCount = computed(() => this.selectedItems().size, /* @ts-ignore */
|
|
141
|
+
...(ngDevMode ? [{ debugName: "selectedCount" }] : /* istanbul ignore next */ []));
|
|
142
|
+
this.isAllSelected = computed(() => {
|
|
143
|
+
if (!this.multiple() || this.items().length === 0) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return this.items().every(item => this.selectedItems().has(this.getItemKey(item)));
|
|
147
|
+
}, /* @ts-ignore */
|
|
148
|
+
...(ngDevMode ? [{ debugName: "isAllSelected" }] : /* istanbul ignore next */ []));
|
|
149
|
+
this.isIndeterminate = computed(() => {
|
|
150
|
+
if (!this.multiple()) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
const selectedCount = this.items().filter(item => this.selectedItems().has(this.getItemKey(item))).length;
|
|
154
|
+
return selectedCount > 0 && selectedCount < this.items().length;
|
|
155
|
+
}, /* @ts-ignore */
|
|
156
|
+
...(ngDevMode ? [{ debugName: "isIndeterminate" }] : /* istanbul ignore next */ []));
|
|
157
|
+
this._destroyRef = inject(DestroyRef);
|
|
158
|
+
// 监听搜索变化,带防抖
|
|
159
|
+
effect(() => {
|
|
160
|
+
const provider = this.dataProvider();
|
|
161
|
+
if (!provider)
|
|
162
|
+
return;
|
|
163
|
+
untracked(() => {
|
|
164
|
+
this.searchControl.valueChanges.pipe(startWith(''), debounceTime(300), distinctUntilChanged(), tap(() => this.loading.set(true)), switchMap((search) => {
|
|
165
|
+
// 在闭包中捕获当前的排序状态
|
|
166
|
+
const currentSort = this.sortState();
|
|
167
|
+
return provider.loadPage({
|
|
168
|
+
page: 1,
|
|
169
|
+
size: this.pagination().itemsPerPage,
|
|
170
|
+
search: search ?? undefined,
|
|
171
|
+
orderBy: currentSort.active,
|
|
172
|
+
desc: currentSort.direction === 'desc'
|
|
173
|
+
});
|
|
174
|
+
}), takeUntilDestroyed(this._destroyRef), catchError((error) => {
|
|
175
|
+
console.error('Search failed:', error);
|
|
176
|
+
this.items.set([]);
|
|
177
|
+
return EMPTY;
|
|
178
|
+
})).subscribe((result) => {
|
|
179
|
+
// 确保即使返回空数组也正确更新状态
|
|
180
|
+
this.items.set(result.data || []);
|
|
181
|
+
this.pagination.update(p => ({ ...p, currentPage: 1, totalItems: result.total || 0 }));
|
|
182
|
+
this.loading.set(false);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 加载数据(公共方法,用于初始化和重置)
|
|
189
|
+
*/
|
|
190
|
+
loadData() {
|
|
191
|
+
this._loadPageData(this.pagination().currentPage, this.pagination().itemsPerPage, this.searchControl.value ?? undefined);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* 重置组件状态(用于重新打开时)
|
|
195
|
+
*/
|
|
196
|
+
reset() {
|
|
197
|
+
// 重置分页状态
|
|
198
|
+
this.pagination.set({
|
|
199
|
+
currentPage: 1,
|
|
200
|
+
itemsPerPage: this.pageSize(),
|
|
201
|
+
totalItems: 0
|
|
202
|
+
});
|
|
203
|
+
// 重置排序状态
|
|
204
|
+
this.sortState.set({});
|
|
205
|
+
// 清空搜索(不触发事件,避免重复加载)
|
|
206
|
+
this.searchControl.setValue('', { emitEvent: false });
|
|
207
|
+
// 清空选中项
|
|
208
|
+
this.selectedItems.set(new Map());
|
|
209
|
+
// 清空数据列表
|
|
210
|
+
this.items.set([]);
|
|
211
|
+
// 重新加载数据
|
|
212
|
+
this._loadPageData(1, this.pageSize(), '', undefined, undefined);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 获取项的唯一键
|
|
216
|
+
*/
|
|
217
|
+
getItemKey(item) {
|
|
218
|
+
return item[this.keyField()];
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 判断是否选中
|
|
222
|
+
*/
|
|
223
|
+
isSelected(item) {
|
|
224
|
+
return this.selectedItems().has(this.getItemKey(item));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 切换单个项的选中状态
|
|
228
|
+
*/
|
|
229
|
+
toggleSelection(item, checked) {
|
|
230
|
+
const key = this.getItemKey(item);
|
|
231
|
+
const newMap = new Map(this.selectedItems());
|
|
232
|
+
if (checked) {
|
|
233
|
+
newMap.set(key, item);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
newMap.delete(key);
|
|
237
|
+
}
|
|
238
|
+
this.selectedItems.set(newMap);
|
|
239
|
+
this._emitSelectionChange();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 单选模式
|
|
243
|
+
*/
|
|
244
|
+
selectSingle(item) {
|
|
245
|
+
const key = this.getItemKey(item);
|
|
246
|
+
const newMap = new Map();
|
|
247
|
+
newMap.set(key, item);
|
|
248
|
+
this.selectedItems.set(newMap);
|
|
249
|
+
this._emitSelectionChange();
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* 全选/取消全选当前页
|
|
253
|
+
*/
|
|
254
|
+
toggleSelectAll(checked) {
|
|
255
|
+
const newMap = new Map(this.selectedItems());
|
|
256
|
+
if (checked) {
|
|
257
|
+
// 选中当前页所有项
|
|
258
|
+
this.items().forEach((item) => {
|
|
259
|
+
newMap.set(this.getItemKey(item), item);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// 取消当前页所有项
|
|
264
|
+
const currentKeys = new Set(this.items().map(item => this.getItemKey(item)));
|
|
265
|
+
currentKeys.forEach(key => newMap.delete(key));
|
|
266
|
+
}
|
|
267
|
+
this.selectedItems.set(newMap);
|
|
268
|
+
this._emitSelectionChange();
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* 行点击事件
|
|
272
|
+
*/
|
|
273
|
+
onRowClick(item) {
|
|
274
|
+
if (this.multiple()) {
|
|
275
|
+
const checked = !this.isSelected(item);
|
|
276
|
+
this.toggleSelection(item, checked);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
this.selectSingle(item);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* 排序变化
|
|
284
|
+
*/
|
|
285
|
+
onSortChange(sort) {
|
|
286
|
+
// 更新排序状态
|
|
287
|
+
this.sortState.set({
|
|
288
|
+
active: sort.active || undefined,
|
|
289
|
+
direction: sort.direction === 'asc' || sort.direction === 'desc' ? sort.direction : undefined
|
|
290
|
+
});
|
|
291
|
+
// 重置到第一页并重新加载数据
|
|
292
|
+
this.pagination.update(p => ({ ...p, currentPage: 1 }));
|
|
293
|
+
this._loadPageData(1, this.pagination().itemsPerPage, this.searchControl.value ?? undefined, sort.active || undefined, sort.direction === 'desc');
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 页码变化
|
|
297
|
+
*/
|
|
298
|
+
onPageChange(page) {
|
|
299
|
+
this.pagination.update(p => ({ ...p, currentPage: page }));
|
|
300
|
+
const currentSort = this.sortState();
|
|
301
|
+
this._loadPageData(page, this.pagination().itemsPerPage, this.searchControl.value ?? undefined, currentSort.active, currentSort.direction === 'desc');
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* 每页数量变化
|
|
305
|
+
*/
|
|
306
|
+
onPageSizeChange(size) {
|
|
307
|
+
// 更新分页状态
|
|
308
|
+
this.pagination.update(p => ({ ...p, itemsPerPage: size, currentPage: 1 }));
|
|
309
|
+
// 直接使用新的 size 加载第一页数据
|
|
310
|
+
const currentSort = this.sortState();
|
|
311
|
+
this._loadPageData(1, size, this.searchControl.value ?? undefined, currentSort.active, currentSort.direction === 'desc');
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* 获取选中的项数组
|
|
315
|
+
*/
|
|
316
|
+
getSelectedArray() {
|
|
317
|
+
return Array.from(this.selectedItems().values());
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* 设置选中项(用于初始化)
|
|
321
|
+
*/
|
|
322
|
+
setSelectedItems(items) {
|
|
323
|
+
const newMap = new Map();
|
|
324
|
+
items.forEach((item) => {
|
|
325
|
+
newMap.set(this.getItemKey(item), item);
|
|
326
|
+
});
|
|
327
|
+
this.selectedItems.set(newMap);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* 加载数据(统一入口,私有方法)
|
|
331
|
+
*/
|
|
332
|
+
_loadPageData(page, size, search, orderBy, desc) {
|
|
333
|
+
const provider = this.dataProvider();
|
|
334
|
+
if (!provider) {
|
|
335
|
+
this.loading.set(false);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
this.loading.set(true);
|
|
339
|
+
provider.loadPage({
|
|
340
|
+
page,
|
|
341
|
+
size,
|
|
342
|
+
search: search ?? undefined,
|
|
343
|
+
orderBy,
|
|
344
|
+
desc
|
|
345
|
+
}).subscribe({
|
|
346
|
+
next: (result) => {
|
|
347
|
+
// 确保即使返回空数组也正确更新状态
|
|
348
|
+
this.items.set(result.data || []);
|
|
349
|
+
this.pagination.update(p => ({ ...p, totalItems: result.total || 0 }));
|
|
350
|
+
// 无论数据是否为空,都要关闭加载状态
|
|
351
|
+
this.loading.set(false);
|
|
352
|
+
},
|
|
353
|
+
error: (error) => {
|
|
354
|
+
console.error('Failed to load data:', error);
|
|
355
|
+
// 发生错误时也要关闭加载状态
|
|
356
|
+
this.items.set([]);
|
|
357
|
+
this.loading.set(false);
|
|
358
|
+
},
|
|
359
|
+
complete: () => {
|
|
360
|
+
// 确保在流完成时也关闭加载状态(防御性编程)
|
|
361
|
+
if (this.loading()) {
|
|
362
|
+
this.loading.set(false);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* 发出选择变化事件(私有方法)
|
|
369
|
+
*/
|
|
370
|
+
_emitSelectionChange() {
|
|
371
|
+
const keys = new Set(this.selectedItems().keys());
|
|
372
|
+
this.selectionChange.emit(keys);
|
|
373
|
+
}
|
|
374
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
375
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.2", type: CmatDataPickerListComponent, isStandalone: true, selector: "cmat-data-picker-list", inputs: { dataProvider: { classPropertyName: "dataProvider", publicName: "dataProvider", isSignal: true, isRequired: true, transformFunction: null }, columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: true, transformFunction: null }, keyField: { classPropertyName: "keyField", publicName: "keyField", isSignal: true, isRequired: false, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, searchable: { classPropertyName: "searchable", publicName: "searchable", isSignal: true, isRequired: false, transformFunction: null }, pageSize: { classPropertyName: "pageSize", publicName: "pageSize", isSignal: true, isRequired: false, transformFunction: null }, searchPlaceholder: { classPropertyName: "searchPlaceholder", publicName: "searchPlaceholder", isSignal: true, isRequired: false, transformFunction: null }, emptyText: { classPropertyName: "emptyText", publicName: "emptyText", isSignal: true, isRequired: false, transformFunction: null }, paginationId: { classPropertyName: "paginationId", publicName: "paginationId", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selectionChange: "selectionChange" }, ngImport: i0, template: "<div class=\"flex flex-col h-full\">\r\n <!-- \u641C\u7D22\u6846 -->\r\n @if (searchable()) {\r\n <div class=\"px-4 py-3 border-b\">\r\n <mat-form-field class=\"w-full\">\r\n <mat-icon matPrefix [svgIcon]=\"'heroicons_outline:magnifying-glass'\"></mat-icon>\r\n <input matInput [formControl]=\"searchControl\" [placeholder]=\"searchPlaceholder()\" />\r\n </mat-form-field>\r\n </div>\r\n }\r\n\r\n <!-- \u6570\u636E\u8868\u683C -->\r\n <div class=\"flex-1 overflow-y-auto scrollbar-custom\">\r\n @if (loading()) {\r\n <div class=\"flex items-center justify-center h-full min-h-30\">\r\n <mat-progress-spinner mode=\"indeterminate\" diameter=\"40\"></mat-progress-spinner>\r\n </div>\r\n } @else if (items().length === 0) {\r\n <div class=\"flex flex-col items-center justify-center h-full py-8\">\r\n <mat-icon class=\"icon-size-16 text-hint\" [svgIcon]=\"'heroicons_outline:inbox'\"></mat-icon>\r\n <p class=\"mt-2 text-secondary\">{{ emptyText() }}</p>\r\n </div>\r\n } @else {\r\n <table mat-table matSort class=\"w-full\"\r\n [dataSource]=\"items() | paginate: {id:paginationId(),currentPage: pagination().currentPage, itemsPerPage: pagination().itemsPerPage, totalItems: pagination().totalItems}\"\r\n (matSortChange)=\"onSortChange($event)\">\r\n\r\n <!-- \u9009\u62E9\u5217 -->\r\n <ng-container matColumnDef=\"_selection\">\r\n <th *matHeaderCellDef mat-header-cell class=\"w-12\">\r\n @if (multiple()) {\r\n <mat-checkbox [checked]=\"isAllSelected()\" [indeterminate]=\"isIndeterminate()\"\r\n (change)=\"toggleSelectAll($event.checked)\">\r\n </mat-checkbox>\r\n }\r\n </th>\r\n <td *matCellDef=\"let item\" mat-cell class=\"w-12\">\r\n @if (multiple()) {\r\n <mat-checkbox [checked]=\"isSelected(item)\" (click)=\"$event.stopPropagation()\"\r\n (change)=\"toggleSelection(item, $event.checked)\">\r\n </mat-checkbox>\r\n } @else {\r\n <mat-radio-button [checked]=\"isSelected(item)\" (click)=\"$event.stopPropagation()\"\r\n (change)=\"selectSingle(item)\">\r\n </mat-radio-button>\r\n }\r\n </td>\r\n </ng-container>\r\n\r\n <!-- \u6570\u636E\u5217 -->\r\n @for (column of columns(); track column.key) {\r\n <ng-container [matColumnDef]=\"column.key\">\r\n <th *matHeaderCellDef mat-header-cell \r\n [mat-sort-header]=\"column.sortable ? column.key : ''\"\r\n [disabled]=\"!column.sortable\"\r\n [start]=\"column.sortable ? 'asc' : ''\">\r\n {{ column.name }}\r\n </th>\r\n <td *matCellDef=\"let item\" mat-cell>\r\n <div class=\"has-label-on-mobile\" [attr.data-label]=\"column.name + ':'\">\r\n {{ item[column.key] }}\r\n </div>\r\n </td>\r\n </ng-container>\r\n }\r\n\r\n <tr *matHeaderRowDef=\"displayedColumns(); sticky: true\" mat-header-row></tr>\r\n <tr *matRowDef=\"let item; columns: displayedColumns()\" mat-row class=\"cursor-pointer\" (click)=\"onRowClick(item)\">\r\n </tr>\r\n </table>\r\n }\r\n </div>\r\n\r\n <!-- \u5206\u9875\u5668 -->\r\n <div class=\"border-t\">\r\n <cmat-pagination class=\"bg-slate-50 dark:bg-transparent\" [id]=\"paginationId()\" [initPerPage]=\"pageSize()\"\r\n [ngClass]=\"{'pointer-events-none': loading()}\" [hidden]=\"pagination().totalItems=== 0\" (pageChange)=\"onPageChange($event)\"\r\n (perPageCountChange)=\"onPageSizeChange($event)\">\r\n </cmat-pagination>\r\n </div>\r\n\r\n</div>", styles: ["cmat-data-picker-list{display:flex;flex-direction:column;width:100%}cmat-data-picker-list .mat-mdc-row{border-width:1px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "ngmodule", type: MatCheckboxModule }, { kind: "component", type: i3.MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "aria-expanded", "aria-controls", "aria-owns", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "disabledInteractive", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2$1.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i5.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "component", type: i5.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i5.MatPrefix, selector: "[matPrefix], [matIconPrefix], [matTextPrefix]", inputs: ["matTextPrefix"] }, { kind: "ngmodule", type: MatProgressSpinnerModule }, { kind: "component", type: i6.MatProgressSpinner, selector: "mat-progress-spinner, mat-spinner", inputs: ["color", "mode", "value", "diameter", "strokeWidth"], exportAs: ["matProgressSpinner"] }, { kind: "ngmodule", type: MatRadioModule }, { kind: "component", type: i7.MatRadioButton, selector: "mat-radio-button", inputs: ["id", "name", "aria-label", "aria-labelledby", "aria-describedby", "disableRipple", "tabIndex", "checked", "value", "labelPosition", "disabled", "required", "color", "disabledInteractive"], outputs: ["change"], exportAs: ["matRadioButton"] }, { kind: "ngmodule", type: MatSortModule }, { kind: "directive", type: i8.MatSort, selector: "[matSort]", inputs: ["matSortActive", "matSortStart", "matSortDirection", "matSortDisableClear", "matSortDisabled"], outputs: ["matSortChange"], exportAs: ["matSort"] }, { kind: "component", type: i8.MatSortHeader, selector: "[mat-sort-header]", inputs: ["mat-sort-header", "arrowPosition", "start", "disabled", "sortActionDescription", "disableClear"], exportAs: ["matSortHeader"] }, { kind: "ngmodule", type: MatTableModule }, { kind: "component", type: i9.MatTable, selector: "mat-table, table[mat-table]", exportAs: ["matTable"] }, { kind: "directive", type: i9.MatHeaderCellDef, selector: "[matHeaderCellDef]" }, { kind: "directive", type: i9.MatHeaderRowDef, selector: "[matHeaderRowDef]", inputs: ["matHeaderRowDef", "matHeaderRowDefSticky"] }, { kind: "directive", type: i9.MatColumnDef, selector: "[matColumnDef]", inputs: ["matColumnDef"] }, { kind: "directive", type: i9.MatCellDef, selector: "[matCellDef]" }, { kind: "directive", type: i9.MatRowDef, selector: "[matRowDef]", inputs: ["matRowDefColumns", "matRowDefWhen"] }, { kind: "directive", type: i9.MatHeaderCell, selector: "mat-header-cell, th[mat-header-cell]" }, { kind: "directive", type: i9.MatCell, selector: "mat-cell, td[mat-cell]" }, { kind: "component", type: i9.MatHeaderRow, selector: "mat-header-row, tr[mat-header-row]", exportAs: ["matHeaderRow"] }, { kind: "component", type: i9.MatRow, selector: "mat-row, tr[mat-row]", exportAs: ["matRow"] }, { kind: "component", type: CmatPaginationComponent, selector: "cmat-pagination", inputs: ["id", "maxSize", "itemsPerPages", "initPerPage", "autoHide"], outputs: ["pageChange", "pageBoundsCorrection", "perPageCountChange"], exportAs: ["cmatPagination"] }, { kind: "pipe", type: CmatPaginatePipe, name: "paginate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
376
|
+
}
|
|
377
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerListComponent, decorators: [{
|
|
378
|
+
type: Component,
|
|
379
|
+
args: [{ selector: 'cmat-data-picker-list', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, imports: [
|
|
380
|
+
CommonModule,
|
|
381
|
+
ReactiveFormsModule,
|
|
382
|
+
MatButtonModule,
|
|
383
|
+
MatCheckboxModule,
|
|
384
|
+
MatIconModule,
|
|
385
|
+
MatInputModule,
|
|
386
|
+
MatProgressSpinnerModule,
|
|
387
|
+
MatRadioModule,
|
|
388
|
+
MatSortModule,
|
|
389
|
+
MatTableModule,
|
|
390
|
+
CmatPaginationComponent,
|
|
391
|
+
CmatPaginatePipe
|
|
392
|
+
], template: "<div class=\"flex flex-col h-full\">\r\n <!-- \u641C\u7D22\u6846 -->\r\n @if (searchable()) {\r\n <div class=\"px-4 py-3 border-b\">\r\n <mat-form-field class=\"w-full\">\r\n <mat-icon matPrefix [svgIcon]=\"'heroicons_outline:magnifying-glass'\"></mat-icon>\r\n <input matInput [formControl]=\"searchControl\" [placeholder]=\"searchPlaceholder()\" />\r\n </mat-form-field>\r\n </div>\r\n }\r\n\r\n <!-- \u6570\u636E\u8868\u683C -->\r\n <div class=\"flex-1 overflow-y-auto scrollbar-custom\">\r\n @if (loading()) {\r\n <div class=\"flex items-center justify-center h-full min-h-30\">\r\n <mat-progress-spinner mode=\"indeterminate\" diameter=\"40\"></mat-progress-spinner>\r\n </div>\r\n } @else if (items().length === 0) {\r\n <div class=\"flex flex-col items-center justify-center h-full py-8\">\r\n <mat-icon class=\"icon-size-16 text-hint\" [svgIcon]=\"'heroicons_outline:inbox'\"></mat-icon>\r\n <p class=\"mt-2 text-secondary\">{{ emptyText() }}</p>\r\n </div>\r\n } @else {\r\n <table mat-table matSort class=\"w-full\"\r\n [dataSource]=\"items() | paginate: {id:paginationId(),currentPage: pagination().currentPage, itemsPerPage: pagination().itemsPerPage, totalItems: pagination().totalItems}\"\r\n (matSortChange)=\"onSortChange($event)\">\r\n\r\n <!-- \u9009\u62E9\u5217 -->\r\n <ng-container matColumnDef=\"_selection\">\r\n <th *matHeaderCellDef mat-header-cell class=\"w-12\">\r\n @if (multiple()) {\r\n <mat-checkbox [checked]=\"isAllSelected()\" [indeterminate]=\"isIndeterminate()\"\r\n (change)=\"toggleSelectAll($event.checked)\">\r\n </mat-checkbox>\r\n }\r\n </th>\r\n <td *matCellDef=\"let item\" mat-cell class=\"w-12\">\r\n @if (multiple()) {\r\n <mat-checkbox [checked]=\"isSelected(item)\" (click)=\"$event.stopPropagation()\"\r\n (change)=\"toggleSelection(item, $event.checked)\">\r\n </mat-checkbox>\r\n } @else {\r\n <mat-radio-button [checked]=\"isSelected(item)\" (click)=\"$event.stopPropagation()\"\r\n (change)=\"selectSingle(item)\">\r\n </mat-radio-button>\r\n }\r\n </td>\r\n </ng-container>\r\n\r\n <!-- \u6570\u636E\u5217 -->\r\n @for (column of columns(); track column.key) {\r\n <ng-container [matColumnDef]=\"column.key\">\r\n <th *matHeaderCellDef mat-header-cell \r\n [mat-sort-header]=\"column.sortable ? column.key : ''\"\r\n [disabled]=\"!column.sortable\"\r\n [start]=\"column.sortable ? 'asc' : ''\">\r\n {{ column.name }}\r\n </th>\r\n <td *matCellDef=\"let item\" mat-cell>\r\n <div class=\"has-label-on-mobile\" [attr.data-label]=\"column.name + ':'\">\r\n {{ item[column.key] }}\r\n </div>\r\n </td>\r\n </ng-container>\r\n }\r\n\r\n <tr *matHeaderRowDef=\"displayedColumns(); sticky: true\" mat-header-row></tr>\r\n <tr *matRowDef=\"let item; columns: displayedColumns()\" mat-row class=\"cursor-pointer\" (click)=\"onRowClick(item)\">\r\n </tr>\r\n </table>\r\n }\r\n </div>\r\n\r\n <!-- \u5206\u9875\u5668 -->\r\n <div class=\"border-t\">\r\n <cmat-pagination class=\"bg-slate-50 dark:bg-transparent\" [id]=\"paginationId()\" [initPerPage]=\"pageSize()\"\r\n [ngClass]=\"{'pointer-events-none': loading()}\" [hidden]=\"pagination().totalItems=== 0\" (pageChange)=\"onPageChange($event)\"\r\n (perPageCountChange)=\"onPageSizeChange($event)\">\r\n </cmat-pagination>\r\n </div>\r\n\r\n</div>", styles: ["cmat-data-picker-list{display:flex;flex-direction:column;width:100%}cmat-data-picker-list .mat-mdc-row{border-width:1px}\n"] }]
|
|
393
|
+
}], ctorParameters: () => [], propDecorators: { dataProvider: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataProvider", required: true }] }], columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: true }] }], keyField: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyField", required: false }] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", required: false }] }], searchable: [{ type: i0.Input, args: [{ isSignal: true, alias: "searchable", required: false }] }], pageSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "pageSize", required: false }] }], searchPlaceholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "searchPlaceholder", required: false }] }], emptyText: [{ type: i0.Input, args: [{ isSignal: true, alias: "emptyText", required: false }] }], paginationId: [{ type: i0.Input, args: [{ isSignal: true, alias: "paginationId", required: false }] }], selectionChange: [{ type: i0.Output, args: ["selectionChange"] }] } });
|
|
394
|
+
|
|
395
|
+
class CmatDataPickerSheetComponent {
|
|
396
|
+
constructor() {
|
|
397
|
+
this.data = inject(MAT_BOTTOM_SHEET_DATA);
|
|
398
|
+
this.title = computed(() => this.data.multiple ? '选择多项' : '选择一项', /* @ts-ignore */
|
|
399
|
+
...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
|
|
400
|
+
this._listComponent = viewChild.required((CmatDataPickerListComponent));
|
|
401
|
+
this._bottomSheetRef = inject((MatBottomSheetRef));
|
|
402
|
+
this._selectedKeys = new Set();
|
|
403
|
+
// 初始化选中项
|
|
404
|
+
if (this.data.initialSelection && this.data.initialSelection.length > 0) {
|
|
405
|
+
const keys = this.data.initialSelection.map(item => item[this.data.keyField]);
|
|
406
|
+
this._selectedKeys = new Set(keys);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
ngAfterViewInit() {
|
|
410
|
+
// 在视图初始化后,如果已有选中项,设置到 list 组件
|
|
411
|
+
if (this.data.initialSelection && this.data.initialSelection.length > 0) {
|
|
412
|
+
this._listComponent().setSelectedItems(this.data.initialSelection);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
onSelectionChange(keys) {
|
|
416
|
+
this._selectedKeys = keys;
|
|
417
|
+
}
|
|
418
|
+
dismiss() {
|
|
419
|
+
this._bottomSheetRef.dismiss();
|
|
420
|
+
}
|
|
421
|
+
confirm() {
|
|
422
|
+
const selectedItems = this._listComponent().getSelectedArray();
|
|
423
|
+
const result = this.data.multiple ? selectedItems : (selectedItems[0] ?? null);
|
|
424
|
+
this._bottomSheetRef.dismiss(result);
|
|
425
|
+
}
|
|
426
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerSheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
427
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", type: CmatDataPickerSheetComponent, isStandalone: true, selector: "cmat-data-picker-sheet", viewQueries: [{ propertyName: "_listComponent", first: true, predicate: (CmatDataPickerListComponent), descendants: true, isSignal: true }], ngImport: i0, template: "<div class=\"flex flex-col h-full max-h-[70vh] -mx-4\">\r\n <!-- \u5934\u90E8 -->\r\n <div class=\"flex items-center justify-between px-4 py-3 border-b bg-card\">\r\n <h2 class=\"text-lg font-semibold\">{{ title() }}</h2>\r\n <button matIconButton (click)=\"dismiss()\">\r\n <mat-icon [svgIcon]=\"'heroicons_outline:x-mark'\"></mat-icon>\r\n </button>\r\n </div>\r\n\r\n <!-- \u5217\u8868\u5185\u5BB9 -->\r\n <div class=\"flex-1 overflow-hidden min-h-0 flex\">\r\n <cmat-data-picker-list [dataProvider]=\"data.dataProvider\" [columns]=\"data.columns\" [keyField]=\"data.keyField\"\r\n [multiple]=\"data.multiple\" [searchable]=\"data.searchable\" [pageSize]=\"data.pageSize\"\r\n (selectionChange)=\"onSelectionChange($event)\">\r\n </cmat-data-picker-list>\r\n </div>\r\n <!-- \u5E95\u90E8\u64CD\u4F5C\u680F -->\r\n <div class=\"px-4 py-3 border-t flex justify-end gap-2\">\r\n <button matButton=\"filled\" color=\"primary\" (click)=\"confirm()\">\r\n \u786E\u5B9A\r\n </button>\r\n <button matButton=\"outlined\" (click)=\"dismiss()\">\u53D6\u6D88</button>\r\n </div>\r\n</div>", styles: [":host{display:block;height:100%}\n"], dependencies: [{ kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i1$1.MatButton, selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ", inputs: ["matButton"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i1$1.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2$1.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: CmatDataPickerListComponent, selector: "cmat-data-picker-list", inputs: ["dataProvider", "columns", "keyField", "multiple", "searchable", "pageSize", "searchPlaceholder", "emptyText", "paginationId"], outputs: ["selectionChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
428
|
+
}
|
|
429
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerSheetComponent, decorators: [{
|
|
430
|
+
type: Component,
|
|
431
|
+
args: [{ selector: 'cmat-data-picker-sheet', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, imports: [
|
|
432
|
+
MatButtonModule,
|
|
433
|
+
MatIconModule,
|
|
434
|
+
CmatDataPickerListComponent
|
|
435
|
+
], template: "<div class=\"flex flex-col h-full max-h-[70vh] -mx-4\">\r\n <!-- \u5934\u90E8 -->\r\n <div class=\"flex items-center justify-between px-4 py-3 border-b bg-card\">\r\n <h2 class=\"text-lg font-semibold\">{{ title() }}</h2>\r\n <button matIconButton (click)=\"dismiss()\">\r\n <mat-icon [svgIcon]=\"'heroicons_outline:x-mark'\"></mat-icon>\r\n </button>\r\n </div>\r\n\r\n <!-- \u5217\u8868\u5185\u5BB9 -->\r\n <div class=\"flex-1 overflow-hidden min-h-0 flex\">\r\n <cmat-data-picker-list [dataProvider]=\"data.dataProvider\" [columns]=\"data.columns\" [keyField]=\"data.keyField\"\r\n [multiple]=\"data.multiple\" [searchable]=\"data.searchable\" [pageSize]=\"data.pageSize\"\r\n (selectionChange)=\"onSelectionChange($event)\">\r\n </cmat-data-picker-list>\r\n </div>\r\n <!-- \u5E95\u90E8\u64CD\u4F5C\u680F -->\r\n <div class=\"px-4 py-3 border-t flex justify-end gap-2\">\r\n <button matButton=\"filled\" color=\"primary\" (click)=\"confirm()\">\r\n \u786E\u5B9A\r\n </button>\r\n <button matButton=\"outlined\" (click)=\"dismiss()\">\u53D6\u6D88</button>\r\n </div>\r\n</div>", styles: [":host{display:block;height:100%}\n"] }]
|
|
436
|
+
}], ctorParameters: () => [], propDecorators: { _listComponent: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CmatDataPickerListComponent), { isSignal: true }] }] } });
|
|
437
|
+
|
|
438
|
+
class CmatDataPickerDialogComponent {
|
|
439
|
+
constructor() {
|
|
440
|
+
this.data = inject(MAT_DIALOG_DATA);
|
|
441
|
+
this.title = computed(() => this.data.multiple ? '选择多项' : '选择一项', /* @ts-ignore */
|
|
442
|
+
...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
|
|
443
|
+
this._listComponent = viewChild.required((CmatDataPickerListComponent));
|
|
444
|
+
this._dialogRef = inject((MatDialogRef));
|
|
445
|
+
this._selectedKeys = new Set();
|
|
446
|
+
// 初始化选中项
|
|
447
|
+
if (this.data.initialSelection && this.data.initialSelection.length > 0) {
|
|
448
|
+
const keys = this.data.initialSelection.map(item => item[this.data.keyField]);
|
|
449
|
+
this._selectedKeys = new Set(keys);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
ngAfterViewInit() {
|
|
453
|
+
// 在视图初始化后,如果已有选中项,设置到 list 组件
|
|
454
|
+
if (this.data.initialSelection && this.data.initialSelection.length > 0) {
|
|
455
|
+
this._listComponent().setSelectedItems(this.data.initialSelection);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
onSelectionChange(keys) {
|
|
459
|
+
this._selectedKeys = keys;
|
|
460
|
+
}
|
|
461
|
+
dismiss() {
|
|
462
|
+
this._dialogRef.close();
|
|
463
|
+
}
|
|
464
|
+
confirm() {
|
|
465
|
+
const selectedItems = this._listComponent().getSelectedArray();
|
|
466
|
+
const result = this.data.multiple ? selectedItems : (selectedItems[0] ?? null);
|
|
467
|
+
this._dialogRef.close(result);
|
|
468
|
+
}
|
|
469
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerDialogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
470
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", type: CmatDataPickerDialogComponent, isStandalone: true, selector: "cmat-data-picker-dialog", viewQueries: [{ propertyName: "_listComponent", first: true, predicate: (CmatDataPickerListComponent), descendants: true, isSignal: true }], ngImport: i0, template: "<div class=\"flex flex-col h-full max-h-[80vh]\">\r\n <!-- \u5934\u90E8 -->\r\n <div class=\"flex items-center justify-between px-6 py-4 border-b\">\r\n <h2 class=\"text-xl font-semibold\">{{ title() }}</h2>\r\n <button matIconButton (click)=\"dismiss()\">\r\n <mat-icon [svgIcon]=\"'heroicons_outline:x-mark'\"></mat-icon>\r\n </button>\r\n </div>\r\n\r\n <!-- \u5217\u8868\u5185\u5BB9 -->\r\n <div class=\"flex-1 overflow-hidden min-h-0 flex\">\r\n <cmat-data-picker-list [dataProvider]=\"data.dataProvider\" [columns]=\"data.columns\" [keyField]=\"data.keyField\"\r\n [multiple]=\"data.multiple\" [searchable]=\"data.searchable\" [pageSize]=\"data.pageSize\"\r\n (selectionChange)=\"onSelectionChange($event)\">\r\n </cmat-data-picker-list>\r\n </div>\r\n\r\n <!-- \u5E95\u90E8\u64CD\u4F5C\u680F -->\r\n <div class=\"px-6 py-4 border-t flex justify-end gap-2\">\r\n <button matButton=\"filled\" color=\"primary\" (click)=\"confirm()\">\r\n \u786E\u5B9A\r\n </button>\r\n <button matButton=\"outlined\" (click)=\"dismiss()\">\u53D6\u6D88</button>\r\n </div>\r\n</div>", dependencies: [{ kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i1$1.MatButton, selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ", inputs: ["matButton"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i1$1.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2$1.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: CmatDataPickerListComponent, selector: "cmat-data-picker-list", inputs: ["dataProvider", "columns", "keyField", "multiple", "searchable", "pageSize", "searchPlaceholder", "emptyText", "paginationId"], outputs: ["selectionChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
471
|
+
}
|
|
472
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerDialogComponent, decorators: [{
|
|
473
|
+
type: Component,
|
|
474
|
+
args: [{ selector: 'cmat-data-picker-dialog', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, imports: [
|
|
475
|
+
MatButtonModule,
|
|
476
|
+
MatIconModule,
|
|
477
|
+
CmatDataPickerListComponent
|
|
478
|
+
], template: "<div class=\"flex flex-col h-full max-h-[80vh]\">\r\n <!-- \u5934\u90E8 -->\r\n <div class=\"flex items-center justify-between px-6 py-4 border-b\">\r\n <h2 class=\"text-xl font-semibold\">{{ title() }}</h2>\r\n <button matIconButton (click)=\"dismiss()\">\r\n <mat-icon [svgIcon]=\"'heroicons_outline:x-mark'\"></mat-icon>\r\n </button>\r\n </div>\r\n\r\n <!-- \u5217\u8868\u5185\u5BB9 -->\r\n <div class=\"flex-1 overflow-hidden min-h-0 flex\">\r\n <cmat-data-picker-list [dataProvider]=\"data.dataProvider\" [columns]=\"data.columns\" [keyField]=\"data.keyField\"\r\n [multiple]=\"data.multiple\" [searchable]=\"data.searchable\" [pageSize]=\"data.pageSize\"\r\n (selectionChange)=\"onSelectionChange($event)\">\r\n </cmat-data-picker-list>\r\n </div>\r\n\r\n <!-- \u5E95\u90E8\u64CD\u4F5C\u680F -->\r\n <div class=\"px-6 py-4 border-t flex justify-end gap-2\">\r\n <button matButton=\"filled\" color=\"primary\" (click)=\"confirm()\">\r\n \u786E\u5B9A\r\n </button>\r\n <button matButton=\"outlined\" (click)=\"dismiss()\">\u53D6\u6D88</button>\r\n </div>\r\n</div>" }]
|
|
479
|
+
}], ctorParameters: () => [], propDecorators: { _listComponent: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CmatDataPickerListComponent), { isSignal: true }] }] } });
|
|
480
|
+
|
|
481
|
+
class CmatDataPickerDrawerComponent {
|
|
482
|
+
constructor() {
|
|
483
|
+
this.title = computed(() => this.data?.multiple ? '选择多项' : '选择一项', /* @ts-ignore */
|
|
484
|
+
...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
|
|
485
|
+
this._listComponent = viewChild.required((CmatDataPickerListComponent));
|
|
486
|
+
this._selectedKeys = new Set();
|
|
487
|
+
}
|
|
488
|
+
ngAfterViewInit() {
|
|
489
|
+
// 在视图初始化后,如果已有选中项,设置到 list 组件
|
|
490
|
+
if (this.data.initialSelection && this.data.initialSelection.length > 0) {
|
|
491
|
+
const keys = this.data.initialSelection.map(item => item[this.data.keyField]);
|
|
492
|
+
this._selectedKeys = new Set(keys);
|
|
493
|
+
this._listComponent().setSelectedItems(this.data.initialSelection);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
onSelectionChange(keys) {
|
|
497
|
+
this._selectedKeys = keys;
|
|
498
|
+
}
|
|
499
|
+
dismiss() {
|
|
500
|
+
// 触发关闭回调
|
|
501
|
+
if (this.data.onClose) {
|
|
502
|
+
this.data.onClose();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
confirm() {
|
|
506
|
+
const selectedItems = this._listComponent().getSelectedArray();
|
|
507
|
+
const result = this.data.multiple ? selectedItems : (selectedItems[0] ?? null);
|
|
508
|
+
if (this.data.onConfirm) {
|
|
509
|
+
this.data.onConfirm(result);
|
|
510
|
+
}
|
|
511
|
+
// 确认后也要关闭
|
|
512
|
+
if (this.data.onClose) {
|
|
513
|
+
this.data.onClose();
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerDrawerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
517
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.2", type: CmatDataPickerDrawerComponent, isStandalone: true, selector: "cmat-data-picker-drawer", viewQueries: [{ propertyName: "_listComponent", first: true, predicate: (CmatDataPickerListComponent), descendants: true, isSignal: true }], ngImport: i0, template: "<div class=\"flex flex-col h-full\">\r\n <!-- \u5934\u90E8 -->\r\n <div class=\"flex items-center justify-between px-6 py-4 border-b bg-card\">\r\n <h2 class=\"text-xl font-semibold\">{{ title() }}</h2>\r\n <button matIconButton (click)=\"dismiss()\">\r\n <mat-icon [svgIcon]=\"'heroicons_outline:x-mark'\"></mat-icon>\r\n </button>\r\n </div>\r\n\r\n <!-- \u5217\u8868\u5185\u5BB9 -->\r\n <div class=\"flex-1 overflow-hidden min-h-0 flex\">\r\n <cmat-data-picker-list [dataProvider]=\"data.dataProvider\" [columns]=\"data.columns\" [keyField]=\"data.keyField\"\r\n [multiple]=\"data.multiple\" [searchable]=\"data.searchable\" [pageSize]=\"data.pageSize\"\r\n (selectionChange)=\"onSelectionChange($event)\">\r\n </cmat-data-picker-list>\r\n </div>\r\n\r\n <!-- \u5E95\u90E8\u64CD\u4F5C\u680F -->\r\n <div class=\"px-6 py-4 border-t bg-card flex justify-end gap-2\">\r\n <button matButton=\"filled\" color=\"primary\" (click)=\"confirm()\">\r\n \u786E\u5B9A\r\n </button>\r\n <button matButton=\"outlined\" (click)=\"dismiss()\">\u53D6\u6D88</button>\r\n </div>\r\n</div>", styles: ["cmat-data-picker-drawer{display:block;width:100%}\n"], dependencies: [{ kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i1$1.MatButton, selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ", inputs: ["matButton"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i1$1.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2$1.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: CmatDataPickerListComponent, selector: "cmat-data-picker-list", inputs: ["dataProvider", "columns", "keyField", "multiple", "searchable", "pageSize", "searchPlaceholder", "emptyText", "paginationId"], outputs: ["selectionChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
518
|
+
}
|
|
519
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerDrawerComponent, decorators: [{
|
|
520
|
+
type: Component,
|
|
521
|
+
args: [{ selector: 'cmat-data-picker-drawer', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, imports: [
|
|
522
|
+
MatButtonModule,
|
|
523
|
+
MatIconModule,
|
|
524
|
+
CmatDataPickerListComponent
|
|
525
|
+
], template: "<div class=\"flex flex-col h-full\">\r\n <!-- \u5934\u90E8 -->\r\n <div class=\"flex items-center justify-between px-6 py-4 border-b bg-card\">\r\n <h2 class=\"text-xl font-semibold\">{{ title() }}</h2>\r\n <button matIconButton (click)=\"dismiss()\">\r\n <mat-icon [svgIcon]=\"'heroicons_outline:x-mark'\"></mat-icon>\r\n </button>\r\n </div>\r\n\r\n <!-- \u5217\u8868\u5185\u5BB9 -->\r\n <div class=\"flex-1 overflow-hidden min-h-0 flex\">\r\n <cmat-data-picker-list [dataProvider]=\"data.dataProvider\" [columns]=\"data.columns\" [keyField]=\"data.keyField\"\r\n [multiple]=\"data.multiple\" [searchable]=\"data.searchable\" [pageSize]=\"data.pageSize\"\r\n (selectionChange)=\"onSelectionChange($event)\">\r\n </cmat-data-picker-list>\r\n </div>\r\n\r\n <!-- \u5E95\u90E8\u64CD\u4F5C\u680F -->\r\n <div class=\"px-6 py-4 border-t bg-card flex justify-end gap-2\">\r\n <button matButton=\"filled\" color=\"primary\" (click)=\"confirm()\">\r\n \u786E\u5B9A\r\n </button>\r\n <button matButton=\"outlined\" (click)=\"dismiss()\">\u53D6\u6D88</button>\r\n </div>\r\n</div>", styles: ["cmat-data-picker-drawer{display:block;width:100%}\n"] }]
|
|
526
|
+
}], propDecorators: { _listComponent: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CmatDataPickerListComponent), { isSignal: true }] }] } });
|
|
527
|
+
|
|
528
|
+
let NEXT_ID = 0;
|
|
529
|
+
class CmatDataPickerComponent {
|
|
530
|
+
constructor() {
|
|
531
|
+
this.id = `cmat-data-picker-${NEXT_ID++}`;
|
|
532
|
+
this.stateChanges = new Subject();
|
|
533
|
+
this.controlType = 'cmat-data-picker';
|
|
534
|
+
this.ngControl = inject(NgControl, { optional: true, self: true });
|
|
535
|
+
this.apiUrl = input(/* @ts-ignore */
|
|
536
|
+
...(ngDevMode ? [undefined, { debugName: "apiUrl" }] : /* istanbul ignore next */ []));
|
|
537
|
+
this.dataSource = input(/* @ts-ignore */
|
|
538
|
+
...(ngDevMode ? [undefined, { debugName: "dataSource" }] : /* istanbul ignore next */ []));
|
|
539
|
+
this.dataProvider = input(/* @ts-ignore */
|
|
540
|
+
...(ngDevMode ? [undefined, { debugName: "dataProvider" }] : /* istanbul ignore next */ []));
|
|
541
|
+
this.columns = input([], /* @ts-ignore */
|
|
542
|
+
...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
543
|
+
this.keyField = input('id', /* @ts-ignore */
|
|
544
|
+
...(ngDevMode ? [{ debugName: "keyField" }] : /* istanbul ignore next */ []));
|
|
545
|
+
this.labelField = input('name', /* @ts-ignore */
|
|
546
|
+
...(ngDevMode ? [{ debugName: "labelField" }] : /* istanbul ignore next */ []));
|
|
547
|
+
this.displayTemplate = input(/* @ts-ignore */
|
|
548
|
+
...(ngDevMode ? [undefined, { debugName: "displayTemplate" }] : /* istanbul ignore next */ []));
|
|
549
|
+
this.displayLabelFn = input(/* @ts-ignore */
|
|
550
|
+
...(ngDevMode ? [undefined, { debugName: "displayLabelFn" }] : /* istanbul ignore next */ []));
|
|
551
|
+
this.multiple = input(false, /* @ts-ignore */
|
|
552
|
+
...(ngDevMode ? [{ debugName: "multiple" }] : /* istanbul ignore next */ []));
|
|
553
|
+
this.searchable = input(true, /* @ts-ignore */
|
|
554
|
+
...(ngDevMode ? [{ debugName: "searchable" }] : /* istanbul ignore next */ []));
|
|
555
|
+
this.debounceTime = input(300, /* @ts-ignore */
|
|
556
|
+
...(ngDevMode ? [{ debugName: "debounceTime" }] : /* istanbul ignore next */ []));
|
|
557
|
+
this.pageSize = input(20, /* @ts-ignore */
|
|
558
|
+
...(ngDevMode ? [{ debugName: "pageSize" }] : /* istanbul ignore next */ []));
|
|
559
|
+
this.uiMode = input('auto', /* @ts-ignore */
|
|
560
|
+
...(ngDevMode ? [{ debugName: "uiMode" }] : /* istanbul ignore next */ []));
|
|
561
|
+
this.drawerPosition = input('end', /* @ts-ignore */
|
|
562
|
+
...(ngDevMode ? [{ debugName: "drawerPosition" }] : /* istanbul ignore next */ []));
|
|
563
|
+
this.drawerWidth = input('600px', /* @ts-ignore */
|
|
564
|
+
...(ngDevMode ? [{ debugName: "drawerWidth" }] : /* istanbul ignore next */ []));
|
|
565
|
+
this.dialogWidth = input('800px', /* @ts-ignore */
|
|
566
|
+
...(ngDevMode ? [{ debugName: "dialogWidth" }] : /* istanbul ignore next */ []));
|
|
567
|
+
this.dialogMaxHeight = input('80vh', /* @ts-ignore */
|
|
568
|
+
...(ngDevMode ? [{ debugName: "dialogMaxHeight" }] : /* istanbul ignore next */ []));
|
|
569
|
+
this.selectionChange = output();
|
|
570
|
+
this.selectedItems = signal(new Map(), /* @ts-ignore */
|
|
571
|
+
...(ngDevMode ? [{ debugName: "selectedItems" }] : /* istanbul ignore next */ []));
|
|
572
|
+
this._placeholderSignal = signal('请选择...', /* @ts-ignore */
|
|
573
|
+
...(ngDevMode ? [{ debugName: "_placeholderSignal" }] : /* istanbul ignore next */ []));
|
|
574
|
+
this._disabledSignal = signal(false, /* @ts-ignore */
|
|
575
|
+
...(ngDevMode ? [{ debugName: "_disabledSignal" }] : /* istanbul ignore next */ []));
|
|
576
|
+
this._requiredSignal = signal(false, /* @ts-ignore */
|
|
577
|
+
...(ngDevMode ? [{ debugName: "_requiredSignal" }] : /* istanbul ignore next */ []));
|
|
578
|
+
this._focusedSignal = signal(false, /* @ts-ignore */
|
|
579
|
+
...(ngDevMode ? [{ debugName: "_focusedSignal" }] : /* istanbul ignore next */ []));
|
|
580
|
+
this._valueSignal = signal(null, /* @ts-ignore */
|
|
581
|
+
...(ngDevMode ? [{ debugName: "_valueSignal" }] : /* istanbul ignore next */ []));
|
|
582
|
+
this._formField = inject(MatFormField, { optional: true });
|
|
583
|
+
this._overlay = inject(Overlay);
|
|
584
|
+
this._bottomSheet = inject(MatBottomSheet);
|
|
585
|
+
this._dialog = inject(MatDialog);
|
|
586
|
+
this._cmatMediaWatcherService = inject(CmatMediaWatcherService);
|
|
587
|
+
this._elementRef = inject(ElementRef);
|
|
588
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
589
|
+
this.isHandSet = computed(() => {
|
|
590
|
+
return !this._cmatMediaWatcherService.mediaChange().matchingAliases.includes('lg');
|
|
591
|
+
}, /* @ts-ignore */
|
|
592
|
+
...(ngDevMode ? [{ debugName: "isHandSet" }] : /* istanbul ignore next */ []));
|
|
593
|
+
// === Internal Callbacks ===
|
|
594
|
+
this._onChange = () => { };
|
|
595
|
+
this._onTouched = () => { };
|
|
596
|
+
if (this.ngControl != null) {
|
|
597
|
+
this.ngControl.valueAccessor = this;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
get appearanceIsFill() {
|
|
601
|
+
if (this._formField?.appearance === 'fill') {
|
|
602
|
+
return true;
|
|
603
|
+
}
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
get focused() {
|
|
607
|
+
return this._focusedSignal();
|
|
608
|
+
}
|
|
609
|
+
get empty() {
|
|
610
|
+
return this.selectedItems().size === 0;
|
|
611
|
+
}
|
|
612
|
+
get errorState() {
|
|
613
|
+
if (this.ngControl == null) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
return (this.ngControl.invalid && (this.ngControl.dirty ?? this.ngControl.touched)) ?? false;
|
|
617
|
+
}
|
|
618
|
+
get shouldLabelFloat() {
|
|
619
|
+
return this.focused || !this.empty;
|
|
620
|
+
}
|
|
621
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
622
|
+
get placeholder() {
|
|
623
|
+
return this._placeholderSignal();
|
|
624
|
+
}
|
|
625
|
+
set placeholder(value) {
|
|
626
|
+
this._placeholderSignal.set(value);
|
|
627
|
+
this.stateChanges.next();
|
|
628
|
+
}
|
|
629
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
630
|
+
get value() {
|
|
631
|
+
return this._valueSignal();
|
|
632
|
+
}
|
|
633
|
+
set value(val) {
|
|
634
|
+
if (val !== this._valueSignal()) {
|
|
635
|
+
this._valueSignal.set(val);
|
|
636
|
+
// 同步更新 selectedItems
|
|
637
|
+
if (val === null || val === undefined) {
|
|
638
|
+
this.selectedItems.set(new Map());
|
|
639
|
+
}
|
|
640
|
+
else if (Array.isArray(val)) {
|
|
641
|
+
const newMap = new Map();
|
|
642
|
+
val.forEach((item) => {
|
|
643
|
+
const key = item[this.keyField()];
|
|
644
|
+
newMap.set(key, item);
|
|
645
|
+
});
|
|
646
|
+
this.selectedItems.set(newMap);
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
const newMap = new Map();
|
|
650
|
+
const key = val[this.keyField()];
|
|
651
|
+
newMap.set(key, val);
|
|
652
|
+
this.selectedItems.set(newMap);
|
|
653
|
+
}
|
|
654
|
+
this.stateChanges.next();
|
|
655
|
+
this._onChange(val);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
659
|
+
get required() {
|
|
660
|
+
return this._requiredSignal();
|
|
661
|
+
}
|
|
662
|
+
set required(value) {
|
|
663
|
+
this._requiredSignal.set(coerceBooleanProperty(value));
|
|
664
|
+
this.stateChanges.next();
|
|
665
|
+
}
|
|
666
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
667
|
+
get disabled() {
|
|
668
|
+
if (this.ngControl?.disabled != null) {
|
|
669
|
+
return this.ngControl.disabled;
|
|
670
|
+
}
|
|
671
|
+
return this._disabledSignal();
|
|
672
|
+
}
|
|
673
|
+
set disabled(value) {
|
|
674
|
+
const coerced = coerceBooleanProperty(value);
|
|
675
|
+
this._disabledSignal.set(coerced);
|
|
676
|
+
this.stateChanges.next();
|
|
677
|
+
}
|
|
678
|
+
ngOnInit() {
|
|
679
|
+
// Initialize data provider if needed
|
|
680
|
+
const ds = this.dataSource();
|
|
681
|
+
const url = this.apiUrl();
|
|
682
|
+
if (url && !ds) {
|
|
683
|
+
// Cannot set input() signals, log warning for parent component to handle
|
|
684
|
+
console.warn('apiUrl is provided without dataSource. Please provide complete dataSource or dataProvider from parent component.');
|
|
685
|
+
}
|
|
686
|
+
if (!this.dataProvider() && ds) {
|
|
687
|
+
// Create provider internally but cannot update the input signal
|
|
688
|
+
// Parent component should provide dataProvider directly
|
|
689
|
+
console.warn('dataSource is provided without dataProvider. Please create dataProvider using createHttpDataProvider in parent component.');
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
ngOnDestroy() {
|
|
693
|
+
this.stateChanges.complete();
|
|
694
|
+
}
|
|
695
|
+
setDescribedByIds(ids) {
|
|
696
|
+
if (ids.length) {
|
|
697
|
+
this.userAriaDescribedBy = ids.join(' ');
|
|
698
|
+
this._elementRef.nativeElement.setAttribute('aria-describedby', ids.join(' '));
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
this.userAriaDescribedBy = undefined;
|
|
702
|
+
this._elementRef.nativeElement.removeAttribute('aria-describedby');
|
|
703
|
+
}
|
|
704
|
+
this.stateChanges.next();
|
|
705
|
+
}
|
|
706
|
+
onContainerClick() {
|
|
707
|
+
if (!this.focused) {
|
|
708
|
+
this.openPicker();
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
writeValue(value) {
|
|
712
|
+
this._valueSignal.set(value);
|
|
713
|
+
if (value === null || value === undefined) {
|
|
714
|
+
this.selectedItems.set(new Map());
|
|
715
|
+
}
|
|
716
|
+
else if (Array.isArray(value)) {
|
|
717
|
+
const newMap = new Map();
|
|
718
|
+
value.forEach((item) => {
|
|
719
|
+
const key = item[this.keyField()];
|
|
720
|
+
newMap.set(key, item);
|
|
721
|
+
});
|
|
722
|
+
this.selectedItems.set(newMap);
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
const newMap = new Map();
|
|
726
|
+
const key = value[this.keyField()];
|
|
727
|
+
newMap.set(key, value);
|
|
728
|
+
this.selectedItems.set(newMap);
|
|
729
|
+
}
|
|
730
|
+
this.stateChanges.next();
|
|
731
|
+
}
|
|
732
|
+
registerOnChange(fn) {
|
|
733
|
+
this._onChange = fn;
|
|
734
|
+
}
|
|
735
|
+
registerOnTouched(fn) {
|
|
736
|
+
this._onTouched = fn;
|
|
737
|
+
}
|
|
738
|
+
setDisabledState(isDisabled) {
|
|
739
|
+
this.disabled = isDisabled;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Open picker
|
|
743
|
+
*/
|
|
744
|
+
openPicker() {
|
|
745
|
+
if (this.disabled) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
const mode = this.resolveUIMode();
|
|
749
|
+
const data = this.getPickerData();
|
|
750
|
+
switch (mode) {
|
|
751
|
+
case 'bottom-sheet':
|
|
752
|
+
this.openBottomSheet(data);
|
|
753
|
+
break;
|
|
754
|
+
case 'dialog':
|
|
755
|
+
this.openDialog(data);
|
|
756
|
+
break;
|
|
757
|
+
case 'drawer':
|
|
758
|
+
this.openDrawer();
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
this._onTouched();
|
|
762
|
+
}
|
|
763
|
+
removeItem(item) {
|
|
764
|
+
const key = item[this.keyField()];
|
|
765
|
+
const newMap = new Map(this.selectedItems());
|
|
766
|
+
newMap.delete(key);
|
|
767
|
+
const selectedArray = Array.from(newMap.values());
|
|
768
|
+
const finalValue = this.multiple() ? selectedArray : (selectedArray[0] ?? null);
|
|
769
|
+
// 直接设置 value,它会同时更新 _valueSignal、selectedItems,并触发 _onChange
|
|
770
|
+
this.value = finalValue;
|
|
771
|
+
this.selectionChange.emit(finalValue);
|
|
772
|
+
}
|
|
773
|
+
hasValue() {
|
|
774
|
+
return this.selectedItems().size > 0;
|
|
775
|
+
}
|
|
776
|
+
getDisplayLabel(item) {
|
|
777
|
+
// First use custom function
|
|
778
|
+
const labelFn = this.displayLabelFn();
|
|
779
|
+
if (labelFn) {
|
|
780
|
+
return labelFn(item);
|
|
781
|
+
}
|
|
782
|
+
// Second use template
|
|
783
|
+
const template = this.displayTemplate();
|
|
784
|
+
if (template) {
|
|
785
|
+
return this.formatTemplate(template, item);
|
|
786
|
+
}
|
|
787
|
+
// Default use labelField
|
|
788
|
+
return item[this.labelField()] ?? String(item);
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Get selected items array
|
|
792
|
+
*/
|
|
793
|
+
getSelectedArray() {
|
|
794
|
+
return Array.from(this.selectedItems().values());
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Handle focus event
|
|
798
|
+
*/
|
|
799
|
+
onFocusIn() {
|
|
800
|
+
if (!this.focused) {
|
|
801
|
+
this._focusedSignal.set(true);
|
|
802
|
+
this.stateChanges.next();
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Handle blur event
|
|
807
|
+
*/
|
|
808
|
+
onFocusOut() {
|
|
809
|
+
if (this.focused) {
|
|
810
|
+
this._focusedSignal.set(false);
|
|
811
|
+
this._onTouched();
|
|
812
|
+
this.stateChanges.next();
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Resolve UI mode
|
|
817
|
+
*/
|
|
818
|
+
resolveUIMode() {
|
|
819
|
+
const mode = this.uiMode();
|
|
820
|
+
if (mode !== 'auto') {
|
|
821
|
+
return mode;
|
|
822
|
+
}
|
|
823
|
+
return this.isHandSet() ? 'bottom-sheet' : 'dialog';
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Get picker data
|
|
827
|
+
*/
|
|
828
|
+
getPickerData() {
|
|
829
|
+
return {
|
|
830
|
+
dataProvider: this.dataProvider(),
|
|
831
|
+
columns: this.columns(),
|
|
832
|
+
keyField: this.keyField(),
|
|
833
|
+
multiple: this.multiple(),
|
|
834
|
+
searchable: this.searchable(),
|
|
835
|
+
pageSize: this.pageSize(),
|
|
836
|
+
initialSelection: Array.from(this.selectedItems().values()),
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Open BottomSheet
|
|
841
|
+
*/
|
|
842
|
+
openBottomSheet(data) {
|
|
843
|
+
const sheetRef = this._bottomSheet.open(CmatDataPickerSheetComponent, {
|
|
844
|
+
data,
|
|
845
|
+
});
|
|
846
|
+
sheetRef.afterDismissed().subscribe((result) => {
|
|
847
|
+
if (result !== undefined) {
|
|
848
|
+
this.updateSelection(result);
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Open Dialog
|
|
854
|
+
*/
|
|
855
|
+
openDialog(data) {
|
|
856
|
+
const dialogRef = this._dialog.open(CmatDataPickerDialogComponent, {
|
|
857
|
+
width: this.dialogWidth(),
|
|
858
|
+
maxHeight: this.dialogMaxHeight(),
|
|
859
|
+
data,
|
|
860
|
+
});
|
|
861
|
+
dialogRef.afterClosed().subscribe((result) => {
|
|
862
|
+
if (result !== undefined) {
|
|
863
|
+
this.updateSelection(result);
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Open Drawer
|
|
869
|
+
*/
|
|
870
|
+
openDrawer() {
|
|
871
|
+
// 创建 Overlay 配置
|
|
872
|
+
const positionStrategy = this.drawerPosition() === 'end'
|
|
873
|
+
? this._overlay.position().global().right('0')
|
|
874
|
+
: this._overlay.position().global().left('0');
|
|
875
|
+
const overlayRef = this._overlay.create({
|
|
876
|
+
hasBackdrop: true,
|
|
877
|
+
backdropClass: 'cdk-overlay-transparent-backdrop',
|
|
878
|
+
positionStrategy,
|
|
879
|
+
width: this.drawerWidth(),
|
|
880
|
+
height: '100%',
|
|
881
|
+
panelClass: ['cmat-data-picker-drawer-overlay', 'cmat-drawer-enter'],
|
|
882
|
+
});
|
|
883
|
+
// 创建 Drawer 组件实例
|
|
884
|
+
const drawerPortal = new ComponentPortal(CmatDataPickerDrawerComponent);
|
|
885
|
+
const drawerRef = overlayRef.attach(drawerPortal);
|
|
886
|
+
// 传递数据到 Drawer 组件
|
|
887
|
+
const data = {
|
|
888
|
+
dataProvider: this.dataProvider(),
|
|
889
|
+
columns: this.columns(),
|
|
890
|
+
keyField: this.keyField(),
|
|
891
|
+
multiple: this.multiple(),
|
|
892
|
+
searchable: this.searchable(),
|
|
893
|
+
pageSize: this.pageSize(),
|
|
894
|
+
initialSelection: Array.from(this.selectedItems().values()),
|
|
895
|
+
onConfirm: (result) => {
|
|
896
|
+
if (result !== undefined) {
|
|
897
|
+
this.updateSelection(result);
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
onClose: () => {
|
|
901
|
+
// 添加退出动画类
|
|
902
|
+
const paneElement = overlayRef.overlayElement;
|
|
903
|
+
if (paneElement) {
|
|
904
|
+
paneElement.classList.remove('cmat-drawer-enter');
|
|
905
|
+
paneElement.classList.add('cmat-drawer-leave');
|
|
906
|
+
// 等待动画完成后销毁
|
|
907
|
+
setTimeout(() => {
|
|
908
|
+
overlayRef.dispose();
|
|
909
|
+
}, 300);
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
overlayRef.dispose();
|
|
913
|
+
}
|
|
914
|
+
},
|
|
915
|
+
};
|
|
916
|
+
drawerRef.instance.data = data;
|
|
917
|
+
// 监听背景点击关闭
|
|
918
|
+
overlayRef.backdropClick().subscribe(() => {
|
|
919
|
+
const paneElement = overlayRef.overlayElement;
|
|
920
|
+
if (paneElement) {
|
|
921
|
+
paneElement.classList.remove('cmat-drawer-enter');
|
|
922
|
+
paneElement.classList.add('cmat-drawer-leave');
|
|
923
|
+
setTimeout(() => {
|
|
924
|
+
overlayRef.dispose();
|
|
925
|
+
}, 300);
|
|
926
|
+
}
|
|
927
|
+
else {
|
|
928
|
+
overlayRef.dispose();
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
// 组件销毁时清理资源
|
|
932
|
+
overlayRef.detachments().subscribe(() => {
|
|
933
|
+
overlayRef.dispose();
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Update selection
|
|
938
|
+
*/
|
|
939
|
+
updateSelection(newValue) {
|
|
940
|
+
// 直接设置 value,它会同时更新 _valueSignal、selectedItems,并触发 _onChange
|
|
941
|
+
this.value = newValue;
|
|
942
|
+
this.selectionChange.emit(newValue);
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Format template string
|
|
946
|
+
* 支持两种格式:
|
|
947
|
+
* 1. Mustache 风格: {{name}} ({{department}})
|
|
948
|
+
* 2. 模板字符串风格: ${name} (${department})
|
|
949
|
+
*/
|
|
950
|
+
formatTemplate(template, item) {
|
|
951
|
+
const record = item;
|
|
952
|
+
// 先处理 Mustache 风格: {{key}}
|
|
953
|
+
let result = template.replace(/\{\{(\w+)\}\}/g, (_, key) => {
|
|
954
|
+
const value = record[key];
|
|
955
|
+
return value ?? '';
|
|
956
|
+
});
|
|
957
|
+
// 再处理模板字符串风格: ${key}
|
|
958
|
+
result = result.replace(/\$\{(\w+)\}/g, (_, key) => {
|
|
959
|
+
const value = record[key];
|
|
960
|
+
return value ?? '';
|
|
961
|
+
});
|
|
962
|
+
return result;
|
|
963
|
+
}
|
|
964
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
965
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.2", type: CmatDataPickerComponent, isStandalone: true, selector: "cmat-data-picker", inputs: { apiUrl: { classPropertyName: "apiUrl", publicName: "apiUrl", isSignal: true, isRequired: false, transformFunction: null }, dataSource: { classPropertyName: "dataSource", publicName: "dataSource", isSignal: true, isRequired: false, transformFunction: null }, dataProvider: { classPropertyName: "dataProvider", publicName: "dataProvider", isSignal: true, isRequired: false, transformFunction: null }, columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: false, transformFunction: null }, keyField: { classPropertyName: "keyField", publicName: "keyField", isSignal: true, isRequired: false, transformFunction: null }, labelField: { classPropertyName: "labelField", publicName: "labelField", isSignal: true, isRequired: false, transformFunction: null }, displayTemplate: { classPropertyName: "displayTemplate", publicName: "displayTemplate", isSignal: true, isRequired: false, transformFunction: null }, displayLabelFn: { classPropertyName: "displayLabelFn", publicName: "displayLabelFn", isSignal: true, isRequired: false, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, searchable: { classPropertyName: "searchable", publicName: "searchable", isSignal: true, isRequired: false, transformFunction: null }, debounceTime: { classPropertyName: "debounceTime", publicName: "debounceTime", isSignal: true, isRequired: false, transformFunction: null }, pageSize: { classPropertyName: "pageSize", publicName: "pageSize", isSignal: true, isRequired: false, transformFunction: null }, uiMode: { classPropertyName: "uiMode", publicName: "uiMode", isSignal: true, isRequired: false, transformFunction: null }, drawerPosition: { classPropertyName: "drawerPosition", publicName: "drawerPosition", isSignal: true, isRequired: false, transformFunction: null }, drawerWidth: { classPropertyName: "drawerWidth", publicName: "drawerWidth", isSignal: true, isRequired: false, transformFunction: null }, dialogWidth: { classPropertyName: "dialogWidth", publicName: "dialogWidth", isSignal: true, isRequired: false, transformFunction: null }, dialogMaxHeight: { classPropertyName: "dialogMaxHeight", publicName: "dialogMaxHeight", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: false, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: false, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: false, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: false, isRequired: false, transformFunction: null } }, outputs: { selectionChange: "selectionChange" }, host: { properties: { "attr.id": "id" } }, providers: [
|
|
966
|
+
{ provide: MatFormFieldControl, useExisting: CmatDataPickerComponent }
|
|
967
|
+
], ngImport: i0, template: "<div class=\"cmat-data-picker\">\r\n <!-- \u89E6\u53D1\u5668 -->\r\n <div class=\"picker-trigger\" tabindex=\"0\" role=\"button\" [class.has-value]=\"hasValue()\" [class.disabled]=\"disabled\"\r\n (click)=\"openPicker()\" (focus)=\"onFocusIn()\" (blur)=\"onFocusOut()\" (keydown.enter)=\"openPicker()\"\r\n (keydown.space)=\"$event.preventDefault(); openPicker()\">\r\n\r\n @if (selectedItems().size > 0) {\r\n <mat-chip-grid class=\"items-center\">\r\n @for (item of getSelectedArray(); track item) {\r\n <mat-chip-row (removed)=\"removeItem(item)\">\r\n {{ getDisplayLabel(item) }}\r\n <button matChipRemove class=\"print:hidden\">\r\n <mat-icon class=\"icon-size-5\" [svgIcon]=\"'mat_solid:cancel'\"></mat-icon>\r\n </button>\r\n </mat-chip-row>\r\n }\r\n </mat-chip-grid>\r\n } @else {\r\n <span class=\"placeholder\">{{appearanceIsFill? placeholder:''}}</span>\r\n }\r\n\r\n <mat-icon class=\"trigger-icon\" [svgIcon]=\"'mat_outline:arrow_drop_down'\"></mat-icon>\r\n </div>\r\n</div>", styles: ["cmat-data-picker{width:100%}.cmat-data-picker{width:100%}.picker-trigger{display:flex;align-items:center;box-sizing:border-box}.picker-trigger .placeholder{color:#0009;line-height:1;display:inline-block}.picker-trigger .trigger-icon{margin-right:-6px}.cmat-data-picker-drawer-overlay{box-shadow:-2px 0 8px #00000026;z-index:2000}.cmat-data-picker-drawer-overlay.cmat-drawer-enter{animation:slideInFromRight .3s ease-out}.cmat-data-picker-drawer-overlay.cmat-drawer-leave{animation:slideOutToRight .3s ease-in forwards}.cmat-data-picker-drawer-overlay[style*=\"left: 0\"]{box-shadow:2px 0 8px #00000026}.cmat-data-picker-drawer-overlay[style*=\"left: 0\"].cmat-drawer-enter{animation:slideInFromLeft .3s ease-out}.cmat-data-picker-drawer-overlay[style*=\"left: 0\"].cmat-drawer-leave{animation:slideOutToLeft .3s ease-in forwards}@keyframes slideInFromRight{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes slideInFromLeft{0%{transform:translate(-100%)}to{transform:translate(0)}}@keyframes slideOutToRight{0%{transform:translate(0)}to{transform:translate(100%)}}@keyframes slideOutToLeft{0%{transform:translate(0)}to{transform:translate(-100%)}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: MatChipsModule }, { kind: "component", type: i1$2.MatChipGrid, selector: "mat-chip-grid", inputs: ["disabled", "placeholder", "required", "value", "errorStateMatcher"], outputs: ["change", "valueChange"] }, { kind: "directive", type: i1$2.MatChipRemove, selector: "[matChipRemove]" }, { kind: "component", type: i1$2.MatChipRow, selector: "mat-chip-row, [mat-chip-row], mat-basic-chip-row, [mat-basic-chip-row]", inputs: ["editable"], outputs: ["edited"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2$1.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
968
|
+
}
|
|
969
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: CmatDataPickerComponent, decorators: [{
|
|
970
|
+
type: Component,
|
|
971
|
+
args: [{ selector: 'cmat-data-picker', providers: [
|
|
972
|
+
{ provide: MatFormFieldControl, useExisting: CmatDataPickerComponent }
|
|
973
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, imports: [
|
|
974
|
+
CommonModule,
|
|
975
|
+
MatChipsModule,
|
|
976
|
+
MatIconModule
|
|
977
|
+
], host: {
|
|
978
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
979
|
+
'[attr.id]': 'id'
|
|
980
|
+
}, template: "<div class=\"cmat-data-picker\">\r\n <!-- \u89E6\u53D1\u5668 -->\r\n <div class=\"picker-trigger\" tabindex=\"0\" role=\"button\" [class.has-value]=\"hasValue()\" [class.disabled]=\"disabled\"\r\n (click)=\"openPicker()\" (focus)=\"onFocusIn()\" (blur)=\"onFocusOut()\" (keydown.enter)=\"openPicker()\"\r\n (keydown.space)=\"$event.preventDefault(); openPicker()\">\r\n\r\n @if (selectedItems().size > 0) {\r\n <mat-chip-grid class=\"items-center\">\r\n @for (item of getSelectedArray(); track item) {\r\n <mat-chip-row (removed)=\"removeItem(item)\">\r\n {{ getDisplayLabel(item) }}\r\n <button matChipRemove class=\"print:hidden\">\r\n <mat-icon class=\"icon-size-5\" [svgIcon]=\"'mat_solid:cancel'\"></mat-icon>\r\n </button>\r\n </mat-chip-row>\r\n }\r\n </mat-chip-grid>\r\n } @else {\r\n <span class=\"placeholder\">{{appearanceIsFill? placeholder:''}}</span>\r\n }\r\n\r\n <mat-icon class=\"trigger-icon\" [svgIcon]=\"'mat_outline:arrow_drop_down'\"></mat-icon>\r\n </div>\r\n</div>", styles: ["cmat-data-picker{width:100%}.cmat-data-picker{width:100%}.picker-trigger{display:flex;align-items:center;box-sizing:border-box}.picker-trigger .placeholder{color:#0009;line-height:1;display:inline-block}.picker-trigger .trigger-icon{margin-right:-6px}.cmat-data-picker-drawer-overlay{box-shadow:-2px 0 8px #00000026;z-index:2000}.cmat-data-picker-drawer-overlay.cmat-drawer-enter{animation:slideInFromRight .3s ease-out}.cmat-data-picker-drawer-overlay.cmat-drawer-leave{animation:slideOutToRight .3s ease-in forwards}.cmat-data-picker-drawer-overlay[style*=\"left: 0\"]{box-shadow:2px 0 8px #00000026}.cmat-data-picker-drawer-overlay[style*=\"left: 0\"].cmat-drawer-enter{animation:slideInFromLeft .3s ease-out}.cmat-data-picker-drawer-overlay[style*=\"left: 0\"].cmat-drawer-leave{animation:slideOutToLeft .3s ease-in forwards}@keyframes slideInFromRight{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes slideInFromLeft{0%{transform:translate(-100%)}to{transform:translate(0)}}@keyframes slideOutToRight{0%{transform:translate(0)}to{transform:translate(100%)}}@keyframes slideOutToLeft{0%{transform:translate(0)}to{transform:translate(-100%)}}\n"] }]
|
|
981
|
+
}], ctorParameters: () => [], propDecorators: { apiUrl: [{ type: i0.Input, args: [{ isSignal: true, alias: "apiUrl", required: false }] }], dataSource: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataSource", required: false }] }], dataProvider: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataProvider", required: false }] }], columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: false }] }], keyField: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyField", required: false }] }], labelField: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelField", required: false }] }], displayTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "displayTemplate", required: false }] }], displayLabelFn: [{ type: i0.Input, args: [{ isSignal: true, alias: "displayLabelFn", required: false }] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", required: false }] }], searchable: [{ type: i0.Input, args: [{ isSignal: true, alias: "searchable", required: false }] }], debounceTime: [{ type: i0.Input, args: [{ isSignal: true, alias: "debounceTime", required: false }] }], pageSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "pageSize", required: false }] }], uiMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "uiMode", required: false }] }], drawerPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "drawerPosition", required: false }] }], drawerWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "drawerWidth", required: false }] }], dialogWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "dialogWidth", required: false }] }], dialogMaxHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "dialogMaxHeight", required: false }] }], selectionChange: [{ type: i0.Output, args: ["selectionChange"] }], placeholder: [{
|
|
982
|
+
type: Input
|
|
983
|
+
}], value: [{
|
|
984
|
+
type: Input
|
|
985
|
+
}], required: [{
|
|
986
|
+
type: Input
|
|
987
|
+
}], disabled: [{
|
|
988
|
+
type: Input
|
|
989
|
+
}] } });
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Generated bundle index. Do not edit.
|
|
993
|
+
*/
|
|
994
|
+
|
|
995
|
+
export { CmatDataPickerComponent, CmatDataPickerDialogComponent, CmatDataPickerDrawerComponent, CmatDataPickerListComponent, CmatDataPickerSheetComponent, HttpDataPickerProvider, createHttpDataProvider };
|
|
996
|
+
//# sourceMappingURL=cmat-components-data-picker.mjs.map
|