|
@@ -0,0 +1,179 @@
|
|
|
|
+import {
|
|
|
|
+ ActionType,
|
|
|
|
+ PageContainer,
|
|
|
|
+ ProForm,
|
|
|
|
+ ProFormText,
|
|
|
|
+ ProFormTreeSelect,
|
|
|
|
+ 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 { deletePeakLevelRemoveApi, getPeakLevelDetailsApi, postPeakLevelSaveApi, getPeakLevelListTreeApi } from '@/services/swagger/peakLevelAdmin';
|
|
|
|
+
|
|
|
|
+const Edit: React.FC<{ bundle: EditBundle; onSuccess?: () => void }> = (props) => {
|
|
|
|
+ let {bundle} = props;
|
|
|
|
+
|
|
|
|
+ const [form] = ProForm.useForm<SectApi.PeakLevelSaveQuery>();
|
|
|
|
+ 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 postPeakLevelSaveApi({
|
|
|
|
+ id: bundle.id,
|
|
|
|
+ ...form.getFieldsValue(),
|
|
|
|
+ });
|
|
|
|
+ } finally {
|
|
|
|
+ setLoading(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ props.onSuccess?.();
|
|
|
|
+ bundle.close();
|
|
|
|
+ }}
|
|
|
|
+ onClose={() => {
|
|
|
|
+ form.resetFields();
|
|
|
|
+ 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 getPeakLevelDetailsApi({id: bundle.id});
|
|
|
|
+
|
|
|
|
+ return res.data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Promise.resolve({});
|
|
|
|
+ }}
|
|
|
|
+
|
|
|
|
+ initialValues={{
|
|
|
|
+ type: 1 ,
|
|
|
|
+ status: 2,
|
|
|
|
+ target: 1,
|
|
|
|
+ hasRefresh: 0
|
|
|
|
+ } }
|
|
|
|
+
|
|
|
|
+ >
|
|
|
|
+
|
|
|
|
+ <ProFormTreeSelect
|
|
|
|
+ label='父等级' name='parentId'
|
|
|
|
+ style={{width: '100%'}}
|
|
|
|
+ placeholder="请选择父等级ID"
|
|
|
|
+ allowClear
|
|
|
|
+ request={async () => {
|
|
|
|
+ const transformToTreeData = (data: SectApi.PeakLevelVO[]): any[] =>
|
|
|
|
+ data.map((item) => ({
|
|
|
|
+ title: item.name,
|
|
|
|
+ value: item.id,
|
|
|
|
+ key: item.id,
|
|
|
|
+ children: item.children ? transformToTreeData(item.children) : [],
|
|
|
|
+ }));
|
|
|
|
+ const res = await getPeakLevelListTreeApi()
|
|
|
|
+ return transformToTreeData(res.data);
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ </ProFormTreeSelect>
|
|
|
|
+
|
|
|
|
+ <ProFormText name='name' label={'名称'} placeholder={'请输入名称'}></ProFormText>
|
|
|
|
+ <ProFormText name='level' label={'等级'} placeholder={'请输入等级'}></ProFormText>
|
|
|
|
+ <ProFormText name='exp' label={'经验值'} placeholder={'请输入经验值'}></ProFormText>
|
|
|
|
+ </ProForm>
|
|
|
|
+ </Modal>
|
|
|
|
+ );
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const MenuExp: 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.PeakLevelVO>
|
|
|
|
+ rowKey={'id'}
|
|
|
|
+ request={async () => {
|
|
|
|
+ const res = await getPeakLevelListTreeApi()
|
|
|
|
+ return {
|
|
|
|
+ success: res.success,
|
|
|
|
+ data: res.data,
|
|
|
|
+ };
|
|
|
|
+ }}
|
|
|
|
+
|
|
|
|
+ columns={[
|
|
|
|
+ {
|
|
|
|
+ title: '等级',
|
|
|
|
+ dataIndex: 'level',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '名称',
|
|
|
|
+ dataIndex: 'name',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '经验值',
|
|
|
|
+ dataIndex: 'exp',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ 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 deletePeakLevelRemoveApi({id:record.id});
|
|
|
|
+ ref.current?.reload();
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ 删除
|
|
|
|
+ </a>,
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+ ]}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ pagination={false}
|
|
|
|
+ actionRef={ref}
|
|
|
|
+ toolbar={{
|
|
|
|
+ actions: [
|
|
|
|
+ <Button icon={<AddOutline/>} key={'add'} type={'primary'} onClick={bundle.create}>
|
|
|
|
+ 添加
|
|
|
|
+ </Button>,
|
|
|
|
+ ],
|
|
|
|
+ settings: [],
|
|
|
|
+ }}
|
|
|
|
+ search={false}
|
|
|
|
+ ></ProTable>
|
|
|
|
+ </Card>
|
|
|
|
+ </PageContainer>
|
|
|
|
+ </>
|
|
|
|
+ );
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export default MenuExp;
|