表格修改

This commit is contained in:
fangyunong 2025-07-10 22:27:33 +08:00
parent 4837af2094
commit 77a6853df0

View File

@ -27,7 +27,9 @@
<script setup lang='ts'> <script setup lang='ts'>
import { SearchOutline } from '@vicons/ionicons5'; import { SearchOutline } from '@vicons/ionicons5';
import { getUserList } from '@/api/roleApi'; import { getUserList } from '@/api/roleApi';
import { DataTableColumns, NButton, useMessage } from 'naive-ui';
const message = useMessage();
const tableMainRef = ref<HTMLElement | null>(null); const tableMainRef = ref<HTMLElement | null>(null);
const roleName = ref(''); const roleName = ref('');
const pagination = reactive<PageController>({ const pagination = reactive<PageController>({
@ -35,31 +37,64 @@ const pagination = reactive<PageController>({
page: 1, 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' key: 'name'
}, },
{ {
title: 'Age', title: '性别',
key: 'age' key: 'sex'
}, },
{ {
title: 'Address', title: 'Address',
key: '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 height = ref(null);
const data = Array.from({ length: 46 }).map((_, index) => ({ const data = Array.from({ length: 10 }).map((_, index) => ({
key: index, key: index,
name: `Edward King ${index}`, name: `Edward King ${index}`,
age: 32, sex: 'female',
address: `London, Park Lane no. ${index}` address: `London, Park Lane no. ${index}`
})); }));
const init = async () => { const init = async () => {
try { try {
const result = await getUserList(pagination); const result = await getUserList(pagination);
console.log(result,'result'); console.log(result, 'result');
} catch (error) { } catch (error) {
} }