表格修改
This commit is contained in:
parent
4837af2094
commit
77a6853df0
@ -27,7 +27,9 @@
|
||||
<script setup lang='ts'>
|
||||
import { SearchOutline } from '@vicons/ionicons5';
|
||||
import { getUserList } from '@/api/roleApi';
|
||||
import { DataTableColumns, NButton, useMessage } from 'naive-ui';
|
||||
|
||||
const message = useMessage();
|
||||
const tableMainRef = ref<HTMLElement | null>(null);
|
||||
const roleName = ref('');
|
||||
const pagination = reactive<PageController>({
|
||||
@ -35,31 +37,64 @@ const pagination = reactive<PageController>({
|
||||
page: 1,
|
||||
});
|
||||
|
||||
const columns = [
|
||||
// 列接口数据
|
||||
interface RowData{
|
||||
name:string
|
||||
sex:'female' | 'male' | 'unknown',
|
||||
address:string
|
||||
}
|
||||
// 类似render - 函数式组件渲染
|
||||
function createColumns({
|
||||
sendMail
|
||||
}: {
|
||||
sendMail: (rowData: RowData) => void
|
||||
}): DataTableColumns<RowData> {
|
||||
return [
|
||||
{
|
||||
title: 'Name',
|
||||
title: '用户名',
|
||||
key: 'name'
|
||||
},
|
||||
{
|
||||
title: 'Age',
|
||||
key: 'age'
|
||||
title: '性别',
|
||||
key: 'sex'
|
||||
},
|
||||
{
|
||||
title: 'Address',
|
||||
key: 'address'
|
||||
},
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'actions',
|
||||
render(row) {
|
||||
return h(
|
||||
NButton,
|
||||
{
|
||||
size: 'small',
|
||||
onClick: () => sendMail(row)
|
||||
},
|
||||
{ default: () => 'Send Email' }
|
||||
)
|
||||
}
|
||||
];
|
||||
}
|
||||
]
|
||||
}
|
||||
// 生成表格列
|
||||
const columns = createColumns({
|
||||
sendMail(rowData) {
|
||||
message.error(`我点击了${rowData.name}`);
|
||||
}
|
||||
})
|
||||
const height = ref(null);
|
||||
const data = Array.from({ length: 46 }).map((_, index) => ({
|
||||
const data = Array.from({ length: 10 }).map((_, index) => ({
|
||||
key: index,
|
||||
name: `Edward King ${index}`,
|
||||
age: 32,
|
||||
sex: 'female',
|
||||
address: `London, Park Lane no. ${index}`
|
||||
}));
|
||||
const init = async () => {
|
||||
try {
|
||||
const result = await getUserList(pagination);
|
||||
console.log(result,'result');
|
||||
console.log(result, 'result');
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user