From 09726a51bffe4f019a57d5c4af93c5b63bd91524 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Thu, 27 Jun 2024 10:02:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=92=8C=E5=90=AF=E7=94=A8=E5=92=8C=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/locales/zh/account.json | 3 +++ src/stores/Account.js | 12 +++++------ src/views/account/Management.jsx | 35 +++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/public/locales/zh/account.json b/public/locales/zh/account.json index 35c0dc0..3849f07 100644 --- a/public/locales/zh/account.json +++ b/public/locales/zh/account.json @@ -12,7 +12,10 @@ "createdOn": "创建时间", "action": "操作", "action.edit": "编辑", + "action.enable": "启用", "action.disable": "禁用", + "action.enable.title": "确定启用该账号吗?", + "action.disable.title": "确定禁用该账号吗?", "action.resetPassword": "重置密码", "accountList": "管理账号", diff --git a/src/stores/Account.js b/src/stores/Account.js index 01010d8..ee3daca 100644 --- a/src/stores/Account.js +++ b/src/stores/Account.js @@ -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, diff --git a/src/views/account/Management.jsx b/src/views/account/Management.jsx index 676ed9a..5496997 100644 --- a/src/views/account/Management.jsx +++ b/src/views/account/Management.jsx @@ -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 ( - + { + showDisableConfirm(account, checked) + }} /> ) @@ -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: , - 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() { },