index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
  3. <DeptTree class="w-1/4 xl:w-1/5" @select="handleSelect" />
  4. <BasicTable @register="registerTable" class="w-3/4 xl:w-4/5" :searchInfo="searchInfo">
  5. <template #toolbar>
  6. <a-button type="primary" @click="handleCreate">新增账号</a-button>
  7. </template>
  8. <template #action="{ record }">
  9. <TableAction
  10. :actions="[
  11. {
  12. icon: 'clarity:eye-show-solid',
  13. title: '查看用户详情',
  14. onClick: handleView.bind(null, record),
  15. },
  16. {
  17. icon: 'clarity:note-edit-line',
  18. title: '编辑用户资料',
  19. onClick: handleEdit.bind(null, record),
  20. },
  21. {
  22. icon: 'ant-design:delete-outlined',
  23. color: 'error',
  24. title: '删除此账号',
  25. popConfirm: {
  26. title: '是否确认删除',
  27. confirm: handleDelete.bind(null, record),
  28. },
  29. },
  30. ]"
  31. />
  32. </template>
  33. </BasicTable>
  34. <AccountModal @register="registerModal" @success="handleSuccess" />
  35. </PageWrapper>
  36. </template>
  37. <script lang="ts">
  38. import { defineComponent, reactive } from 'vue';
  39. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  40. import { getAccountList } from '/@/api/demo/system';
  41. import { PageWrapper } from '/@/components/Page';
  42. import DeptTree from './DeptTree.vue';
  43. import { useModal } from '/@/components/Modal';
  44. import AccountModal from './AccountModal.vue';
  45. import { columns, searchFormSchema } from './account.data';
  46. import { useGo } from '/@/hooks/web/usePage';
  47. export default defineComponent({
  48. name: 'AccountManagement',
  49. components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction },
  50. setup() {
  51. const go = useGo();
  52. const [registerModal, { openModal }] = useModal();
  53. const searchInfo = reactive<Recordable>({});
  54. const [registerTable, { reload, updateTableDataRecord }] = useTable({
  55. title: '账号列表',
  56. api: getAccountList,
  57. rowKey: 'id',
  58. columns,
  59. formConfig: {
  60. labelWidth: 120,
  61. schemas: searchFormSchema,
  62. },
  63. useSearchForm: true,
  64. showTableSetting: true,
  65. bordered: true,
  66. actionColumn: {
  67. width: 120,
  68. title: '操作',
  69. dataIndex: 'action',
  70. slots: { customRender: 'action' },
  71. },
  72. });
  73. function handleCreate() {
  74. openModal(true, {
  75. isUpdate: false,
  76. });
  77. }
  78. function handleEdit(record: Recordable) {
  79. console.log(record);
  80. openModal(true, {
  81. record,
  82. isUpdate: true,
  83. });
  84. }
  85. function handleDelete(record: Recordable) {
  86. console.log(record);
  87. }
  88. function handleSuccess({ isUpdate, values }) {
  89. if (isUpdate) {
  90. // 演示不刷新表格直接更新内部数据。
  91. // 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
  92. const result = updateTableDataRecord(values.id, values);
  93. console.log(result);
  94. } else {
  95. reload();
  96. }
  97. }
  98. function handleSelect(deptId = '') {
  99. searchInfo.deptId = deptId;
  100. reload();
  101. }
  102. function handleView(record: Recordable) {
  103. go('/system/account_detail/' + record.id);
  104. }
  105. return {
  106. registerTable,
  107. registerModal,
  108. handleCreate,
  109. handleEdit,
  110. handleDelete,
  111. handleSuccess,
  112. handleSelect,
  113. handleView,
  114. searchInfo,
  115. };
  116. },
  117. });
  118. </script>