|
@@ -0,0 +1,261 @@
|
|
|
+import {ActionType, PageContainer, ProForm, ProFormSelect, ProFormText, ProTable,} from '@ant-design/pro-components';
|
|
|
+import {Button, Card, Modal} from 'antd';
|
|
|
+import React, {useRef} from 'react';
|
|
|
+import {AddOutline} from 'antd-mobile-icons';
|
|
|
+import {EditBundle, useEdit} from '@/core/hooks/useEdit';
|
|
|
+import { deleteUserRemoveApi, getUserDetailsApi, postUserPageApi, postUserSaveApi } from '@/services/swagger/userAdmin';
|
|
|
+import {getPeakListApi} from "@/services/swagger/peakAdmin";
|
|
|
+import {getUserLevelListApi} from "@/services/swagger/userLevelAdmin";
|
|
|
+import {getFactionLevelListApi} from "@/services/swagger/factionLevelAdmin";
|
|
|
+
|
|
|
+const Edit: React.FC<{ bundle: EditBundle; onSuccess?: () => void }> = (props) => {
|
|
|
+ const {bundle} = props;
|
|
|
+ const [form] = ProForm.useForm<SectApi.UserSaveQuery>();
|
|
|
+ const [loading, setLoading] = React.useState(false);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Modal
|
|
|
+ confirmLoading={loading}
|
|
|
+ title={bundle.id ? '编辑用户' : '添加用户'}
|
|
|
+ open={bundle.open}
|
|
|
+ onOk={async () => {
|
|
|
+ await form.validateFields();
|
|
|
+
|
|
|
+ try {
|
|
|
+ setLoading(true);
|
|
|
+
|
|
|
+ await postUserSaveApi({
|
|
|
+ id: bundle.id,
|
|
|
+ ...form.getFieldsValue()
|
|
|
+ });
|
|
|
+ } finally {
|
|
|
+ setLoading(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ props.onSuccess?.();
|
|
|
+ bundle.close();
|
|
|
+ }}
|
|
|
+ onCancel={() => {
|
|
|
+ form.resetFields();
|
|
|
+ bundle.close();
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <ProForm
|
|
|
+ className={'mt-5'}
|
|
|
+ form={form}
|
|
|
+ labelCol={{span: 4}}
|
|
|
+ layout={'horizontal'}
|
|
|
+ submitter={false}
|
|
|
+ request={async () => {
|
|
|
+ if (bundle.id !== undefined) {
|
|
|
+ console.log(bundle.id, 'bundle');
|
|
|
+ const res = await getUserDetailsApi({id: bundle.id});
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...res.data
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Promise.resolve({});
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <ProFormText name="name" label={'用户名称'} rules={[{required: true, message: '请输入用户名称',}]} placeholder={'请输入用户名'}></ProFormText>
|
|
|
+ <ProFormText name="mobile" label={'手机号'} rules={[{required: true, message: '请输入手机号',}]} placeholder={'请输入手机号'}></ProFormText>
|
|
|
+ <ProFormText name="nickname" label={'昵称'} rules={[{required: true, message: '请输入昵称',}]} placeholder={'请输入昵称'}></ProFormText>
|
|
|
+ <ProFormText name="purpleCoin" label={'紫币'} rules={[{required: true, message: '请输入紫币',}]} placeholder={'请输入紫币'}></ProFormText>
|
|
|
+ <ProFormText name="purpleSpar" label={'紫晶'} rules={[{required: true, message: '请输入紫晶',}]} placeholder={'请输入紫晶'}></ProFormText>
|
|
|
+
|
|
|
+ <ProFormSelect
|
|
|
+ fieldProps={{
|
|
|
+ 'mode': 'multiple',
|
|
|
+ }}
|
|
|
+ name="peakId"
|
|
|
+ label="所属峰"
|
|
|
+ request={async () => {
|
|
|
+ const res = await getPeakListApi();
|
|
|
+ const records = res.data ?? []
|
|
|
+ return records.map(record => ({
|
|
|
+ label: record.name,
|
|
|
+ value: record.id,
|
|
|
+ }))
|
|
|
+ }}
|
|
|
+ placeholder="请选择所属峰"
|
|
|
+ rules={[{required: true, message: '请选择所属峰'}]}
|
|
|
+ />
|
|
|
+ <ProFormSelect
|
|
|
+ fieldProps={{
|
|
|
+ 'mode': 'multiple',
|
|
|
+ }}
|
|
|
+ name="userLevel"
|
|
|
+ label="会员等级"
|
|
|
+ request={async () => {
|
|
|
+ const res = await getUserLevelListApi();
|
|
|
+ const records = res.data ?? []
|
|
|
+ return records.map(record => ({
|
|
|
+ label: record.name,
|
|
|
+ value: record.id,
|
|
|
+ }))
|
|
|
+ }}
|
|
|
+ placeholder="请选择会员等级"
|
|
|
+ rules={[{required: true, message: '请选择会员等级'}]}
|
|
|
+ />
|
|
|
+ <ProFormSelect
|
|
|
+ fieldProps={{
|
|
|
+ 'mode': 'multiple',
|
|
|
+ }}
|
|
|
+ name="factionLevel"
|
|
|
+ label="宗门等级"
|
|
|
+ request={async () => {
|
|
|
+ const res = await getFactionLevelListApi();
|
|
|
+ const records = res.data ?? []
|
|
|
+ return records.map(record => ({
|
|
|
+ label: record.name,
|
|
|
+ value: record.id,
|
|
|
+ }))
|
|
|
+ }}
|
|
|
+ placeholder="请选择宗门等级"
|
|
|
+ rules={[{required: true, message: '请选择宗门等级'}]}
|
|
|
+ />
|
|
|
+
|
|
|
+ <ProFormText.Password
|
|
|
+ name="password"
|
|
|
+ label="密码"
|
|
|
+ placeholder={'请输入密码'}
|
|
|
+ rules={[
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '请输入密码',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ min: 6,
|
|
|
+ max: 50,
|
|
|
+ message: '密码长度必须在6-50之间',
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ />
|
|
|
+ </ProForm>
|
|
|
+ </Modal>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+const Staff: React.FC = () => {
|
|
|
+ const bundle = useEdit();
|
|
|
+ const ref = useRef<ActionType>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return (
|
|
|
+ <PageContainer content={''}>
|
|
|
+ {bundle.open && <Edit bundle={bundle} onSuccess={() => ref.current?.reload()}></Edit>}
|
|
|
+ <Card>
|
|
|
+ <ProTable<SectApi.StaffVO>
|
|
|
+ rowKey={'id'}
|
|
|
+
|
|
|
+ request={async (params, ...rest) => {
|
|
|
+ console.log(params, ...rest)
|
|
|
+
|
|
|
+ const res = await postUserPageApi(
|
|
|
+
|
|
|
+ {
|
|
|
+ current: params.current || 1,
|
|
|
+ size: params.pageSize || 10,
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ return {
|
|
|
+ success: res.success,
|
|
|
+ total: res.data.total,
|
|
|
+ data: res.data.records,
|
|
|
+ };
|
|
|
+ }}
|
|
|
+ columns={[
|
|
|
+ {
|
|
|
+ title: 'ID',
|
|
|
+ dataIndex: 'id',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '所属峰',
|
|
|
+ dataIndex: 'peakName',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '名称',
|
|
|
+ dataIndex: 'name',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '手机号码',
|
|
|
+ dataIndex: 'mobile',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '昵称',
|
|
|
+ dataIndex: 'nickname',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '会员等级',
|
|
|
+ dataIndex: 'userLevelName',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '宗门等级',
|
|
|
+ dataIndex: 'factionLevelName',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '紫币',
|
|
|
+ dataIndex: 'purpleCoin',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '紫晶',
|
|
|
+ dataIndex: 'purpleSpar',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '状态',
|
|
|
+ dataIndex: 'status',
|
|
|
+ render: (text, _) => {
|
|
|
+ return text === 1 ? "启用" : "禁用"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ valueType: 'option',
|
|
|
+ render: (_, record) => [
|
|
|
+ <a key={'edit'} onClick={() => bundle.update(record.id as number)}>
|
|
|
+ 编辑
|
|
|
+ </a>,
|
|
|
+ <a
|
|
|
+ key={'delete'}
|
|
|
+ onClick={async () => {
|
|
|
+ if(record.id) {
|
|
|
+ await deleteUserRemoveApi({id: record.id})
|
|
|
+ ref.current?.reload();
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </a>,
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ search={{
|
|
|
+ labelWidth: 'auto',
|
|
|
+ }}
|
|
|
+ form={{
|
|
|
+ ignoreRules: false,
|
|
|
+ }}
|
|
|
+
|
|
|
+
|
|
|
+ actionRef={ref}
|
|
|
+ toolbar={{
|
|
|
+ actions: [
|
|
|
+ <Button icon={<AddOutline/>} key={'add'} type={'primary'} onClick={bundle.create}>
|
|
|
+ 添加
|
|
|
+ </Button>,
|
|
|
+ ],
|
|
|
+ settings: [],
|
|
|
+ }}
|
|
|
+
|
|
|
+ ></ProTable>
|
|
|
+ </Card>
|
|
|
+ </PageContainer>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default Staff;
|