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 @@
...
@@ -32,7 +32,7 @@
},
},
"uni_modules"
:
{
"uni_modules"
:
{
"uni-ext-api"
:
{
"uni-ext-api"
:
{
"uni"
:
"getBatteryInfo"
"uni"
:
[
"getBatteryInfo"
]
},
},
"dependencies"
:
[],
"dependencies"
:
[],
"encrypt"
:
[],
"encrypt"
:
[],
...
...
uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts
浏览文件 @
6c8538df
import Context from "android.content.Context";
import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import BatteryManager from "android.os.BatteryManager";
import { UTSAndroid } from "io.dcloud.uts";
import { UTSAndroid } from "io.dcloud.uts";
import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoFail, GetBatteryInfoOptions } from '../interface.uts'
type GetBatteryInfoOptions = {
success?: (res: UTSJSONObject) => void
export const getBatteryInfo : GetBatteryInfo = function (options) {
fail?: (res: UTSJSONObject) => void
const context = UTSAndroid.getAppContext();
complete?: (res: UTSJSONObject) => void
if (context != null) {
}
const manager = context.getSystemService(
Context.BATTERY_SERVICE
export default function getBatteryInfo(options: GetBatteryInfoOptions) {
) as BatteryManager;
const context = UTSAndroid.getAppContext();
const level = manager.getIntProperty(
if (context != null) {
BatteryManager.BATTERY_PROPERTY_CAPACITY
const manager = context.getSystemService(
);
Context.BATTERY_SERVICE
const res : GetBatteryInfoSuccess = {
) as BatteryManager;
errCode: 0,
const level = manager.getIntProperty(
errSubject: "uni-getBatteryInfo",
BatteryManager.BATTERY_PROPERTY_CAPACITY
errMsg: 'getBatteryInfo:ok',
);
level,
const res = {
isCharging: manager.isCharging()
errCode: 0,
}
errSubject: "uni-getBatteryInfo",
options.success?.(res)
errMsg: 'getBatteryInfo:ok',
options.complete?.(res)
level,
} else {
isCharging: manager.isCharging()
const res : GetBatteryInfoFail = {
}
errSubject: "uni-getBatteryInfo",
options.success?.(res)
errCode: 1001,
options.complete?.(res)
errMsg: 'getBatteryInfo:fail getAppContext is null',
} else {
cause: null
const res = {
}
errSubject: "uni-getBatteryInfo",
options.fail?.(res)
errCode: 1001,
options.complete?.(res)
errMsg: 'getBatteryInfo:fail getAppContext is null'
}
}
}
options.fail?.(res)
\ No newline at end of file
options.complete?.(res)
}
}
uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts
浏览文件 @
6c8538df
// 引用 iOS 原生平台 api
// 引用 iOS 原生平台 api
import { UIDevice } from "UIKit";
import { UIDevice } from "UIKit";
import { Int } from 'Swift';
import { Int } from 'Swift';
/**
import { GetBatteryInfo, GetBatteryInfoSuccess } from '../interface.uts';
* 定义 接口参数
*/
/**
type GetBatteryInfoOptions = {
* 导出 获取电量方法
success?: (res: object) => void;
*/
fail?: (res: object) => void;
export const getBatteryInfo : GetBatteryInfo = function (options) {
complete?: (res: object) => void;
};
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
/**
* 导出 获取电量方法
// 返回数据
*/
const res : GetBatteryInfoSuccess = {
export default function getBatteryInfo(options: GetBatteryInfoOptions) {
errCode: 0,
errSubject: "uni-getBatteryInfo",
// 开启电量检测
errMsg: "getBatteryInfo:ok",
UIDevice.current.isBatteryMonitoringEnabled = true
level: new Int(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
// 返回数据
};
const res = {
options.success?.(res);
errCode: 0,
options.complete?.(res);
errSubject: "uni-getBatteryInfo",
errMsg: "getBatteryInfo:ok",
level: new Int(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
};
options.success?.(res);
options.complete?.(res);
}
}
\ No newline at end of file
uni_modules/uni-getbatteryinfo/utssdk/interface.uts
浏览文件 @
6c8538df
type GetBatteryInfoResult
= {
export type GetBatteryInfoSuccess
= {
/**
/**
* 错误码
* 错误码
* 0:成功
* 0:成功
* 1001:getAppContext is null
* 1001:getAppContext is null
* 1002:navigator.getBattery is unsupported
* 1002:navigator.getBattery is unsupported
*/
*/
errCode : number,
errCode : number,
/**
/**
* 调用API的名称
* 调用API的名称
*/
*/
errSubject : string,
errSubject : string,
/**
/**
* 错误的详细信息
* 错误的详细信息
*/
*/
errMsg : string,
errMsg : string,
/**
/**
* 设备电量,范围1 - 100
* 设备电量,范围1 - 100
*/
*/
level : number,
level : number,
/**
/**
* 是否正在充电中
* 是否正在充电中
*/
*/
isCharging : boolean
isCharging : boolean
}
}
interface UniError<T>
{
export type GetBatteryInfoFail =
{
/**
/**
* 错误码
* 错误码
*/
*/
errCode : number,
errCode : number,
/**
/**
* 调用API的名称
* 调用API的名称
*/
*/
errSubject : string,
errSubject : string,
/**
/**
* 错误的详细信息
* 错误的详细信息
*/
*/
errMsg : string,
errMsg : string,
/**
/**
* 错误来源
* 错误来源
*/
*/
cause : any
cause : any | null
}
}
export type GetBatteryInfoOptions = {
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
* @param {GetBatteryInfoOptions} options
*
*
*
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.11
* @since 3.6.11
*
*
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @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" })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
*/
export default function getBatteryInfo(options : GetBatteryInfoOptions) : void
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
)
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
)
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
)
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
)
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
)
{
if
(
navigator
.
getBattery
)
{
navigator
.
getBattery
().
then
(
battery
=>
{
navigator
.
getBattery
().
then
(
battery
=>
{
const
res
=
{
const
res
=
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录