Blame view

src/views/demo/system/account/index.vue 3.91 KB
1
<template>
2
3
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <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
8
9
10
11
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
12
              icon: 'clarity:info-standard-line',
13
              tooltip: '查看用户详情',
14
15
16
              onClick: handleView.bind(null, record),
            },
            {
Vben authored
17
              icon: 'clarity:note-edit-line',
18
              tooltip: '编辑用户资料',
19
20
21
              onClick: handleEdit.bind(null, record),
            },
            {
Vben authored
22
              icon: 'ant-design:delete-outlined',
23
              color: 'error',
24
              tooltip: '删除此账号',
25
26
              popConfirm: {
                title: '是否确认删除',
27
                placement: 'left',
28
29
30
31
32
33
34
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
35
    <AccountModal @register="registerModal" @success="handleSuccess" />
36
  </PageWrapper>
37
38
</template>
<script lang="ts">
39
  import { defineComponent, reactive } from 'vue';
40
41
42

  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getAccountList } from '/@/api/demo/system';
43
44
  import { PageWrapper } from '/@/components/Page';
  import DeptTree from './DeptTree.vue';
45
46
47
48
49

  import { useModal } from '/@/components/Modal';
  import AccountModal from './AccountModal.vue';

  import { columns, searchFormSchema } from './account.data';
50
  import { useGo } from '/@/hooks/web/usePage';
51
52
53

  export default defineComponent({
    name: 'AccountManagement',
54
    components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction },
55
    setup() {
56
      const go = useGo();
57
      const [registerModal, { openModal }] = useModal();
58
      const searchInfo = reactive<Recordable>({});
59
      const [registerTable, { reload, updateTableDataRecord }] = useTable({
60
61
        title: '账号列表',
        api: getAccountList,
62
        rowKey: 'id',
63
64
65
66
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
67
          autoSubmitOnEnter: true,
68
69
70
        },
        useSearchForm: true,
        showTableSetting: true,
Vben authored
71
        bordered: true,
72
73
74
75
        handleSearchInfoFn(info) {
          console.log('handleSearchInfoFn', info);
          return info;
        },
76
        actionColumn: {
77
          width: 120,
78
79
80
81
82
83
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });
84
      function handleCreate() {
85
86
87
88
89
90
        openModal(true, {
          isUpdate: false,
        });
      }

      function handleEdit(record: Recordable) {
Vben authored
91
        console.log(record);
92
93
94
95
96
97
98
99
100
101
        openModal(true, {
          record,
          isUpdate: true,
        });
      }

      function handleDelete(record: Recordable) {
        console.log(record);
      }
102
103
104
105
106
107
108
109
110
      function handleSuccess({ isUpdate, values }) {
        if (isUpdate) {
          // 演示不刷新表格直接更新内部数据。
          // 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
          const result = updateTableDataRecord(values.id, values);
          console.log(result);
        } else {
          reload();
        }
111
112
      }
113
      function handleSelect(deptId = '') {
114
115
        searchInfo.deptId = deptId;
        reload();
116
117
      }
118
119
120
121
      function handleView(record: Recordable) {
        go('/system/account_detail/' + record.id);
      }
122
123
124
      return {
        registerTable,
        registerModal,
125
        handleCreate,
126
127
        handleEdit,
        handleDelete,
128
        handleSuccess,
129
        handleSelect,
130
        handleView,
131
        searchInfo,
132
133
134
135
      };
    },
  });
</script>