fix: 解决轨迹放大缩小
This commit is contained in:
		
							parent
							
								
									78436c39f7
								
							
						
					
					
						commit
						94d7ba9194
					
				| @ -35,7 +35,7 @@ export default struct SignalDisplayComponent { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   aboutToDisappear(): void { |   aboutToDisappear(): void { | ||||||
|     DifferentialAndSignal.onMsg(this.getMsg) |     DifferentialAndSignal.offMsg(this.getMsg) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getMsg = (data: string) => { |   getMsg = (data: string) => { | ||||||
| @ -162,6 +162,7 @@ export default struct SignalDisplayComponent { | |||||||
| struct trajectoryComponent { | struct trajectoryComponent { | ||||||
|   @State scaleNum: number = 100 |   @State scaleNum: number = 100 | ||||||
|   scaleFn = async (num: number) => { |   scaleFn = async (num: number) => { | ||||||
|  |     console.log("缩放传入数据", num.toString()) | ||||||
|     const scaleNum = this.scaleNum |     const scaleNum = this.scaleNum | ||||||
|     if (scaleNum > 0 && scaleNum < 5000) { |     if (scaleNum > 0 && scaleNum < 5000) { | ||||||
|       this.scaleNum += num; |       this.scaleNum += num; | ||||||
| @ -172,6 +173,7 @@ struct trajectoryComponent { | |||||||
|     if (scaleNum > 5000 && num < 0) { |     if (scaleNum > 5000 && num < 0) { | ||||||
|       this.scaleNum += num; |       this.scaleNum += num; | ||||||
|     } |     } | ||||||
|  |     console.log("缩放数据", this.scaleNum.toString()) | ||||||
|     await examJudgeMapSetScaling(this.scaleNum); |     await examJudgeMapSetScaling(this.scaleNum); | ||||||
|   } |   } | ||||||
|   getScaleNum = (): number => { |   getScaleNum = (): number => { | ||||||
| @ -206,7 +208,7 @@ struct trajectoryComponent { | |||||||
|         }) |         }) | ||||||
|       Row() { |       Row() { | ||||||
|         Image($rawfile('judge/big.png')).width(60).onClick(() => { |         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(() => { |         Image($rawfile('judge/small.png')).width(60).onClick(() => { | ||||||
|           this.scaleFn(this.getScaleNum()) |           this.scaleFn(this.getScaleNum()) | ||||||
|  | |||||||
| @ -12,6 +12,8 @@ export default class TcpClient { | |||||||
|   private tcpSendNum: number = 0 |   private tcpSendNum: number = 0 | ||||||
|   private tcp: socket.TCPSocket = socket.constructTCPSocketInstance() |   private tcp: socket.TCPSocket = socket.constructTCPSocketInstance() | ||||||
|   private events: Array<Function> = [] |   private events: Array<Function> = [] | ||||||
|  |   // 连接状态是否成功 | ||||||
|  |   private linkStatus: boolean = false | ||||||
| 
 | 
 | ||||||
|   constructor() { |   constructor() { | ||||||
|     if (!TcpClient.instance) { |     if (!TcpClient.instance) { | ||||||
| @ -58,6 +60,7 @@ export default class TcpClient { | |||||||
|         }, timeout: 1000 * 15 |         }, timeout: 1000 * 15 | ||||||
|       }) |       }) | ||||||
|         .then(() => { |         .then(() => { | ||||||
|  |           this.linkStatus = true | ||||||
|           this.getMessage() |           this.getMessage() | ||||||
|           console.log(TCPTag, "tcp connect success") |           console.log(TCPTag, "tcp connect success") | ||||||
|           return this.tcp.setExtraOptions({ |           return this.tcp.setExtraOptions({ | ||||||
| @ -68,6 +71,7 @@ export default class TcpClient { | |||||||
|           resolve(true) |           resolve(true) | ||||||
|         }) |         }) | ||||||
|         .catch((err: BusinessError) => { |         .catch((err: BusinessError) => { | ||||||
|  |           this.linkStatus = false | ||||||
|           console.log(TCPTag, "tcp connect or keepAlive error: ", JSON.stringify(err)) |           console.log(TCPTag, "tcp connect or keepAlive error: ", JSON.stringify(err)) | ||||||
|           console.log(TCPTag, "tcp 重启服务") |           console.log(TCPTag, "tcp 重启服务") | ||||||
|           reject(err) |           reject(err) | ||||||
| @ -76,6 +80,10 @@ export default class TcpClient { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getMessage() { |   getMessage() { | ||||||
|  |     if (!this.linkStatus) { | ||||||
|  |       console.log(TCPTag, '不允许获取消息: TCP未连接'); | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|     this.tcp.on("message", value => { |     this.tcp.on("message", value => { | ||||||
|       let data = new DataView(value.message) |       let data = new DataView(value.message) | ||||||
|       this.events.forEach(cb => { |       this.events.forEach(cb => { | ||||||
| @ -88,6 +96,7 @@ export default class TcpClient { | |||||||
| 
 | 
 | ||||||
|   // 重新绑定tcp |   // 重新绑定tcp | ||||||
|   async reBind() { |   async reBind() { | ||||||
|  |     console.log(TCPTag, 'tcp rebind') | ||||||
|     await this.close() |     await this.close() | ||||||
|     this.tcp = socket.constructTCPSocketInstance(); |     this.tcp = socket.constructTCPSocketInstance(); | ||||||
|     await this.bindTcp() |     await this.bindTcp() | ||||||
| @ -109,11 +118,19 @@ export default class TcpClient { | |||||||
| 
 | 
 | ||||||
|   // 监听tcp消息 |   // 监听tcp消息 | ||||||
|   onMsg(callback: Function) { |   onMsg(callback: Function) { | ||||||
|     this.events.push(callback) |     if (this.events.includes(callback)) { | ||||||
|  |       console.log(TCPTag, '已经存在这个获取消息方法了'); | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |     this.events.push(callback); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // 接收tcp消息 |   // 接收tcp消息 | ||||||
|   sendMsg(data: string): Promise<void> { |   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({ |     return this.tcp?.send({ | ||||||
|       data |       data | ||||||
|     }).catch(async (err: BusinessError) => { |     }).catch(async (err: BusinessError) => { | ||||||
|  | |||||||
| @ -37,6 +37,8 @@ export default class UdpClient { | |||||||
|   private messageEvents: Array<Function> = [] |   private messageEvents: Array<Function> = [] | ||||||
|   private errorEvents: Array<Function> = [] |   private errorEvents: Array<Function> = [] | ||||||
|   private dealMethod?: DealMethod<object> |   private dealMethod?: DealMethod<object> | ||||||
|  |   // 连接状态 | ||||||
|  |   private linkStatus: boolean = false | ||||||
| 
 | 
 | ||||||
|   // 绑定udp连接 |   // 绑定udp连接 | ||||||
|   bindUdp(): Promise<void> | undefined { |   bindUdp(): Promise<void> | undefined { | ||||||
|  | |||||||
| @ -67,7 +67,8 @@ class differentialAndSignal { | |||||||
|   getMessage() { |   getMessage() { | ||||||
|     this.workerInstance.onmessage = (e: MessageEvents): void => { |     this.workerInstance.onmessage = (e: MessageEvents): void => { | ||||||
|       if (e.data) { |       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) => { |         this.events.forEach((callback) => { | ||||||
|           callback(e.data); |           callback(e.data); | ||||||
|         }); |         }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user