fix: 解决轨迹放大缩小

This commit is contained in:
wangzhongjie 2025-07-22 14:26:37 +08:00
parent 78436c39f7
commit 94d7ba9194
4 changed files with 26 additions and 4 deletions

View File

@ -35,7 +35,7 @@ export default struct SignalDisplayComponent {
}
aboutToDisappear(): void {
DifferentialAndSignal.onMsg(this.getMsg)
DifferentialAndSignal.offMsg(this.getMsg)
}
getMsg = (data: string) => {
@ -162,6 +162,7 @@ export default struct SignalDisplayComponent {
struct trajectoryComponent {
@State scaleNum: number = 100
scaleFn = async (num: number) => {
console.log("缩放传入数据", num.toString())
const scaleNum = this.scaleNum
if (scaleNum > 0 && scaleNum < 5000) {
this.scaleNum += num;
@ -172,6 +173,7 @@ struct trajectoryComponent {
if (scaleNum > 5000 && num < 0) {
this.scaleNum += num;
}
console.log("缩放数据", this.scaleNum.toString())
await examJudgeMapSetScaling(this.scaleNum);
}
getScaleNum = (): number => {
@ -206,7 +208,7 @@ struct trajectoryComponent {
})
Row() {
Image($rawfile('judge/big.png')).width(60).onClick(() => {
this.scaleFn(this.getScaleNum() - 1)
this.scaleFn(-this.getScaleNum())
})
Image($rawfile('judge/small.png')).width(60).onClick(() => {
this.scaleFn(this.getScaleNum())

View File

@ -12,6 +12,8 @@ export default class TcpClient {
private tcpSendNum: number = 0
private tcp: socket.TCPSocket = socket.constructTCPSocketInstance()
private events: Array<Function> = []
// 连接状态是否成功
private linkStatus: boolean = false
constructor() {
if (!TcpClient.instance) {
@ -58,6 +60,7 @@ export default class TcpClient {
}, timeout: 1000 * 15
})
.then(() => {
this.linkStatus = true
this.getMessage()
console.log(TCPTag, "tcp connect success")
return this.tcp.setExtraOptions({
@ -68,6 +71,7 @@ export default class TcpClient {
resolve(true)
})
.catch((err: BusinessError) => {
this.linkStatus = false
console.log(TCPTag, "tcp connect or keepAlive error: ", JSON.stringify(err))
console.log(TCPTag, "tcp 重启服务")
reject(err)
@ -76,6 +80,10 @@ export default class TcpClient {
}
getMessage() {
if (!this.linkStatus) {
console.log(TCPTag, '不允许获取消息: TCP未连接');
return;
}
this.tcp.on("message", value => {
let data = new DataView(value.message)
this.events.forEach(cb => {
@ -88,6 +96,7 @@ export default class TcpClient {
// 重新绑定tcp
async reBind() {
console.log(TCPTag, 'tcp rebind')
await this.close()
this.tcp = socket.constructTCPSocketInstance();
await this.bindTcp()
@ -109,11 +118,19 @@ export default class TcpClient {
// 监听tcp消息
onMsg(callback: Function) {
this.events.push(callback)
if (this.events.includes(callback)) {
console.log(TCPTag, '已经存在这个获取消息方法了');
return;
}
this.events.push(callback);
}
// 接收tcp消息
sendMsg(data: string): Promise<void> {
if (!this.linkStatus) {
console.log(TCPTag, '不允许发送: TCP未连接');
return Promise.reject(new Error('TCP connection is not established'));
}
return this.tcp?.send({
data
}).catch(async (err: BusinessError) => {

View File

@ -37,6 +37,8 @@ export default class UdpClient {
private messageEvents: Array<Function> = []
private errorEvents: Array<Function> = []
private dealMethod?: DealMethod<object>
// 连接状态
private linkStatus: boolean = false
// 绑定udp连接
bindUdp(): Promise<void> | undefined {

View File

@ -67,7 +67,8 @@ class differentialAndSignal {
getMessage() {
this.workerInstance.onmessage = (e: MessageEvents): void => {
if (e.data) {
// console.log(WorkerTag, "Worker 收到消息: " + e.data);
console.log(WorkerTag, "Worker 收到消息: " + e.data);
console.log(WorkerTag, "Worker 目前监听数量: " + this.events.length.toString());
this.events.forEach((callback) => {
callback(e.data);
});