index.vue 4.0 KB

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