新增SSE
This commit is contained in:
parent
8b2acb15c5
commit
06c26fb6f7
13
package-lock.json
generated
13
package-lock.json
generated
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -173,7 +173,6 @@ export default function Payment(props: IPaymentProps) {
|
||||
|
||||
|
||||
const renderMoney = () => {
|
||||
console.log(form.getFieldValue('rechargeMoney'))
|
||||
if (isRechargeMoneyEdit) {
|
||||
return (
|
||||
<div>
|
||||
@ -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);
|
||||
|
@ -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 (
|
||||
<>
|
||||
|
@ -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);
|
||||
|
||||
|
||||
}}>
|
||||
<UserEdit handleConfirm={(data) => {
|
||||
modal.confirm({
|
||||
|
@ -19,7 +19,6 @@ export default function Home() {
|
||||
// setListType(state.listType)
|
||||
// }
|
||||
// console.log('传递过来的',listType);
|
||||
console.log('页面判断',indexListContext.type);
|
||||
|
||||
|
||||
return (
|
||||
|
@ -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: {
|
||||
|
@ -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<IDictionary[]>({
|
||||
messageApi,
|
||||
url: `/api/data/listbyparentid/${parentId}`,
|
||||
onSuccess({data}) {
|
||||
onSuccess({ data }) {
|
||||
resolve(data);
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user