List.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <script lang="ts" setup>
  2. import { h, reactive, ref } from 'vue';
  3. import { BasicTable, TableAction } from '@/components/Table';
  4. import { BasicForm, useForm } from '@/components/Form/index';
  5. import { del, page as getPage } from '@/api/aigc/message';
  6. import { columns, searchSchemas } from './columns';
  7. import { DeleteOutlined } from '@vicons/antd';
  8. import { useDialog, useMessage } from 'naive-ui';
  9. const message = useMessage();
  10. const dialog = useDialog();
  11. const actionRef = ref();
  12. const actionColumn = reactive({
  13. width: 100,
  14. title: '操作',
  15. key: 'action',
  16. fixed: 'right',
  17. align: 'center',
  18. render(record: any) {
  19. return h(TableAction as any, {
  20. style: 'text',
  21. actions: [
  22. {
  23. type: 'error',
  24. icon: DeleteOutlined,
  25. onClick: handleDelete.bind(null, record),
  26. },
  27. ],
  28. });
  29. },
  30. });
  31. const [register, { getFieldsValue }] = useForm({
  32. gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
  33. labelWidth: 80,
  34. schemas: searchSchemas,
  35. showAdvancedButton: false,
  36. });
  37. const loadDataTable = async (res: any) => {
  38. return await getPage({ ...getFieldsValue(), ...res });
  39. };
  40. function reloadTable() {
  41. actionRef.value.reload();
  42. }
  43. function handleDelete(record: Recordable) {
  44. dialog.info({
  45. title: '提示',
  46. content: `您想删除此条记录?`,
  47. positiveText: '确定',
  48. negativeText: '取消',
  49. onPositiveClick: async () => {
  50. await del(record.id);
  51. message.success('删除成功');
  52. reloadTable();
  53. },
  54. onNegativeClick: () => {},
  55. });
  56. }
  57. function handleReset(values: Recordable) {
  58. reloadTable();
  59. }
  60. </script>
  61. <template>
  62. <div class="h-full">
  63. <n-card :bordered="false">
  64. <BasicForm @register="register" @reset="handleReset" @submit="reloadTable" />
  65. <BasicTable
  66. ref="actionRef"
  67. :actionColumn="actionColumn"
  68. :columns="columns"
  69. :request="loadDataTable"
  70. :row-key="(row:any) => row.id"
  71. :single-line="false"
  72. :size="'small'"
  73. />
  74. </n-card>
  75. </div>
  76. </template>
  77. <style lang="less" scoped></style>