@ctzy-web-client/plugin-component-vue 1.0.47 → 1.0.49

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,13 +1,11 @@
1
1
  <template>
2
- <!-- 🔥 最外层:自动适配所有容器,弹框/页面通用 -->
3
- <div
4
- :class="ns.b()"
5
- ref="dataTableEl"
6
- style="width:100%; height:100%; display:flex; flex-direction:column; min-height:0;"
7
- >
2
+ <div :class="ns.b()" ref="dataTableEl" :style="{display: realHeight === 'auto' ? 'flex' : 'block',
3
+ flexDirection: realHeight === 'auto' ? 'column' : 'unset'}">
8
4
  <slot :dataTable="dataTable">
9
5
  <ElTable
10
6
  class="content"
7
+ :height="realHeight"
8
+ :max-height="maxHeight"
11
9
  ref="elTable"
12
10
  :data="data"
13
11
  :row-key="dataTable.primaryKey"
@@ -27,7 +25,7 @@
27
25
  </div>
28
26
  </ElTableColumn>
29
27
  <slot v-if="selection" name="selection">
30
- <ElTableColumn type="selection" :fixed="fixedSelection" align="center" width="56" :reserve-selection="true" />
28
+ <ElTableColumn type="selection" :fixed="fixedSelection" align="center" width="56" :reserve-selection="true" />
31
29
  </slot>
32
30
  <slot v-if="showIndex" name="index">
33
31
  <ElTableColumn
@@ -46,8 +44,8 @@
46
44
  :label="item.title"
47
45
  :prop="item.fullAttrName"
48
46
  :min-width="item.width"
47
+ :fixed="item.fixed"
49
48
  :align="item.align"
50
- :fixed="item.fixed"
51
49
  v-bind="item.componentProps"
52
50
  :sortable="item.sortable=='custom'"
53
51
  >
@@ -72,12 +70,11 @@
72
70
  </slot>
73
71
 
74
72
  <slot name="column-append"></slot>
75
- <template #empty>
76
- <slot name="empty-table"></slot>
77
- </template>
73
+ <template #empty>
74
+ <slot name="empty-table"></slot>
75
+ </template>
78
76
  </ElTable>
79
77
  </slot>
80
-
81
78
  <div v-if="showPagination" :class="ns.e('pagination')">
82
79
  <div :class="ns.e('pagination-info')">
83
80
  共{{ totalPage }}页,{{ dataTable.totalRecCount }}条
@@ -93,7 +90,6 @@
93
90
  :teleported="false"
94
91
  />
95
92
  </div>
96
-
97
93
  <div
98
94
  v-if="barRectangle"
99
95
  :class="ns.e('dragbar')"
@@ -106,138 +102,398 @@
106
102
  ></div>
107
103
  </div>
108
104
  </template>
109
-
110
105
  <script setup>
111
- // ------------- 你的原有 JS 代码 完全不动 -------------
112
- // 我只需要你删除原来的 realHeight 相关计算即可
113
106
  import { ElMessage, ElPagination, ElTable, ElTableColumn } from 'element-plus';
114
- import { computed, nextTick, onBeforeUnmount, onUnmounted, provide, reactive, watch, ref, unref, useAttrs } from 'vue';
115
- import { dataTableKey, useNamespace, useEventDispatcher, useGlobalConfig, useService } from '@ctzy-web-client/web-base-client-vue';
107
+ import {
108
+ computed,
109
+ nextTick,
110
+ onBeforeUnmount,
111
+ onMounted,
112
+ onUnmounted,
113
+ provide,
114
+ reactive,
115
+ watch,
116
+ ref,
117
+ unref,
118
+ useAttrs,
119
+ } from 'vue';
120
+ import {
121
+ dataTableKey,
122
+ useNamespace,
123
+ useEventDispatcher,
124
+ useGlobalConfig,
125
+ useService,
126
+ } from '@ctzy-web-client/web-base-client-vue';
116
127
  import DynamicComponent from './dynamic-component.js';
117
128
  import BwaDataTableColumn from './data-table-column.vue';
118
129
  import { useDataTableDrag } from './use-datatable-drag';
119
130
  import { get } from 'lodash';
120
- import { from, delayWhen, map, skipWhile, Observable, filter, Subject, debounceTime } from 'rxjs';
131
+ import {
132
+ from,
133
+ delayWhen,
134
+ map,
135
+ skipWhile,
136
+ Observable,
137
+ filter,
138
+ Subject,
139
+ debounceTime,
140
+ } from 'rxjs';
121
141
 
122
142
  defineOptions({ name: 'BwaDataTable' });
123
143
 
124
144
  const props = defineProps({
125
- dataTable: { type: Object, required: true },
126
- autoLoad: { type: Boolean, default: true },
127
- height: { type: [String, Number], default: "auto" }, // 这个保留,但不再使用
128
- showIndex: { type: Boolean, default: false },
129
- indexColumnLabel: { type: String, default: '编号' },
130
- selection: { type: Boolean, default: false },
131
- fixedSelection: { type: [Boolean, String], default: false },
132
- paginationLayout: { type: String, default: 'sizes, prev, pager, next, jumper' },
133
- paginationPageSizes: { type: Array, default: () => [10, 20, 50, 100, 200] },
134
- showPagination: { type: Boolean, default: true },
135
- whereParamName: { type: String, default: '' },
136
- showDrag: { type: Boolean, default: false },
137
- border: { type: Boolean, default: true }
145
+ dataTable: {
146
+ type: Object,
147
+ required: true,
148
+ },
149
+ autoLoad: {
150
+ type: Boolean,
151
+ default: true,
152
+ },
153
+ height: {
154
+ type: [String, Number],
155
+ default: "auto",
156
+ },
157
+ fixedSelection: { type: [Boolean, String], default: false },
158
+ showIndex: {
159
+ type: Boolean,
160
+ default: false,
161
+ },
162
+ indexColumnLabel: {
163
+ type: String,
164
+ default: '编号',
165
+ },
166
+ selection: {
167
+ type: Boolean,
168
+ default: false,
169
+ },
170
+ paginationLayout: {
171
+ type: String,
172
+ default: 'sizes, prev, pager, next, jumper',
173
+ },
174
+ paginationPageSizes: {
175
+ type: Array,
176
+ default: () => [10, 20, 50, 100, 200],
177
+ },
178
+ showPagination: {
179
+ type: Boolean,
180
+ default: true,
181
+ },
182
+ whereParamName: {
183
+ type: String,
184
+ default: '',
185
+ },
186
+ showDrag: {
187
+ type: Boolean,
188
+ default: false,
189
+ },
190
+ border: {
191
+ type: Boolean,
192
+ default: true,
193
+ }
138
194
  });
139
195
 
140
196
  const attrs = useAttrs();
197
+
141
198
  const userService = useService('UserService');
199
+
142
200
  const elTable = ref(null);
201
+
143
202
  const dataTable = props.dataTable;
144
203
  dataTable._userService = userService.value?.getUserList
204
+
145
205
  const dataTableEl = ref(null);
206
+ // const realHeight = computed(() => props.height)
207
+ const realHeight = computed(() => {
208
+ // 如果用户传了 height,就用用户的
209
+ if (props.height !== 'auto') {
210
+ return props.height
211
+ }
212
+ // 否则自动计算表格高度
213
+ return tableAutoHeight.value
214
+ })
215
+ const maxHeight = ref(0)
146
216
 
147
- // 🔥 删掉你原来的 realHeight 计算!!!
148
- // const realHeight = computed(...)
217
+ // 计算最大高度
218
+ function updateMaxHeight(list) {
219
+ if (list?.length) {
220
+ maxHeight.value = list.length * 64 + 62
221
+ } else {
222
+ maxHeight.value = 0
223
+ }
224
+ }
225
+ // ====================
226
+ // 自动高度计算(react-base-table 同款逻辑)
227
+ // ====================
228
+ const tableAutoHeight = ref(300)
229
+
230
+
231
+ // 分页高度(固定,根据你的样式调整)
232
+ const PAGINATION_HEIGHT = 160
233
+
234
+ // 计算表格高度 = 屏幕高度 - 自身offsetTop高度 - 分页高度
235
+ function calcTableHeight() {
236
+ nextTick(() => {
237
+ if (!dataTableEl.value) return
238
+ const top = dataTableEl.value.offsetTop // 自动获取顶部距离
239
+ const viewHeight = window.innerHeight
240
+ const height = viewHeight - top - PAGINATION_HEIGHT-45
241
+ console.log(height)
242
+ tableAutoHeight.value = Math.max(height, 100) // 最小200px
243
+
244
+ })
245
+ }
149
246
 
150
- const displayColumns = computed(() => unref(dataTable).getDisplayColumns() || []);
247
+ // 防抖监听窗口缩放
248
+ let resizeTimer = null
249
+ function watchResize() {
250
+ clearTimeout(resizeTimer)
251
+ resizeTimer = setTimeout(calcTableHeight, 100)
252
+ }
253
+ onMounted(() => {
254
+ calcTableHeight()
255
+ window.addEventListener('resize', watchResize)
256
+ })
257
+
258
+ onBeforeUnmount(() => {
259
+ window.removeEventListener('resize', watchResize)
260
+ clearTimeout(resizeTimer)
261
+ })
262
+
263
+ const displayColumns = computed(
264
+ () => unref(dataTable).getDisplayColumns() || []
265
+ );
151
266
 
152
- // ------------- 下面你的原有逻辑全部保持不变 -------------
153
- watch(computed(() => props.whereParamName), (whereParamName) => {
154
- dataTable.setWhereParamName(whereParamName || '');
155
- }, { immediate: true, flush: 'sync' });
267
+ watch(
268
+ computed(() => props.whereParamName),
269
+ (whereParamName) => {
270
+ dataTable.setWhereParamName(whereParamName || '');
271
+ },
272
+ { immediate: true, flush: 'sync' }
273
+ );
156
274
 
157
275
  const searchParams = computed(() => props.searchParams);
276
+
158
277
  const emit = defineEmits(['drag','headerWidthChange']);
278
+
159
279
  const debounceDelay = useGlobalConfig('debounceDelay', 500);
160
- provide(dataTableKey, reactive({ dataTable, displayColumns }));
280
+
281
+ //当前data table 上下文对象
282
+ provide(
283
+ dataTableKey,
284
+ reactive({
285
+ dataTable,
286
+ displayColumns,
287
+ })
288
+ );
289
+
161
290
  const ns = useNamespace('datatable');
162
- const { barRectangle } = useDataTableDrag(dataTableEl, '.bwa-datatable__drag', '.el-table__row', { emit });
291
+
292
+ const { barRectangle } = useDataTableDrag(
293
+ dataTableEl,
294
+ '.bwa-datatable__drag',
295
+ '.el-table__row',
296
+ { emit }
297
+ );
298
+
163
299
  const processing = ref(false);
164
- const data = computed(() => props.dataTable.data);
300
+
301
+ const data = computed(() => {
302
+ return props.dataTable.data;
303
+ });
165
304
 
166
305
  useEventDispatcher(dataTable, 'load-successfully', async (res) => {
167
- if (res.code != 0) return;
306
+ if (res.code != 0) {
307
+ return;
308
+ }
309
+ updateMaxHeight(res.data)
168
310
  const _userService = unref(userService);
169
- if (!_userService) return;
311
+
312
+ if (!_userService) {
313
+ return;
314
+ }
315
+
170
316
  let columns = dataTable.getColumns();
317
+
171
318
  const componentNames = ['BwaUserSelect', 'BwaUserMultiSelect'];
172
- columns = columns.filter(c => componentNames.includes(c.formComponent)).filter(c => c.visible).filter(c => c.isExtend);
173
- if (!columns.length) return;
319
+
320
+ columns = columns
321
+ .filter((column) => componentNames.includes(column.formComponent))
322
+ .filter((column) => column.visible)
323
+ .filter((column) => column.isExtend);
324
+
325
+ if (!columns.length) {
326
+ return;
327
+ }
328
+
174
329
  processing.value = true;
330
+
175
331
  const data = res.data;
176
- let ids = data.reduce((r, i) => r.concat(columns.reduce((rr, cc) => rr.concat(Array.isArray(get(i, cc.fullAttrName)) ? get(i, cc.fullAttrName) : get(i, cc.fullAttrName) ? [get(i, cc.fullAttrName)] : []) , [])), []).map(id => id + '');
332
+
333
+ let ids = data
334
+ .reduce((result, item) => {
335
+ return result.concat(
336
+ columns.reduce((result, column) => {
337
+ let value = get(item, column.fullAttrName);
338
+
339
+ value = Array.isArray(value) ? value : value ? [value] : [];
340
+
341
+ return result.concat(value);
342
+ }, [])
343
+ );
344
+ }, [])
345
+ .map((id) => id + '');
346
+
177
347
  ids = [...new Set(ids)];
348
+
178
349
  try {
179
350
  const userListResult = await _userService.getUserListByIds(ids);
180
- if (userListResult.code != 0) return;
351
+
352
+ if (userListResult.code != 0) {
353
+ return;
354
+ }
355
+
181
356
  for (const column of columns) {
182
357
  column.componentProps = column.componentProps || {};
183
- column.componentProps.options = (userListResult.data || []).map(item => ({ label: item.label, value: item.value }));
358
+ column.componentProps.options = (userListResult.data || []).map(
359
+ (item) => ({
360
+ label: item.label,
361
+ value: item.value,
362
+ })
363
+ );
184
364
  }
185
- } finally { processing.value = false; }
186
- });
187
365
 
188
- const sortHandle = (column) => {
189
- let sortColumn = '';
190
- let sortType = '';
191
- if (column.order) {
192
- sortColumn = column.prop;
193
- sortType = column.order === "descending" ? 0 : 1;
194
- dataTable.setParam('sortColumn', sortColumn);
195
- dataTable.setParam('sortType', sortType);
196
- } else {
197
- dataTable.setParam('sortColumn', '');
198
- dataTable.setParam('sortType', '');
366
+ } finally {
367
+ processing.value = false;
199
368
  }
200
- dataTable.load();
201
- };
369
+ });
370
+
371
+ //手动排序
372
+ const sortHandle = (column, prop, order) => {
373
+ let sortColumn = ''
374
+ let sortType = ''
375
+ if (column.order){
376
+ sortColumn = column.prop
377
+ sortType = column.order=="descending"?0:1
378
+ dataTable.setParam('sortColumn', sortColumn);
379
+ dataTable.setParam('sortType', sortType);
380
+ }else{
381
+ dataTable.setParam('sortColumn', sortColumn);
382
+ dataTable.setParam('sortType', sortType);
383
+ }
384
+ dataTable.load()
385
+ }
202
386
 
203
387
  useEventDispatcher(dataTable, 'load-successfully', (res) => {
204
- if (!elTable.value) return;
205
- if (unref(elTable)?.store?.updateSelectionByRowKey) unref(elTable).store.updateSelectionByRowKey();
206
- if (res.code != 0) ElMessage.error(res.msg);
388
+ if (!elTable.value) {
389
+ return;
390
+ }
391
+
392
+ if (unref(elTable)?.store?.updateSelectionByRowKey) {
393
+ unref(elTable).store.updateSelectionByRowKey()
394
+ }
395
+ // else {
396
+ // console.log('方法不存在,当前 store 结构:', unref(elTable)?.store)
397
+ // }
398
+ // unref(elTable).store.updateSelectionByRowKey();
399
+
400
+ if (res.code != 0) {
401
+ ElMessage.error(res.msg);
402
+ }
403
+ updateMaxHeight(res.data)
207
404
  });
208
405
 
209
406
  function sortColumn(array) {
210
- array.forEach(item => { item.no = item.getColumnIndex?.(); if (item.children?.length) sortColumn(item.children); });
407
+ array.forEach((item) => {
408
+ item.no = item.getColumnIndex?.();
409
+ if (item.children?.length) {
410
+ sortColumn(item.children);
411
+ }
412
+ });
211
413
  array.sort((cur, pre) => cur.no - pre.no);
212
414
  }
213
415
 
214
416
  const tableSelectSubject = new Subject();
215
417
  const selectionChange = tableSelectSubject.next.bind(tableSelectSubject);
216
- const headerDragend = (newWidth, oldWidth, column) => {
217
- emit('headerWidthChange', { newWidth: Math.round(newWidth), oldWidth: Math.round(oldWidth), column });
218
- };
418
+ const headerDragend = (newWidth,oldWidth,column) =>{
419
+
420
+
421
+ let widthObj = {
422
+ newWidth:Math.round(newWidth),
423
+ oldWidth:Math.round(oldWidth),
424
+ column:column
425
+ }
426
+ emit('headerWidthChange',widthObj)
427
+ }
219
428
  const totalPage = computed(() => dataTable.getTotalPage());
220
- const tableSelectSubscription = tableSelectSubject.pipe(debounceTime(debounceDelay)).subscribe(unref(dataTable).setSelection.bind(unref(dataTable)));
221
-
222
- const selectChangeAPIObservable = new Observable((observer) => useEventDispatcher(props.dataTable, 'select-change', observer.next.bind(observer)))
223
- .pipe(filter((selection) => {
224
- if (!unref(elTable)) return false;
225
- const selectionRows = unref(elTable).getSelectionRows();
226
- if (selectionRows.length !== selection.length) return true;
227
- const primaryKey = dataTable.primaryKey;
228
- return !selectionRows.every(item => selection.find(it => item[primaryKey] === it[primaryKey]));
229
- })).subscribe((selection) => {
429
+
430
+ const tableSelectSubscription = tableSelectSubject
431
+ .pipe(debounceTime(debounceDelay))
432
+ .subscribe(unref(dataTable).setSelection.bind(unref(dataTable)));
433
+
434
+ const selectChangeAPIObservable = new Observable((observer) =>
435
+ useEventDispatcher(
436
+ props.dataTable,
437
+ 'select-change',
438
+ observer.next.bind(observer)
439
+ )
440
+ )
441
+ .pipe(
442
+ filter((selection) => {
443
+ if (!unref(elTable)) {
444
+ return false;
445
+ }
446
+
447
+ const selectionRows = unref(elTable).getSelectionRows();
448
+
449
+ if (selectionRows.length !== selection.length) {
450
+ return true;
451
+ }
452
+
453
+ const primaryKey = dataTable.primaryKey;
454
+ return !selectionRows.every((item) =>
455
+ selection.find((itm) => item[primaryKey] === item[primaryKey])
456
+ );
457
+ })
458
+ )
459
+ .subscribe((selection) => {
230
460
  unref(elTable).clearSelection();
231
- for (const item of selection) unref(elTable).toggleRowSelection(item, true);
461
+ for (const item of selection) {
462
+ unref(elTable).toggleRowSelection(item, true);
463
+ }
232
464
  });
233
465
 
234
- if (props.autoLoad) dataTable.load();
235
- const searchParamsSubscription = new Observable((observer) => useEventDispatcher(props.dataTable.filterPanel, 'params-change', observer.next.bind(observer)))
236
- .pipe(filter(() => props.dataTable.filterPanel.ready), debounceTime(unref(debounceDelay))).subscribe(() => props.dataTable.load());
466
+ if (props.autoLoad) {
467
+ //初始化加载
468
+ dataTable.load();
469
+ }
237
470
 
238
- const subscription = props.dataTable.getDisplayColumnsSubject()
239
- .pipe(map(() => unref(elTable)), delayWhen(() => from(nextTick())), map(el => el?.store), skipWhile(store => !store)).subscribe(store => {
471
+ const searchParamsSubscription = new Observable((observer) =>
472
+ useEventDispatcher(
473
+ props.dataTable.filterPanel,
474
+ 'params-change',
475
+ observer.next.bind(observer)
476
+ )
477
+ )
478
+ .pipe(
479
+ filter(() => props.dataTable.filterPanel.ready),
480
+ debounceTime(unref(debounceDelay))
481
+ )
482
+ .subscribe(() => {
483
+ props.dataTable.load();
484
+ });
485
+
486
+ const subscription = props.dataTable
487
+ .getDisplayColumnsSubject()
488
+ .pipe(
489
+ map(() => unref(elTable)),
490
+ delayWhen(() => from(nextTick())),
491
+ map((elTable) => elTable?.store),
492
+ skipWhile((store) => !store)
493
+ )
494
+ .subscribe((store) => {
240
495
  sortColumn(unref(store.states._columns));
496
+
241
497
  store.updateColumns();
242
498
  store.scheduleLayout();
243
499
  });
@@ -250,46 +506,3 @@ onUnmounted(() => {
250
506
  });
251
507
  </script>
252
508
 
253
-
254
- <style scoped lang="scss">
255
- .bwa-datatable {
256
- width: 100%;
257
- height: 100%;
258
- display: flex;
259
- flex-direction: column;
260
- min-height: 0;
261
- .content {
262
- flex: 1;
263
- display: flex;
264
- flex-direction: column;
265
- width: 100%;
266
- }
267
-
268
- :deep(.el-table) {
269
- flex: 1 !important;
270
- width: 100% !important;
271
- display: flex !important;
272
- flex-direction: column !important;
273
- }
274
-
275
- :deep(.el-table__inner-wrapper) {
276
- flex: 1 !important;
277
- display: flex !important;
278
- flex-direction: column !important;
279
- }
280
-
281
- :deep(.el-table__body-wrapper) {
282
- flex: 1 !important;
283
- overflow: auto !important;
284
- }
285
-
286
- .bwa-datatable__pagination {
287
-
288
- display: flex;
289
- justify-content: space-between;
290
- align-items: center;
291
- }
292
- }
293
-
294
-
295
- </style>
@@ -41,7 +41,7 @@
41
41
  >
42
42
  <div v-if="showTitle" :class="ns.e('title')" style="padding-right: 8px">{{searchTitle}}</div>
43
43
  <ElInput
44
- prefix-icon="Search"
44
+ suffix-icon="Search"
45
45
 
46
46
  clearable
47
47
  v-model="searchValue"
@@ -1,13 +0,0 @@
1
- // Inject __name helper
2
- if (typeof __name === 'undefined') {
3
- function __name(obj, name) {
4
- Object.defineProperty(obj, "name", {
5
- value: name,
6
- configurable: true
7
- });
8
- }
9
- }
10
-
11
- var undefined$1 = undefined;
12
-
13
- export { undefined$1 as default };
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- // Inject __name helper
6
- if (typeof __name === 'undefined') {
7
- function __name(obj, name) {
8
- Object.defineProperty(obj, "name", {
9
- value: name,
10
- configurable: true
11
- });
12
- }
13
- }
14
-
15
- var undefined$1 = undefined;
16
-
17
- exports["default"] = undefined$1;