From f9e7112f8fb1cf68e17177e691f45150667a662e Mon Sep 17 00:00:00 2001 From: tangcp-ub Date: Thu, 20 Oct 2022 19:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8F=8A=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tangcp-ub --- entry/src/main/ets/view/DeviceDialog.ets | 81 ++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 entry/src/main/ets/view/DeviceDialog.ets diff --git a/entry/src/main/ets/view/DeviceDialog.ets b/entry/src/main/ets/view/DeviceDialog.ets new file mode 100644 index 0000000..c305f14 --- /dev/null +++ b/entry/src/main/ets/view/DeviceDialog.ets @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hardware_deviceManager from '@ohos.distributedHardware.deviceManager' +import Logger from '../model/Logger' + +const TAG: string = 'DeviceDialog' + +@CustomDialog +export struct DeviceDialog { + controller: CustomDialogController + private deviceLists: Array = [] + private selectedIndex: number = 0 + private that: any + private selectedIndexChange: (selectedIndex: number) => void//经实际测试,这里似乎写不写后面的传参类型都可以 + + build() { + Column() { + Text($r('app.string.choiceDevice')) + .fontSize(30) + .width('100%') + .fontColor(Color.Black) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Bold) + List() { + ForEach(this.deviceLists, (item, index) => { + ListItem() { + Row() { + Text(item.deviceName) + .fontSize(21) + .width('90%') + .fontColor(Color.Black) + Image(index === this.selectedIndex ? $r('app.media.checked') : $r('app.media.uncheck')) + .width('8%') + .objectFit(ImageFit.Contain) + } + .height(55) + .onClick(() => { + Logger.info(TAG, `select device: ${item.deviceId}`) + if (index === this.selectedIndex) { + Logger.info(TAG, 'index === this.selectedIndex') + return + } + this.selectedIndex = index + this.controller.close() + this.selectedIndexChange.apply(this.that,[this.selectedIndex]) +// this.selectedIndexChange.call(this.that,this.selectedIndex) call似乎用不了,只能用apply + }) + } + }, item => item.deviceName) + } + + Button() { + Text($r('app.string.cancel')) + .width('90%') + .fontSize(21) + .fontColor('#0D9FFB') + .textAlign(TextAlign.Center) + } + .type(ButtonType.Capsule) + .backgroundColor(Color.White) + .onClick(() => { + this.controller.close() + }) + } + .padding(10) + .backgroundColor(Color.White) + .border({ color: Color.White, radius: 20 }) + } +} \ No newline at end of file -- Gitee