提交 f401ca72 编写于 作者: fxy060608's avatar fxy060608

refactor(web): 调整 getBatteryInfo web 代码为 uts 实现

上级 b65ab10a
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)
}
}
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)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册