表单提交

This commit is contained in:
lyp 2025-04-18 18:50:21 +08:00
parent b3537caa07
commit 9b1d9206d2
3 changed files with 278 additions and 207 deletions

View File

@ -2,9 +2,14 @@ import './head.css'
// import { NodeJS } from 'types/node'; // import { NodeJS } from 'types/node';
import { import {
useDispatch, useDispatch,
useSelector useSelector,
} from 'react-redux' } from 'react-redux'
import { getCode, checkPhone, updatePhone } from '../../request/api' import { operatorBaseUrl } from '../../util/AjaxUtils.ts'
import {
getCode, checkPhone,
// updatePhone
} from '../../request/api'
import BalanceHead from '../../components/balance/BalanceHead.tsx'; import BalanceHead from '../../components/balance/BalanceHead.tsx';
import RechargeHead from '../../components/recharge/RechargeHead.tsx'; import RechargeHead from '../../components/recharge/RechargeHead.tsx';
import { import {
@ -110,7 +115,7 @@ interface DataType {
// ]; // ];
import { DownOutlined, UserOutlined, QuestionCircleOutlined, BellOutlined, KeyOutlined, LogoutOutlined, GiftOutlined, AccountBookOutlined, ContainerOutlined, MenuFoldOutlined, UsergroupAddOutlined, TableOutlined } from "@ant-design/icons"; import { DownOutlined, UserOutlined, QuestionCircleOutlined, BellOutlined, KeyOutlined, LogoutOutlined, GiftOutlined, AccountBookOutlined, ContainerOutlined, MenuFoldOutlined, UsergroupAddOutlined, TableOutlined } from "@ant-design/icons";
import { useContext, useEffect, useState } from "react"; import { useContext, useEffect, useState, useRef } from "react";
import { import {
put, get, put, get,
// post, // post,
@ -136,52 +141,102 @@ import NoticeModal from '../../components/NoticeModal/NoticeModal.tsx';
import type { import type {
TableColumnsType, TableColumnsType,
} from 'antd'; } from 'antd';
// import { log } from 'console';
// import HeadCouponModal from '../../components/CouponModal/HeadCouponModal.tsx' // import HeadCouponModal from '../../components/CouponModal/HeadCouponModal.tsx'
export default function Head() { export default function Head() {
// const currentUrl = window.location.href;
const formRef = useRef<HTMLFormElement>(null);
// const triggerFormSubmit = () => {
// if (formRef.current) {
// formRef.current.submit();
// }
// };
// lyp // lyp
const [form] = Form.useForm<any>(); const [form] = Form.useForm<any>();
const [isUpdateWxUsernamePhone, setIsUpdateWxUsernamePhone] = useState(false); // 绑定手机号号弹窗 const [isUpdateWxUsernamePhone, setIsUpdateWxUsernamePhone] = useState(false); // 绑定手机号号弹窗
const [userId, setUserId] = useState(''); // 验证码ID const [userId, setUserId] = useState(''); // 验证码ID
const submit = async (phone: any, code: any) => { // const submit = async (phone: string, code: string) => {
try { // try {
const formData = new URLSearchParams(); // const formData = new URLSearchParams();
formData.append('userId', userId); // formData.append('userId', userId);
formData.append('phone', phone); // formData.append('phone', phone);
formData.append('smsCode', code); // formData.append('smsCode', code);
const res = await updatePhone(formData.toString()); // // await updatePhone();
console.log(res); // const res = await updatePhone(formData);
// console.log('表单提交数据', res)
// // console.log(res);
} catch (error: any) { // } catch (error: any) {
setPhoneLoading(false) // setPhoneLoading(false)
if (error.response) { // if (error.response) {
const data = error.response.data; // const data = error.response.data;
messageApi.open({ // messageApi.open({
type: 'error', // type: 'error',
content: data.msg ? data.msg : `${data.path}(${data.status})`, // content: data.msg ? data.msg : `${data.path}(${data.status})`,
}); // });
} else { // } else {
console.error(error) // console.error(error)
} // }
} // }
} // }
const [phoneloading, setPhoneLoading] = useState(false) const [phoneloading, setPhoneLoading] = useState(false)
// const handleFormSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
// e.preventDefault(); // 阻止表单默认提交行为
// // const form = e.currentTarget;
// // const formData = new FormData(form);
// // const url = operatorBaseUrl + '/operator/oauth/wx/update/phone';
// // console.log('嘻嘻',formData);
// // await fetch(url, {
// // method: 'POST',
// // body: formData
// // });
// // console.log(response);
// // if (!response.ok) {
// // // 响应状态码不是 200-299 时,认为请求失败
// // const errorData = await response.json();
// // messageApi.open({
// // type: 'error',
// // content: errorData.msg ? errorData.msg : `请求失败,状态码: ${response.status}`
// // });
// // } else {
// // console.log('表单提交成功');
// // const result = await response.json();
// // console.log('响应数据:', result);
// // }
// };
const onFinish = async (values: any) => { const onFinish = async (values: any) => {
// console.log('Success:', values); // console.log('Success:', values);
try { try {
const res = await checkPhone(values.phone)
// console.log(res);
if (res.data == 'SUCCESS') {
setPhoneLoading(true) setPhoneLoading(true)
submit(values.phone, values.smsCode) const res = await checkPhone(values.phone)
setPhoneLoading(false) // const formData = new URLSearchParams();
// formData.append('userId', userId);
// formData.append('phone', values.phone);
// formData.append('smsCode', values.smsCode);
// console.log('结果',res);
if (res.data == 'SUCCESS') {
if (formRef.current) {
// // 触发表单提交
formRef.current.submit();
// console.log(formRef.current);
}
} else { } else {
setPhoneLoading(false)
messageApi.open({ messageApi.open({
type: 'error', type: 'error',
content: '手机号已被绑定,请更换手机号', content: '手机号已被绑定,请更换手机号',
}); });
} }
// await submit(values.phone, values.smsCode)
} catch (error: any) { } catch (error: any) {
setPhoneLoading(false) setPhoneLoading(false)
if (error.response) { if (error.response) {
@ -269,8 +324,9 @@ export default function Head() {
}) })
} }
// useEffect(() => { // useEffect(() => {
// getPickList(); // console.log('路径',currentUrl);
// }, [packPage]);
// }, []);
// const [page, setPage] = useState(1) //邀请码使用人数分页 // const [page, setPage] = useState(1) //邀请码使用人数分页
@ -1876,7 +1932,9 @@ export default function Head() {
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}}> }}>
<Spin tip="正在绑定..." spinning={phoneloading} > {/* <Spin tip="..." spinning={phoneloading} style={{
zIndex: 101,
}}> */}
<div className='phoneMaskBox'> <div className='phoneMaskBox'>
<div className='phoneBoxLeft'> <div className='phoneBoxLeft'>
<div <div
@ -1959,7 +2017,9 @@ export default function Head() {
height: '42px', height: '42px',
fontSize: 16, fontSize: 16,
background: '#F7F7F7', background: '#F7F7F7',
}} placeholder="请输入手机号" /> }} placeholder="请输入手机号"
/>
</Form.Item> </Form.Item>
</div> </div>
<div className='phoneBoxInput' style={{ <div className='phoneBoxInput' style={{
@ -1976,17 +2036,7 @@ export default function Head() {
{countdown === 0 ? ( {countdown === 0 ? (
<div <div
className='sendCode' className='sendCode'
// style={{
// width: '90px',
// height: '42px',
// justifyContent: 'center',
// alignItems: 'center',
// display: 'flex',
// cursor: 'pointer',
// color: '#929292',
// paddingRight: 10,
// }}
onClick={sendCode} onClick={sendCode}
> >
@ -2023,6 +2073,7 @@ export default function Head() {
</div> </div>
</Form> </Form>
</div> </div>
<div className='closeTitle' onClick={() => { <div className='closeTitle' onClick={() => {
setIsUpdateWxUsernamePhone(false); setIsUpdateWxUsernamePhone(false);
@ -2032,10 +2083,25 @@ export default function Head() {
}) })
getUserData() getUserData()
}}></div> }}></div>
<div style={{
display: 'none'
}}>
<form ref={formRef}
action={operatorBaseUrl + '/operator/oauth/wx/update/phone'} method='post'
>
<input name="userId" defaultValue={userId} />
<input name="phone" defaultValue={form.getFieldValue('phone') || ''} />
<input name="smsCode" defaultValue={form.getFieldValue('smsCode') || ''} />
{/* <input name="errorRedirectUrl" defaultValue={encodeURI(currentUrl)} /> */}
</form>
</div> </div>
</div> </div>
</div> </div>
</Spin> </div>
{/* </Spin> */}
</div> </div>
</div> </div>

View File

@ -2669,8 +2669,10 @@ export default function Index() {
allowClear allowClear
/> />
<DatePicker placeholder="开始时间" <DatePicker placeholder="开始时间"
style={{ width: '130px', style={{
height: '31px', marginLeft: 5 }} width: '130px',
height: '31px', marginLeft: 5
}}
format={dateFormat} format={dateFormat}
locale={locale} locale={locale}
onChange={sellStratTimeChange} onChange={sellStratTimeChange}
@ -2678,8 +2680,10 @@ export default function Index() {
allowClear allowClear
/> />
<DatePicker placeholder="结束时间" <DatePicker placeholder="结束时间"
style={{ width: '130px', style={{
height: '31px', marginLeft: 5 }} width: '130px',
height: '31px', marginLeft: 5
}}
format={dateFormat} format={dateFormat}
locale={locale} locale={locale}
onChange={sellEndTimeChange} onChange={sellEndTimeChange}
@ -3103,7 +3107,7 @@ export default function Index() {
</Modal> </Modal>
<Modal title="可领取优惠券" <Modal title="可领取优惠券"
footer={null} footer={null}
centered
destroyOnClose destroyOnClose
open={getCouponModal && !phoneModal} open={getCouponModal && !phoneModal}
width={809} width={809}
@ -3329,7 +3333,8 @@ export default function Index() {
</Modal> </Modal>
<div className='couponMask-box' <div className='couponMask-box'
style={{ display: coupon && (location.pathname == '/' || location.pathname.includes('/home')) && couponArray.length == 1 &&!phoneModal? 'unset' : 'none', style={{
display: coupon && (location.pathname == '/' || location.pathname.includes('/home')) && couponArray.length == 1 && !phoneModal ? 'unset' : 'none',
zIndex: 99 zIndex: 99
}} }}
> >

View File

@ -22,8 +22,8 @@ export const WebSocketBaseUrl: string = `ws://${host}:7025/copyright`;
axios.defaults.baseURL = `${copyBaseUrl}/copyright`; axios.defaults.baseURL = `${copyBaseUrl}/copyright`;
export const DevUserId: string = '80d3365e-0597-4988-979e-18ef1c3ec671'; // 18634604067 // export const DevUserId: string = '80d3365e-0597-4988-979e-18ef1c3ec671'; // 18634604067
// export const DevUserId: string = 'a2ab4e3a-fd92-4723-9217-f9955ee92911'; export const DevUserId: string = 'ccb00bbe-a6cd-468a-a8e2-a6f39f6acccb';
// export const DevUserId: string = '6fb8e783-243c-4eec-8d98-c9b1c8aeaa00'; // 15042810561 密码123456 // export const DevUserId: string = '6fb8e783-243c-4eec-8d98-c9b1c8aeaa00'; // 15042810561 密码123456
// export const DevUserId: string = 'c2438eb8-2685-49a9-bf02-5111a5192d96'; // 18647109157 // export const DevUserId: string = 'c2438eb8-2685-49a9-bf02-5111a5192d96'; // 18647109157
// export const DevUserId: string = ''; // export const DevUserId: string = '';