Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
6c8538df
U
uni-api
项目概览
DCloud
/
uni-api
通知
671
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6c8538df
编写于
3月 14, 2023
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
电量:重构
上级
36a07560
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
130 addition
and
142 deletion
+130
-142
uni_modules/uni-getbatteryinfo/package.json
uni_modules/uni-getbatteryinfo/package.json
+1
-1
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
+35
-39
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
+24
-31
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
+65
-66
uni_modules/uni-getbatteryinfo/utssdk/mp-alipay/index.js
uni_modules/uni-getbatteryinfo/utssdk/mp-alipay/index.js
+1
-1
uni_modules/uni-getbatteryinfo/utssdk/mp-baidu/index.js
uni_modules/uni-getbatteryinfo/utssdk/mp-baidu/index.js
+1
-1
uni_modules/uni-getbatteryinfo/utssdk/mp-qq/index.js
uni_modules/uni-getbatteryinfo/utssdk/mp-qq/index.js
+1
-1
uni_modules/uni-getbatteryinfo/utssdk/mp-weixin/index.js
uni_modules/uni-getbatteryinfo/utssdk/mp-weixin/index.js
+1
-1
uni_modules/uni-getbatteryinfo/utssdk/web/index.js
uni_modules/uni-getbatteryinfo/utssdk/web/index.js
+1
-1
未找到文件。
uni_modules/uni-getbatteryinfo/package.json
浏览文件 @
6c8538df
...
...
@@ -32,7 +32,7 @@
},
"uni_modules"
:
{
"uni-ext-api"
:
{
"uni"
:
"getBatteryInfo"
"uni"
:
[
"getBatteryInfo"
]
},
"dependencies"
:
[],
"encrypt"
:
[],
...
...
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
浏览文件 @
6c8538df
...
...
@@ -2,14 +2,9 @@ import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import { UTSAndroid } from "io.dcloud.uts";
import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoFail, GetBatteryInfoOptions } from '../interface.uts'
type GetBatteryInfoOptions = {
success?: (res: UTSJSONObject) => void
fail?: (res: UTSJSONObject) => void
complete?: (res: UTSJSONObject) => void
}
export default function getBatteryInfo(options: GetBatteryInfoOptions) {
export const getBatteryInfo : GetBatteryInfo = function (options) {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
...
...
@@ -18,7 +13,7 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
const res
= {
const res
: GetBatteryInfoSuccess = {
errCode: 0,
errSubject: "uni-getBatteryInfo",
errMsg: 'getBatteryInfo:ok',
...
...
@@ -28,10 +23,11 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
options.success?.(res)
options.complete?.(res)
} else {
const res
= {
const res
: GetBatteryInfoFail = {
errSubject: "uni-getBatteryInfo",
errCode: 1001,
errMsg: 'getBatteryInfo:fail getAppContext is null'
errMsg: 'getBatteryInfo:fail getAppContext is null',
cause: null
}
options.fail?.(res)
options.complete?.(res)
...
...
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
浏览文件 @
6c8538df
...
...
@@ -2,25 +2,18 @@
import { UIDevice } from "UIKit";
import { Int } from 'Swift';
/**
* 定义 接口参数
*/
type GetBatteryInfoOptions = {
success?: (res: object) => void;
fail?: (res: object) => void;
complete?: (res: object) => void;
};
import { GetBatteryInfo, GetBatteryInfoSuccess } from '../interface.uts';
/**
* 导出 获取电量方法
*/
export
default function getBatteryInfo(options: GetBatteryInfoOptions) {
export
const getBatteryInfo : GetBatteryInfo = function (options) {
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
// 返回数据
const res
= {
const res
: GetBatteryInfoSuccess = {
errCode: 0,
errSubject: "uni-getBatteryInfo",
errMsg: "getBatteryInfo:ok",
...
...
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
浏览文件 @
6c8538df
type GetBatteryInfoResult
= {
export type GetBatteryInfoSuccess
= {
/**
* 错误码
* 0:成功
...
...
@@ -24,7 +24,7 @@ type GetBatteryInfoResult = {
isCharging : boolean
}
interface UniError<T>
{
export type GetBatteryInfoFail =
{
/**
* 错误码
*/
...
...
@@ -40,7 +40,7 @@ interface UniError<T> {
/**
* 错误来源
*/
cause : any
cause : any | null
}
...
...
@@ -49,28 +49,27 @@ export type GetBatteryInfoOptions = {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
success ?: (res : GetBatteryInfoResult
) => void
success ?: (res : GetBatteryInfoSuccess
) => void
/**
* 接口调用失败的回调函数
*/
fail ?: (res : UniError
) => void
fail ?: (res : GetBatteryInfoFail
) => void
/**
* 接口调用成功的回调
*/
complete ?: (res : object
) => void
complete ?: (res : any
) => void
}
/**
* 获取电量信息
* @param {GetBatteryInfoOptions} options
*
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.11
*
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
export default function getBatteryInfo(options : GetBatteryInfoOptions) : void
* 获取电量信息
* @param {GetBatteryInfoOptions} options
*
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.11
*
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
export type GetBatteryInfo = (options : GetBatteryInfoOptions) => void
\ No newline at end of file
uni_modules/uni-getbatteryinfo/utssdk/mp-alipay/index.js
浏览文件 @
6c8538df
export
default
function
getBatteryInfo
(
options
)
{
export
function
getBatteryInfo
(
options
)
{
return
my
.
getBatteryInfo
(
options
)
}
uni_modules/uni-getbatteryinfo/utssdk/mp-baidu/index.js
浏览文件 @
6c8538df
export
default
function
getBatteryInfo
(
options
)
{
export
function
getBatteryInfo
(
options
)
{
return
swan
.
getBatteryInfo
(
options
)
}
uni_modules/uni-getbatteryinfo/utssdk/mp-qq/index.js
浏览文件 @
6c8538df
export
default
function
getBatteryInfo
(
options
)
{
export
function
getBatteryInfo
(
options
)
{
return
qq
.
getBatteryInfo
(
options
)
}
uni_modules/uni-getbatteryinfo/utssdk/mp-weixin/index.js
浏览文件 @
6c8538df
export
default
function
getBatteryInfo
(
options
)
{
export
function
getBatteryInfo
(
options
)
{
return
wx
.
getBatteryInfo
(
options
)
}
uni_modules/uni-getbatteryinfo/utssdk/web/index.js
浏览文件 @
6c8538df
export
default
function
getBatteryInfo
(
options
)
{
export
function
getBatteryInfo
(
options
)
{
if
(
navigator
.
getBattery
)
{
navigator
.
getBattery
().
then
(
battery
=>
{
const
res
=
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录