From a4fc2160d7bf29be962e1679d13518ebd9ae761a Mon Sep 17 00:00:00 2001 From: chentianxiang Date: Fri, 26 Aug 2022 17:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87ip=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/aboutDeviceImpl/AboutDeviceModel.ts | 26 ++++++++++++++++++- .../phone/src/main/ets/pages/aboutDevice.ets | 6 ++++- .../main/resources/rawfile/aboutDevice.json | 5 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/product/phone/src/main/ets/model/aboutDeviceImpl/AboutDeviceModel.ts b/product/phone/src/main/ets/model/aboutDeviceImpl/AboutDeviceModel.ts index aef99d84..e75f406d 100644 --- a/product/phone/src/main/ets/model/aboutDeviceImpl/AboutDeviceModel.ts +++ b/product/phone/src/main/ets/model/aboutDeviceImpl/AboutDeviceModel.ts @@ -1,3 +1,4 @@ +// @ts-nocheck /** * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +21,7 @@ import deviceInfo from '@ohos.deviceInfo'; import settings from '@ohos.settings'; import featureAbility from '@ohos.ability.featureAbility'; import CatchError from '../../../../../../../common/utils/src/main/ets/default/baseUtil/CatchError'; +import wifi from '@ohos.wifi' /** * about device service class @@ -49,7 +51,12 @@ export class AboutDeviceModel extends BaseModel { settingAlias: "softwareVersion", settingTitle: "", settingValue: "" - } + }, + { + settingAlias: "ip", + settingTitle: "", + settingValue: "" + } ] constructor(){ @@ -59,6 +66,23 @@ export class AboutDeviceModel extends BaseModel { this.dataAbilityHelper = featureAbility.acquireDataAbilityHelper(globalThis.settingsAbilityContext, this.uri); } + @Log + @CatchError(undefined) + resolveIP() { + //获取ip地址,此地址为数字形式 + let address: string = wifi.getIpInfo().serverIp; + if (address === null) { + return '00:00:000:000'; + } + //数字转IP地址形式 + const ip3 = (address << 0) >>> 24 + const ip2 = (address << 8) >>> 24 + const ip1 = (address << 16) >>> 24 + const ip0 = (address << 24) >>> 24 + let ips = ip3 + '.' + ip2 + '.' + ip1 + '.' + ip0 + LogUtil.info("get wifi linked info: " + ips); + return ips; + } /** * Get Uri */ diff --git a/product/phone/src/main/ets/pages/aboutDevice.ets b/product/phone/src/main/ets/pages/aboutDevice.ets index cbcfdac4..afe53583 100644 --- a/product/phone/src/main/ets/pages/aboutDevice.ets +++ b/product/phone/src/main/ets/pages/aboutDevice.ets @@ -27,7 +27,7 @@ struct Index { @State systemName: string = AboutDeviceModel.getSystemName(); private deviceInfo: any = '' private aboutDeviceList: any[] = [] - + private resolveIp: any = AboutDeviceModel.resolveIP(); build() { Column() { GridContainer({ @@ -141,6 +141,10 @@ struct Index { this.aboutDeviceList[key].settingValue = this.deviceInfo.displayVersion; this.aboutDeviceList[key].settingTitle = $r('app.string.softwareVersion'); } + if ('ip' === value) { + this.aboutDeviceList[key].settingValue =this.resolveIp; + this.aboutDeviceList[key].settingTitle = "IP地址"; + } } } diff --git a/product/phone/src/main/resources/rawfile/aboutDevice.json b/product/phone/src/main/resources/rawfile/aboutDevice.json index 5f977e11..8d16d7a4 100644 --- a/product/phone/src/main/resources/rawfile/aboutDevice.json +++ b/product/phone/src/main/resources/rawfile/aboutDevice.json @@ -18,5 +18,10 @@ "settingAlias": "softwareVersion", "settingTitle": "", "settingValue": "" + }, + { + "settingAlias": "ip", + "settingTitle": "", + "settingValue": "" } ] \ No newline at end of file -- Gitee