Commit 74d47424069c4dca71579637916431aa80014fd8

Authored by vben
1 parent e1e9baa8

fix: the action column appears repeatedly in the table (#53)

src/components/Table/src/BasicTable.vue
... ... @@ -190,6 +190,14 @@
190 190 return !!unref(getDataSourceRef).length;
191 191 });
192 192  
  193 + watch(
  194 + () => unref(getDataSourceRef),
  195 + () => {
  196 + handleSummary();
  197 + },
  198 + { immediate: true }
  199 + );
  200 +
193 201 function getRowClassName(record: TableCustomRecord<any>, index: number) {
194 202 const { striped, rowClassName } = unref(getMergeProps);
195 203 if (!striped) return;
... ... @@ -242,14 +250,6 @@
242 250 }
243 251 }
244 252  
245   - watch(
246   - () => unref(getDataSourceRef),
247   - () => {
248   - handleSummary();
249   - },
250   - { immediate: true }
251   - );
252   -
253 253 function setProps(props: Partial<BasicTableProps>) {
254 254 innerPropsRef.value = deepMerge(unref(innerPropsRef) || {}, props);
255 255 }
... ...
src/components/Table/src/hooks/useColumns.ts
1 1 import { BasicColumn, BasicTableProps } from '../types/table';
2 2 import { PaginationProps } from '../types/pagination';
3   -import { unref, ComputedRef, Ref, computed, watch, ref } from 'vue';
  3 +import { unref, ComputedRef, Ref, computed, watchEffect, ref, toRaw } from 'vue';
4 4 import { isBoolean, isArray, isObject } from '/@/utils/is';
5 5 import { PAGE_SIZE } from '../const';
6 6 import { useProps } from './useProps';
... ... @@ -10,20 +10,9 @@ export function useColumns(
10 10 getPaginationRef: ComputedRef<false | PaginationProps>
11 11 ) {
12 12 const { propsRef } = useProps(refProps);
13   -
14 13 const columnsRef = (ref(unref(propsRef).columns) as unknown) as Ref<BasicColumn[]>;
15 14 const cacheColumnsRef = (ref(unref(propsRef).columns) as unknown) as Ref<BasicColumn[]>;
16 15  
17   - watch(
18   - () => unref(propsRef).columns,
19   - (columns) => {
20   - columnsRef.value = columns;
21   - cacheColumnsRef.value = columns;
22   - },
23   - {
24   - immediate: true,
25   - }
26   - );
27 16 const getColumnsRef = computed(() => {
28 17 const props = unref(propsRef);
29 18 const { showIndexColumn, indexColumnProps, ellipsis, actionColumn, isTreeTable } = props;
... ... @@ -81,16 +70,24 @@ export function useColumns(
81 70 }
82 71 if (actionColumn) {
83 72 const hasIndex = columns.findIndex((column) => column.flag === 'ACTION');
84   - columns.push({
85   - ...(hasIndex === -1 ? columns[hasIndex] : {}),
86   - fixed: 'right',
87   - ...actionColumn,
88   - flag: 'ACTION',
89   - });
  73 + if (hasIndex === -1) {
  74 + columns.push({
  75 + ...columns[hasIndex],
  76 + fixed: 'right',
  77 + ...actionColumn,
  78 + flag: 'ACTION',
  79 + });
  80 + }
90 81 }
91 82 return columns;
92 83 });
93 84  
  85 + watchEffect(() => {
  86 + const columns = toRaw(unref(propsRef).columns);
  87 + columnsRef.value = columns;
  88 + cacheColumnsRef.value = columns;
  89 + });
  90 +
94 91 function setColumns(columns: BasicColumn[] | string[]) {
95 92 if (!isArray(columns)) return;
96 93  
... ...