1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import deviceManager from '@ohos.distributedHardware.deviceManager'; 16let dmClass; 17let TAG = "[DeviceManagerUI:PinDialog]==>" 18@Entry 19@Component 20struct dialogPlusPage { 21 @State messageTitle: string = 'PIN码连接' 22 @State messageTips: string = '请在设备端输入连接码进行验证' 23 @State pinCode: string = "" 24 @State allow: string = '允许' 25 @State cancel: string = '取消' 26 @State isShow: boolean = true 27 @State win: any = "" 28 @State ACTION_CANCEL_PINCODE_DISPLAY: number = 3 29 30 aboutToAppear(){ 31 this.initStatue() 32 console.log("aboutToAppear execute") 33 this.win = globalThis.extensionWin 34 this.pinCode = globalThis.abilityWant.parameters["PinCode"] 35 } 36 37 aboutToDisappear() { 38 console.log(TAG + "aboutToDisappear executed") 39 if (dmClass != null) { 40 dmClass.off('uiStateChange') 41 dmClass.release() 42 dmClass = null 43 } 44 } 45 46 initStatue() { 47 console.log('initStatue' + "windowNum:" + globalThis.windowNum) 48 if (dmClass) { 49 console.log('deviceManager exist') 50 return 51 } 52 deviceManager.createDeviceManager('com.ohos.devicemanagerui', (err, dm) => { 53 if (err) { 54 console.log("createDeviceManager err:" + JSON.stringify(err) + ' --fail:' + JSON.stringify(dm)) 55 return 56 } 57 dmClass = dm 58 dmClass.on('uiStateChange', (data) => { 59 console.log("uiStateChange executed, dialog closed" + JSON.stringify(data)) 60 var tmpStr = JSON.parse(data.param) 61 this.isShow = tmpStr.verifyFailed 62 console.log("uiStateChange executed, dialog closed" + this.isShow) 63 if (!this.isShow) { 64 this.destruction() 65 } 66 }) 67 }); 68 } 69 70 setUserOperation(operation) { 71 console.log('setUserOperation: ' + operation) 72 if(dmClass == null) { 73 console.log('setUserOperation: ' + 'dmClass null') 74 return; 75 } 76 dmClass.setUserOperation(operation, "extra") 77 } 78 79 destruction() { 80 this.win.destroy() 81 globalThis.extensionContext.terminateSelf() 82 } 83 84 build() { 85 Row() { 86 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 87 Column() { 88 Text(this.messageTitle) 89 .fontSize(35) 90 .fontWeight(FontWeight.Bold) 91 Text(this.messageTips) 92 .fontSize(30) 93 .fontWeight(FontWeight.Medium) 94 Row() {}.height('2%') 95 Text(this.pinCode) 96 .fontSize(30) 97 .fontWeight(FontWeight.Bold) 98 Row() {}.height('2%') 99 Button(this.cancel) 100 .fontSize(25) 101 .fontColor(0xffffff) 102 .border({ width: 1.5, color: (0xe7e7e7), radius: 50 }) 103 .fontWeight(FontWeight.Normal) 104 .onClick(() => { 105 this.setUserOperation(this.ACTION_CANCEL_PINCODE_DISPLAY) 106 this.destruction() 107 }) 108 }.width('100%') 109 }.width('100%') 110 .height('100%') 111 }.width('100%') 112 } 113}