You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.7 KiB
106 lines
2.7 KiB
import { computed, ref } from 'vue' |
|
import { deleteUser, exportUsers, resetPasswordByIds, unlockUserByIds } from '@/api/system/user' |
|
import type { TableActionType } from '@/components/Table' |
|
import { useMessage } from '@/hooks/web/useMessage' |
|
import { downloadByData } from '@/utils/file/download' |
|
import { useModal } from '@/components/Modal' |
|
import { noop } from '@/utils' |
|
|
|
export function useUserActions(tableMethods: TableActionType) { |
|
const { createMessage, createConfirm } = useMessage() |
|
|
|
function handleDelete(id?: string) { |
|
const { getSelectRowKeys, clearSelectedRowKeys, reload } = tableMethods |
|
const ids = id ? [id] : (getSelectRowKeys() as string[]) |
|
|
|
if (!ids.length) |
|
return createMessage.warning('请先选择数据') |
|
|
|
async function execute() { |
|
try { |
|
await deleteUser(ids) |
|
createMessage.success('删除成功') |
|
await reload() |
|
clearSelectedRowKeys() |
|
} |
|
catch {} |
|
} |
|
|
|
if (id) |
|
return execute() |
|
|
|
createConfirm({ |
|
iconType: 'warning', |
|
title: '是否要删除选择的用户?', |
|
onOk: execute, |
|
}) |
|
} |
|
|
|
function resetPassword() { |
|
const ids = tableMethods.getSelectRowKeys() as string[] |
|
|
|
if (!ids.length) |
|
return createMessage.warning('请先选择数据') |
|
|
|
createConfirm({ |
|
title: '确定将选择账号密码重置为 123456?', |
|
iconType: 'warning', |
|
onOk() { |
|
resetPasswordByIds(ids) |
|
.then(() => { |
|
createMessage.success('重置成功') |
|
}) |
|
.catch(noop) |
|
}, |
|
}) |
|
} |
|
|
|
function unlockUser() { |
|
const ids = tableMethods.getSelectRowKeys() as string[] |
|
|
|
if (!ids.length) |
|
return createMessage.warning('请先选择数据') |
|
|
|
createConfirm({ |
|
title: '确定将选择账号解封?', |
|
iconType: 'warning', |
|
onOk() { |
|
unlockUserByIds(ids) |
|
.then(() => { |
|
createMessage.success('解封成功') |
|
}) |
|
.catch(noop) |
|
}, |
|
}) |
|
} |
|
|
|
function handleExportUsers() { |
|
exportUsers() |
|
.then((blob) => { |
|
downloadByData(blob, '用户数据.xlsx') |
|
}) |
|
.catch(noop) |
|
} |
|
|
|
const [registerImportModal, { openModal: openImportModal }] = useModal() |
|
const isImportCovered = ref(0) |
|
const importModalProps = computed(() => { |
|
return { |
|
title: '用户数据导入', |
|
hint: '请上传 .xls,.xlsx 标准格式文件', |
|
uploadUrl: `/baymax-system/user/import-user?isCovered=${isImportCovered.value}`, |
|
templateUrl: '/baymax-system/user/export-template', |
|
} |
|
}) |
|
|
|
return { |
|
handleDelete, |
|
resetPassword, |
|
unlockUser, |
|
handleExportUsers, |
|
registerImportModal, |
|
openImportModal, |
|
importModalProps, |
|
isImportCovered, |
|
} |
|
}
|
|
|