diff --git a/product/phone/src/main/ets/model/aboutDeviceImpl/AboutDeviceModel.ts b/product/phone/src/main/ets/model/aboutDeviceImpl/AboutDeviceModel.ts index aef99d8424feb6e608896319a5c3dc7c0064b428..e75f406d5bfecae5e7eb29a17e79f53553ad3f2d 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 cbcfdac48899ba6c23b8a9a4142949377584f4d9..afe53583a81e0edab148de95328d60e64c989376 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 5f977e119fc7553500fa7d0db33fc56a8a4e7d15..8d16d7a4e8e50f7872152f4a3de58d79979885f1 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