-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor[element-plus]: refactor table-pro
- Loading branch information
Showing
12 changed files
with
4,927 additions
and
3,875 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/element-plus/components/table-pro/drag-sort-icon.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="1em" | ||
height="1em" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
fill="currentColor" | ||
d="M6 20q-.825 0-1.413-.588T4 18q0-.825.588-1.413T6 16q.825 0 1.413.588T8 18q0 .825-.588 1.413T6 20Zm6 0q-.825 0-1.413-.588T10 18q0-.825.588-1.413T12 16q.825 0 1.413.588T14 18q0 .825-.588 1.413T12 20Zm6 0q-.825 0-1.413-.588T16 18q0-.825.588-1.413T18 16q.825 0 1.413.588T20 18q0 .825-.588 1.413T18 20ZM6 14q-.825 0-1.413-.588T4 12q0-.825.588-1.413T6 10q.825 0 1.413.588T8 12q0 .825-.588 1.413T6 14Zm6 0q-.825 0-1.413-.588T10 12q0-.825.588-1.413T12 10q.825 0 1.413.588T14 12q0 .825-.588 1.413T12 14Zm6 0q-.825 0-1.413-.588T16 12q0-.825.588-1.413T18 10q.825 0 1.413.588T20 12q0 .825-.588 1.413T18 14ZM6 8q-.825 0-1.413-.588T4 6q0-.825.588-1.413T6 4q.825 0 1.413.588T8 6q0 .825-.588 1.413T6 8Zm6 0q-.825 0-1.413-.588T10 6q0-.825.588-1.413T12 4q.825 0 1.413.588T14 6q0 .825-.588 1.413T12 8Zm6 0q-.825 0-1.413-.588T16 6q0-.825.588-1.413T18 4q.825 0 1.413.588T20 6q0 .825-.588 1.413T18 8Z" | ||
></path> | ||
</svg> | ||
</template> | ||
|
||
<script lang="ts"> | ||
export default { | ||
name: 'DragSortIcon', | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
packages/element-plus/components/table-pro/table-columns-action.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<script setup lang="ts" name="ColumnsOperation"> | ||
import { noop } from '@cc-heart/utils' | ||
import { ComputedRef, PropType, Ref, computed, unref } from 'vue' | ||
import draggable from 'vuedraggable' | ||
import DragSortIcon from './drag-sort-icon.vue' | ||
import { | ||
ElIcon, | ||
ElPopover, | ||
ElCheckbox, | ||
ElButton, | ||
ElCheckboxGroup, | ||
ElDivider, | ||
} from 'element-plus' | ||
const props = defineProps({ | ||
sortedColumns: { | ||
type: [Array, Object] as PropType< | ||
Array<Record<string, any>> | Ref<Array<Record<string, any>>> | ||
>, | ||
default: () => [], | ||
}, | ||
columnsField: { | ||
type: Array as PropType<Array<string> | Ref<Array<string>>>, | ||
default: () => [], | ||
}, | ||
rowKey: { | ||
type: String as PropType<ComputedRef<string> | string>, | ||
default: 'key', | ||
}, | ||
onUpdateSortedColumns: { | ||
type: Function as PropType<(val: Record<string, any>[]) => void>, | ||
default: noop, | ||
}, | ||
onUpdateColumnsField: { | ||
type: Function as PropType<(val: (string | number)[]) => void>, | ||
default: noop, | ||
}, | ||
onReset: { | ||
type: Function as PropType<() => void>, | ||
default: noop, | ||
}, | ||
}) | ||
let tempColumnSettings = [] as any[] | ||
const handleChangeColumns = (val: any[]) => { | ||
tempColumnSettings = val | ||
} | ||
const emitChangeColumn = () => { | ||
props.onUpdateSortedColumns(tempColumnSettings) | ||
} | ||
const handleChangeCheckbox = (columnIds: Array<any>) => { | ||
props.onUpdateColumnsField(columnIds) | ||
} | ||
const isAllSelected = computed(() => { | ||
return unref(props.columnsField).length === unref(props.sortedColumns).length | ||
}) | ||
const toggleShowColumns = () => { | ||
if (isAllSelected.value) { | ||
props.onUpdateColumnsField([]) | ||
} else { | ||
props.onUpdateColumnsField( | ||
unref(props.sortedColumns).map( | ||
(item: Record<string, any>) => | ||
Reflect.get(item, unref(props.rowKey) as string)! | ||
) | ||
) | ||
} | ||
} | ||
const handleReset = () => { | ||
props.onReset() | ||
} | ||
</script> | ||
<template> | ||
<ElPopover trigger="click"> | ||
<template #reference> | ||
<slot /> | ||
</template> | ||
<div class="flex items-center"> | ||
<ElCheckbox :checked="isAllSelected" @update:checked="toggleShowColumns" | ||
>列展示</ElCheckbox | ||
> | ||
<ElButton link @click="handleReset"> 重置 </ElButton> | ||
</div> | ||
<ElDivider /> | ||
|
||
<ElCheckboxGroup | ||
:modelValue="unref(columnsField)" | ||
@change="handleChangeCheckbox" | ||
> | ||
<draggable | ||
:model-value="unref(sortedColumns)" | ||
@update:model-value="handleChangeColumns" | ||
@end="emitChangeColumn" | ||
group="description" | ||
animation="300" | ||
class="flex flex-col" | ||
handle=".drag-handle" | ||
item-key="prop" | ||
> | ||
<template #item="{ element }"> | ||
<ElCheckbox | ||
:key="element.prop" | ||
:value="element.prop" | ||
:label="element.label" | ||
> | ||
<div class="drag-handle m-r-1"> | ||
<DragSortIcon /> | ||
</div> | ||
{{ element.label }} | ||
</ElCheckbox> | ||
</template> | ||
</draggable> | ||
</ElCheckboxGroup> | ||
</ElPopover> | ||
</template> | ||
<style lang="scss"> | ||
.drag-handle { | ||
display: inline-flex; | ||
} | ||
.flex { | ||
display: flex; | ||
} | ||
.flex-col { | ||
flex-direction: column; | ||
} | ||
.items-center { | ||
align-items: center; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.