feat(register): 添加注册后重定向功能

从URL参数获取redirect值并在注册成功后跳转
This commit is contained in:
linxd
2025-07-18 10:34:37 +08:00
parent db9bcdac11
commit 90b8628eb8

View File

@ -1,6 +1,6 @@
// 供应商注册 // 供应商注册
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { useIntl, history } from 'umi'; import { useIntl, history, useLocation } from 'umi';
import { Form, Button, message, Radio, Checkbox, Modal, Spin } from 'antd'; import { Form, Button, message, Radio, Checkbox, Modal, Spin } from 'antd';
import { HomeOutlined } from '@ant-design/icons'; import { HomeOutlined } from '@ant-design/icons';
import DomesticForm from './supplier/DomesticForm'; import DomesticForm from './supplier/DomesticForm';
@ -25,12 +25,17 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
const [modalVisible, setModalVisible] = useState(false); const [modalVisible, setModalVisible] = useState(false);
const [surveyQuestions, setSurveyQuestions] = useState<API.SurveyQuestionResponse>([]); const [surveyQuestions, setSurveyQuestions] = useState<API.SurveyQuestionResponse>([]);
const [fetchingQuestions, setFetchingQuestions] = useState(false); const [fetchingQuestions, setFetchingQuestions] = useState(false);
const location = useLocation();
const redirectRef = useRef<string>('');
// 获取问卷列表 // 获取问卷列表
useEffect(() => { useEffect(() => {
const searchParams = new URLSearchParams(location.search);
const redirect = searchParams.get('redirect'); // 获取 redirect 参数
if (redirect) {
redirectRef.current = redirect;
}
//供应商带录入 //供应商带录入
if (supplierWithInput) { if (supplierWithInput) {
} }
const fetchQuestions = async () => { const fetchQuestions = async () => {
setFetchingQuestions(true); setFetchingQuestions(true);
@ -85,17 +90,19 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
values.coscoSupplierBase = values.coscoSupplierBase || {}; values.coscoSupplierBase = values.coscoSupplierBase || {};
values.coscoSupplierBase.supplierType = supplierType; values.coscoSupplierBase.supplierType = supplierType;
if(supplierType === 'pe') { if (supplierType === 'pe') {
values.coscoSupplierBase.personName = values.coscoSupplierBase.name; values.coscoSupplierBase.personName = values.coscoSupplierBase.name;
values.coscoSupplierBase.personPhone = values.coscoSupplierBase.contactPhone; values.coscoSupplierBase.personPhone = values.coscoSupplierBase.contactPhone;
values.coscoSupplierSurveyAttachments = [{ values.coscoSupplierSurveyAttachments = [
attachmentsType: "accessory", {
fileName: values.attachments.file.response.fileName, attachmentsType: 'accessory',
fileType: values.attachments.file.response.fileType, fileName: values.attachments.file.response.fileName,
fileSize: values.attachments.file.response.fileSize, fileType: values.attachments.file.response.fileType,
filePath: values.attachments.file.response.filePath, fileSize: values.attachments.file.response.fileSize,
fileUrl: values.attachments.file.response.filePath, filePath: values.attachments.file.response.filePath,
}] fileUrl: values.attachments.file.response.filePath,
},
];
} }
console.log('供应商注册信息:', values); console.log('供应商注册信息:', values);
// 直接调用API supplierWithInput === true 供应商注册代录 否则 注册 accessory // 直接调用API supplierWithInput === true 供应商注册代录 否则 注册 accessory
@ -103,6 +110,10 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
const response = await (supplierWithInput ? addAgent(values) : coscoSupplierBaseAdd(values)); const response = await (supplierWithInput ? addAgent(values) : coscoSupplierBaseAdd(values));
if (response.success) { if (response.success) {
if (redirectRef.current) {
window.location.href = redirectRef.current;
return;
}
if (!supplierWithInput) { if (!supplierWithInput) {
message.success('注册成功,请登录'); message.success('注册成功,请登录');
history.push('/login'); history.push('/login');
@ -143,7 +154,6 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
</> </>
)} )}
<Spin spinning={fetchingQuestions}> <Spin spinning={fetchingQuestions}>
<Form <Form
form={form} form={form}
@ -158,16 +168,17 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
wrapperCol={{ span: 17 }} wrapperCol={{ span: 17 }}
> >
<Form.Item label="境内/境外" labelCol={{ span: 2 }} wrapperCol={{ span: 19 }}> <Form.Item label="境内/境外" labelCol={{ span: 2 }} wrapperCol={{ span: 19 }}>
<Radio.Group onChange={handleSupplierTypeChange} buttonStyle="solid" value={supplierType}> <Radio.Group
onChange={handleSupplierTypeChange}
buttonStyle="solid"
value={supplierType}
>
<Radio.Button value="dvs">/</Radio.Button> <Radio.Button value="dvs">/</Radio.Button>
<Radio.Button value="ovs"></Radio.Button> <Radio.Button value="ovs"></Radio.Button>
{supplierWithInput && ( {supplierWithInput && <Radio.Button value="pe"></Radio.Button>}
<Radio.Button value="pe"></Radio.Button>
)}
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
{supplierType === 'dvs' ? ( {supplierType === 'dvs' ? (
<DomesticForm <DomesticForm
form={form} form={form}
@ -205,25 +216,23 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
]} ]}
> >
<div style={{ textAlign: 'center' }}> <div style={{ textAlign: 'center' }}>
<Checkbox> <Checkbox>
<Button <Button
type="link" type="link"
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
setModalVisible(true); setModalVisible(true);
}} }}
> >
</Button> </Button>
</Checkbox> </Checkbox>
</div> </div>
</Form.Item> </Form.Item>
)} )}
<Form.Item wrapperCol={{ span: 24 }}> <Form.Item wrapperCol={{ span: 24 }}>
<div style={{ textAlign: 'center' }}> <div style={{ textAlign: 'center' }}>
<Button type="primary" htmlType="submit" loading={loading}> <Button type="primary" htmlType="submit" loading={loading}>
@ -251,7 +260,7 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
okText="我知道了" okText="我知道了"
cancelButtonProps={{ style: { display: 'none' } }} cancelButtonProps={{ style: { display: 'none' } }}
destroyOnClose destroyOnClose
// maskClosable={false} // maskClosable={false}
> >
<div style={{ maxHeight: '60vh', overflow: 'auto' }}> <div style={{ maxHeight: '60vh', overflow: 'auto' }}>
<p></p> <p></p>