style: perfect tableDemo

This commit is contained in:
kailong321200875 2022-08-13 09:03:52 +08:00
parent c43e833582
commit c589edd960
7 changed files with 22 additions and 5 deletions

View File

@ -1,9 +1,11 @@
import Table from './src/Table.vue' import Table from './src/Table.vue'
import { ElTable } from 'element-plus'
export interface TableExpose { export interface TableExpose {
setProps: (props: Recordable) => void setProps: (props: Recordable) => void
setColumn: (columnProps: TableSetPropsType[]) => void setColumn: (columnProps: TableSetPropsType[]) => void
selections: Recordable[] selections: Recordable[]
elTableRef: ComponentRef<typeof ElTable>
} }
export { Table } export { Table }

View File

@ -99,7 +99,8 @@ export default defineComponent({
expose({ expose({
setProps, setProps,
setColumn, setColumn,
selections selections,
elTableRef
}) })
const pagination = computed(() => { const pagination = computed(() => {

View File

@ -89,7 +89,7 @@ export const useTable = <T = any>(config?: UseTableConfig<T>) => {
const register = (ref: typeof Table & TableExpose, elRef: ComponentRef<typeof ElTable>) => { const register = (ref: typeof Table & TableExpose, elRef: ComponentRef<typeof ElTable>) => {
tableRef.value = ref tableRef.value = ref
elTableRef.value = elRef elTableRef.value = unref(elRef)
} }
const getTable = async () => { const getTable = async () => {

View File

@ -377,7 +377,8 @@ export default {
showExpandedRows: 'Show expanded rows', showExpandedRows: 'Show expanded rows',
hiddenExpandedRows: 'Hidden expanded rows', hiddenExpandedRows: 'Hidden expanded rows',
changeTitle: 'Change title', changeTitle: 'Change title',
header: 'Header' header: 'Header',
selectAllNone: 'Select all / none'
}, },
richText: { richText: {
richText: 'Rich text', richText: 'Rich text',

View File

@ -374,7 +374,8 @@ export default {
showExpandedRows: '显示展开行', showExpandedRows: '显示展开行',
hiddenExpandedRows: '隐藏展开行', hiddenExpandedRows: '隐藏展开行',
changeTitle: '修改标题', changeTitle: '修改标题',
header: '头部' header: '头部',
selectAllNone: '全选/全不选'
}, },
richText: { richText: {
richText: '富文本', richText: '富文本',

View File

@ -125,6 +125,10 @@ const showExpandedRows = (show: boolean) => {
expand: show expand: show
}) })
} }
const selectAllNone = () => {
unref(tableRef)?.elTableRef?.toggleAllSelection()
}
</script> </script>
<template> <template>
@ -146,6 +150,8 @@ const showExpandedRows = (show: boolean) => {
<ElButton @click="showExpandedRows(true)">{{ t('tableDemo.showExpandedRows') }}</ElButton> <ElButton @click="showExpandedRows(true)">{{ t('tableDemo.showExpandedRows') }}</ElButton>
<ElButton @click="showExpandedRows(false)">{{ t('tableDemo.hiddenExpandedRows') }}</ElButton> <ElButton @click="showExpandedRows(false)">{{ t('tableDemo.hiddenExpandedRows') }}</ElButton>
<ElButton @click="selectAllNone">{{ t('tableDemo.selectAllNone') }}</ElButton>
</ContentWrap> </ContentWrap>
<ContentWrap :title="`RefTable ${t('tableDemo.example')}`"> <ContentWrap :title="`RefTable ${t('tableDemo.example')}`">
<Table <Table

View File

@ -8,7 +8,7 @@ import { ref, h, reactive, unref } from 'vue'
import { ElTag, ElButton } from 'element-plus' import { ElTag, ElButton } from 'element-plus'
import { useTable } from '@/hooks/web/useTable' import { useTable } from '@/hooks/web/useTable'
const { register, tableObject, methods } = useTable<TableData>({ const { register, tableObject, methods, elTableRef } = useTable<TableData>({
getListApi: getTableListApi, getListApi: getTableListApi,
response: { response: {
list: 'list', list: 'list',
@ -124,6 +124,10 @@ const showExpandedRows = (show: boolean) => {
expand: show expand: show
}) })
} }
const selectAllNone = () => {
unref(elTableRef)?.toggleAllSelection()
}
</script> </script>
<template> <template>
@ -145,6 +149,8 @@ const showExpandedRows = (show: boolean) => {
<ElButton @click="showExpandedRows(true)">{{ t('tableDemo.showExpandedRows') }}</ElButton> <ElButton @click="showExpandedRows(true)">{{ t('tableDemo.showExpandedRows') }}</ElButton>
<ElButton @click="showExpandedRows(false)">{{ t('tableDemo.hiddenExpandedRows') }}</ElButton> <ElButton @click="showExpandedRows(false)">{{ t('tableDemo.hiddenExpandedRows') }}</ElButton>
<ElButton @click="selectAllNone">{{ t('tableDemo.selectAllNone') }}</ElButton>
</ContentWrap> </ContentWrap>
<ContentWrap :title="`UseTable ${t('tableDemo.example')}`"> <ContentWrap :title="`UseTable ${t('tableDemo.example')}`">
<Table <Table