Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
70bafaf6
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1598
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
70bafaf6
编写于
9月 01, 2022
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merge battery plugin
上级
e13b0eeb
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
161 addition
and
32 deletion
+161
-32
pages/SystemAPI/SystemAPI.vue
pages/SystemAPI/SystemAPI.vue
+29
-32
uni_modules/uts-batteryinfo/changelog.md
uni_modules/uts-batteryinfo/changelog.md
+0
-0
uni_modules/uts-batteryinfo/package.json
uni_modules/uts-batteryinfo/package.json
+81
-0
uni_modules/uts-batteryinfo/readme.md
uni_modules/uts-batteryinfo/readme.md
+5
-0
uni_modules/uts-batteryinfo/utssdk/app-android/index.uts
uni_modules/uts-batteryinfo/utssdk/app-android/index.uts
+24
-0
uni_modules/uts-batteryinfo/utssdk/mp-weixin/index.js
uni_modules/uts-batteryinfo/utssdk/mp-weixin/index.js
+9
-0
uni_modules/uts-batteryinfo/utssdk/web/index.js
uni_modules/uts-batteryinfo/utssdk/web/index.js
+13
-0
未找到文件。
pages/SystemAPI/SystemAPI.vue
浏览文件 @
70bafaf6
<
template
>
<
template
>
<view>
<view>
<page-head
:title=
"title"
></page-head>
<page-head
:title=
"title"
></page-head>
<view
class=
"uni-btn-v uni-common-mt"
>
<view
class=
"uni-btn-v uni-common-mt"
>
<button
type=
"primary"
@
tap=
"testGetBatteryCapacity"
>
获取电池电量
</button>
<button
type=
"primary"
@
tap=
"testGetBatteryCapacity"
>
获取电池电量
</button>
</view>
</view>
</view>
</view>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
import
getBatteryInfo
from
"
../../uni_modules/uts-batteryinfo
"
;
getBatteryCapacity
}
from
"
../../uni_modules/uts-osapi
"
;
export
default
{
data
()
{
export
default
{
return
{
data
()
{
title
:
'
系统API示例
'
,
return
{
}
title
:
'
系统API示例
'
,
},
}
onUnload
:
function
()
{},
},
methods
:
{
onUnload
:
function
(){
testGetBatteryCapacity
:
async
function
()
{
},
var
info
=
await
getBatteryInfo
()
methods
:
{
console
.
log
(
info
);
testGetBatteryCapacity
:
function
()
{
uni
.
showToast
({
var
capacity
=
getBatteryCapacity
()
title
:
"
当前电量:
"
+
info
.
level
+
'
%
'
,
console
.
log
(
capacity
);
icon
:
'
none
'
uni
.
showToast
({
});
title
:
"
当前电量:
"
+
capacity
,
icon
:
'
none
'
},
});
}
},
}
}
}
</
script
>
</
script
>
<
style
>
<
style
>
</
style
>
</
style
>
uni_modules/uts-batteryinfo/changelog.md
0 → 100644
浏览文件 @
70bafaf6
uni_modules/uts-batteryinfo/package.json
0 → 100644
浏览文件 @
70bafaf6
{
"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
uni_modules/uts-batteryinfo/readme.md
0 → 100644
浏览文件 @
70bafaf6
# 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
uni_modules/uts-batteryinfo/utssdk/app-android/index.uts
0 → 100644
浏览文件 @
70bafaf6
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
<
UTSJSONObject
>
{
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
uni_modules/uts-batteryinfo/utssdk/mp-weixin/index.js
0 → 100644
浏览文件 @
70bafaf6
export
default
async
function
getBatteryInfo
()
{
return
new
Promise
((
resolve
)
=>
{
wx
.
getBatteryInfo
({
success
(
res
)
{
resolve
(
res
)
}
})
})
}
uni_modules/uts-batteryinfo/utssdk/web/index.js
0 → 100644
浏览文件 @
70bafaf6
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
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录