system-copyright-react/src/route/proj/ProjNew.tsx

185 lines
7.7 KiB
TypeScript
Raw Normal View History

2024-03-14 18:33:58 +08:00
import './proj-new.css';
2024-03-20 18:30:39 +08:00
import {Link, useNavigate, useParams, useSearchParams} from "react-router-dom";
import {Breadcrumb, Button, Flex, Form, Input, message, Modal, Spin} from "antd";
import {useEffect, useState} from "react";
import {get, post} from "../../util/AjaxUtils.ts";
import {IProjCharge, ProjAdditionalType, ProjChargeType} from "../../interfaces/proj/IProj.ts";
2024-03-14 18:33:58 +08:00
const {TextArea} = Input;
2024-03-20 18:30:39 +08:00
type ProjInfo = {
projName: string;
projIntroduction: string;
2024-03-14 18:33:58 +08:00
};
export default function ProjNew() {
const nav = useNavigate();
2024-03-20 18:30:39 +08:00
const pathParams = useParams();
const [queryParams] = useSearchParams();
2024-03-14 18:33:58 +08:00
2024-03-20 18:30:39 +08:00
const [messageApi, contextHolder] = message.useMessage();
const [loading, setLoading] = useState<boolean>(false);
const height = window.innerHeight - 150;
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const [chargePrice, setChargePrice] = useState(0);
const [projInfo, setProjInfo] = useState<ProjInfo>({
projName: '',
projIntroduction: '',
});
2024-03-21 22:22:35 +08:00
const [createProjId, setCreateProjId] = useState('');
2024-03-20 18:30:39 +08:00
const listProjChargeAdditional: string[] = [];
2024-03-14 23:34:40 +08:00
2024-03-20 18:30:39 +08:00
useEffect(() => {
get({
messageApi: messageApi,
url: '/api/proj/charge/get',
onSuccess({data}) {
const charge = data as IProjCharge;
let price = 0;
switch (pathParams.projChargeType) {
case ProjChargeType.ALL:
price = charge.proj.all;
break;
case ProjChargeType.MATERIAL_AGENT:
price = charge.proj.materialAgent;
break;
case ProjChargeType.MATERIAL_AGENT_URGENT:
price = charge.proj.materialAgentUrgent;
break;
case ProjChargeType.MATERIAL:
price = charge.proj.material;
break;
case ProjChargeType.FREE:
price = charge.proj.free;
break;
default:
messageApi.error({
type: 'error',
content: '价格类型错误',
})
}
if (queryParams.get('pkg')) {
price += charge.additional.pkg;
listProjChargeAdditional.push(ProjAdditionalType.PKG);
}
if (queryParams.get('videoDemo')) {
price += charge.additional.videoDemo;
listProjChargeAdditional.push(ProjAdditionalType.VIDEO_DEMO);
}
setChargePrice(price);
}
})
}, []);
2024-03-14 23:34:40 +08:00
2024-03-14 18:33:58 +08:00
return (
<>
2024-03-20 18:30:39 +08:00
{contextHolder}
2024-03-14 18:33:58 +08:00
<Breadcrumb
items={[
{title: <Link to={'/'}></Link>},
{title: <Link to={'/proj-create'}></Link>},
2024-03-14 23:34:40 +08:00
{title: '新建项目'},
2024-03-14 18:33:58 +08:00
]}
/>
2024-03-14 23:34:40 +08:00
<div style={{height: `${height}px`, overflow: 'auto'}}>
<div className="proj-new">
<div className="proj-title"></div>
<div className="proj-form">
<Form
name="basic"
layout={'vertical'}
labelCol={{span: 24}}
wrapperCol={{span: 24}}
style={{width: 500}}
initialValues={{remember: true}}
2024-03-20 18:30:39 +08:00
onFinish={(formData) => {
setIsCreateModalOpen(true);
setProjInfo({
projName: formData.projName,
projIntroduction: formData.projIntroduction
})
}}
2024-03-14 23:34:40 +08:00
autoComplete="off"
2024-03-14 18:33:58 +08:00
>
2024-03-20 18:30:39 +08:00
<Form.Item<ProjInfo>
2024-03-14 23:34:40 +08:00
label="系统标题"
2024-03-20 18:30:39 +08:00
name="projName"
2024-03-14 23:34:40 +08:00
rules={[{required: true, message: '请输入系统标题'}]}
>
<Input placeholder="请输入系统标题"/>
</Form.Item>
2024-03-14 18:33:58 +08:00
2024-03-20 18:30:39 +08:00
<Form.Item<ProjInfo>
2024-03-14 23:34:40 +08:00
label="简单描述"
2024-03-20 18:30:39 +08:00
name="projIntroduction"
2024-03-14 23:34:40 +08:00
rules={[{required: true, message: '请输入简单描述'}]}
>
<TextArea rows={6} placeholder="请用一段话简单描述系统"/>
</Form.Item>
2024-03-14 18:33:58 +08:00
2024-03-14 23:34:40 +08:00
<Form.Item>
<Flex align="center" justify="center" gap="large">
2024-03-20 18:30:39 +08:00
<Button type="primary" htmlType="submit"
style={{backgroundColor: 'var(--color-primary)'}}>
2024-03-14 23:34:40 +08:00
</Button>
2024-03-21 22:22:35 +08:00
<Button type="default" htmlType="button" onClick={() => {
nav(-1);
}}>
2024-03-14 23:34:40 +08:00
</Button>
</Flex>
</Form.Item>
</Form>
</div>
2024-03-14 18:33:58 +08:00
</div>
</div>
2024-03-20 18:30:39 +08:00
<Modal title="提示"
okText="确定"
cancelText="取消"
open={isCreateModalOpen}
onOk={() => {
setIsCreateModalOpen(false);
post({
messageApi,
url: '/api/proj/create',
body: {
projName: projInfo.projName,
projIntroduction: projInfo.projIntroduction,
projChargeType: pathParams.projChargeType,
listProjChargeAdditional: listProjChargeAdditional
},
onBefore() {
setLoading(true);
},
onSuccess({data}) {
setIsEditModalOpen(true);
2024-03-21 22:22:35 +08:00
setCreateProjId(data.data);
2024-03-20 18:30:39 +08:00
},
onFinally() {
setLoading(false);
}
})
}}
onCancel={() => {
setIsCreateModalOpen(false);
}}>
<div> {chargePrice / 100} </div>
</Modal>
<Modal title="提示"
okText="确定"
cancelText="取消"
open={isEditModalOpen}
onOk={() => {
nav(`/proj-edit/${createProjId}`);
}}
onCancel={() => {
setIsEditModalOpen(false);
}}>
<div></div>
2024-03-14 23:34:40 +08:00
</Modal>
2024-03-20 18:30:39 +08:00
<Spin tip="正在提交..." spinning={loading} fullscreen/>
2024-03-14 18:33:58 +08:00
</>
)
}