mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 22:04:30 +08:00
fix: the action column appears repeatedly in the table (#53)
This commit is contained in:
@@ -190,6 +190,14 @@
|
|||||||
return !!unref(getDataSourceRef).length;
|
return !!unref(getDataSourceRef).length;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => unref(getDataSourceRef),
|
||||||
|
() => {
|
||||||
|
handleSummary();
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
function getRowClassName(record: TableCustomRecord<any>, index: number) {
|
function getRowClassName(record: TableCustomRecord<any>, index: number) {
|
||||||
const { striped, rowClassName } = unref(getMergeProps);
|
const { striped, rowClassName } = unref(getMergeProps);
|
||||||
if (!striped) return;
|
if (!striped) return;
|
||||||
@@ -242,14 +250,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
|
||||||
() => unref(getDataSourceRef),
|
|
||||||
() => {
|
|
||||||
handleSummary();
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
function setProps(props: Partial<BasicTableProps>) {
|
function setProps(props: Partial<BasicTableProps>) {
|
||||||
innerPropsRef.value = deepMerge(unref(innerPropsRef) || {}, props);
|
innerPropsRef.value = deepMerge(unref(innerPropsRef) || {}, props);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { BasicColumn, BasicTableProps } from '../types/table';
|
import { BasicColumn, BasicTableProps } from '../types/table';
|
||||||
import { PaginationProps } from '../types/pagination';
|
import { PaginationProps } from '../types/pagination';
|
||||||
import { unref, ComputedRef, Ref, computed, watch, ref } from 'vue';
|
import { unref, ComputedRef, Ref, computed, watchEffect, ref, toRaw } from 'vue';
|
||||||
import { isBoolean, isArray, isObject } from '/@/utils/is';
|
import { isBoolean, isArray, isObject } from '/@/utils/is';
|
||||||
import { PAGE_SIZE } from '../const';
|
import { PAGE_SIZE } from '../const';
|
||||||
import { useProps } from './useProps';
|
import { useProps } from './useProps';
|
||||||
@@ -10,20 +10,9 @@ export function useColumns(
|
|||||||
getPaginationRef: ComputedRef<false | PaginationProps>
|
getPaginationRef: ComputedRef<false | PaginationProps>
|
||||||
) {
|
) {
|
||||||
const { propsRef } = useProps(refProps);
|
const { propsRef } = useProps(refProps);
|
||||||
|
|
||||||
const columnsRef = (ref(unref(propsRef).columns) as unknown) as Ref<BasicColumn[]>;
|
const columnsRef = (ref(unref(propsRef).columns) as unknown) as Ref<BasicColumn[]>;
|
||||||
const cacheColumnsRef = (ref(unref(propsRef).columns) as unknown) as Ref<BasicColumn[]>;
|
const cacheColumnsRef = (ref(unref(propsRef).columns) as unknown) as Ref<BasicColumn[]>;
|
||||||
|
|
||||||
watch(
|
|
||||||
() => unref(propsRef).columns,
|
|
||||||
(columns) => {
|
|
||||||
columnsRef.value = columns;
|
|
||||||
cacheColumnsRef.value = columns;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
immediate: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const getColumnsRef = computed(() => {
|
const getColumnsRef = computed(() => {
|
||||||
const props = unref(propsRef);
|
const props = unref(propsRef);
|
||||||
const { showIndexColumn, indexColumnProps, ellipsis, actionColumn, isTreeTable } = props;
|
const { showIndexColumn, indexColumnProps, ellipsis, actionColumn, isTreeTable } = props;
|
||||||
@@ -81,16 +70,24 @@ export function useColumns(
|
|||||||
}
|
}
|
||||||
if (actionColumn) {
|
if (actionColumn) {
|
||||||
const hasIndex = columns.findIndex((column) => column.flag === 'ACTION');
|
const hasIndex = columns.findIndex((column) => column.flag === 'ACTION');
|
||||||
|
if (hasIndex === -1) {
|
||||||
columns.push({
|
columns.push({
|
||||||
...(hasIndex === -1 ? columns[hasIndex] : {}),
|
...columns[hasIndex],
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
...actionColumn,
|
...actionColumn,
|
||||||
flag: 'ACTION',
|
flag: 'ACTION',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return columns;
|
return columns;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
const columns = toRaw(unref(propsRef).columns);
|
||||||
|
columnsRef.value = columns;
|
||||||
|
cacheColumnsRef.value = columns;
|
||||||
|
});
|
||||||
|
|
||||||
function setColumns(columns: BasicColumn[] | string[]) {
|
function setColumns(columns: BasicColumn[] | string[]) {
|
||||||
if (!isArray(columns)) return;
|
if (!isArray(columns)) return;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user