File tree 3 files changed +23
-17
lines changed
miniprogram/page/API/pages/get-battery-info
3 files changed +23
-17
lines changed Original file line number Diff line number Diff line change 1
1
// miniprogram/page/API/pages/get-battery-info/get-battery-info.js
2
2
Page ( {
3
3
data : {
4
- level : 0 ,
5
- isCharging : false ,
4
+
6
5
} ,
7
6
8
7
getBatteryInfo ( ) {
9
8
wx . getBatteryInfo ( {
10
9
complete : ( res ) => {
10
+ const msg = res . isCharging ? '充电中' : '使用电池中' ;
11
11
this . setData ( {
12
12
level : res . level ,
13
- isCharging : res . isCharging ,
13
+ isCharging : msg ,
14
14
} )
15
15
} ,
16
16
} )
Original file line number Diff line number Diff line change 2
2
<import src="../../../common/foot.wxml" />
3
3
4
4
<view class="container">
5
- <template is="head" data="{{title: '获取手机电量 '}}"/>
5
+ <template is="head" data="{{title: 'getBatteryInfo '}}"/>
6
6
7
7
<view class="page-body">
8
8
<view class="page-section">
9
- <view class="battery-info">
10
- <text class="info-text" wx:if="{{level}}">当前电量: {{level}} %</text>
11
- <text class="info-text" wx:if="{{isCharging}}">充电中</text>
9
+ <view class="weui-cells weui-cells_after-title">
10
+ <view class="weui-cell weui-cell_input">
11
+ <view class="weui-cell__hd">
12
+ <view class="weui-label">当前电量</view>
13
+ </view>
14
+ <view class="weui-cell__bd">
15
+ <input class="weui-input" type="text" disabled="{{true}}" placeholder="未获取" value="{{level}}"></input>
16
+ </view>
17
+ </view>
18
+ <view class="weui-cell weui-cell_input">
19
+ <view class="weui-cell__hd">
20
+ <view class="weui-label">电池模式</view>
21
+ </view>
22
+ <view class="weui-cell__bd">
23
+ <input class="weui-input" type="text" disabled="{{true}}" placeholder="未获取" value="{{isCharging}}"></input>
24
+ </view>
25
+ </view>
12
26
</view>
13
27
<button type="primary" bind:tap="getBatteryInfo" >
14
- 获取电量信息
28
+ 获取电量信息信息
15
29
</button>
16
30
</view>
17
31
</view>
Original file line number Diff line number Diff line change 1
- .battery-info{
2
- display: flex;
3
- flex-direction: column;
4
- align-items: center;
5
- margin: 40rpx 0;
6
- }
1
+ @import "../../../common/lib/weui.wxss";
7
2
8
- .info-text {
9
- line-height: 80rpx;
10
- }
You can’t perform that action at this time.
0 commit comments