From f401ca72e4e6b416a7b6f1716bfd278566504208 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 9 Jan 2024 14:26:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(web):=20=E8=B0=83=E6=95=B4=20getBatter?= =?UTF-8?q?yInfo=20web=20=E4=BB=A3=E7=A0=81=E4=B8=BA=20uts=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-getbatteryinfo/utssdk/web/index.js | 23 ------------------- .../uni-getbatteryinfo/utssdk/web/index.uts | 22 ++++++++++++++++++ 2 files changed, 22 insertions(+), 23 deletions(-) delete mode 100644 uni_modules/uni-getbatteryinfo/utssdk/web/index.js create mode 100644 uni_modules/uni-getbatteryinfo/utssdk/web/index.uts diff --git a/uni_modules/uni-getbatteryinfo/utssdk/web/index.js b/uni_modules/uni-getbatteryinfo/utssdk/web/index.js deleted file mode 100644 index 4049f504..00000000 --- a/uni_modules/uni-getbatteryinfo/utssdk/web/index.js +++ /dev/null @@ -1,23 +0,0 @@ -export function getBatteryInfo(options) { - if (navigator.getBattery) { - navigator.getBattery().then(battery => { - const res = { - errCode: 0, - errSubject: "uni-getBatteryInfo", - errMsg: 'getBatteryInfo:ok', - level: battery.level * 100, - isCharging: battery.charging - } - options.success && options.success(res) - options.complete && options.complete(res) - }) - } else { - const res = { - errCode: 1002, - errSubject: "uni-getBatteryInfo", - errMsg: 'getBatteryInfo:fail navigator.getBattery is unsupported' - } - options.fail && options.fail(res) - options.complete && options.complete(res) - } -} diff --git a/uni_modules/uni-getbatteryinfo/utssdk/web/index.uts b/uni_modules/uni-getbatteryinfo/utssdk/web/index.uts new file mode 100644 index 00000000..85a3c945 --- /dev/null +++ b/uni_modules/uni-getbatteryinfo/utssdk/web/index.uts @@ -0,0 +1,22 @@ +import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess } from '../interface.uts' +export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) { + // @ts-expect-error + if (navigator.getBattery) { + // @ts-expect-error + navigator.getBattery().then(battery => { + const res = { + errCode: 0, + errSubject: "uni-getBatteryInfo", + errMsg: 'getBatteryInfo:ok', + level: battery.level * 100, + isCharging: battery.charging + } as GetBatteryInfoSuccess + options.success && options.success(res) + options.complete && options.complete(res) + }) + } else { + const res = new UniError("uni-getBatteryInfo", 1002, "getBatteryInfo:fail navigator.getBattery is unsupported") + options.fail && options.fail(res) + options.complete && options.complete(res) + } +} -- GitLab