yiJianShengDian.vue 3.1 KB

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