feat: 增加账号状态和启用和禁用功能

perf/export-docx
Jimmy Liow 1 year ago
parent 81f1c9cea9
commit 09726a51bf

@ -12,7 +12,10 @@
"createdOn": "创建时间",
"action": "操作",
"action.edit": "编辑",
"action.enable": "启用",
"action.disable": "禁用",
"action.enable.title": "确定启用该账号吗?",
"action.disable.title": "确定禁用该账号吗?",
"action.resetPassword": "重置密码",
"accountList": "管理账号",

@ -70,16 +70,15 @@ const useAccountStore = create((set, get) => ({
accountList: [],
disableAccount: async (userId) => {
toggleAccountStatus: async (userId, status) => {
const statusValue = status ? 'enable' : 'disable'
const formData = new FormData()
formData.append('lmi_sn', userId)
// enable | disable
formData.append('account_status', 'disable')
const result = await postAccountStatus(formData)
formData.append('account_status', statusValue)
console.info(result)
return postAccountStatus(formData)
},
resetAccountPassword: async (userId, password) => {
@ -147,6 +146,7 @@ const useAccountStore = create((set, get) => ({
lastLogin: r.wu_lastlogindate,
travelAgencyName: r.travel_agency_name,
travelAgencyId: r.travel_agency_id,
disabled: r.wu_limitsign,
// 数据库支持逗号分隔多角色(5,6,7),目前界面只需单个。
roleId: parseInt(r.roles),
role: r.roles_name,

@ -3,7 +3,7 @@ import useAccountStore, { fetchRoleList, fetchTravelAgencyByName } from '@/store
import useFormStore from '@/stores/Form'
import { isEmpty } from '@/utils/commons'
import { ExclamationCircleFilled } from '@ant-design/icons'
import { App, Button, Col, Form, Input, Modal, Row, Select, Space, Table, Typography } from 'antd'
import { App, Button, Col, Form, Input, Modal, Row, Select, Space, Table, Typography, Switch } from 'antd'
import dayjs from 'dayjs'
import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
@ -53,10 +53,12 @@ function Management() {
)
}
function actionRender(text, account) {
function actionRender(_, account) {
return (
<Space key='actionRenderSpace' size='middle'>
<Button type='link' key='disable' onClick={() => showDisableConfirm(account)}>{t('account:action.disable')}</Button>
<Switch checkedChildren={t('account:action.enable')} unCheckedChildren={t('account:action.disable')} checked={account.disabled==0} onChange={(checked) => {
showDisableConfirm(account, checked)
}} />
<Button type='link' key='resetPassword' onClick={() => showResetPasswordConfirm(account)}>{t('account:action.resetPassword')}</Button>
</Space>
)
@ -69,9 +71,9 @@ function Management() {
const [currentTravelAgency, setCurrentTravelAgency] = useState(null)
const [accountForm] = Form.useForm()
const [searchAccountByCriteria, accountList, disableAccount, saveOrUpdateAccount, resetAccountPassword] =
const [searchAccountByCriteria, accountList, toggleAccountStatus, saveOrUpdateAccount, resetAccountPassword] =
useAccountStore((state) =>
[state.searchAccountByCriteria, state.accountList, state.disableAccount, state.saveOrUpdateAccount, state.resetAccountPassword])
[state.searchAccountByCriteria, state.accountList, state.toggleAccountStatus, state.saveOrUpdateAccount, state.resetAccountPassword])
const formValues = useFormStore(state => state.formValues)
const { notification, modal } = App.useApp()
@ -116,7 +118,6 @@ function Management() {
}
const onAccountFinish = (values) => {
console.log(values)
saveOrUpdateAccount(values)
.then(() => {
handelAccountSearch()
@ -156,13 +157,27 @@ function Management() {
setCurrentTravelAgency(newValue)
}
const showDisableConfirm = (account) => {
const showDisableConfirm = (account, status) => {
const confirmTitle = status ? t('account:action.enable.title') : t('account:action.disable.title')
modal.confirm({
title: 'Do you want to disable this account?',
title: confirmTitle,
icon: <ExclamationCircleFilled />,
content: `Username: ${account.username}, Realname: ${account.realname}`,
content: t('account:username') + ': ' + account.username + ', ' + t('account:realname') + ': ' + account.realname,
onOk() {
disableAccount(account.userId)
toggleAccountStatus(account.userId, status)
.then(() => {
handelAccountSearch()
})
.catch(ex => {
notification.error({
message: 'Notification',
description: ex.message,
placement: 'top',
duration: 4,
})
})
},
onCancel() {
},

Loading…
Cancel
Save