wupengfei
8 天以前 f8cd1dd96477b4c7ba8b80cbd35095fb0d036cdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
  <LoadingLayout :loading="state.loading">
    <AppContainer>
      <ProTableQueryFilterBar @on-reset="reset">
        <template #query>
          <QueryFilterItem>
            <SearchInput
              v-model="extraParamState.keywords"
              style="width: 250px"
              placeholder="姓名/账号/手机号"
              @on-click-search="getList"
              @keyup.enter="getList()"
            >
            </SearchInput>
          </QueryFilterItem>
        </template>
      </ProTableQueryFilterBar>
      <ProTableV2 v-bind="proTableProps" :columns="column" :operationBtns="operationBtns">
        <template #roles="{ row }">
          {{ row.roles?.map((x) => formatRoleName(x.name)).join() }}
        </template>
        <template #status="{ row }">
          <FieldSwitch
            v-model="row.status"
            active-text="启用"
            inactive-text="禁用"
            :active-value="EnumUserInfoStatus.Normal"
            :inactive-value="EnumUserInfoStatus.Disabled"
            :before-change="() => setStatus(row)"
          />
        </template>
      </ProTableV2>
    </AppContainer>
    <SetOperationUserRoleDialog v-bind="dialogProps" />
  </LoadingLayout>
</template>
 
<script setup lang="ts">
import {
  ProTableQueryFilterBar,
  OperationBtnType,
  ProTableV2,
  SearchInput,
  LoadingLayout,
  AppContainer,
  QueryFilterItem,
  useTable,
  FieldSwitch,
  useFormDialog,
} from '@bole-core/components';
import { useAccess } from '@/hooks';
import { formatRoleName } from '@/utils';
import * as userInfoServices from '@/services/api/userInfo';
import { Message } from '@bole-core/core';
import { EnumUserInfoStatus } from '@/constants';
import SetOperationUserRoleDialog from './components/SetOperationUserRoleDialog.vue';
 
defineOptions({
  name: 'OperationUserManage',
});
 
const operationBtnMap: Record<string, OperationBtnType> = {
  setRoleBtn: { emits: { onClick: (role) => openDialog(role) } },
};
 
const { checkSubModuleItemShow, column, operationBtns } = useAccess({
  operationBtnMap,
});
 
const BaseState = {
  loading: true,
};
 
const state = reactive({ ...BaseState });
 
onMounted(async () => {
  await getList();
  state.loading = false;
});
 
const {
  getDataSource: getList,
  proTableProps,
  paginationState,
  extraParamState,
  reset,
} = useTable(
  async ({ pageIndex, pageSize }, extraParamState) => {
    try {
      let params: API.GetOperationUserInfosQuery = {
        pageModel: {
          rows: pageSize,
          page: pageIndex,
          orderInput: extraParamState.orderInput,
        },
        keywords: extraParamState.keywords,
      };
      let res = await userInfoServices.getOperationUserInfos(params, {
        showLoading: !state.loading,
      });
      return res;
    } catch (error) {}
  },
  {
    defaultExtraParams: {
      keywords: '',
      orderInput: [{ property: 'id', order: EnumPagedListOrder.Desc }],
    },
    queryKey: ['userInfoServices/getOperationUserInfos'],
    columnsRenderProps: {},
  }
);
 
async function setStatus(row: API.GetOperationUserInfosQueryResultItem) {
  try {
    await Message.tipMessage(
      `确认要${row.status === EnumUserInfoStatus.Normal ? '禁用' : '启用'}该账号吗?`
    );
    let params: API.SetUserInfoStatusCommand = {
      ids: [row.id],
      status:
        row.status === EnumUserInfoStatus.Normal
          ? EnumUserInfoStatus.Disabled
          : EnumUserInfoStatus.Normal,
    };
    let res = await userInfoServices.setUserInfoStatus(params);
    return !!res;
  } catch (error) {}
}
 
const { dialogProps, handleEdit, editForm } = useFormDialog({
  onConfirm: setUserInfoRoles,
  defaultFormParams: {
    roleIds: [] as string[],
    userInfoId: '',
    roles: [] as API.GetOperationUserInfosQueryResultItem[],
  },
});
 
async function openDialog(row?: API.GetOperationUserInfosQueryResultItem) {
  if (row) {
    const roles = await getUserInfoRoles(row);
    handleEdit({
      userInfoId: row.id,
      roleIds: row.roles?.map((x) => x.id),
      roles: roles,
    });
  }
}
 
async function setUserInfoRoles() {
  try {
    let params: API.SetUserInfoRolesCommand = {
      userInfoId: editForm.userInfoId,
      roleIds: editForm.roleIds,
    };
    let res = await userInfoServices.setUserInfoRoles(params);
    if (res) {
      Message.successMessage('操作成功');
      getList(paginationState.pageIndex);
    }
  } catch (error) {}
}
 
async function getUserInfoRoles(row: API.GetOperationUserInfosQueryResultItem) {
  try {
    let params: API.APIgetUserInfoRolesParams = {
      userInfoId: row.id,
      // clientType: row.clientType,
    };
    let res = await userInfoServices.getUserInfoRoles(params);
    return res;
  } catch (error) {}
}
</script>