Blame view

src/views/demo/system/account/index.vue 3.88 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
27
28
29
30
31
32
33
              popConfirm: {
                title: '是否确认删除',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
34
    <AccountModal @register="registerModal" @success="handleSuccess" />
35
  </PageWrapper>
36
37
</template>
<script lang="ts">
38
  import { defineComponent, reactive } from 'vue';
39
40
41

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

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

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

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

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

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