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