@jetlinks-web/components 2.0.1 → 2.0.2-2

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.
@@ -1,551 +1,551 @@
1
- import { Empty, AIcon } from '../../../components';
2
- import { Table, Pagination, Button, Alert, Spin, RadioGroup, RadioButton } from 'ant-design-vue'
3
- import type { RadioChangeEvent } from 'ant-design-vue/lib/radio';
4
- import type { TableProps } from 'ant-design-vue/lib/table';
5
- import { tableProps as _tableProps } from 'ant-design-vue/lib/table';
6
- import {
7
- defineComponent,
8
- onMounted,
9
- onUnmounted,
10
- PropType,
11
- ref,
12
- watch,
13
- } from 'vue';
14
- import {
15
- JColumnProps,
16
- ModelEnum,
17
- TypeEnum,
18
- RequestData,
19
- } from './proTableTypes';
20
- import { get, debounce, isArray } from 'lodash-es';
21
-
22
- export interface JTableProps extends TableProps {
23
- request?: (params?: Record<string, any>) => Promise<Partial<RequestData>>;
24
- cardBodyClass?: string;
25
- columns: JColumnProps[];
26
- model?: keyof typeof ModelEnum | undefined; // 显示table还是card
27
-
28
- modelValue?: keyof typeof ModelEnum | undefined;
29
- noPagination?: boolean;
30
- rowSelection?: TableProps['rowSelection'];
31
- dataSource?: Record<string, any>[];
32
- params?: Record<string, any>;
33
- gridColumn?: number;
34
- gridColumns?: number[];
35
- alertRender?: boolean;
36
- type?: keyof typeof TypeEnum;
37
- defaultParams?: Record<string, any>;
38
- bodyStyle?: Record<string, any>;
39
- pageIndex: number;
40
- pageSize: number;
41
- total: number;
42
- column: number;
43
- }
44
-
45
- const tableProps = () => {
46
- return {
47
- ..._tableProps(),
48
- loading: {
49
- type: Boolean,
50
- default: undefined,
51
- },
52
- request: {
53
- type: Function,
54
- default: undefined,
55
- },
56
- cardBodyClass: {
57
- type: String,
58
- default: '',
59
- },
60
- bodyStyle: {
61
- type: Object,
62
- default: {},
63
- },
64
- columns: {
65
- type: Array,
66
- default: () => [],
67
- },
68
- model: {
69
- type: [String, undefined],
70
- default: undefined,
71
- },
72
- modelValue: {
73
- type: String,
74
- default: undefined,
75
- },
76
- noPagination: {
77
- type: Boolean,
78
- default: false,
79
- },
80
- rowSelection: {
81
- type: Object as PropType<TableProps['rowSelection']>,
82
- default: () => undefined,
83
- },
84
- dataSource: {
85
- type: Array,
86
- default: () => [],
87
- },
88
- gridColumns: {
89
- type: Array as PropType<number[]>,
90
- default: () => [],
91
- },
92
- gridColumn: {
93
- type: Number,
94
- default: 4,
95
- },
96
- alertRender: {
97
- type: Boolean,
98
- default: true,
99
- },
100
- params: {
101
- type: Object,
102
- default: () => {
103
- },
104
- },
105
- type: {
106
- type: String,
107
- default: 'PAGE',
108
- },
109
- scroll: {
110
- type: Object,
111
- default: () => {
112
- x: 1366;
113
- },
114
- },
115
- defaultParams: {
116
- type: Object,
117
- default: () => {
118
- },
119
- },
120
- rowKey: {
121
- type: [String, Function],
122
- default: 'id',
123
- },
124
- pagination: {
125
- type: Object, // Boolean,
126
- default: () => {
127
- return {
128
- showSizeChanger: true,
129
- showQuickJumper: false,
130
- size: 'size',
131
- pageSizeOptions: ['12', '24', '48', '96'],
132
- };
133
- },
134
- },
135
- };
136
- };
137
-
138
- const ProTable = defineComponent<JTableProps>({
139
- name: 'ProTable',
140
- slots: [
141
- 'headerTitle', // 顶部左边插槽
142
- 'card', // 卡片内容
143
- 'rightExtraRender',
144
- 'paginationRender', // 分页
145
- ],
146
- props: tableProps() as any,
147
- emits: ['update:modelValue', 'modelChange'],
148
- setup(props: JTableProps, {slots, expose, emit}) {
149
- const _model = ref<keyof typeof ModelEnum>(
150
- props.model ? props.model : ModelEnum.CARD,
151
- ); // 模式切换
152
-
153
- const _dataSource = ref<Record<string, any>[]>([]);
154
- const pageIndex = ref<number>(0);
155
- const pageSize = ref<number>(12);
156
- const total = ref<number>(0);
157
- const _loading = ref<boolean>(false);
158
- const column = ref<number>(props.gridColumn || 4);
159
-
160
- if (
161
- !props.noPagination &&
162
- props.pagination &&
163
- isArray(props.pagination?.pageSizeOptions)
164
- ) {
165
- pageSize.value = props.pagination.pageSizeOptions[0] as number;
166
- }
167
-
168
- /**
169
- * 监听宽度,计算显示卡片个数
170
- */
171
- const windowChange = () => {
172
- if (window.innerWidth <= 1440) {
173
- const _column =
174
- props.gridColumn && props.gridColumn < 2
175
- ? props.gridColumn
176
- : 2;
177
- column.value = props.gridColumns?.[0]
178
- ? props.gridColumns[0]
179
- : _column;
180
- } else if (window.innerWidth > 1440 && window.innerWidth <= 1600) {
181
- const _column =
182
- props.gridColumn && props.gridColumn < 3
183
- ? props.gridColumn
184
- : 3;
185
- column.value = props.gridColumns?.[1]
186
- ? props.gridColumns[1]
187
- : _column;
188
- } else if (window.innerWidth > 1600) {
189
- const _column =
190
- props.gridColumn && props.gridColumn < 4
191
- ? props.gridColumn
192
- : 4;
193
- column.value = props.gridColumns?.[2]
194
- ? props.gridColumns[2]
195
- : _column;
196
- }
197
- };
198
-
199
- const handleSearch = async (_params?: Record<string, any>) => {
200
- _loading.value =
201
- props.loading !== undefined ? (props.loading as boolean) : true;
202
- if (props.request) {
203
- console.log(_params);
204
- const resp: any = await props
205
- .request({
206
- pageIndex: 0,
207
- pageSize: Number(pageSize.value),
208
- ...props.defaultParams,
209
- ..._params,
210
- terms: [
211
- ...(props.defaultParams?.terms || []),
212
- ...(_params?.terms || []),
213
- ],
214
- })
215
- .catch(() => {
216
- _loading.value =
217
- props.loading !== undefined
218
- ? (props.loading as boolean)
219
- : false;
220
- });
221
- if (resp.status === 200) {
222
- if (props.type === 'PAGE') {
223
- // 判断如果是最后一页且最后一页为空,就跳转到前一页
224
- if (
225
- resp?.result?.total &&
226
- resp?.result?.pageSize &&
227
- resp?.result?.pageIndex &&
228
- resp?.result?.data?.length === 0
229
- ) {
230
- pageIndex.value =
231
- pageIndex.value > 0 ? pageIndex.value - 1 : 0;
232
-
233
- handleSearch({
234
- ..._params,
235
- pageSize: pageSize.value,
236
- pageIndex: pageIndex.value,
237
- });
238
- } else {
239
- _dataSource.value = resp?.result?.data || [];
240
- pageIndex.value = resp?.result?.pageIndex || 0;
241
- pageSize.value = resp?.result?.pageSize || 12;
242
- total.value = resp?.result?.total || 0;
243
- }
244
- } else {
245
- _dataSource.value = resp?.result || [];
246
- }
247
- } else {
248
- _dataSource.value = [];
249
- }
250
- } else {
251
- _dataSource.value = props?.dataSource || [];
252
- }
253
- _loading.value =
254
- props.loading !== undefined
255
- ? (props.loading as boolean)
256
- : false;
257
- };
258
-
259
- const _debounceFn = debounce(handleSearch, 300);
260
-
261
- watch(
262
- () => props.params,
263
- (newValue) => {
264
- _debounceFn(newValue || {});
265
- },
266
- {deep: true, immediate: true},
267
- );
268
-
269
- watch(
270
- () => props.dataSource,
271
- (newVal) => {
272
- if (newVal && !props.request) {
273
- handleSearch(props.params);
274
- }
275
- },
276
- {deep: true, immediate: true},
277
- );
278
-
279
- watch(
280
- () => props.modelValue,
281
- () => {
282
- if (props.modelValue) {
283
- _model.value = props.modelValue;
284
- }
285
- },
286
- {immediate: true},
287
- );
288
-
289
- /**
290
- * 刷新数据
291
- * @param _params
292
- */
293
- const reload = (_params?: Record<string, any>) => {
294
- handleSearch({
295
- ...props.params,
296
- ..._params,
297
- pageSize: pageSize.value || 12, // 刷新页面不改变分页情况
298
- pageIndex: pageIndex.value || 0,
299
- });
300
- };
301
-
302
- onMounted(() => {
303
- windowChange(); // 初始化
304
- window.onresize = () => {
305
- windowChange();
306
- };
307
- });
308
-
309
- onUnmounted(() => {
310
- window.onresize = null;
311
- });
312
-
313
- /**
314
- * 导出方法
315
- */
316
- expose({reload, _dataSource});
317
-
318
- return () => (
319
- <div class="jtable-body-spin" style={{...props.bodyStyle}}>
320
- <Spin spinning={_loading.value}>
321
- <div class={'jtable-body'}>
322
- <div class={'jtable-body-header'}>
323
- <div class={'jtable-body-header-left'}>
324
- {/* 顶部左边插槽 */}
325
- {slots.headerTitle && slots.headerTitle()}
326
- </div>
327
- <div class={'jtable-body-header-right'}>
328
- {/* 顶部右边插槽 */}
329
- {slots.rightExtraRender &&
330
- slots.rightExtraRender()}
331
- {!props.model && (
332
- <div
333
- class={
334
- 'jtable-body-header-right-button'
335
- }
336
- >
337
- <RadioGroup
338
- class="jtable-body-header-right-button"
339
- value={_model.value}
340
- onChange={(e: RadioChangeEvent) => {
341
- _model.value = e.target.value;
342
- emit(
343
- 'update:modelValue',
344
- e.target.value,
345
- );
346
- emit(
347
- 'modelChange',
348
- e.target.value,
349
- );
350
- }}
351
- >
352
- <RadioButton
353
- value={ModelEnum.TABLE}
354
- >
355
- <AIcon
356
- class={'right-button-icon'}
357
- type="UnorderedListOutlined"
358
- />
359
- </RadioButton>
360
- <RadioButton value={ModelEnum.CARD}>
361
- <AIcon
362
- class={'right-button-icon'}
363
- type="AppstoreOutlined"
364
- />
365
- </RadioButton>
366
- </RadioGroup>
367
- </div>
368
- )}
369
- </div>
370
- </div>
371
- {/* content */}
372
- <div class={'jtable-content'}>
373
- {props.alertRender &&
374
- props?.rowSelection &&
375
- props?.rowSelection?.selectedRowKeys &&
376
- props.rowSelection.selectedRowKeys?.length ? (
377
- <div class={'jtable-alert'}>
378
- <Alert
379
- message={
380
- '已选择' +
381
- props?.rowSelection?.selectedRowKeys
382
- ?.length +
383
- '项'
384
- }
385
- type="info"
386
- onClose={() => {
387
- // if (props.rowSelection?.onSelectNone) {
388
- // // 取消选择清空被选数据
389
- // }
390
- props.rowSelection?.onChange?.(
391
- [],
392
- [],
393
- );
394
- props.rowSelection?.onSelectNone?.();
395
- }}
396
- closeText={
397
- <Button type="link">
398
- 取消选择
399
- </Button>
400
- }
401
- />
402
- </div>
403
- ) : null}
404
- {_model.value === ModelEnum.CARD ? (
405
- <div
406
- class={'jtable-card'}
407
- style={
408
- props.scroll && props.scroll.y
409
- ? {
410
- maxHeight:
411
- props.scroll.y + 'px',
412
- overflow: 'auto',
413
- }
414
- : undefined
415
- }
416
- >
417
- {_dataSource.value.length ? (
418
- <div
419
- class={'jtable-card-items'}
420
- style={{
421
- gridTemplateColumns: `repeat(${column.value}, 1fr)`,
422
- }}
423
- >
424
- {_dataSource.value.map((item) =>
425
- slots.card ? (
426
- <div
427
- class={[
428
- 'jtable-card-item',
429
- props.cardBodyClass,
430
- ]}
431
- >
432
- {slots.card(item)}
433
- </div>
434
- ) : null,
435
- )}
436
- </div>
437
- ) : (
438
- <div class="j-table-empty">
439
- <Empty/>
440
- </div>
441
- )}
442
- </div>
443
- ) : (
444
- <div>
445
- <Table
446
- {...props}
447
- dataSource={_dataSource.value}
448
- columns={props.columns.filter(
449
- (i) => !i?.hideInTable,
450
- )}
451
- pagination={false}
452
- rowSelection={props.rowSelection}
453
- scroll={props.scroll}
454
- v-slots={{
455
- headerCell: (
456
- dt: Record<string, any>,
457
- ) => {
458
- const {column, title} = dt;
459
- if (column?.headerCell) {
460
- return slots?.[
461
- column?.headerCell
462
- ]!(column.title);
463
- } else {
464
- return title || '';
465
- }
466
- },
467
- bodyCell: (
468
- dt: Record<string, any>,
469
- ) => {
470
- const {column, record} = dt;
471
- if (
472
- (column?.key ||
473
- column?.dataIndex) &&
474
- column?.scopedSlots &&
475
- (slots?.[
476
- column?.dataIndex
477
- ] ||
478
- slots?.[column?.key])
479
- ) {
480
- const _key =
481
- column?.key ||
482
- column?.dataIndex;
483
- return slots?.[_key]!(
484
- record,
485
- );
486
- } else {
487
- const _value = get(
488
- record,
489
- column?.dataIndex,
490
- );
491
- // 获取数据
492
- return _value;
493
- }
494
- },
495
- emptyText: () => <Empty/>,
496
- }}
497
- />
498
- </div>
499
- )}
500
- </div>
501
- {/* 分页 */}
502
- {!!_dataSource.value.length &&
503
- !props.noPagination &&
504
- props.type === 'PAGE' && (
505
- <div class={'jtable-pagination'}>
506
- {slots?.paginationRender ? (
507
- slots.paginationRender()
508
- ) : (
509
- <Pagination
510
- {...props.pagination}
511
- total={total.value}
512
- current={pageIndex.value + 1}
513
- pageSize={pageSize.value}
514
- showTotal={(num) => {
515
- const minSize =
516
- pageIndex.value *
517
- pageSize.value +
518
- 1;
519
- const MaxSize =
520
- (pageIndex.value + 1) *
521
- pageSize.value;
522
- return `第 ${minSize} - ${
523
- MaxSize > num
524
- ? num
525
- : MaxSize
526
- } 条/总共 ${num} 条`;
527
- }}
528
- onChange={(page, size) => {
529
- handleSearch({
530
- ...props.params,
531
- pageSize: size,
532
- pageIndex:
533
- pageSize.value === size
534
- ? page
535
- ? page - 1
536
- : 0
537
- : 0,
538
- });
539
- }}
540
- />
541
- )}
542
- </div>
543
- )}
544
- </div>
545
- </Spin>
546
- </div>
547
- );
548
- },
549
- });
550
-
551
- export default ProTable;
1
+ import { Empty, AIcon } from '../../../components';
2
+ import { Table, Pagination, Button, Alert, Spin, RadioGroup, RadioButton } from 'ant-design-vue'
3
+ import type { RadioChangeEvent } from 'ant-design-vue/es/radio';
4
+ import type { TableProps } from 'ant-design-vue/es/table';
5
+ import { tableProps as _tableProps } from 'ant-design-vue/es/table';
6
+ import {
7
+ defineComponent,
8
+ onMounted,
9
+ onUnmounted,
10
+ PropType,
11
+ ref,
12
+ watch,
13
+ } from 'vue';
14
+ import {
15
+ JColumnProps,
16
+ ModelEnum,
17
+ TypeEnum,
18
+ RequestData,
19
+ } from './proTableTypes';
20
+ import { get, debounce, isArray } from 'lodash-es';
21
+
22
+ export interface JTableProps extends TableProps {
23
+ request?: (params?: Record<string, any>) => Promise<Partial<RequestData>>;
24
+ cardBodyClass?: string;
25
+ columns: JColumnProps[];
26
+ model?: keyof typeof ModelEnum | undefined; // 显示table还是card
27
+
28
+ modelValue?: keyof typeof ModelEnum | undefined;
29
+ noPagination?: boolean;
30
+ rowSelection?: TableProps['rowSelection'];
31
+ dataSource?: Record<string, any>[];
32
+ params?: Record<string, any>;
33
+ gridColumn?: number;
34
+ gridColumns?: number[];
35
+ alertRender?: boolean;
36
+ type?: keyof typeof TypeEnum;
37
+ defaultParams?: Record<string, any>;
38
+ bodyStyle?: Record<string, any>;
39
+ pageIndex: number;
40
+ pageSize: number;
41
+ total: number;
42
+ column: number;
43
+ }
44
+
45
+ const tableProps = () => {
46
+ return {
47
+ ..._tableProps(),
48
+ loading: {
49
+ type: Boolean,
50
+ default: undefined,
51
+ },
52
+ request: {
53
+ type: Function,
54
+ default: undefined,
55
+ },
56
+ cardBodyClass: {
57
+ type: String,
58
+ default: '',
59
+ },
60
+ bodyStyle: {
61
+ type: Object,
62
+ default: {},
63
+ },
64
+ columns: {
65
+ type: Array,
66
+ default: () => [],
67
+ },
68
+ model: {
69
+ type: [String, undefined],
70
+ default: undefined,
71
+ },
72
+ modelValue: {
73
+ type: String,
74
+ default: undefined,
75
+ },
76
+ noPagination: {
77
+ type: Boolean,
78
+ default: false,
79
+ },
80
+ rowSelection: {
81
+ type: Object as PropType<TableProps['rowSelection']>,
82
+ default: () => undefined,
83
+ },
84
+ dataSource: {
85
+ type: Array,
86
+ default: () => [],
87
+ },
88
+ gridColumns: {
89
+ type: Array as PropType<number[]>,
90
+ default: () => [],
91
+ },
92
+ gridColumn: {
93
+ type: Number,
94
+ default: 4,
95
+ },
96
+ alertRender: {
97
+ type: Boolean,
98
+ default: true,
99
+ },
100
+ params: {
101
+ type: Object,
102
+ default: () => {
103
+ },
104
+ },
105
+ type: {
106
+ type: String,
107
+ default: 'PAGE',
108
+ },
109
+ scroll: {
110
+ type: Object,
111
+ default: () => {
112
+ x: 1366;
113
+ },
114
+ },
115
+ defaultParams: {
116
+ type: Object,
117
+ default: () => {
118
+ },
119
+ },
120
+ rowKey: {
121
+ type: [String, Function],
122
+ default: 'id',
123
+ },
124
+ pagination: {
125
+ type: Object, // Boolean,
126
+ default: () => {
127
+ return {
128
+ showSizeChanger: true,
129
+ showQuickJumper: false,
130
+ size: 'size',
131
+ pageSizeOptions: ['12', '24', '48', '96'],
132
+ };
133
+ },
134
+ },
135
+ };
136
+ };
137
+
138
+ const ProTable = defineComponent<JTableProps>({
139
+ name: 'ProTable',
140
+ slots: [
141
+ 'headerTitle', // 顶部左边插槽
142
+ 'card', // 卡片内容
143
+ 'rightExtraRender',
144
+ 'paginationRender', // 分页
145
+ ],
146
+ props: tableProps() as any,
147
+ emits: ['update:modelValue', 'modelChange'],
148
+ setup(props: JTableProps, {slots, expose, emit}) {
149
+ const _model = ref<keyof typeof ModelEnum>(
150
+ props.model ? props.model : ModelEnum.CARD,
151
+ ); // 模式切换
152
+
153
+ const _dataSource = ref<Record<string, any>[]>([]);
154
+ const pageIndex = ref<number>(0);
155
+ const pageSize = ref<number>(12);
156
+ const total = ref<number>(0);
157
+ const _loading = ref<boolean>(false);
158
+ const column = ref<number>(props.gridColumn || 4);
159
+
160
+ if (
161
+ !props.noPagination &&
162
+ props.pagination &&
163
+ isArray(props.pagination?.pageSizeOptions)
164
+ ) {
165
+ pageSize.value = props.pagination.pageSizeOptions[0] as number;
166
+ }
167
+
168
+ /**
169
+ * 监听宽度,计算显示卡片个数
170
+ */
171
+ const windowChange = () => {
172
+ if (window.innerWidth <= 1440) {
173
+ const _column =
174
+ props.gridColumn && props.gridColumn < 2
175
+ ? props.gridColumn
176
+ : 2;
177
+ column.value = props.gridColumns?.[0]
178
+ ? props.gridColumns[0]
179
+ : _column;
180
+ } else if (window.innerWidth > 1440 && window.innerWidth <= 1600) {
181
+ const _column =
182
+ props.gridColumn && props.gridColumn < 3
183
+ ? props.gridColumn
184
+ : 3;
185
+ column.value = props.gridColumns?.[1]
186
+ ? props.gridColumns[1]
187
+ : _column;
188
+ } else if (window.innerWidth > 1600) {
189
+ const _column =
190
+ props.gridColumn && props.gridColumn < 4
191
+ ? props.gridColumn
192
+ : 4;
193
+ column.value = props.gridColumns?.[2]
194
+ ? props.gridColumns[2]
195
+ : _column;
196
+ }
197
+ };
198
+
199
+ const handleSearch = async (_params?: Record<string, any>) => {
200
+ _loading.value =
201
+ props.loading !== undefined ? (props.loading as boolean) : true;
202
+ if (props.request) {
203
+ console.log(_params);
204
+ const resp: any = await props
205
+ .request({
206
+ pageIndex: 0,
207
+ pageSize: Number(pageSize.value),
208
+ ...props.defaultParams,
209
+ ..._params,
210
+ terms: [
211
+ ...(props.defaultParams?.terms || []),
212
+ ...(_params?.terms || []),
213
+ ],
214
+ })
215
+ .catch(() => {
216
+ _loading.value =
217
+ props.loading !== undefined
218
+ ? (props.loading as boolean)
219
+ : false;
220
+ });
221
+ if (resp.status === 200) {
222
+ if (props.type === 'PAGE') {
223
+ // 判断如果是最后一页且最后一页为空,就跳转到前一页
224
+ if (
225
+ resp?.result?.total &&
226
+ resp?.result?.pageSize &&
227
+ resp?.result?.pageIndex &&
228
+ resp?.result?.data?.length === 0
229
+ ) {
230
+ pageIndex.value =
231
+ pageIndex.value > 0 ? pageIndex.value - 1 : 0;
232
+
233
+ handleSearch({
234
+ ..._params,
235
+ pageSize: pageSize.value,
236
+ pageIndex: pageIndex.value,
237
+ });
238
+ } else {
239
+ _dataSource.value = resp?.result?.data || [];
240
+ pageIndex.value = resp?.result?.pageIndex || 0;
241
+ pageSize.value = resp?.result?.pageSize || 12;
242
+ total.value = resp?.result?.total || 0;
243
+ }
244
+ } else {
245
+ _dataSource.value = resp?.result || [];
246
+ }
247
+ } else {
248
+ _dataSource.value = [];
249
+ }
250
+ } else {
251
+ _dataSource.value = props?.dataSource || [];
252
+ }
253
+ _loading.value =
254
+ props.loading !== undefined
255
+ ? (props.loading as boolean)
256
+ : false;
257
+ };
258
+
259
+ const _debounceFn = debounce(handleSearch, 300);
260
+
261
+ watch(
262
+ () => props.params,
263
+ (newValue) => {
264
+ _debounceFn(newValue || {});
265
+ },
266
+ {deep: true, immediate: true},
267
+ );
268
+
269
+ watch(
270
+ () => props.dataSource,
271
+ (newVal) => {
272
+ if (newVal && !props.request) {
273
+ handleSearch(props.params);
274
+ }
275
+ },
276
+ {deep: true, immediate: true},
277
+ );
278
+
279
+ watch(
280
+ () => props.modelValue,
281
+ () => {
282
+ if (props.modelValue) {
283
+ _model.value = props.modelValue;
284
+ }
285
+ },
286
+ {immediate: true},
287
+ );
288
+
289
+ /**
290
+ * 刷新数据
291
+ * @param _params
292
+ */
293
+ const reload = (_params?: Record<string, any>) => {
294
+ handleSearch({
295
+ ...props.params,
296
+ ..._params,
297
+ pageSize: pageSize.value || 12, // 刷新页面不改变分页情况
298
+ pageIndex: pageIndex.value || 0,
299
+ });
300
+ };
301
+
302
+ onMounted(() => {
303
+ windowChange(); // 初始化
304
+ window.onresize = () => {
305
+ windowChange();
306
+ };
307
+ });
308
+
309
+ onUnmounted(() => {
310
+ window.onresize = null;
311
+ });
312
+
313
+ /**
314
+ * 导出方法
315
+ */
316
+ expose({reload, _dataSource});
317
+
318
+ return () => (
319
+ <div class="jtable-body-spin" style={{...props.bodyStyle}}>
320
+ <Spin spinning={_loading.value}>
321
+ <div class={'jtable-body'}>
322
+ <div class={'jtable-body-header'}>
323
+ <div class={'jtable-body-header-left'}>
324
+ {/* 顶部左边插槽 */}
325
+ {slots.headerTitle && slots.headerTitle()}
326
+ </div>
327
+ <div class={'jtable-body-header-right'}>
328
+ {/* 顶部右边插槽 */}
329
+ {slots.rightExtraRender &&
330
+ slots.rightExtraRender()}
331
+ {!props.model && (
332
+ <div
333
+ class={
334
+ 'jtable-body-header-right-button'
335
+ }
336
+ >
337
+ <RadioGroup
338
+ class="jtable-body-header-right-button"
339
+ value={_model.value}
340
+ onChange={(e: RadioChangeEvent) => {
341
+ _model.value = e.target.value;
342
+ emit(
343
+ 'update:modelValue',
344
+ e.target.value,
345
+ );
346
+ emit(
347
+ 'modelChange',
348
+ e.target.value,
349
+ );
350
+ }}
351
+ >
352
+ <RadioButton
353
+ value={ModelEnum.TABLE}
354
+ >
355
+ <AIcon
356
+ class={'right-button-icon'}
357
+ type="UnorderedListOutlined"
358
+ />
359
+ </RadioButton>
360
+ <RadioButton value={ModelEnum.CARD}>
361
+ <AIcon
362
+ class={'right-button-icon'}
363
+ type="AppstoreOutlined"
364
+ />
365
+ </RadioButton>
366
+ </RadioGroup>
367
+ </div>
368
+ )}
369
+ </div>
370
+ </div>
371
+ {/* content */}
372
+ <div class={'jtable-content'}>
373
+ {props.alertRender &&
374
+ props?.rowSelection &&
375
+ props?.rowSelection?.selectedRowKeys &&
376
+ props.rowSelection.selectedRowKeys?.length ? (
377
+ <div class={'jtable-alert'}>
378
+ <Alert
379
+ message={
380
+ '已选择' +
381
+ props?.rowSelection?.selectedRowKeys
382
+ ?.length +
383
+ '项'
384
+ }
385
+ type="info"
386
+ onClose={() => {
387
+ // if (props.rowSelection?.onSelectNone) {
388
+ // // 取消选择清空被选数据
389
+ // }
390
+ props.rowSelection?.onChange?.(
391
+ [],
392
+ [],
393
+ );
394
+ props.rowSelection?.onSelectNone?.();
395
+ }}
396
+ closeText={
397
+ <Button type="link">
398
+ 取消选择
399
+ </Button>
400
+ }
401
+ />
402
+ </div>
403
+ ) : null}
404
+ {_model.value === ModelEnum.CARD ? (
405
+ <div
406
+ class={'jtable-card'}
407
+ style={
408
+ props.scroll && props.scroll.y
409
+ ? {
410
+ maxHeight:
411
+ props.scroll.y + 'px',
412
+ overflow: 'auto',
413
+ }
414
+ : undefined
415
+ }
416
+ >
417
+ {_dataSource.value.length ? (
418
+ <div
419
+ class={'jtable-card-items'}
420
+ style={{
421
+ gridTemplateColumns: `repeat(${column.value}, 1fr)`,
422
+ }}
423
+ >
424
+ {_dataSource.value.map((item) =>
425
+ slots.card ? (
426
+ <div
427
+ class={[
428
+ 'jtable-card-item',
429
+ props.cardBodyClass,
430
+ ]}
431
+ >
432
+ {slots.card(item)}
433
+ </div>
434
+ ) : null,
435
+ )}
436
+ </div>
437
+ ) : (
438
+ <div class="j-table-empty">
439
+ <Empty/>
440
+ </div>
441
+ )}
442
+ </div>
443
+ ) : (
444
+ <div>
445
+ <Table
446
+ {...props}
447
+ dataSource={_dataSource.value}
448
+ columns={props.columns.filter(
449
+ (i) => !i?.hideInTable,
450
+ )}
451
+ pagination={false}
452
+ rowSelection={props.rowSelection}
453
+ scroll={props.scroll}
454
+ v-slots={{
455
+ headerCell: (
456
+ dt: Record<string, any>,
457
+ ) => {
458
+ const {column, title} = dt;
459
+ if (column?.headerCell) {
460
+ return slots?.[
461
+ column?.headerCell
462
+ ]!(column.title);
463
+ } else {
464
+ return title || '';
465
+ }
466
+ },
467
+ bodyCell: (
468
+ dt: Record<string, any>,
469
+ ) => {
470
+ const {column, record} = dt;
471
+ if (
472
+ (column?.key ||
473
+ column?.dataIndex) &&
474
+ column?.scopedSlots &&
475
+ (slots?.[
476
+ column?.dataIndex
477
+ ] ||
478
+ slots?.[column?.key])
479
+ ) {
480
+ const _key =
481
+ column?.key ||
482
+ column?.dataIndex;
483
+ return slots?.[_key]!(
484
+ record,
485
+ );
486
+ } else {
487
+ const _value = get(
488
+ record,
489
+ column?.dataIndex,
490
+ );
491
+ // 获取数据
492
+ return _value;
493
+ }
494
+ },
495
+ emptyText: () => <Empty/>,
496
+ }}
497
+ />
498
+ </div>
499
+ )}
500
+ </div>
501
+ {/* 分页 */}
502
+ {!!_dataSource.value.length &&
503
+ !props.noPagination &&
504
+ props.type === 'PAGE' && (
505
+ <div class={'jtable-pagination'}>
506
+ {slots?.paginationRender ? (
507
+ slots.paginationRender()
508
+ ) : (
509
+ <Pagination
510
+ {...props.pagination}
511
+ total={total.value}
512
+ current={pageIndex.value + 1}
513
+ pageSize={pageSize.value}
514
+ showTotal={(num) => {
515
+ const minSize =
516
+ pageIndex.value *
517
+ pageSize.value +
518
+ 1;
519
+ const MaxSize =
520
+ (pageIndex.value + 1) *
521
+ pageSize.value;
522
+ return `第 ${minSize} - ${
523
+ MaxSize > num
524
+ ? num
525
+ : MaxSize
526
+ } 条/总共 ${num} 条`;
527
+ }}
528
+ onChange={(page, size) => {
529
+ handleSearch({
530
+ ...props.params,
531
+ pageSize: size,
532
+ pageIndex:
533
+ pageSize.value === size
534
+ ? page
535
+ ? page - 1
536
+ : 0
537
+ : 0,
538
+ });
539
+ }}
540
+ />
541
+ )}
542
+ </div>
543
+ )}
544
+ </div>
545
+ </Spin>
546
+ </div>
547
+ );
548
+ },
549
+ });
550
+
551
+ export default ProTable;