index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div :class="[prefixCls]">
  3. <BasicTable @register="registerTable">
  4. <template #toolbar>
  5. <a-button type="primary" @click="handleCreateAccount"> 新增账号 </a-button>
  6. </template>
  7. <template #action="{ record }">
  8. <TableAction
  9. :actions="[
  10. {
  11. label: '编辑',
  12. onClick: handleEdit.bind(null, record),
  13. },
  14. {
  15. label: '删除',
  16. color: 'error',
  17. popConfirm: {
  18. title: '是否确认删除',
  19. confirm: handleDelete.bind(null, record),
  20. },
  21. },
  22. ]"
  23. />
  24. </template>
  25. </BasicTable>
  26. <AccountModal @register="registerModal" />
  27. </div>
  28. </template>
  29. <script lang="ts">
  30. import { defineComponent } from 'vue';
  31. import { useDesign } from '/@/hooks/web/useDesign';
  32. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  33. import { getAccountList } from '/@/api/demo/system';
  34. import { useModal } from '/@/components/Modal';
  35. import AccountModal from './AccountModal.vue';
  36. import { columns, searchFormSchema } from './account.data';
  37. export default defineComponent({
  38. name: 'AccountManagement',
  39. components: { BasicTable, AccountModal, TableAction },
  40. setup() {
  41. const { prefixCls } = useDesign('account-management');
  42. const [registerModal, { openModal }] = useModal();
  43. const [registerTable] = useTable({
  44. title: '账号列表',
  45. api: getAccountList,
  46. columns,
  47. formConfig: {
  48. labelWidth: 120,
  49. schemas: searchFormSchema,
  50. },
  51. useSearchForm: true,
  52. showTableSetting: true,
  53. actionColumn: {
  54. width: 160,
  55. title: '操作',
  56. dataIndex: 'action',
  57. slots: { customRender: 'action' },
  58. },
  59. });
  60. function handleCreateAccount() {
  61. openModal(true, {
  62. isUpdate: false,
  63. });
  64. }
  65. function handleEdit(record: Recordable) {
  66. openModal(true, {
  67. record,
  68. isUpdate: true,
  69. });
  70. }
  71. function handleDelete(record: Recordable) {
  72. console.log(record);
  73. }
  74. return {
  75. prefixCls,
  76. registerTable,
  77. registerModal,
  78. handleCreateAccount,
  79. handleEdit,
  80. handleDelete,
  81. };
  82. },
  83. });
  84. </script>
  85. <style lang="less" scoped>
  86. @prefix-cls: ~'@{namespace}-account-management';
  87. .@{prefix-cls} {
  88. display: flex;
  89. }
  90. </style>