Blame view

src/views/project/account/index.vue 5.2 KB
1
<template>
2
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
sanmu authored
3
4
    <!-- <DeptTree class="w-1/4 xl:w-1/5" @select="handleSelect" /> -->
    <BasicTable @register="registerTable" :searchInfo="searchInfo">
5
      <template #toolbar>
6
        <a-button type="primary" @click="handleCreate">新增账号</a-button>
7
      </template>
8
9
10
11
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
sanmu authored
12
13
14
15
16
              // {
              //   icon: 'clarity:info-standard-line',
              //   tooltip: '查看用户详情',
              //   onClick: handleView.bind(null, record),
              // },
17
              {
18
19
                label: '编辑',
                // tooltip: '编辑用户资料',
20
21
                onClick: handleEdit.bind(null, record),
              },
sanmu authored
22
23
24
25
26
27
28
29
30
31
32
33
              {
                label: '重置密码',
                // tooltip: '编辑用户资料',
                popConfirm: {
                  title: '是否确认重置密码',
                  placement: 'left',
                  confirm: handleResetPassword.bind(null, record),
                },
              },
              {
                // icon: 'ant-design:delete-outlined',
                color: 'error',
34
                label: record.status === 10 ? '离职' : '启用',
sanmu authored
35
                popConfirm: {
36
37
38
39
                  title:
                    record.status === 10
                      ? '是否确认离职该用户,离职用户无法通过忘记密码进行手机验证码修改密码。请管理员重置其账号密码并修改。'
                      : '是否确认启用',
sanmu authored
40
41
42
43
44
45
46
47
48
49
50
51
52
53
                  placement: 'left',
                  confirm: handleForbid.bind(null, record),
                },
              },
              {
                // icon: 'ant-design:delete-outlined',
                color: 'error',
                label: '删除',
                popConfirm: {
                  title: '是否确认删除',
                  placement: 'left',
                  confirm: handleDelete.bind(null, record),
                },
              },
54
55
56
            ]"
          />
        </template>
57
58
      </template>
    </BasicTable>
59
    <AccountModal @register="registerModal" @success="handleSuccess" />
60
  </PageWrapper>
61
62
</template>
<script lang="ts">
63
  import { defineComponent, reactive } from 'vue';
64
65

  import { BasicTable, useTable, TableAction } from '/@/components/Table';
sanmu authored
66
67
68
69
70
71
72
  import {
    getUserList,
    userAdd,
    userEdit,
    userOpt,
    userResetPassword,
  } from '/@/api/project/account';
73
74
  import { PageWrapper } from '/@/components/Page';
  import DeptTree from './DeptTree.vue';
75
76
77
78
79

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

  import { columns, searchFormSchema } from './account.data';
80
  import { useGo } from '/@/hooks/web/usePage';
81
82
83

  export default defineComponent({
    name: 'AccountManagement',
84
    components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction },
85
    setup() {
86
      const go = useGo();
87
      const [registerModal, { openModal }] = useModal();
sanmu authored
88
      const searchInfo = reactive({});
sanmu authored
89
      const [registerTable, { reload }] = useTable({
90
        title: '账号列表',
sanmu authored
91
        api: getUserList,
92
        rowKey: 'id',
93
94
95
96
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
97
          autoSubmitOnEnter: true,
98
99
100
        },
        useSearchForm: true,
        showTableSetting: true,
sanmu authored
101
102
103
        tableSetting: {
          setting: false,
        },
Vben authored
104
        bordered: true,
105
106
107
108
        handleSearchInfoFn(info) {
          console.log('handleSearchInfoFn', info);
          return info;
        },
109
        actionColumn: {
sanmu authored
110
          width: 280,
111
112
          title: '操作',
          dataIndex: 'action',
113
          // slots: { customRender: 'action' },
114
115
116
        },
      });
117
      function handleCreate() {
118
119
120
121
122
        openModal(true, {
          isUpdate: false,
        });
      }
sanmu authored
123
      function handleEdit(record) {
Vben authored
124
        console.log(record);
125
126
127
128
129
130
        openModal(true, {
          record,
          isUpdate: true,
        });
      }
sanmu authored
131
132
133
      async function handleDelete(record) {
        await userOpt({ ids: [record.id], optType: 20 });
        reload();
134
135
      }
sanmu authored
136
      async function handleSuccess({ isUpdate, values }) {
137
        if (isUpdate) {
sanmu authored
138
          await userEdit({ ...values });
139
        } else {
sanmu authored
140
          await userAdd({ ...values });
141
        }
sanmu authored
142
        reload();
143
144
      }
sanmu authored
145
146
147
148
149
150
151
152
153
154
      async function handleForbid(record) {
        await userOpt({ ids: [record.id], optType: record.status === 10 ? 30 : 10 });
        reload();
      }

      async function handleResetPassword(record) {
        await userResetPassword({ userId: record.id });
        // reload();
      }
155
      function handleSelect(deptId = '') {
156
157
        searchInfo.deptId = deptId;
        reload();
158
159
      }
sanmu authored
160
      function handleView(record) {
161
162
163
        go('/system/account_detail/' + record.id);
      }
164
165
166
      return {
        registerTable,
        registerModal,
167
        handleCreate,
168
169
        handleEdit,
        handleDelete,
170
        handleSuccess,
171
        handleSelect,
172
        handleView,
sanmu authored
173
174
        handleForbid,
        handleResetPassword,
175
        searchInfo,
176
177
178
179
      };
    },
  });
</script>