diff --git a/package-lock.json b/package-lock.json
index 5821feb..d195b67 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,7 @@
"@ant-design/cssinjs": "^1.19.1",
"antd": "^5.15.2",
"axios": "^1.6.7",
+ "event-source-polyfill": "^1.0.31",
"localforage": "^1.10.0",
"match-sorter": "^6.3.4",
"pinyin-pro": "^3.19.6",
@@ -22,6 +23,7 @@
"sort-by": "^1.2.0"
},
"devDependencies": {
+ "@types/event-source-polyfill": "^1.0.5",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.0.2",
@@ -1438,6 +1440,12 @@
"integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==",
"dev": true
},
+ "node_modules/@types/event-source-polyfill": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmmirror.com/@types/event-source-polyfill/-/event-source-polyfill-1.0.5.tgz",
+ "integrity": "sha512-iaiDuDI2aIFft7XkcwMzDWLqo7LVDixd2sR6B4wxJut9xcp/Ev9bO4EFg4rm6S9QxATLBj5OPxdeocgmhjwKaw==",
+ "dev": true
+ },
"node_modules/@types/json-schema": {
"version": "7.0.15",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
@@ -2444,6 +2452,11 @@
"node": ">=0.10.0"
}
},
+ "node_modules/event-source-polyfill": {
+ "version": "1.0.31",
+ "resolved": "https://registry.npmmirror.com/event-source-polyfill/-/event-source-polyfill-1.0.31.tgz",
+ "integrity": "sha512-4IJSItgS/41IxN5UVAVuAyczwZF7ZIEsM1XAoUzIHA6A+xzusEZUutdXz2Nr+MQPLxfTiCvqE79/C8HT8fKFvA=="
+ },
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
diff --git a/package.json b/package.json
index 8057907..fffa6a3 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"@ant-design/cssinjs": "^1.19.1",
"antd": "^5.15.2",
"axios": "^1.6.7",
+ "event-source-polyfill": "^1.0.31",
"localforage": "^1.10.0",
"match-sorter": "^6.3.4",
"pinyin-pro": "^3.19.6",
@@ -24,6 +25,7 @@
"sort-by": "^1.2.0"
},
"devDependencies": {
+ "@types/event-source-polyfill": "^1.0.5",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.0.2",
diff --git a/src/components/card/CardProj.tsx b/src/components/card/CardProj.tsx
index 8e53caa..92046f9 100644
--- a/src/components/card/CardProj.tsx
+++ b/src/components/card/CardProj.tsx
@@ -88,8 +88,6 @@ export default function CardProj(props: any) {
}
useEffect(() => {
- console.log('查找图片', data);
-
const charge = props.item.pay.charge.split(':')[0];
let chargeName = '';
if (charge == ProjChargeType.ALL) {
diff --git a/src/components/list/ListProj.tsx b/src/components/list/ListProj.tsx
index 9db2d0b..84d4f46 100644
--- a/src/components/list/ListProj.tsx
+++ b/src/components/list/ListProj.tsx
@@ -67,7 +67,6 @@ export default function ListProj() {
setIsLoading(true);
},
onSuccess({ data }) {
- console.log('看看结果', data);
setPage(data.page);
setTotal(data.total);
setProjs(data.rows);
@@ -151,7 +150,6 @@ export default function ListProj() {
reqData(1);
renderCategory();
}
- console.log(page);
setTimeout(() => {
setShowPage(true)
diff --git a/src/components/payment/Payment.tsx b/src/components/payment/Payment.tsx
index 493ddf0..b830867 100644
--- a/src/components/payment/Payment.tsx
+++ b/src/components/payment/Payment.tsx
@@ -173,7 +173,6 @@ export default function Payment(props: IPaymentProps) {
const renderMoney = () => {
- console.log(form.getFieldValue('rechargeMoney'))
if (isRechargeMoneyEdit) {
return (
@@ -363,7 +362,6 @@ export default function Payment(props: IPaymentProps) {
style={{ marginBottom: '0' }}
valuePropName="fileList"
getValueFromEvent={(e: any) => {
- console.log(e);
if (e.file.status === 'done') {
rechargeVoucherArray.push(e.file.response.data.fileId);
setRechargeVoucherArray(rechargeVoucherArray);
diff --git a/src/components/recharge/RechargeHead.tsx b/src/components/recharge/RechargeHead.tsx
index b91f6a3..5ab73e3 100644
--- a/src/components/recharge/RechargeHead.tsx
+++ b/src/components/recharge/RechargeHead.tsx
@@ -1,11 +1,43 @@
import './recharge-head.css';
import Payment from "../payment/Payment.tsx";
-import { Modal } from "antd";
-import { useState } from "react";
+import { Modal, message } from "antd";
+import { useEffect, useState, useContext } from "react";
+import { Axios, DevUserId } from "../../util/AjaxUtils.ts";
+import { EventSourcePolyfill } from 'event-source-polyfill';
+import { GlobalContext, GlobalDispatchContext, reloadUser } from "../../context/GlobalContext.ts";
+
+type SseMsg = {
+ msg: string;
+ type: string;
+}
export default function RechargeHead() {
const [isPaymentModalOpen, setIsPaymentModalOpen] = useState(false);
+ const globalContext = useContext(GlobalContext);
+ const globalDispatchContext = useContext(GlobalDispatchContext);
+ const [messageApi] = message.useMessage();
+
+ // sse
+ const initSse = () => {
+ const evtSource = new EventSourcePolyfill(`${Axios.defaults.baseURL}/api/sse/connect`, {
+ headers: {
+ 'X-USER-ID': DevUserId
+ }
+ });
+ evtSource.onmessage = function (event:any) {
+ const msg = JSON.parse(event.data) as SseMsg;
+ if(msg.type === 'AMOUNT_RECEIVED') {
+ reloadUser(messageApi, globalDispatchContext).then(() => {
+ setIsPaymentModalOpen(false);
+ });
+ }
+ };
+ }
+
+ useEffect(() => {
+ initSse();
+ }, [globalContext.user])
return (
<>
diff --git a/src/layout/head/Head.tsx b/src/layout/head/Head.tsx
index 5e73c98..d0e1437 100644
--- a/src/layout/head/Head.tsx
+++ b/src/layout/head/Head.tsx
@@ -16,6 +16,7 @@ import { reMenuActive } from '../../util/cache';
// import BelongPeople from '../../components/BelongPeople/BelongPeople.tsx'
import BelongPeople from '../../components/BelongPeople/BelongPeople.tsx'
import ContactPeople from '../../components/ContactPeople/ContactPeople.tsx'
+
export default function Head() {
const globalContext = useContext(GlobalContext);
const globalDispatchContext = useContext(GlobalDispatchContext);
@@ -53,6 +54,7 @@ export default function Head() {
applyContactPhone: '',
applyContactCompany: ''
})
+
useEffect(() => {
reloadUser(messageApi, globalDispatchContext).then((data) => {
if (!data.hasUserInfo) {
@@ -182,13 +184,13 @@ export default function Head() {
title="个人信息"
footer={false}
onCancel={() => {
- if (!globalContext.user.hasUserInfo ) {
+ if (!globalContext.user.hasUserInfo) {
messageApi.info('请完善个人信息');
return;
}
setIsSelfModalOpen(false)
// console.log('用户信息',globalContext.user.hasUserInfo);
-
+
}}>
{
modal.confirm({
diff --git a/src/route/Home/Home.tsx b/src/route/Home/Home.tsx
index b0b60c6..72dd741 100644
--- a/src/route/Home/Home.tsx
+++ b/src/route/Home/Home.tsx
@@ -19,7 +19,6 @@ export default function Home() {
// setListType(state.listType)
// }
// console.log('传递过来的',listType);
- console.log('页面判断',indexListContext.type);
return (
diff --git a/src/route/index/Index.tsx b/src/route/index/Index.tsx
index 7f0a065..3cd24ff 100644
--- a/src/route/index/Index.tsx
+++ b/src/route/index/Index.tsx
@@ -200,7 +200,6 @@ export default function Index() {
const [showSearchBox, setShowSearchBox] = useState(true)
useEffect(() => {
// const nowname = sessionStorage.getItem('now')
- console.log('路由名字', location.pathname);
if (location.pathname.includes('/home')) {
setNow('首页')
setPathArray([{ title: '首页' }])
@@ -331,7 +330,6 @@ export default function Index() {
}, []);
useEffect(() => {
- console.log('监听type', type);
if (location.pathname.includes('/home')) {
nav('/home', {
state: {
diff --git a/src/util/AjaxUtils.ts b/src/util/AjaxUtils.ts
index e6656e2..dc7c0ee 100644
--- a/src/util/AjaxUtils.ts
+++ b/src/util/AjaxUtils.ts
@@ -1,15 +1,15 @@
-import axios, {AxiosRequestConfig, AxiosResponse} from "axios";
-import type {MessageInstance} from "antd/es/message/interface";
+import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
+import type { MessageInstance } from "antd/es/message/interface";
export const Axios = axios;
-axios.defaults.baseURL = 'http://192.168.0.15:7025/copyright';
+// axios.defaults.baseURL = 'http://192.168.0.15:7025/copyright';
// axios.defaults.baseURL = 'http://192.168.43.145:7025/copyright';
-// axios.defaults.baseURL = 'http://127.0.0.1:7025/copyright';
+axios.defaults.baseURL = 'http://127.0.0.1:7025/copyright';
// axios.defaults.baseURL = 'https://www.aimzhu.com/copyright';
// axios.defaults.baseURL = '/copyright';
-// export const WebSocketBaseUrl: string = 'ws://127.0.0.1:7025/copyright';
-export const WebSocketBaseUrl: string = 'ws://192.168.0.15:7025/copyright';
+export const WebSocketBaseUrl: string = 'ws://127.0.0.1:7025/copyright';
+// export const WebSocketBaseUrl: string = 'ws://192.168.0.15:7025/copyright';
// export const WebSocketBaseUrl: string = '/copyright';
export const DevUserId: string = '80d3365e-0597-4988-979e-18ef1c3ec671'; // 18634604067
// export const DevUserId: string = 'eb9a82a6-6ed3-4ba0-90e6-d836cefff915'; // 15042810561
@@ -34,13 +34,12 @@ export interface IDictionary {
}
axios.interceptors.request.use(config => {
- if (config.method === 'get') {
- config.data = {unused: 0} // 这个是关键点,解决get 请求添加不上content_type
- }
- config.headers['X-USER-ID'] = DevUserId;
- return config
+ if (config.method === 'get') {
+ config.data = { unused: 0 } // 这个是关键点,解决get 请求添加不上content_type
}
-);
+ config.headers['X-USER-ID'] = DevUserId;
+ return config
+});
export function websocketUrl() {
if (WebSocketBaseUrl.startsWith('ws')) {
@@ -70,7 +69,7 @@ export async function listDictionary(parentId: string, messageApi: MessageInstan
get({
messageApi,
url: `/api/data/listbyparentid/${parentId}`,
- onSuccess({data}) {
+ onSuccess({ data }) {
resolve(data);
}
})