Unverified Commit 33a54d12 authored by Licho's avatar Licho Committed by GitHub

feat: append receive data (#1785)

parent 7471ba6f
......@@ -17,65 +17,61 @@
*
*/
import { Input, Space } from "antd";
const { Search } = Input;
import { StateType } from "@/pages/DataStudio/model";
import { registerWatchTable, unRegisterWatchTable } from "@/pages/DataStudio/service";
import { connect } from "umi";
import { useEffect, useState, useRef } from "react";
import stompClient from "@/utils/stompClient"
import { Scrollbars } from 'react-custom-scrollbars';
import {Input, Space} from "antd";
import {StateType} from "@/pages/DataStudio/model";
import {registerWatchTable, unRegisterWatchTable} from "@/pages/DataStudio/service";
import {connect} from "umi";
import {useEffect, useRef, useState} from "react";
import stompClientUtil from "@/utils/stompClientUtil"
import {Scrollbars} from 'react-custom-scrollbars';
import CodeShow from "@/components/Common/CodeShow";
const {Search} = Input;
const StudioData = (props: any) => {
const { height, isActive } = props;
const {height, isActive} = props;
const [consoleInfo, setConsoleInfo] = useState<string>("");
const preConsoleInfo = useRef(consoleInfo)
const [tableName, setTableName] = useState<string>("");
const preTableNameRef = useRef(tableName)
const preTableName = preTableNameRef.current
let consoleHeight = (height - 37.6);
const id = Number(localStorage.getItem('dlink-tenantId'));
const onSearchName = (value: string) => {
unRegisterWatchTable({ id, table: preTableName }).then(res => {
unRegisterWatchTable({id, table: preTableNameRef.current}).then(res => {
setConsoleInfo("")
stompClient.unsubscribe();
registerWatchTable({ id, table: value }).then(res => {
stompClient.subObj = stompClient.mqClient.subscribe(res.msg, (res) => {
setConsoleInfo(consoleInfo + res.body)
stompClientUtil.unsubscribe();
registerWatchTable({id, table: value}).then(res => {
stompClientUtil.subScription = stompClientUtil.stompClient.subscribe(res.msg, (res: any) => {
preConsoleInfo.current = preConsoleInfo.current + "\n" + res.body
if (preConsoleInfo.current.length > 1024 * 1024) {
preConsoleInfo.current = preConsoleInfo.current.substring(1024, preConsoleInfo.current.length)
}
setConsoleInfo(preConsoleInfo.current);
})
})
})
setTableName(value)
};
useEffect(() => {
stompClient.con();
stompClientUtil.connect();
}, [isActive])
return (<div style={{ width: '100%' }}>
<Space direction="horizontal" style={{ margin: 10 }}>
<Search placeholder="请输入表名" onSearch={onSearchName} style={{ width: 200 }} />
return (<div style={{width: '100%'}}>
<Space direction="horizontal" style={{margin: 10}}>
<Search placeholder="table name" onSearch={onSearchName} style={{width: 200}}/>
</Space>
<Scrollbars style={{ height: consoleHeight }}>
{/* <CodeShow code={consoleInfo} language='Markdown' height={height} theme="vs" /> */}
<CodeShow code={JSON.stringify((consoleInfo ? consoleInfo : ""), null, "\t")} language='json'
height={height} theme="vs-dark" />
<Scrollbars style={{height: consoleHeight}}>
<CodeShow code={consoleInfo} language='text' height={height} theme="vs-dark" />
</Scrollbars>
</div>)
};
export default connect(({ Studio }: { Studio: StateType }) => ({
export default connect(({Studio}: { Studio: StateType }) => ({
current: Studio.current,
}))(StudioData);
import { reject } from "lodash";
import Stomp, { Subscription } from "stompjs";
interface SocketRes {
body: string,
ack?: () => {},
command?: string,
headers?: object,
nack?: () => {},
}
export let stompClient: Stomp.Client;
let connetStatus = false;
class MyStompClient {
mqClient: Stomp.Client;
connetStatus: boolean;
subObj: Subscription;
constructor() {
const baseUrl = "ws://127.0.0.1:8888/stomp";
let socket = new WebSocket(baseUrl);
this.mqClient = Stomp.over(socket);
this.connetStatus = false;
this.subObj = { id: "", unsubscribe: () => { } };
this.con();
}
con() {
this.mqClient.connect(
{},
() => {
this.connetStatus = true;
console.log("connectsuccess>>>>>>>>>>>>>>>>>>>");
},
(err: any) => {
console.log("error");
console.log(err);
}
);
}
close() {
if (this.mqClient) {
this.mqClient.disconnect(() => {
console.log("============connect release============");
this.connetStatus = false;
});
}
}
subscribe(topicurl: string) {
return new Promise<string>((resolve, reject) => {
this.subObj = this.mqClient.subscribe(topicurl, (res: SocketRes) => {
resolve(res.body)
})
}).catch(err => {
console.log(err);
reject(err)
})
}
unsubscribe() {
this.subObj.unsubscribe()
this.subObj = { id: "", unsubscribe: () => { } };
}
}
export default new MyStompClient()
import Stomp, { Subscription } from "stompjs";
class StompClientUtil {
stompClient: Stomp.Client;
connectStatus: boolean;
subScription: Subscription;
constructor() {
const baseUrl = "ws://127.0.0.1:8888/stomp";
const socket = new WebSocket(baseUrl);
this.stompClient = Stomp.over(socket);
this.connectStatus = false;
this.subScription = { id: "", unsubscribe: () => { } };
this.connect();
}
connect() {
this.stompClient.connect(
{},
() => {
this.connectStatus = true;
console.log("connect success>>>>>>>>>>>>>>>>>>>");
},
(err: any) => {
console.log("error");
console.log(err);
}
);
}
close() {
if (this.stompClient) {
this.stompClient.disconnect(() => {
console.log("============connect release============");
this.connectStatus = false;
});
}
}
unsubscribe() {
this.subScription.unsubscribe()
this.subScription = { id: "", unsubscribe: () => { } };
}
}
export default new StompClientUtil()
......@@ -67,7 +67,6 @@
<javax.mail>1.6.2</javax.mail>
<jaxb.version>2.3.0</jaxb.version>
<jedis.version>2.9.0</jedis.version>
<jedis.version>2.9.0</jedis.version>
<junit5.version>5.9.1</junit5.version>
<knife4j.version>3.0.3</knife4j.version>
<log4j.version>2.19.0</log4j.version>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment