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