index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <view>
  3. <view class="top-box">
  4. <view class="container-top" @click="showDayPicker = true">
  5. <view class="top-left">
  6. <view class="word">今日</view>
  7. <text>{{formatDate(dayValue)}}</text>
  8. </view>
  9. <!-- <view class="top-right" @click.stop="fullscreenFn">
  10. <image src="/static/image/full.png" mode=""></image>
  11. </view> -->
  12. </view>
  13. <view class="chartsMain" v-if="Area.categories.length">
  14. <canvas canvas-id="canvasArea" id="canvasArea" class="charts"></canvas>
  15. </view>
  16. <view class="chartsMain" v-else>
  17. <image src="/static/image/none.png" mode=""></image>
  18. </view>
  19. </view>
  20. <view class="content-box">
  21. <view class="word-box">
  22. <view class="word-title">
  23. 海拔记录
  24. </view>
  25. </view>
  26. <view class="list-box">
  27. <block v-for="(item,index) in dayInfo.list">
  28. <view class="list-box-item">
  29. <view class="list-box-left">
  30. <image src="/static/image/hearticon.png" mode=""></image>
  31. <text>{{formatHms(item.createTime)}}</text>
  32. </view>
  33. <view class="list-box-right">
  34. <view class="num">{{item.altitude}}</view>
  35. <view>m</view>
  36. </view>
  37. </view>
  38. </block>
  39. </view>
  40. </view>
  41. <van-popup :show="showDayPicker" position="bottom">
  42. <van-datetime-picker @cancel="showDayPicker=false" @confirm="onConfirm" :value="currentDay" type="date" />
  43. </van-popup>
  44. </view>
  45. </template>
  46. <script>
  47. // 图表
  48. import uCharts from "@/components/ucharts/ucharts.js";
  49. import * as infoApi from '@/api/info/index.js';
  50. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  51. import {
  52. mapGetters
  53. } from "vuex";
  54. var _self;
  55. var canvaRing = null;
  56. var canvaArea = null;
  57. var canvaGauge = null;
  58. var canvaPie = null;
  59. var canvaColumn = null;
  60. var canvaFunnel = null;
  61. var canvaWord = null;
  62. export default {
  63. data() {
  64. return {
  65. cWidth: '',
  66. cHeight: '',
  67. pixelRatio: 1,
  68. dayValue: new Date(),
  69. showDayPicker: false,
  70. currentDay: new Date().getTime(),
  71. dayInfo: {},
  72. list: [{
  73. time: '09:00',
  74. num: 63
  75. }, {
  76. time: '09:10',
  77. num: 63
  78. }, {
  79. time: '09:10',
  80. num: 63
  81. }],
  82. // 折线图
  83. Area: {
  84. categories: [],
  85. // categories: ['08:22','08:22','08:22','08:22'],
  86. series: [{
  87. name: '',
  88. data: [],
  89. // data: [68,89,66,79],
  90. color: '#F35546'
  91. }]
  92. }
  93. };
  94. },
  95. computed: mapGetters(['deviceId']),
  96. async onLoad() {
  97. _self = this;
  98. this.cWidth = uni.upx2px(680);
  99. this.cHeight = uni.upx2px(400);
  100. await this.getData()
  101. this.getServerData();
  102. },
  103. mounted() {
  104. },
  105. methods: {
  106. async onConfirm(value) {
  107. this.dayValue = value.detail;
  108. await this.getData()
  109. this.getServerData();
  110. this.showDayPicker = false;
  111. },
  112. getData() {
  113. let data = this.formatDate(this.dayValue).split("-"); // ["2023", "10", "18"]
  114. let params = {
  115. deviceId: this.deviceId,
  116. year: data[0],
  117. month: data[1],
  118. day: data[2],
  119. // day:"17",
  120. }
  121. return infoApi.getAltitude(params).then(res => {
  122. console.log(res, 44);
  123. this.dayInfo = res.data
  124. // 组装接口数据。上方折线图若超过10条,截取10条
  125. let categoriesArr = res.data.list.map(item => this.formatHHmm(item.createTime))
  126. let seriesArr = res.data.list.map(item => item.altitude)
  127. this.Area.categories = categoriesArr.length > 10 ? categoriesArr.slice(-10) :
  128. categoriesArr
  129. this.Area.series[0].data = seriesArr.length > 10 ? seriesArr.slice(-10) : seriesArr
  130. })
  131. .catch(err => {
  132. return this.$util.Tips({
  133. title: err,
  134. // icon: 'error'
  135. });
  136. });
  137. },
  138. formatHHmm: function(date) {
  139. return dayjs(date).format("HH:mm");
  140. },
  141. formatDate: function(date) {
  142. return dayjs(date).format("YYYY-MM-DD");
  143. },
  144. formatHms: function(date) {
  145. return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
  146. },
  147. getServerData() {
  148. _self.showArea("canvasArea", this.chartData);
  149. },
  150. // 折线图
  151. showArea(canvasId, chartData) {
  152. canvaArea = new uCharts({
  153. $this: _self,
  154. canvasId: canvasId,
  155. type: 'area',
  156. fontSize: 11,
  157. legend: true,
  158. dataLabel: false,
  159. dataPointShape: true,
  160. background: '#FFFFFF',
  161. pixelRatio: _self.pixelRatio,
  162. categories: _self.Area.categories,
  163. series: _self.Area.series,
  164. animation: true,
  165. xAxis: {
  166. type: 'grid',
  167. gridColor: '#CCCCCC',
  168. gridType: 'dash',
  169. dashLength: 8,
  170. rotateLabel: true,
  171. rotateAngle: -50,
  172. },
  173. yAxis: {
  174. gridType: 'dash',
  175. gridColor: '#CCCCCC',
  176. dashLength: 8,
  177. splitNumber: 5,
  178. min: 10,
  179. max: 180,
  180. },
  181. width: _self.cWidth * _self.pixelRatio,
  182. height: _self.cHeight * _self.pixelRatio,
  183. extra: {
  184. area: {
  185. type: 'straight',
  186. opacity: 0.2,
  187. addLine: true,
  188. width: 2
  189. }
  190. }
  191. });
  192. },
  193. touchArea(e) {
  194. canvaArea.showToolTip(e, {
  195. format: function(item, category) {
  196. return item.name + ' ' + category + ' ' + ':' + item.data
  197. }
  198. });
  199. },
  200. }
  201. };
  202. </script>
  203. <style lang="scss" scoped>
  204. .top-box {
  205. padding: 28rpx 32rpx 19rpx;
  206. background-color: #fff;
  207. .container-top {
  208. display: flex;
  209. align-items: center;
  210. justify-content: space-between;
  211. margin-bottom: 28rpx;
  212. .top-left {
  213. .word {
  214. font-size: 36rpx;
  215. font-weight: 500;
  216. color: #000000;
  217. }
  218. text {
  219. font-size: 24rpx;
  220. font-weight: 500;
  221. color: #777777;
  222. line-height: 33rpx;
  223. }
  224. }
  225. .top-right {
  226. width: 32rpx;
  227. height: 32rpx;
  228. image {
  229. width: 32rpx;
  230. height: 32rpx;
  231. }
  232. }
  233. }
  234. .chartsMain {
  235. width: 100%;
  236. // height: 450rpx;
  237. // box-sizing: border-box;
  238. background: #fff;
  239. border-top: 2rpx solid #f2f2f2;
  240. text-align: center;
  241. image {
  242. width: 70%;
  243. // height: 100%;
  244. }
  245. .charts {
  246. width: 680rpx;
  247. height: 400rpx;
  248. box-sizing: border-box;
  249. }
  250. }
  251. }
  252. .content-box {
  253. background-color: #F7F7F7;
  254. // height: 100vh;
  255. .word-box {
  256. margin-top: 16rpx;
  257. background-color: #fff;
  258. padding: 32rpx;
  259. font-size: 32rpx;
  260. font-weight: 600;
  261. color: #000000;
  262. }
  263. .list-box {
  264. margin-top: 16rpx;
  265. background-color: #fff;
  266. padding: 0 32rpx;
  267. .list-box-item {
  268. height: 88rpx;
  269. display: flex;
  270. align-items: center;
  271. justify-content: space-between;
  272. .list-box-left {
  273. display: flex;
  274. align-items: center;
  275. image {
  276. width: 48rpx;
  277. height: 48rpx;
  278. }
  279. text {
  280. margin-left: 32rpx;
  281. font-size: 32rpx;
  282. font-weight: 400;
  283. color: #000000;
  284. }
  285. }
  286. .list-box-right {
  287. display: flex;
  288. font-size: 32rpx;
  289. font-weight: 600;
  290. color: #000000;
  291. .num {
  292. margin-right: 30rpx;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. </style>