system-copyright-react/src/App.tsx

307 lines
12 KiB
TypeScript
Raw Normal View History

2025-03-28 09:44:48 +08:00
2024-07-31 16:00:30 +08:00
// 引入Provider
import { Provider } from 'react-redux';
// 引入仓库
2025-04-11 16:20:46 +08:00
import './App.css'
2024-07-31 16:00:30 +08:00
import store from './store';
2024-03-11 19:13:42 +08:00
import Head from './layout/head/Head.tsx';
2024-03-12 18:53:51 +08:00
import Body from './layout/body/Body.tsx';
2024-05-07 17:00:32 +08:00
// import Foot from './layout/foot/Foot.tsx';
2024-03-26 21:09:41 +08:00
import {
GlobalContext,
GlobalData,
GlobalDataAction,
GlobalDataActionType,
2024-04-02 18:45:46 +08:00
GlobalDispatchContext,
2024-03-26 21:09:41 +08:00
} from "./context/GlobalContext.ts";
2025-03-28 09:44:48 +08:00
import React, { Reducer, useReducer, useState, useEffect } from "react";
2025-04-14 17:38:30 +08:00
// import { getCode, checkPhone,updatePhone } from './request/api.ts'
2025-03-28 09:44:48 +08:00
import {
2025-04-11 16:20:46 +08:00
message,
2025-04-14 17:38:30 +08:00
// Modal,
// Form,
// Button,
// Input
2025-03-28 09:44:48 +08:00
} from 'antd';
import { get } from "./util/AjaxUtils.ts";
2024-03-11 19:13:42 +08:00
const App: React.FC = () => {
2025-04-14 17:38:30 +08:00
2025-03-28 09:44:48 +08:00
const [isTokenFetched, setIsTokenFetched] = useState(false);
2025-04-14 17:38:30 +08:00
// const [isUpdateWxUsernamePhone, setIsUpdateWxUsernamePhone] = useState(false); // 绑定手机号号弹窗
// const [form] = Form.useForm<any>();
2024-03-26 21:09:41 +08:00
const globalDataReducer = (state: GlobalData, action: GlobalDataAction) => {
if (action.type == GlobalDataActionType.REFRESH_SELF) {
2024-04-19 18:20:51 +08:00
if (action.user) {
2024-03-26 21:09:41 +08:00
state.user.balance = action.user.balance;
2024-04-19 18:20:51 +08:00
state.user.userId = action.user.userId;
2024-03-26 21:09:41 +08:00
state.user.nickname = action.user.nickname;
state.user.username = action.user.username;
state.user.hasUserInfo = action.user.hasUserInfo;
}
}
return {
...state
}
2024-03-26 11:54:30 +08:00
}
2024-03-26 21:09:41 +08:00
const [globalData, dispatch] = useReducer<Reducer<GlobalData, GlobalDataAction>>(globalDataReducer, {
user: {
balance: '0',
2024-04-19 18:20:51 +08:00
userId: '',
2024-03-26 21:09:41 +08:00
username: '',
nickname: '',
hasUserInfo: false
}
});
2025-04-11 16:20:46 +08:00
const [messageApi, messageContext] = message.useMessage();
2025-04-14 17:38:30 +08:00
// const [userId, setUserId] = useState(''); // 验证码ID
// const submit = async(phone:any,code:any) => {
// try{
// const formData = new URLSearchParams();
// formData.append('userId', userId);
// formData.append('phone', phone);
// formData.append('smsCode', code);
// const res = await updatePhone(formData.toString());
// console.log(res);
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// }catch (error: any) {
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// if (error.response) {
// const data = error.response.data;
// messageApi.open({
// type: 'error',
// content: data.msg ? data.msg : `${data.path}(${data.status})`,
// });
// } else {
// console.error(error)
// }
// }
// }
// const onFinish = async (values: any) => {
// // console.log('Success:', values);
// try {
// const res = await checkPhone(values.phone)
// // console.log(res);
// if(res.data == 'SUCCESS'){
// submit(values.phone,values.smsCode)
// }else{
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// messageApi.open({
// type: 'error',
// content: '手机号已被绑定,请更换手机号',
// });
// }
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// } catch (error: any) {
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// if (error.response) {
// const data = error.response.data;
// messageApi.open({
// type: 'error',
// content: data.msg ? data.msg : `${data.path}(${data.status})`,
// });
// } else {
// console.error(error)
// }
// }
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// };
// const [countdown, setCountdown] = useState(0); // 倒计时状态
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// const sendCode = async () => {
// try {
// // 验证手机号输入项
// await form.validateFields(['phone']);
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// setCountdown(120);
// console.log('发送验证码');
// const timer = setInterval(() => {
// setCountdown((prevCountdown) => {
// if (prevCountdown > 0) {
// return prevCountdown - 1;
// } else {
// clearInterval(timer);
// return 0;
// }
// });
// }, 1000);
// // 获取表单phone的值
// // const phone = form.getFieldValue('phone');
// await getCode(form.getFieldValue('phone'))
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// } catch (error: any) {
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// if (error.response) {
// const data = error.response.data;
// messageApi.open({
// type: 'error',
// content: data.msg ? data.msg : `${data.path}(${data.status})`,
// });
// } else {
// console.error(error)
// }
// }
2025-04-11 16:20:46 +08:00
2025-04-14 17:38:30 +08:00
// }
2025-04-11 16:20:46 +08:00
2025-03-28 09:44:48 +08:00
// const nav = useNavigate();
useEffect(() => {
get<any>({
messageApi,
url: '/api/user-info/get-user-self',
onSuccess({ data }: any) {
2025-04-14 16:14:27 +08:00
// console.log('嘻嘻嘻', data);
2025-04-11 16:20:46 +08:00
// setIsUpdateWxUsernamePhone(data.isUpdateWxUsernamePhone);
// if (data.isUpdateWxUsernamePhone == 1) {
2025-04-14 17:38:30 +08:00
// if (data.isUpdateWxUsernamePhone == 1) {
// setIsUpdateWxUsernamePhone(true);
// }
// setUserId(data.userId);
2025-03-28 09:44:48 +08:00
// const currentToken = sessionStorage.getItem('token');
sessionStorage.setItem('token', data.accessToken);
const token = sessionStorage.getItem('token');
if (token) {
// 若 token 存在,设置 isTokenFetched 为 true
setIsTokenFetched(true);
}
}
})
}, []);
// const token = sessionStorage.getItem('token');
// useEffect(() => {
// if (token) {
// setIsTokenFetched(true)
// }
// }, [token]);
// 如果 token 还未获取,显示加载页面
// if (!isTokenFetched) {
// return (
// <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
// <p>正在加载,请稍候...</p>
// </div>
// );
// }
if (isTokenFetched) {
return (
<div>
2025-04-11 16:20:46 +08:00
{messageContext}
2025-03-28 09:44:48 +08:00
<Provider store={store}>
<GlobalContext.Provider value={globalData}>
<GlobalDispatchContext.Provider value={dispatch}>
<Head />
<Body />
{/* <Foot/> */}
</GlobalDispatchContext.Provider>
</GlobalContext.Provider>
</Provider>
2025-04-14 17:38:30 +08:00
{/* <Modal
2025-04-11 16:20:46 +08:00
title="绑定手机号"
okText="确认"
cancelText="取消"
destroyOnClose={true}
footer={null}
open={isUpdateWxUsernamePhone}
// onOk={() => {
// setOrderDetailModal(false)
// }}
onCancel={() => {
setIsUpdateWxUsernamePhone(false);
}}
width={500}
centered
2025-04-14 17:38:30 +08:00
// zIndex={100}
2025-04-11 16:20:46 +08:00
>
<div className='phoneBox'>
<Form name="Form"
form={form}
onFinish={onFinish}
initialValues={{ softWare: '' }}
// style={{ maxWidth: 600 }}
>
<div className='phoneBoxInput'>
<div className='phoneBoxTitle'><span style={{ color: 'red' }}>*</span></div>
<Form.Item name="phone" label="" rules={[{ required: true, message: '请输入手机号' },
{
pattern: /^1[3-9]\d{9}$/,
message: '请输入有效的手机号'
}
]}>
<Input style={{
width: '300px',
height: '42px',
}} placeholder="请输入手机号" />
</Form.Item>
</div>
<div className='phoneBoxInput' style={{
position: 'relative',
// backgroundColor:'pink',
}}>
<div className='phoneBoxTitle'><span style={{ color: 'red' }}>*</span></div>
<Form.Item name="smsCode" label="" rules={[{ required: true, message: '请输入验证码' }]}>
<Input style={{
width: '300px',
height: '42px',
}} placeholder="请输入验证码" />
</Form.Item>
{countdown === 0 ? (
<div
style={{
position: 'absolute',
right: '0',
top: '0',
width: '90px',
height: '42px',
justifyContent: 'center',
alignItems: 'center',
display: 'flex',
cursor: 'pointer',
color: '#929292',
paddingRight: 10,
}}
onClick={sendCode}
>
</div>
) : (
<div
style={{
position: 'absolute',
right: '0',
top: '0',
width: '90px',
height: '42px',
justifyContent: 'center',
alignItems: 'center',
display: 'flex',
color: '#929292',
paddingRight: 10,
}}
>
{countdown}
</div>
)}
</div>
<div>
<Form.Item>
<Button type="primary" htmlType="submit">
</Button>
</Form.Item>
</div>
</Form>
</div>
2025-04-14 17:38:30 +08:00
</Modal> */}
2025-03-28 09:44:48 +08:00
</div>
2025-04-11 16:20:46 +08:00
2025-03-28 09:44:48 +08:00
);
}
2024-03-26 11:54:30 +08:00
2024-03-11 19:13:42 +08:00
};
export default App;