|
@@ -1,29 +1,34 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div class="app-table" v-loading="loading">
|
|
<div class="app-table" v-loading="loading">
|
|
|
- <div class="app-table__header" v-if="showHeader">
|
|
|
|
|
- <div>
|
|
|
|
|
|
|
+ <div class="app-table__header">
|
|
|
|
|
+ <div class="block block--left">
|
|
|
<slot name="header"></slot>
|
|
<slot name="header"></slot>
|
|
|
</div>
|
|
</div>
|
|
|
- <div>
|
|
|
|
|
- <el-button-group>
|
|
|
|
|
- <el-button icon="Refresh" @click="refresh" />
|
|
|
|
|
- <el-button icon="Setting" @click="showTableSetting = true" />
|
|
|
|
|
- </el-button-group>
|
|
|
|
|
|
|
+ <div class="block block--right" v-if="showToolbar">
|
|
|
|
|
+ <slot name="toolbar">
|
|
|
|
|
+ <el-button-group>
|
|
|
|
|
+ <el-button icon="Refresh" @click="refresh" />
|
|
|
|
|
+ <el-button icon="Setting" @click="showTableSetting = true" />
|
|
|
|
|
+ </el-button-group>
|
|
|
|
|
+ </slot>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="app-table__container">
|
|
<div class="app-table__container">
|
|
|
- <el-table ref="tableRef" v-bind="$attrs" highlight-current-row scrollbar-always-on border>
|
|
|
|
|
|
|
+ <el-table ref="tableRef" :header-cell-class-name="selectionType" v-bind="$attrs" highlight-current-row
|
|
|
|
|
+ scrollbar-always-on @row-click="onRowClick" @select="onSelect">
|
|
|
<!-- 展开行 -->
|
|
<!-- 展开行 -->
|
|
|
<el-table-column type="expand" v-if="$slots.expand">
|
|
<el-table-column type="expand" v-if="$slots.expand">
|
|
|
<template #default="{ row, $index }">
|
|
<template #default="{ row, $index }">
|
|
|
<slot name="expand" :row="row" :index="$index"></slot>
|
|
<slot name="expand" :row="row" :index="$index"></slot>
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
|
|
+ <!-- 选择列 -->
|
|
|
|
|
+ <el-table-column type="selection" width="55" align="center" fixed v-if="selectionType" />
|
|
|
<!-- 数据列 -->
|
|
<!-- 数据列 -->
|
|
|
<template v-for="(item, index) in columns" :key="index">
|
|
<template v-for="(item, index) in columns" :key="index">
|
|
|
- <el-table-column :class-name="item.className" :align="item.align ?? 'left'" :min-width="120"
|
|
|
|
|
|
|
+ <el-table-column :class-name="item.className" :align="item.align ?? 'center'" :min-width="120"
|
|
|
:width="item.width" :label="item.label" :prop="item.prop" :fixed="item.fixed || false"
|
|
:width="item.width" :label="item.label" :prop="item.prop" :fixed="item.fixed || false"
|
|
|
- :sortable="item.sortable" v-if="item.show">
|
|
|
|
|
|
|
+ :sortable="item.sortable" show-overflow-tooltip v-if="item.show ?? true">
|
|
|
<template #default="{ row, $index }">
|
|
<template #default="{ row, $index }">
|
|
|
<slot :name="item.prop" :row="row" :value="row[item.prop]" :index="$index">
|
|
<slot :name="item.prop" :row="row" :value="row[item.prop]" :index="$index">
|
|
|
{{ handleNoneValue(row[item.prop]) }}
|
|
{{ handleNoneValue(row[item.prop]) }}
|
|
@@ -51,13 +56,14 @@ export default defineComponent({
|
|
|
components: {
|
|
components: {
|
|
|
AppTableSetting
|
|
AppTableSetting
|
|
|
},
|
|
},
|
|
|
- emits: ['refresh', 'update:columns'],
|
|
|
|
|
|
|
+ emits: ['refresh', 'update:columns', 'rowClick', 'select'],
|
|
|
props: {
|
|
props: {
|
|
|
columns: {
|
|
columns: {
|
|
|
type: Array as PropType<Model.TableColumn[]>,
|
|
type: Array as PropType<Model.TableColumn[]>,
|
|
|
default: () => ([])
|
|
default: () => ([])
|
|
|
},
|
|
},
|
|
|
- showHeader: {
|
|
|
|
|
|
|
+ // 是否显示头部工具栏
|
|
|
|
|
+ showToolbar: {
|
|
|
type: Boolean,
|
|
type: Boolean,
|
|
|
default: true
|
|
default: true
|
|
|
},
|
|
},
|
|
@@ -65,20 +71,59 @@ export default defineComponent({
|
|
|
type: Boolean,
|
|
type: Boolean,
|
|
|
default: false
|
|
default: false
|
|
|
},
|
|
},
|
|
|
|
|
+ // 选择列类型
|
|
|
|
|
+ selectionType: {
|
|
|
|
|
+ type: String as PropType<'single' | 'multiple'>,
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
setup(props, { emit, expose }) {
|
|
setup(props, { emit, expose }) {
|
|
|
const tableRef = shallowRef()
|
|
const tableRef = shallowRef()
|
|
|
|
|
+ const tableRadio = shallowRef()
|
|
|
const showTableSetting = shallowRef(false)
|
|
const showTableSetting = shallowRef(false)
|
|
|
const refresh = () => emit('refresh')
|
|
const refresh = () => emit('refresh')
|
|
|
const updateColumn = (value: Model.TableColumn[]) => emit('update:columns', value)
|
|
const updateColumn = (value: Model.TableColumn[]) => emit('update:columns', value)
|
|
|
|
|
|
|
|
|
|
+ // 当某一行被勾选时触发的事件
|
|
|
|
|
+ const onSelect = (selection: unknown[], currentRow: unknown) => {
|
|
|
|
|
+ const el = tableRef.value
|
|
|
|
|
+ const rows = selection.filter((e) => {
|
|
|
|
|
+ if (props.selectionType === 'single') {
|
|
|
|
|
+ if (e === currentRow) {
|
|
|
|
|
+ el.setCurrentRow(currentRow) // 高亮行
|
|
|
|
|
+ return true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ el.toggleRowSelection(e, false) // 单选取消其他选中的行
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true
|
|
|
|
|
+ })
|
|
|
|
|
+ emit('select', rows, currentRow)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 当某一行被点击时选中该行
|
|
|
|
|
+ const onRowClick = (row: unknown) => {
|
|
|
|
|
+ // if (props.selectionType) {
|
|
|
|
|
+ // const el = tableRef.value
|
|
|
|
|
+ // const selection = el.getSelectionRows()
|
|
|
|
|
+ // const selected = selection.find((e: unknown) => e === row)
|
|
|
|
|
+ // el.toggleRowSelection(row, selected ? false : true)
|
|
|
|
|
+ // onSelect(el.getSelectionRows(), row)
|
|
|
|
|
+ // }
|
|
|
|
|
+ emit('rowClick', row)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 暴露组件属性
|
|
|
expose({
|
|
expose({
|
|
|
elTable: tableRef
|
|
elTable: tableRef
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
tableRef,
|
|
tableRef,
|
|
|
|
|
+ tableRadio,
|
|
|
showTableSetting,
|
|
showTableSetting,
|
|
|
|
|
+ onSelect,
|
|
|
|
|
+ onRowClick,
|
|
|
handleNoneValue,
|
|
handleNoneValue,
|
|
|
refresh,
|
|
refresh,
|
|
|
updateColumn,
|
|
updateColumn,
|