From a7cb25a015ba8a517af958bb6da6cd8df81d6d08 Mon Sep 17 00:00:00 2001 From: lizhongyi Date: Fri, 27 Oct 2023 17:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E8=A7=84=E8=8C=83=E8=B0=83=E6=95=B4?= =?UTF-8?q?=20uni-getbatteryinfo=20errcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .hbuilderx/launch.json | 5 +-- .../utssdk/app-android/index.uts | 5 +-- .../utssdk/app-ios/index.uts | 4 +-- .../uni-getbatteryinfo/utssdk/interface.uts | 14 +++++++- .../uni-getbatteryinfo/utssdk/unierror.uts | 34 +++++++++++++++++++ 5 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 uni_modules/uni-getbatteryinfo/utssdk/unierror.uts diff --git a/.hbuilderx/launch.json b/.hbuilderx/launch.json index ad7c2a6..cc4f2a1 100644 --- a/.hbuilderx/launch.json +++ b/.hbuilderx/launch.json @@ -14,8 +14,9 @@ }, { "bundleId" : "io.dcloud.test123456", - "certificateFile" : "/Users/lizhongyi/Desktop/文件/证书/dev_123.p12", - "certificateProfileFile" : "/Users/lizhongyi/Desktop/文件/证书/io_dcloud_test123456.mobileprovision", + "certificateFile" : "/Users/lizhongyi/Desktop/newProfiles/dev_123.p12", + "certificateProfileFile" : "/Users/lizhongyi/Desktop/newProfiles/wildcard.mobileprovision", + "runSignStatus" : 1, "type" : "uni-app:app-ios" } ] diff --git a/uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts b/uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts index 060043b..5ae056d 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts +++ b/uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts @@ -5,6 +5,7 @@ import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess, GetBatter import IntentFilter from 'android.content.IntentFilter'; import Intent from 'android.content.Intent'; +import { GetBatteryInfoFailImpl } from '../unierror'; /** * 异步获取电量 @@ -33,8 +34,8 @@ export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInf } options.success?.(res) options.complete?.(res) - } else { - const res = new UniError("uni-getBatteryInfo", 1001, "getBatteryInfo:fail getAppContext is null") + } else { + let res = new GetBatteryInfoFailImpl(1001); options.fail?.(res) options.complete?.(res) } diff --git a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts index e33ab29..de45bdc 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts @@ -1,9 +1,7 @@ // 引用 iOS 原生平台 api import { UIDevice } from "UIKit"; -import { Int } from 'Swift'; import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoResult, GetBatteryInfoSync } from '../interface.uts'; - /** * 导出 获取电量方法 */ @@ -15,7 +13,7 @@ export const getBatteryInfo : GetBatteryInfo = function (options) { // 返回数据 const res : GetBatteryInfoSuccess = { errMsg: "getBatteryInfo:ok", - level: new Int(UIDevice.current.batteryLevel * 100), + level: Number(UIDevice.current.batteryLevel * 100), isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging, }; options.success?.(res); diff --git a/uni_modules/uni-getbatteryinfo/utssdk/interface.uts b/uni_modules/uni-getbatteryinfo/utssdk/interface.uts index d674221..9c7f25f 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/interface.uts +++ b/uni_modules/uni-getbatteryinfo/utssdk/interface.uts @@ -55,7 +55,19 @@ export type GetBatteryInfoResult = { * 是否正在充电中 */ isCharging : boolean -} +} + +/** + * 错误码 + * - 1001 getAppContext is null + */ +export type GetBatteryInfoErrorCode = 1001 ; +/** + * myApi 的错误回调参数 + */ +export interface GetBatteryInfoFail extends IUniError { + errCode : GetBatteryInfoErrorCode +}; /** * 获取电量信息 diff --git a/uni_modules/uni-getbatteryinfo/utssdk/unierror.uts b/uni_modules/uni-getbatteryinfo/utssdk/unierror.uts new file mode 100644 index 0000000..511c66c --- /dev/null +++ b/uni_modules/uni-getbatteryinfo/utssdk/unierror.uts @@ -0,0 +1,34 @@ +import { GetBatteryInfoErrorCode, GetBatteryInfoFail } from "./interface.uts" +/** + * 错误主题 + */ +export const UniErrorSubject = 'uni-getBatteryInfo'; + + +/** + * 错误信息 + * @UniError + */ +export const UniErrors : Map = new Map([ + /** + * 错误码及对应的错误信息 + */ + [1001, 'getBatteryInfo:fail getAppContext is null'], +]); + + +/** + * 错误对象实现 + */ +export class GetBatteryInfoFailImpl extends UniError implements GetBatteryInfoFail { + + /** + * 错误对象构造函数 + */ + constructor(errCode : GetBatteryInfoErrorCode) { + super(); + this.errSubject = UniErrorSubject; + this.errCode = errCode; + this.errMsg = UniErrors[errCode] ?? ""; + } +} \ No newline at end of file -- GitLab