提交 2e102333 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

Merge branch 'dev' of gitcode.net:dcloud/hello-uts into dev

......@@ -22,7 +22,6 @@
</view>
</template>
<script>
import getBatteryInfo from "@/uni_modules/uni-getbatteryinfo";
import gotoDemoActivity from "@/uni_modules/uts-nativepage";
......@@ -36,7 +35,7 @@
onUnload: function() {},
methods: {
testGetBatteryCapacity() {
getBatteryInfo({
uni.getBatteryInfo({
success(res) {
uni.showToast({
title: "当前电量:" + res.level + '%',
......
......@@ -31,6 +31,9 @@
"npmurl": ""
},
"uni_modules": {
"exports": {
"uni": "getBatteryInfo"
},
"dependencies": [],
"encrypt": [],
"platforms": {
......
......@@ -9,41 +9,27 @@ type GetBatteryInfoOptions = {
complete?: (res: UTSJSONObject) => void
}
export default async function getBatteryInfo(options: GetBatteryInfoOptions) {
export default function getBatteryInfo(options: GetBatteryInfoOptions) {
const context = getAppContext();
console.log(context);
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
console.log(manager);
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
const res = {
errMsg: 'getBatteryInfo:ok',
level,
isCharging: manager.isCharging()
}
console.log(res);
if (options.success != null) {
options.success!(res)
}
console.log("options.success");
if (options.complete != null) {
options.complete!(res)
}
console.log("options.complete");
options.success?.(res)
options.complete?.(res)
} else {
const res = {
errMsg: 'getBatteryInfo:fail getAppContext is null'
}
if (options.fail != null) {
options.fail!(res)
}
if (options.complete != null) {
options.complete!(res)
}
options.fail?.(res)
options.complete?.(res)
}
}
......@@ -15,10 +15,6 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
level: Number(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
};
if (options.success != null) {
options.success!(res);
}
if (options.complete != null) {
options.complete!(res);
}
options.success?.(res);
options.complete?.(res);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册