问题修改
This commit is contained in:
		
							parent
							
								
									5830ad80fd
								
							
						
					
					
						commit
						74c78e4184
					
				| @ -3,7 +3,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; | ||||
| import { window } from '@kit.ArkUI'; | ||||
| import Logger, { LoggerLevel, LoggerMode } from '../utils/Logger'; | ||||
| import { text } from '@kit.ArkGraphics2D'; | ||||
| import { getDeviceId, requestPermission } from '../utils/System'; | ||||
| import { requestPermission } from '../utils/System'; | ||||
| import { commandService } from '../utils/CommandService'; | ||||
| 
 | ||||
| const DOMAIN = 0x0000; | ||||
| @ -36,6 +36,7 @@ export default class EntryAbility extends UIAbility { | ||||
|     await requestPermission(this.context, ["ohos.permission.CAMERA", "ohos.permission.FILE_ACCESS_MANAGER"]) | ||||
| 
 | ||||
|     windowStage.loadContent('pages/Login', (err) => { | ||||
|       // windowStage.loadContent('pages/control/Index', (err) => { | ||||
|       if (err.code) { | ||||
|         hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); | ||||
|         return; | ||||
|  | ||||
| @ -56,11 +56,6 @@ struct Index { | ||||
|   @StorageLink("account") account: string = '' | ||||
|   @StorageLink("password") password: string = '' | ||||
|   @StorageLink("remember") remember: boolean = false | ||||
|   @State options: SelectOption[] = [ | ||||
|     { value: "1号线" }, | ||||
|     { value: "2号线" }, | ||||
|     { value: "3号线" } | ||||
|   ] | ||||
|   private controller: CustomDialogController = new CustomDialogController({ | ||||
|     builder: Loading(), | ||||
|     autoCancel: false, | ||||
|  | ||||
| @ -22,7 +22,7 @@ class CusButtonModifier implements AttributeModifier<RowAttribute> { | ||||
| 
 | ||||
| @Component | ||||
| export struct CusButton { | ||||
|   public text?: string | ||||
|   @Prop text: string = "" | ||||
|   public normalImage?: Resource | ||||
|   public activeImage?: Resource | ||||
|   public style?: ButtonStyle | ||||
|  | ||||
| @ -5,6 +5,7 @@ import { CusMenuItem } from './components/MenuItem' | ||||
| import { RebootControl } from './utils/Control' | ||||
| import { router } from '@kit.ArkUI' | ||||
| import { CommandCode, commandService } from '../../utils/CommandService' | ||||
| import Logger from '../../utils/Logger' | ||||
| 
 | ||||
| function TouchEventWrapper(callback: Function) { | ||||
|   let tick: number = -1 | ||||
| @ -34,6 +35,7 @@ const button: string[][] = | ||||
| struct Control { | ||||
|   @State select: number = 0 | ||||
|   @State line: API.VcInspectionLine[] = AppStorage.get("line") || [] | ||||
|   @State mode: number = 0 | ||||
|   private control: RebootControl = new RebootControl("ws://192.168.7.101:10000") | ||||
|   private forward: (event: TouchEvent) => void = TouchEventWrapper(() => { | ||||
|     this.control.forward() | ||||
| @ -50,6 +52,9 @@ struct Control { | ||||
| 
 | ||||
|   async aboutToAppear(): Promise<void> { | ||||
|     await this.control.init() | ||||
|     this.control.getMode().then(res => { | ||||
|       Logger.info(res) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   aboutToDisappear(): void { | ||||
|  | ||||
| @ -1,16 +1,28 @@ | ||||
| import Logger from '../../../utils/Logger' | ||||
| import { TaskPool } from '../../../utils/TaskPool' | ||||
| import { WebsocketClient } from '../../../utils/WebsocketUtils' | ||||
| import { EventType, WebsocketClient } from '../../../utils/WebsocketUtils' | ||||
| import { VehicleBean, VehicleInfo } from './Model' | ||||
| import { BusinessError } from '@kit.BasicServicesKit' | ||||
| 
 | ||||
| const Tag = "RebootControl" | ||||
| 
 | ||||
| interface MessageResult { | ||||
|   mode: number | ||||
|   success: number | ||||
| } | ||||
| 
 | ||||
| export class RebootControl { | ||||
|   private service: WebsocketClient | ||||
|   private taskPool: TaskPool<boolean> = new TaskPool() | ||||
|   private callback: Function[] = [] | ||||
| 
 | ||||
|   constructor(url: string) { | ||||
|     this.service = new WebsocketClient(url) | ||||
|     this.service.subscribe(EventType.Message, (message: string) => { | ||||
|       this.callback.forEach(cb => { | ||||
|         cb(message) | ||||
|       }) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   private addTask(data: string) { | ||||
| @ -29,6 +41,26 @@ export class RebootControl { | ||||
|     return this.service.connect() | ||||
|   } | ||||
| 
 | ||||
|   getMode() { | ||||
|     return new Promise<MessageResult>((resolve, reject) => { | ||||
|       this.service.send(JSON.stringify({ | ||||
|         "cmmand": "getMode" | ||||
|       })).then(() => { | ||||
|         let cb = (msg: string) => { | ||||
|           resolve(JSON.parse(msg)) | ||||
|           this.callback = this.callback.filter(item => item != cb) | ||||
|         } | ||||
|         this.callback.push(cb) | ||||
|       }).catch((err: BusinessError) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   setMode(mode: number) { | ||||
|     return this.service.send(JSON.stringify({ mode })) | ||||
|   } | ||||
| 
 | ||||
|   destroy() { | ||||
|     return this.service.close() | ||||
|   } | ||||
|  | ||||
| @ -67,7 +67,7 @@ struct Home { | ||||
| 
 | ||||
|   async getData() { | ||||
|     let deviceId = await getDeviceId() | ||||
|     let lineId = this.select === -1 ? undefined : this.line[this.select].id | ||||
|     let lineId = this.select === -1 ? undefined : this.line[this.select].lineId | ||||
|     getPadIndexInfoUsingGet({ | ||||
|       imei: deviceId, | ||||
|       lineId | ||||
|  | ||||
| @ -54,8 +54,8 @@ export async function request<T>( | ||||
|         connectTimeout: 1000 * 6, //超时时间 | ||||
|       }).then(async (data) => { | ||||
|       let result = data.result as Response | ||||
|       Logger.info(Tag, `请求接口 ${url} 成功, 请求结果: `, JSON.stringify(data.result)) | ||||
|       if (result.code === 200) { | ||||
|         Logger.info(Tag, `请求接口 ${url} 成功, 请求结果: `, JSON.stringify(data.result)) | ||||
|         resolve(data.result as T) | ||||
|       } else { | ||||
|         Logger.error(Tag, `请求接口 ${url} 失败, 失败原因: `, result.msg) | ||||
|  | ||||
| @ -27,12 +27,12 @@ export class WebsocketClient { | ||||
|     return new Promise<void>((resolve, reject) => { | ||||
|       this.close().then(() => { | ||||
|         this.socket = webSocket.createWebSocket() | ||||
|         return this.connect() | ||||
|       }).then(resolve).catch((err: BusinessError) => { | ||||
|         this.connect().then(resolve).catch((err: BusinessError) => { | ||||
|           Logger.error(Tag, JSON.stringify(err)) | ||||
|           reject(err) | ||||
|         }) | ||||
|       }) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   connect(): Promise<void> { | ||||
| @ -43,6 +43,7 @@ export class WebsocketClient { | ||||
|           if (err) { | ||||
|             this.errorCallback?.(err) | ||||
|           } else { | ||||
|             Logger.info(Tag, "receive", message) | ||||
|             this.messageCallback.forEach(cb => { | ||||
|               cb(this.deal ? this.deal(message) : message) | ||||
|             }) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user