index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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:info-standard-line',
  13. tooltip: '查看用户详情',
  14. onClick: handleView.bind(null, record),
  15. },
  16. {
  17. icon: 'clarity:note-edit-line',
  18. tooltip: '编辑用户资料',
  19. onClick: handleEdit.bind(null, record),
  20. },
  21. {
  22. icon: 'ant-design:delete-outlined',
  23. color: 'error',
  24. tooltip: '删除此账号',
  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. autoSubmitOnEnter: true,
  63. },
  64. useSearchForm: true,
  65. showTableSetting: true,
  66. bordered: true,
  67. handleSearchInfoFn(info) {
  68. console.log('handleSearchInfoFn', info);
  69. return info;
  70. },
  71. actionColumn: {
  72. width: 120,
  73. title: '操作',
  74. dataIndex: 'action',
  75. slots: { customRender: 'action' },
  76. },
  77. });
  78. function handleCreate() {
  79. openModal(true, {
  80. isUpdate: false,
  81. });
  82. }
  83. function handleEdit(record: Recordable) {
  84. console.log(record);
  85. openModal(true, {
  86. record,
  87. isUpdate: true,
  88. });
  89. }
  90. function handleDelete(record: Recordable) {
  91. console.log(record);
  92. }
  93. function handleSuccess({ isUpdate, values }) {
  94. if (isUpdate) {
  95. // 演示不刷新表格直接更新内部数据。
  96. // 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
  97. const result = updateTableDataRecord(values.id, values);
  98. console.log(result);
  99. } else {
  100. reload();
  101. }
  102. }
  103. function handleSelect(deptId = '') {
  104. searchInfo.deptId = deptId;
  105. reload();
  106. }
  107. function handleView(record: Recordable) {
  108. go('/system/account_detail/' + record.id);
  109. }
  110. return {
  111. registerTable,
  112. registerModal,
  113. handleCreate,
  114. handleEdit,
  115. handleDelete,
  116. handleSuccess,
  117. handleSelect,
  118. handleView,
  119. searchInfo,
  120. };
  121. },
  122. });
  123. </script>