|
@@ -1,17 +1,9 @@
|
|
|
-import {
|
|
|
- addAccountBg,
|
|
|
- delAccountBg,
|
|
|
- fetchRoleBgList,
|
|
|
- fetchRoleBgStaffListByRoleId,
|
|
|
- updateAccountBg
|
|
|
-} from '@/services/api/permission'
|
|
|
-import consts from '@/utils/consts'
|
|
|
import { PageContainer } from '@ant-design/pro-layout'
|
|
|
import ProTable from '@ant-design/pro-table'
|
|
|
-import { Button, Form, Input, message, Modal } from 'antd'
|
|
|
-import React, { useEffect, useRef, useState } from 'react'
|
|
|
-import { ModalForm, ProFormRadio, ProFormSelect, ProFormText } from '@ant-design/pro-form'
|
|
|
-import { useRequest } from '@umijs/max'
|
|
|
+import useModal from '@/components/Modal'
|
|
|
+import useScripts from './hooks/useScripts'
|
|
|
+import { Button } from 'antd'
|
|
|
+import React, { useState } from 'react'
|
|
|
import classNames from 'classnames'
|
|
|
export enum ModalType {
|
|
|
ADD,
|
|
@@ -19,8 +11,6 @@ export enum ModalType {
|
|
|
}
|
|
|
|
|
|
const Account: React.FC = () => {
|
|
|
- const tRef = useRef<ActionType>(null)
|
|
|
- const formRef = useRef<ProFormInstance>(null)
|
|
|
const [state, setState] = useState({
|
|
|
params: {
|
|
|
search: null
|
|
@@ -29,58 +19,13 @@ const Account: React.FC = () => {
|
|
|
modalType: 'add',
|
|
|
modalVisible: false
|
|
|
})
|
|
|
- const [menuRoles, setMenuRoles] = useState([])
|
|
|
- const { run: tryFetchRoleBgListByMenu } = useRequest(fetchRoleBgList, {
|
|
|
- onSuccess: result => {
|
|
|
- setMenuRoles(result)
|
|
|
- }
|
|
|
- })
|
|
|
- const { run: tryAddAccountBgRole } = useRequest(addAccountBg, {
|
|
|
- manual: true,
|
|
|
- onSuccess: () => {
|
|
|
- message.success('添加成功')
|
|
|
- tRef.current?.reload()
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- const { run: tryUpdateAccountBgRole } = useRequest(updateAccountBg, {
|
|
|
- manual: true,
|
|
|
- onSuccess: () => {
|
|
|
- message.success('编辑成功')
|
|
|
- tRef.current?.reload()
|
|
|
- }
|
|
|
- })
|
|
|
+ const [modal, ModalDOM] = useModal()
|
|
|
+ const { items, loading, addOrEdit, del } = useScripts(modal)
|
|
|
|
|
|
- const { run: tryDelAccountBgRole } = useRequest(delAccountBg, {
|
|
|
- manual: true,
|
|
|
- onSuccess: () => {
|
|
|
- message.success('删除成功')
|
|
|
- tRef.current?.reload()
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- const handleDel = (ID: string) => {
|
|
|
- Modal.confirm({
|
|
|
- title: '删除',
|
|
|
- content: (
|
|
|
- <div>
|
|
|
- <div>确认删除该行数据?</div>
|
|
|
- </div>
|
|
|
- ),
|
|
|
- okButtonProps: {
|
|
|
- danger: true
|
|
|
- },
|
|
|
- onOk: () => tryDelAccountBgRole({ ID })
|
|
|
- })
|
|
|
- }
|
|
|
- useEffect(() => {
|
|
|
- tryFetchRoleBgListByMenu()
|
|
|
- }, [])
|
|
|
const columns: ProColumnType<API.InstitutionRoleParams>[] = [
|
|
|
{
|
|
|
dataIndex: 'account',
|
|
|
title: '账号',
|
|
|
- // align: 'center',
|
|
|
onHeaderCell: () => ({ style: { textAlign: 'center' } })
|
|
|
},
|
|
|
{
|
|
@@ -108,24 +53,12 @@ const Account: React.FC = () => {
|
|
|
<div className="divide-x divide-bg-gray-400 flex flex-row justify-center">
|
|
|
<span
|
|
|
className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
|
|
|
- onClick={() => {
|
|
|
- setTimeout(() => {
|
|
|
- formRef.current?.setFieldsValue({ ...record })
|
|
|
- }, 80)
|
|
|
- setState({
|
|
|
- ...state,
|
|
|
- modalType: ModalType.UPDATE,
|
|
|
- modalVisible: true,
|
|
|
- ID: record.ID,
|
|
|
- name: record.name,
|
|
|
- enable: record.enable
|
|
|
- })
|
|
|
- }}>
|
|
|
+ onClick={() => addOrEdit('edit', record)}>
|
|
|
编辑
|
|
|
</span>
|
|
|
<span
|
|
|
className={'pl-2 text-red-500 cursor-pointer hover:text-red-600'}
|
|
|
- onClick={() => handleDel(record.ID)}>
|
|
|
+ onClick={() => del(record.ID)}>
|
|
|
删除
|
|
|
</span>
|
|
|
</div>
|
|
@@ -138,21 +71,11 @@ const Account: React.FC = () => {
|
|
|
<div className="w-full h-full bg-white">
|
|
|
<ProTable
|
|
|
rowKey="ID"
|
|
|
- actionRef={tRef}
|
|
|
- params={state.params}
|
|
|
columns={columns}
|
|
|
search={false}
|
|
|
scroll={{ y: document.body.clientHeight - 315 }}
|
|
|
- request={async params => {
|
|
|
- const { code = -1, data: { items = [], total = 0 } = {} } = await fetchRoleBgStaffListByRoleId({
|
|
|
- ...params
|
|
|
- })
|
|
|
- return {
|
|
|
- data: items,
|
|
|
- success: code === consts.RET_CODE.SUCCESS,
|
|
|
- total
|
|
|
- }
|
|
|
- }}
|
|
|
+ loading={loading}
|
|
|
+ dataSource={items}
|
|
|
toolbar={{
|
|
|
search: {
|
|
|
onSearch: val => setState({ ...state, params: { ...state.params, search: val } }),
|
|
@@ -161,76 +84,16 @@ const Account: React.FC = () => {
|
|
|
},
|
|
|
actions: [
|
|
|
<>
|
|
|
- <Button
|
|
|
- type="primary"
|
|
|
- key="add_flow_btn"
|
|
|
- onClick={() => {
|
|
|
- setState({
|
|
|
- ...state,
|
|
|
- modalType: ModalType.ADD,
|
|
|
- modalVisible: true
|
|
|
- })
|
|
|
- }}>
|
|
|
+ <Button type="primary" key="add_flow_btn" onClick={() => addOrEdit('add')}>
|
|
|
添加人员
|
|
|
</Button>
|
|
|
</>
|
|
|
]
|
|
|
}}
|
|
|
/>
|
|
|
- <ModalForm
|
|
|
- visible={state.modalVisible}
|
|
|
- isKeyPressSubmit
|
|
|
- layout="horizontal"
|
|
|
- labelCol={{ span: 4 }}
|
|
|
- modalProps={{
|
|
|
- width: '30%'
|
|
|
- }}
|
|
|
- onVisibleChange={visible => {
|
|
|
- setState({ ...state, modalVisible: visible })
|
|
|
- setTimeout(() => {
|
|
|
- if (!visible) formRef.current?.resetFields()
|
|
|
- }, 80)
|
|
|
- }}
|
|
|
- initialValues={{ enable: true }}
|
|
|
- title={`${state.modalType === ModalType.ADD ? '添加' : '编辑'}人员`}
|
|
|
- formRef={formRef}
|
|
|
- onFinish={async values => {
|
|
|
- try {
|
|
|
- if (state.modalType === ModalType.ADD) {
|
|
|
- await tryAddAccountBgRole(values)
|
|
|
- } else {
|
|
|
- await tryUpdateAccountBgRole({ ...values, ID: state.ID })
|
|
|
- }
|
|
|
- tRef.current?.reload()
|
|
|
- return true
|
|
|
- } catch (error) {
|
|
|
- message.error(error)
|
|
|
- return false
|
|
|
- }
|
|
|
- }}>
|
|
|
- <ProFormText name="account" label="账号" rules={[{ required: true, message: '请输入' }]} />
|
|
|
- <ProFormText name="name" label="名称" rules={[{ required: true, message: '请输入' }]} />
|
|
|
- <Form.Item label="密码" name="password" rules={[{ required: true, message: '请输入' }]}>
|
|
|
- <Input.Password placeholder="请输入" />
|
|
|
- </Form.Item>
|
|
|
- <ProFormSelect
|
|
|
- label="角色"
|
|
|
- name="roleIDs"
|
|
|
- className="w-full"
|
|
|
- options={menuRoles?.map(item => ({ value: item.ID, label: item.name }))}
|
|
|
- />
|
|
|
- <ProFormRadio.Group
|
|
|
- options={[
|
|
|
- { label: '启用', value: true },
|
|
|
- { label: '停用', value: false }
|
|
|
- ]}
|
|
|
- name="enable"
|
|
|
- label="状态"
|
|
|
- rules={[{ required: true, message: '请选择' }]}
|
|
|
- />
|
|
|
- </ModalForm>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ {ModalDOM}
|
|
|
</PageContainer>
|
|
|
)
|
|
|
}
|