index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view>
  3. <view class="top-box">
  4. <view class="container-top" @click="showPicker = true">
  5. <view class="top-left">
  6. <view class="word">一周内</view>
  7. <text>{{formatDate(defaultDate[0])}} ~ {{formatDate(defaultDate[1])}}</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-show="Area.categories.length&&!showPicker">
  14. <canvas canvas-id="canvasArea" id="canvasArea" class="charts"></canvas>
  15. </view>
  16. <view class="chartsMain" v-show="!Area.categories.length">
  17. <image src="/static/image/none.png" mode=""></image>
  18. </view>
  19. </view>
  20. <view class="content-box">
  21. <view class="number-box">
  22. <view class="box-item">
  23. <text>最低</text>
  24. <view class="item-under">
  25. <view class="item-under-left">
  26. <image src="/static/image/stepIcon.png" mode=""></image>
  27. <text>{{infoData.min}}</text>
  28. </view>
  29. <text>Step</text>
  30. </view>
  31. </view>
  32. <view class="box-item">
  33. <text>平均</text>
  34. <view class="item-under">
  35. <view class="item-under-left">
  36. <image src="/static/image/stepIcon.png" mode=""></image>
  37. <text>{{infoData.avg}}</text>
  38. </view>
  39. <text>Step</text>
  40. </view>
  41. </view>
  42. <view class="box-item">
  43. <text>最高</text>
  44. <view class="item-under">
  45. <view class="item-under-left">
  46. <image src="/static/image/stepIcon.png" mode=""></image>
  47. <text>{{infoData.max}}</text>
  48. </view>
  49. <text>Step</text>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="word-box">
  54. <view class="word-title">
  55. 步数记录
  56. </view>
  57. </view>
  58. <view class="list-box">
  59. <block v-for="(item,index) in infoData.list">
  60. <view class="list-box-item">
  61. <view class="list-box-left">
  62. <image src="/static/image/hearticon.png" mode=""></image>
  63. <text>{{formatHms(item.createTime)}}</text>
  64. </view>
  65. <view class="list-box-right">
  66. <view class="num">{{item.stepNumber}}</view>
  67. <view>Step</view>
  68. </view>
  69. </view>
  70. </block>
  71. </view>
  72. </view>
  73. <!-- 日历 -->
  74. <van-calendar :show="showPicker" type="range" @confirm="onConfirm" @close="showPicker = false"
  75. :default-date="defaultDate" allow-same-day="true" :min-date="minDate" />
  76. </view>
  77. </template>
  78. <script>
  79. // import contentPage from './components/content.vue'
  80. // 图表
  81. import uCharts from "@/components/ucharts/ucharts.js";
  82. import * as infoApi from '@/api/info/index.js';
  83. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  84. import {
  85. mapGetters
  86. } from "vuex";
  87. // import uCharts from "@/components/u-charts/u-charts.js";
  88. var _self;
  89. var canvaRing = null;
  90. var canvaArea = null;
  91. var canvaGauge = null;
  92. var canvaPie = null;
  93. var canvaColumn = null;
  94. var canvaFunnel = null;
  95. var canvaWord = null;
  96. export default {
  97. // components: {
  98. // contentPage
  99. // },
  100. data() {
  101. return {
  102. cWidth: '',
  103. cHeight: '',
  104. pixelRatio: 1,
  105. // dayValue: new Date(),
  106. defaultDate: [], //默认一周内
  107. showPicker: false, //日
  108. infoData: {}, //日数据
  109. minDate: new Date(2023, 0, 1).getTime(),
  110. list: [{
  111. time: '09:00',
  112. num: 63
  113. }, {
  114. time: '09:10',
  115. num: 63
  116. }, {
  117. time: '09:10',
  118. num: 63
  119. }],
  120. // 折线图
  121. Area: {
  122. categories: [],
  123. // categories: ['08:22','08:22','08:22','08:22'],
  124. series: [{
  125. name: '步数',
  126. data: [],
  127. // data: [68,89,66,79],
  128. color: '#F35546'
  129. }]
  130. }
  131. };
  132. },
  133. computed: mapGetters(['deviceId']),
  134. async onLoad() {
  135. _self = this;
  136. this.cWidth = uni.upx2px(680);
  137. this.cHeight = uni.upx2px(400);
  138. this.defaultDate = [new Date(new Date().getTime() - 6 * 24 * 60 * 60 * 1000).getTime(), new Date()
  139. .getTime()
  140. ]
  141. await this.getData()
  142. this.getServerData();
  143. },
  144. mounted() {
  145. },
  146. methods: {
  147. getData() {
  148. let params = {
  149. deviceId: this.deviceId,
  150. startTime: `${this.formatDate(this.defaultDate[0])} 00:00:00`,
  151. endTime: `${this.formatDate(this.defaultDate[1])} 23:59:59`,
  152. }
  153. console.log(params, 111);
  154. return infoApi.getStepNumber(params).then(res => {
  155. if (res.data === null) {
  156. this.infoData = {}
  157. this.infoData.list = []
  158. this.Area.categories = []
  159. }
  160. if (res.code === 0 && res.data.list.length) {
  161. this.infoData = res.data
  162. // 组装接口数据。上方折线图若超过10条,截取10条
  163. let categoriesArr = res.data.list.map(item => this.formatHHmm(item.createTime))
  164. let seriesArr = res.data.list.map(item => item.stepNumber)
  165. this.Area.categories = categoriesArr.length > 10 ? categoriesArr.slice(-10) :
  166. categoriesArr
  167. this.Area.series[0].data = seriesArr.length > 10 ? seriesArr.slice(-10) : seriesArr
  168. }
  169. })
  170. .catch(err => {
  171. return this.$util.Tips({
  172. title: err,
  173. // icon: 'error'
  174. });
  175. });
  176. },
  177. formatHms: function(date) {
  178. return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
  179. },
  180. formatDate: function(date) {
  181. return dayjs(date).format("YYYY-MM-DD");
  182. },
  183. formatHHmm: function(date) {
  184. return dayjs(date).format("MM-DD");
  185. },
  186. async onConfirm(date) {
  187. console.log(date, 777);
  188. this.defaultDate = date.detail;
  189. await this.getData()
  190. this.getServerData()
  191. this.showPicker = false;
  192. },
  193. getServerData() {
  194. _self.showArea("canvasArea", this.chartData);
  195. },
  196. // 折线图
  197. showArea(canvasId, chartData) {
  198. canvaArea = new uCharts({
  199. $this: _self,
  200. canvasId: canvasId,
  201. type: 'area',
  202. fontSize: 11,
  203. legend: false,
  204. dataLabel: true,
  205. dataPointShape: true,
  206. background: '#FFFFFF',
  207. pixelRatio: _self.pixelRatio,
  208. categories: _self.Area.categories,
  209. series: _self.Area.series,
  210. animation: true,
  211. padding: [20, 10, 10, 10],
  212. xAxis: {
  213. type: 'grid',
  214. gridColor: '#CCCCCC',
  215. gridType: 'solid',
  216. dashLength: 8,
  217. disableGrid: true,
  218. rotateLabel:true,
  219. rotateAngle:-50,
  220. },
  221. yAxis: {
  222. gridType: 'dash',
  223. gridColor: '#CCCCCC',
  224. dashLength: 8,
  225. splitNumber: 5,
  226. min: 0,
  227. // max: 180,
  228. },
  229. width: _self.cWidth * _self.pixelRatio,
  230. height: _self.cHeight * _self.pixelRatio,
  231. extra: {
  232. area: {
  233. type: 'straight',
  234. opacity: 0.2,
  235. addLine: true,
  236. width: 2
  237. }
  238. }
  239. });
  240. },
  241. touchArea(e) {
  242. canvaArea.showToolTip(e, {
  243. format: function(item, category) {
  244. return item.name + ' ' + category + ' ' + ':' + item.data
  245. }
  246. });
  247. },
  248. }
  249. };
  250. </script>
  251. <style lang="scss" scoped>
  252. ::v-deep .van-calendar{
  253. z-index: 15 !important;
  254. }
  255. .top-box {
  256. padding: 28rpx 32rpx 19rpx;
  257. background-color: #fff;
  258. .container-top {
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. margin-bottom: 28rpx;
  263. .top-left {
  264. .word {
  265. font-size: 36rpx;
  266. font-weight: 500;
  267. color: #000000;
  268. }
  269. text {
  270. font-size: 24rpx;
  271. font-weight: 500;
  272. color: #777777;
  273. line-height: 33rpx;
  274. }
  275. }
  276. .top-right {
  277. width: 32rpx;
  278. height: 32rpx;
  279. image {
  280. width: 32rpx;
  281. height: 32rpx;
  282. }
  283. }
  284. }
  285. .chartsMain {
  286. width: 100%;
  287. // height: 450rpx;
  288. // box-sizing: border-box;
  289. background: #fff;
  290. border-top: 2rpx solid #f2f2f2;
  291. text-align: center;
  292. image {
  293. width: 70%;
  294. // height: 100%;
  295. }
  296. .charts {
  297. width: 680rpx;
  298. height: 400rpx;
  299. box-sizing: border-box;
  300. z-index: 10;
  301. }
  302. }
  303. }
  304. .content-box {
  305. background-color: #F7F7F7;
  306. // height: 100vh;
  307. .number-box {
  308. height: 131rpx;
  309. background-color: #fff;
  310. display: flex;
  311. margin-top: 16rpx;
  312. padding: 16rpx 32rpx;
  313. justify-content: space-around;
  314. .box-item {
  315. width: 218rpx;
  316. padding: 10rpx 16rpx;
  317. box-sizing: border-box;
  318. border-radius: 12rpx;
  319. border: 2rpx solid rgba(119, 119, 119, 0.3);
  320. text {
  321. font-size: 24rpx;
  322. font-weight: 400;
  323. color: #777777;
  324. }
  325. .item-under {
  326. display: flex;
  327. justify-content: space-between;
  328. align-items: center;
  329. margin-top: 12rpx;
  330. .item-under-left {
  331. image {
  332. width: 32rpx;
  333. height: 32rpx;
  334. }
  335. text {
  336. margin-left: 15rpx;
  337. font-size: 32rpx;
  338. font-weight: 400;
  339. color: #000000;
  340. }
  341. }
  342. text {
  343. font-size: 24rpx;
  344. font-weight: 400;
  345. color: #777777;
  346. }
  347. }
  348. }
  349. }
  350. .word-box {
  351. margin-top: 16rpx;
  352. background-color: #fff;
  353. padding: 32rpx;
  354. font-size: 32rpx;
  355. font-weight: 600;
  356. color: #000000;
  357. }
  358. .list-box {
  359. margin-top: 16rpx;
  360. background-color: #fff;
  361. padding: 0 32rpx;
  362. .list-box-item {
  363. height: 88rpx;
  364. display: flex;
  365. align-items: center;
  366. justify-content: space-between;
  367. .list-box-left {
  368. display: flex;
  369. align-items: center;
  370. image {
  371. width: 48rpx;
  372. height: 48rpx;
  373. }
  374. text {
  375. margin-left: 32rpx;
  376. font-size: 32rpx;
  377. font-weight: 400;
  378. color: #000000;
  379. }
  380. }
  381. .list-box-right {
  382. display: flex;
  383. font-size: 32rpx;
  384. font-weight: 600;
  385. color: #000000;
  386. .num {
  387. margin-right: 30rpx;
  388. }
  389. }
  390. }
  391. }
  392. }
  393. </style>