|
|
@@ -1,31 +1,88 @@
|
|
|
<template>
|
|
|
- <a-table
|
|
|
- style="width: 100%;"
|
|
|
- v-bind="{...props}"
|
|
|
- :data-source="state.data"
|
|
|
- :loading="state.loading"
|
|
|
- :pagination="state.pagination.total <= 10 ? false : state.pagination"
|
|
|
- @change="handleTableChange"
|
|
|
- >
|
|
|
- <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-row>
|
|
|
+ <a-col span="24" >
|
|
|
+ <a-row justify="end">
|
|
|
+ <a-col>
|
|
|
+ <a-space>
|
|
|
+ <a-button type="primary" >
|
|
|
+ 新增
|
|
|
+ <template #icon>
|
|
|
+ <plus-outlined />
|
|
|
+ </template>
|
|
|
+ </a-button>
|
|
|
+ <a-button type="primary" >
|
|
|
+ 导出
|
|
|
+ <template #icon>
|
|
|
+ <download-outlined />
|
|
|
+ </template>
|
|
|
+ </a-button>
|
|
|
+ <!-- 小组件 -->
|
|
|
+
|
|
|
+ <a-tooltip>
|
|
|
+ <template #title>刷新</template>
|
|
|
+ <reload-outlined />
|
|
|
+ </a-tooltip>
|
|
|
+ <!-- -->
|
|
|
+ </a-space>
|
|
|
</a-col>
|
|
|
- </a-row>
|
|
|
- </a-space>
|
|
|
- </template>
|
|
|
- </template>
|
|
|
- </a-table>
|
|
|
+ </a-row>
|
|
|
+ </a-col>
|
|
|
+ <a-col span="24">
|
|
|
+ <a-table
|
|
|
+ style="width: 100%;margin-top: 10px;"
|
|
|
+ v-bind="{...props}"
|
|
|
+ :data-source="state.data"
|
|
|
+ :loading="state.loading"
|
|
|
+ :pagination="state.pagination.total <= 10 ? false : state.pagination"
|
|
|
+ @change="handleTableChange"
|
|
|
+ >
|
|
|
+ <template #bodyCell="{ column, record }">
|
|
|
+ <template v-if="column.key === 'action'">
|
|
|
+ <a-space>
|
|
|
+ <span v-for="item in column.list" :key="item.name" >
|
|
|
+ <a-popconfirm
|
|
|
+ title="确实要删除吗?"
|
|
|
+ ok-text="确定"
|
|
|
+ cancel-text="取消"
|
|
|
+ @confirm="confirmDel(item, record)"
|
|
|
+ v-if="item.use == 'del'"
|
|
|
+ >
|
|
|
+ <a href="#">删除</a>
|
|
|
+ </a-popconfirm>
|
|
|
+ <a v-else @click="handleAction(item, record)" >{{item.name}}</a>
|
|
|
+ </span>
|
|
|
+ </a-space>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </a-table>
|
|
|
+ </a-col>
|
|
|
+ </a-row>
|
|
|
+
|
|
|
+ <!-- 弹窗 -->
|
|
|
+ <model-pro
|
|
|
+ :visible="state.modelVisible"
|
|
|
+ >
|
|
|
+
|
|
|
+ </model-pro>
|
|
|
</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'
|
|
|
+import { reactive, watch } from 'vue'
|
|
|
+import { PlusOutlined, DownloadOutlined, ReloadOutlined } from '@ant-design/icons-vue'
|
|
|
+/**
|
|
|
+ * formItemProps
|
|
|
+ * rules 校验
|
|
|
+ * request 需要请求的表单项 分别创建id key value name
|
|
|
+ * type: input select radio check datepick
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * pro-able
|
|
|
+ * 'export' | 'add' | search
|
|
|
+*/
|
|
|
|
|
|
export interface ColumnsChildren {
|
|
|
name: '',
|
|
|
@@ -36,14 +93,13 @@ export interface ColumnsChildren {
|
|
|
|
|
|
export interface TablePropPorps extends TableProps {
|
|
|
request: (params: any) => any
|
|
|
+ del: (id: string) => void
|
|
|
params: any,
|
|
|
columns: ColumnsType & {children: ColumnsChildren}
|
|
|
}
|
|
|
|
|
|
const props = defineProps<TablePropPorps>()
|
|
|
|
|
|
-console.log('table pro props:', props.columns[2])
|
|
|
-
|
|
|
const state = reactive({
|
|
|
loading: false,
|
|
|
data: [],
|
|
|
@@ -52,7 +108,7 @@ const state = reactive({
|
|
|
total: 0,
|
|
|
pageSize: 10
|
|
|
},
|
|
|
- actionColumn: []
|
|
|
+ modelVisible: false
|
|
|
})
|
|
|
|
|
|
const handleTableChange = (pag: { pageSize: number; current: number }) => {
|
|
|
@@ -62,7 +118,7 @@ const handleTableChange = (pag: { pageSize: number; current: number }) => {
|
|
|
current: pag.current
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+// 请求table 的data
|
|
|
const request = async () => {
|
|
|
state.loading = true
|
|
|
const data = await props.request(props.params)
|
|
|
@@ -70,6 +126,20 @@ const request = async () => {
|
|
|
console.log('table pro data:', data)
|
|
|
state.data = data
|
|
|
}
|
|
|
+
|
|
|
+// 删除对应的table选项
|
|
|
+const confirmDel = async (item: ColumnsChildren, record: any) => {
|
|
|
+ await props.del(record[item.bindKey])
|
|
|
+ request()
|
|
|
+}
|
|
|
+
|
|
|
+const handleAction = (column: ColumnsChildren, record: any) => {
|
|
|
+ switch (column.use) {
|
|
|
+ case 'copy':
|
|
|
+ useCopy(record[column.bindKey])
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
watch(
|
|
|
() => props.request,
|
|
|
() => request(),
|
|
|
@@ -79,13 +149,6 @@ watch(
|
|
|
}
|
|
|
)
|
|
|
|
|
|
-const handleAction = (column: ColumnsChildren, record: any) => {
|
|
|
- switch (column.use) {
|
|
|
- case 'copy':
|
|
|
- useCopy(record[column.bindKey])
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
</script>
|
|
|
|
|
|
<style>
|