yiJianShengDian.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="content" >
  3. <view :style="{ paddingTop: statusBarHeight + 'px' }"></view>
  4. <view class="box1">
  5. <view class="text-24 mgb-20">
  6. 剩余电量
  7. </view>
  8. <view class="text-52 text-2283ee">
  9. {{ powerNum }}%
  10. </view>
  11. <view class="mgt-16 text-20 text-666">
  12. 预计可用3小时0分钟
  13. </view>
  14. <view class="btn cursor" @click="savePower">
  15. 立即省电 <text style="transform: scale(0.7);">▶</text>
  16. </view>
  17. </view>
  18. <view class="box2">
  19. <view class="title">能耗分析</view>
  20. <view class="statistics">
  21. <qiun-data-charts
  22. type="column"
  23. :opts="opts"
  24. :chartData="chartData"
  25. />
  26. </view>
  27. </view>
  28. <view class="flex mgt-50 jc_between">
  29. <view class="btn_s w-320" @click="navTo('/pages/tools/shengDianJiQiao')">
  30. 省电技巧
  31. </view>
  32. <view class="btn_s w-320" @click="navTo('/pages/tools/baoYangJiQiao')">
  33. 保养技巧
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script setup>
  39. import { ref, onMounted } from "vue";
  40. import { onShow } from "@dcloudio/uni-app";
  41. const powerNum = ref(90)
  42. const chartData = ref({})
  43. var statusBarHeight = uni.getStorageSync('statusBarHeight')
  44. onShow(()=>{
  45. getServerData();
  46. uni.getBatteryInfo({
  47. success: (res) => {
  48. powerNum.value = res.level
  49. console.log(res)
  50. },
  51. fail:(err)=>{
  52. console.log('err',err)
  53. }
  54. })
  55. })
  56. const navTo = (url)=>{
  57. uni.navigateTo({
  58. url
  59. })
  60. }
  61. const opts = ref({
  62. color: ["#2ff8e8","#2fe3f4"],
  63. padding: [15,15,0,5],
  64. enableScroll: false,
  65. dataLabel:false,
  66. legend: {},
  67. xAxis: {
  68. disableGrid: true,
  69. },
  70. yAxis: {
  71. disabled:true,
  72. data: [
  73. {
  74. min: 0
  75. }
  76. ]
  77. },
  78. extra: {
  79. column: {
  80. type: "group",
  81. width: 20,
  82. activeBgColor: "#000000",
  83. activeBgOpacity: 0.08,
  84. linearType: "custom",
  85. seriesGap: 30,
  86. linearOpacity: 0.5,
  87. barBorderCircle: true,
  88. customColor: []
  89. }
  90. }
  91. })
  92. const getServerData = ()=>{
  93. //模拟从服务器获取数据时的延时
  94. setTimeout(() => {
  95. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  96. let res = {
  97. categories: ["待机","上网","导航","影片","音乐","打电话",'游戏'],
  98. series: [
  99. {
  100. name: "目标值",
  101. data: [35,36,31,33,13,34,10]
  102. }
  103. ]
  104. };
  105. chartData.value = JSON.parse(JSON.stringify(res));
  106. }, 50);
  107. }
  108. // 立即省电
  109. const savePower = ()=>{
  110. uni.setScreenBrightness({
  111. value: 1,
  112. success: function () {
  113. console.log('success');
  114. },
  115. fail: (err) => {
  116. console.log('err',err);
  117. }
  118. });
  119. uni.showToast({
  120. title:'开启省电',
  121. icon:'none',
  122. })
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .content{
  127. height: 100vh;
  128. background: linear-gradient(to bottom, #a9d4ff, #cce6ff);
  129. padding: 28rpx;
  130. .box1{
  131. width: 100%;
  132. height: 300rpx;
  133. padding: 40rpx 30rpx 10rpx;
  134. border-radius: 30rpx;
  135. background: url('/static/image/index_banner.jpg') no-repeat;
  136. background-size: cover;
  137. position: relative;
  138. .btn{
  139. position: absolute;
  140. transform: translate(30%,0%);
  141. bottom: 10rpx;
  142. width: 400rpx;
  143. height: 68rpx;
  144. line-height: 68rpx;
  145. border-radius: 60rpx;
  146. text-align: center;
  147. color: #fff;
  148. background: linear-gradient(90deg, #03fedf, #2ed9fb);
  149. }
  150. }
  151. .box2{
  152. background-color: rgba(255,255,255,.6);
  153. margin-top: 40rpx;
  154. height: 600rpx;
  155. border-radius: 30rpx;
  156. padding: 50rpx 30rpx 20rpx;
  157. .statistics{
  158. margin-top: 20rpx;
  159. // height: 200rpx;
  160. }
  161. }
  162. }
  163. </style>