index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. placement: 'left',
  28. confirm: handleDelete.bind(null, record),
  29. },
  30. },
  31. ]"
  32. />
  33. </template>
  34. </BasicTable>
  35. <AccountModal @register="registerModal" @success="handleSuccess" />
  36. </PageWrapper>
  37. </template>
  38. <script lang="ts">
  39. import { defineComponent, reactive } from 'vue';
  40. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  41. import { getAccountList } from '/@/api/demo/system';
  42. import { PageWrapper } from '/@/components/Page';
  43. import DeptTree from './DeptTree.vue';
  44. import { useModal } from '/@/components/Modal';
  45. import AccountModal from './AccountModal.vue';
  46. import { columns, searchFormSchema } from './account.data';
  47. import { useGo } from '/@/hooks/web/usePage';
  48. export default defineComponent({
  49. name: 'AccountManagement',
  50. components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction },
  51. setup() {
  52. const go = useGo();
  53. const [registerModal, { openModal }] = useModal();
  54. const searchInfo = reactive<Recordable>({});
  55. const [registerTable, { reload, updateTableDataRecord }] = useTable({
  56. title: '账号列表',
  57. api: getAccountList,
  58. rowKey: 'id',
  59. columns,
  60. formConfig: {
  61. labelWidth: 120,
  62. schemas: searchFormSchema,
  63. autoSubmitOnEnter: true,
  64. },
  65. useSearchForm: true,
  66. showTableSetting: true,
  67. bordered: true,
  68. handleSearchInfoFn(info) {
  69. console.log('handleSearchInfoFn', info);
  70. return info;
  71. },
  72. actionColumn: {
  73. width: 120,
  74. title: '操作',
  75. dataIndex: 'action',
  76. slots: { customRender: 'action' },
  77. },
  78. });
  79. function handleCreate() {
  80. openModal(true, {
  81. isUpdate: false,
  82. });
  83. }
  84. function handleEdit(record: Recordable) {
  85. console.log(record);
  86. openModal(true, {
  87. record,
  88. isUpdate: true,
  89. });
  90. }
  91. function handleDelete(record: Recordable) {
  92. console.log(record);
  93. }
  94. function handleSuccess({ isUpdate, values }) {
  95. if (isUpdate) {
  96. // 演示不刷新表格直接更新内部数据。
  97. // 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
  98. const result = updateTableDataRecord(values.id, values);
  99. console.log(result);
  100. } else {
  101. reload();
  102. }
  103. }
  104. function handleSelect(deptId = '') {
  105. searchInfo.deptId = deptId;
  106. reload();
  107. }
  108. function handleView(record: Recordable) {
  109. go('/system/account_detail/' + record.id);
  110. }
  111. return {
  112. registerTable,
  113. registerModal,
  114. handleCreate,
  115. handleEdit,
  116. handleDelete,
  117. handleSuccess,
  118. handleSelect,
  119. handleView,
  120. searchInfo,
  121. };
  122. },
  123. });
  124. </script>