|
|
@@ -1,27 +1,49 @@
|
|
|
<template>
|
|
|
- <a-row>
|
|
|
<a-table
|
|
|
style="width: 100%;"
|
|
|
v-bind="{...props}"
|
|
|
- :dataSource="state.data"
|
|
|
+ :data-source="state.data"
|
|
|
:loading="state.loading"
|
|
|
- :pagination="state.pagination"
|
|
|
+ :pagination="state.pagination.total <= 10 ? false : state.pagination"
|
|
|
@change="handleTableChange"
|
|
|
- />
|
|
|
- </a-row>
|
|
|
+ >
|
|
|
+ <template #bodyCell="{ column, record }">
|
|
|
+ <template v-if="column.key === 'action'">
|
|
|
+ <a-space>
|
|
|
+ <a-row>
|
|
|
+ <a-col v-for="item in column.list" :key="item.name" >
|
|
|
+ <a @click="handleAction(item, record)" >{{item.name}}</a>
|
|
|
+ </a-col>
|
|
|
+ </a-row>
|
|
|
+ </a-space>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </a-table>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup >
|
|
|
+import { useCopy } from '@/hooks/dom'
|
|
|
+import { ColumnsType } from 'ant-design-vue/lib/vc-table/interface'
|
|
|
import { TableProps } from 'ant-design-vue/lib/vc-table/Table'
|
|
|
import { onMounted, reactive, watch } from 'vue'
|
|
|
|
|
|
+export interface ColumnsChildren {
|
|
|
+ name: '',
|
|
|
+ use: string,
|
|
|
+ icon: '',
|
|
|
+ bindKey: string
|
|
|
+}
|
|
|
+
|
|
|
export interface TablePropPorps extends TableProps {
|
|
|
request: (params: any) => any
|
|
|
- params: any
|
|
|
+ params: any,
|
|
|
+ columns: ColumnsType & {children: ColumnsChildren}
|
|
|
}
|
|
|
|
|
|
const props = defineProps<TablePropPorps>()
|
|
|
|
|
|
+console.log('table pro props:', props.columns[2])
|
|
|
+
|
|
|
const state = reactive({
|
|
|
loading: false,
|
|
|
data: [],
|
|
|
@@ -29,7 +51,8 @@ const state = reactive({
|
|
|
current: 1,
|
|
|
total: 0,
|
|
|
pageSize: 10
|
|
|
- }
|
|
|
+ },
|
|
|
+ actionColumn: []
|
|
|
})
|
|
|
|
|
|
const handleTableChange = (pag: { pageSize: number; current: number }) => {
|
|
|
@@ -44,10 +67,9 @@ const request = async () => {
|
|
|
state.loading = true
|
|
|
const data = await props.request(props.params)
|
|
|
state.loading = false
|
|
|
- console.log(data)
|
|
|
+ console.log('table pro data:', data)
|
|
|
state.data = data
|
|
|
}
|
|
|
-
|
|
|
watch(
|
|
|
() => props.request,
|
|
|
() => request(),
|
|
|
@@ -57,6 +79,13 @@ watch(
|
|
|
}
|
|
|
)
|
|
|
|
|
|
+const handleAction = (column: ColumnsChildren, record: any) => {
|
|
|
+ switch (column.use) {
|
|
|
+ case 'copy':
|
|
|
+ useCopy(record[column.bindKey])
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<style>
|