From 70bafaf6f9586f317d1483c725f54fe0c39e0702 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Thu, 1 Sep 2022 12:29:23 +0800 Subject: [PATCH] merge battery plugin --- pages/SystemAPI/SystemAPI.vue | 61 +++++++------- uni_modules/uts-batteryinfo/changelog.md | 0 uni_modules/uts-batteryinfo/package.json | 81 +++++++++++++++++++ uni_modules/uts-batteryinfo/readme.md | 5 ++ .../utssdk/app-android/index.uts | 24 ++++++ .../uts-batteryinfo/utssdk/mp-weixin/index.js | 9 +++ .../uts-batteryinfo/utssdk/web/index.js | 13 +++ 7 files changed, 161 insertions(+), 32 deletions(-) create mode 100644 uni_modules/uts-batteryinfo/changelog.md create mode 100644 uni_modules/uts-batteryinfo/package.json create mode 100644 uni_modules/uts-batteryinfo/readme.md create mode 100644 uni_modules/uts-batteryinfo/utssdk/app-android/index.uts create mode 100644 uni_modules/uts-batteryinfo/utssdk/mp-weixin/index.js create mode 100644 uni_modules/uts-batteryinfo/utssdk/web/index.js diff --git a/pages/SystemAPI/SystemAPI.vue b/pages/SystemAPI/SystemAPI.vue index 4cc7cc9..2fdbe96 100644 --- a/pages/SystemAPI/SystemAPI.vue +++ b/pages/SystemAPI/SystemAPI.vue @@ -1,40 +1,37 @@ diff --git a/uni_modules/uts-batteryinfo/changelog.md b/uni_modules/uts-batteryinfo/changelog.md new file mode 100644 index 0000000..e69de29 diff --git a/uni_modules/uts-batteryinfo/package.json b/uni_modules/uts-batteryinfo/package.json new file mode 100644 index 0000000..0191377 --- /dev/null +++ b/uni_modules/uts-batteryinfo/package.json @@ -0,0 +1,81 @@ +{ + "id": "uts-batteryinfo", + "displayName": "uts-batteryinfo", + "version": "1.0.0", + "description": "uts-batteryinfo", + "keywords": [ + "uts-batteryinfo" +], + "repository": "", + "engines": { + "HBuilderX": "^3.1.0" + }, + "dcloudext": { + "type": "uts", + "sale": { + "regular": { + "price": "0.00" + }, + "sourcecode": { + "price": "0.00" + } + }, + "contact": { + "qq": "" + }, + "declaration": { + "ads": "", + "data": "", + "permissions": "" + }, + "npmurl": "" + }, + "uni_modules": { + "dependencies": [], + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "u", + "aliyun": "u" + }, + "client": { + "Vue": { + "vue2": "u", + "vue3": "u" + }, + "App": { + "app-android": "u", + "app-ios": "u" + }, + "H5-mobile": { + "Safari": "u", + "Android Browser": "u", + "微信浏览器(Android)": "u", + "QQ浏览器(Android)": "u" + }, + "H5-pc": { + "Chrome": "u", + "IE": "u", + "Edge": "u", + "Firefox": "u", + "Safari": "u" + }, + "小程序": { + "微信": "u", + "阿里": "u", + "百度": "u", + "字节跳动": "u", + "QQ": "u", + "钉钉": "u", + "快手": "u", + "飞书": "u", + "京东": "u" + }, + "快应用": { + "华为": "u", + "联盟": "u" + } + } + } + } +} \ No newline at end of file diff --git a/uni_modules/uts-batteryinfo/readme.md b/uni_modules/uts-batteryinfo/readme.md new file mode 100644 index 0000000..2ed1b40 --- /dev/null +++ b/uni_modules/uts-batteryinfo/readme.md @@ -0,0 +1,5 @@ +# uts-batteryinfo +### 开发文档 +[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html) +[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html) +[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev) \ No newline at end of file diff --git a/uni_modules/uts-batteryinfo/utssdk/app-android/index.uts b/uni_modules/uts-batteryinfo/utssdk/app-android/index.uts new file mode 100644 index 0000000..59bf6bf --- /dev/null +++ b/uni_modules/uts-batteryinfo/utssdk/app-android/index.uts @@ -0,0 +1,24 @@ +import Context from "android.content.Context"; +import BatteryManager from "android.os.BatteryManager"; +import { getAppContext } from "io.dcloud.uts.android"; + + +export default async function getBatteryInfo(): Promise { + const context = getAppContext(); + if (context != null) { + const manager = context.getSystemService( + Context.BATTERY_SERVICE + ) as BatteryManager; + const level = manager.getIntProperty( + BatteryManager.BATTERY_PROPERTY_CAPACITY + ); + return { + level, + isCharging: manager.isCharging() + }; + } + return { + level: 0, + isCharging: false + }; +} \ No newline at end of file diff --git a/uni_modules/uts-batteryinfo/utssdk/mp-weixin/index.js b/uni_modules/uts-batteryinfo/utssdk/mp-weixin/index.js new file mode 100644 index 0000000..f96417c --- /dev/null +++ b/uni_modules/uts-batteryinfo/utssdk/mp-weixin/index.js @@ -0,0 +1,9 @@ +export default async function getBatteryInfo() { + return new Promise((resolve) => { + wx.getBatteryInfo({ + success(res) { + resolve(res) + } + }) + }) +} diff --git a/uni_modules/uts-batteryinfo/utssdk/web/index.js b/uni_modules/uts-batteryinfo/utssdk/web/index.js new file mode 100644 index 0000000..7d7637e --- /dev/null +++ b/uni_modules/uts-batteryinfo/utssdk/web/index.js @@ -0,0 +1,13 @@ +export default async function getBatteryInfo() { + if ((navigator).getBattery) { + const battery = await navigator.getBattery() + return { + level: battery.level * 100, + isCharging: battery.charging + } + } + return { + level: 0, + isCharging: false + }; +} -- GitLab