123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- <template>
- <view>
- <view class="top-box">
- <view class="container-top" @click="showPicker = true">
- <view class="top-left">
- <view class="word">一周内</view>
- <text>{{formatDate(defaultDate[0])}} ~ {{formatDate(defaultDate[1])}}</text>
- </view>
- <!-- <view class="top-right" @click.stop="fullscreenFn">
- <image src="/static/image/full.png" mode=""></image>
- </view> -->
- </view>
- <view class="chartsMain" v-show="Area.categories.length&&!showPicker">
- <canvas canvas-id="canvasArea" id="canvasArea" class="charts"></canvas>
- </view>
- <view class="chartsMain" v-show="!Area.categories.length">
- <image src="/static/image/none.png" mode=""></image>
- </view>
- </view>
- <view class="content-box">
- <view class="number-box">
- <view class="box-item">
- <text>最低</text>
- <view class="item-under">
- <view class="item-under-left">
- <image src="/static/image/stepIcon.png" mode=""></image>
- <text>{{infoData.min}}</text>
- </view>
- <text>Step</text>
- </view>
- </view>
- <view class="box-item">
- <text>平均</text>
- <view class="item-under">
- <view class="item-under-left">
- <image src="/static/image/stepIcon.png" mode=""></image>
- <text>{{infoData.avg}}</text>
- </view>
- <text>Step</text>
- </view>
- </view>
- <view class="box-item">
- <text>最高</text>
- <view class="item-under">
- <view class="item-under-left">
- <image src="/static/image/stepIcon.png" mode=""></image>
- <text>{{infoData.max}}</text>
- </view>
- <text>Step</text>
- </view>
- </view>
- </view>
- <view class="word-box">
- <view class="word-title">
- 步数记录
- </view>
- </view>
- <view class="list-box">
- <block v-for="(item,index) in infoData.list">
- <view class="list-box-item">
- <view class="list-box-left">
- <image src="/static/image/hearticon.png" mode=""></image>
- <text>{{formatHms(item.createTime)}}</text>
- </view>
- <view class="list-box-right">
- <view class="num">{{item.stepNumber}}</view>
- <view>Step</view>
- </view>
- </view>
- </block>
- </view>
- </view>
- <!-- 日历 -->
- <van-calendar :show="showPicker" type="range" @confirm="onConfirm" @close="showPicker = false"
- :default-date="defaultDate" allow-same-day="true" :min-date="minDate" />
- </view>
- </template>
- <script>
- // import contentPage from './components/content.vue'
- // 图表
- import uCharts from "@/components/ucharts/ucharts.js";
- import * as infoApi from '@/api/info/index.js';
- import dayjs from "@/plugin/dayjs/dayjs.min.js";
- import {
- mapGetters
- } from "vuex";
- // import uCharts from "@/components/u-charts/u-charts.js";
- var _self;
- var canvaRing = null;
- var canvaArea = null;
- var canvaGauge = null;
- var canvaPie = null;
- var canvaColumn = null;
- var canvaFunnel = null;
- var canvaWord = null;
- export default {
- // components: {
- // contentPage
- // },
- data() {
- return {
- cWidth: '',
- cHeight: '',
- pixelRatio: 1,
- // dayValue: new Date(),
- defaultDate: [], //默认一周内
- showPicker: false, //日
- infoData: {}, //日数据
- minDate: new Date(2023, 0, 1).getTime(),
- list: [{
- time: '09:00',
- num: 63
- }, {
- time: '09:10',
- num: 63
- }, {
- time: '09:10',
- num: 63
- }],
- // 折线图
- Area: {
- categories: [],
- // categories: ['08:22','08:22','08:22','08:22'],
- series: [{
- name: '步数',
- data: [],
- // data: [68,89,66,79],
- color: '#F35546'
- }]
- }
- };
- },
- computed: mapGetters(['deviceId']),
- async onLoad() {
- _self = this;
- this.cWidth = uni.upx2px(680);
- this.cHeight = uni.upx2px(400);
- this.defaultDate = [new Date(new Date().getTime() - 6 * 24 * 60 * 60 * 1000).getTime(), new Date()
- .getTime()
- ]
- await this.getData()
- this.getServerData();
- },
- mounted() {
- },
- methods: {
- getData() {
- let params = {
- deviceId: this.deviceId,
- startTime: `${this.formatDate(this.defaultDate[0])} 00:00:00`,
- endTime: `${this.formatDate(this.defaultDate[1])} 23:59:59`,
- }
- console.log(params, 111);
- return infoApi.getStepNumber(params).then(res => {
- if (res.data === null) {
- this.infoData = {}
- this.infoData.list = []
- this.Area.categories = []
- }
- if (res.code === 0 && res.data.list.length) {
- this.infoData = res.data
- // 组装接口数据。上方折线图若超过10条,截取10条
- let categoriesArr = res.data.list.map(item => this.formatHHmm(item.createTime))
- let seriesArr = res.data.list.map(item => item.stepNumber)
- this.Area.categories = categoriesArr.length > 10 ? categoriesArr.slice(-10) :
- categoriesArr
- this.Area.series[0].data = seriesArr.length > 10 ? seriesArr.slice(-10) : seriesArr
- }
- })
- .catch(err => {
- return this.$util.Tips({
- title: err,
- // icon: 'error'
- });
- });
- },
- formatHms: function(date) {
- return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
- },
- formatDate: function(date) {
- return dayjs(date).format("YYYY-MM-DD");
- },
- formatHHmm: function(date) {
- return dayjs(date).format("MM-DD");
- },
- async onConfirm(date) {
- console.log(date, 777);
- this.defaultDate = date.detail;
- await this.getData()
- this.getServerData()
- this.showPicker = false;
- },
- getServerData() {
- _self.showArea("canvasArea", this.chartData);
- },
- // 折线图
- showArea(canvasId, chartData) {
- canvaArea = new uCharts({
- $this: _self,
- canvasId: canvasId,
- type: 'area',
- fontSize: 11,
- legend: false,
- dataLabel: true,
- dataPointShape: true,
- background: '#FFFFFF',
- pixelRatio: _self.pixelRatio,
- categories: _self.Area.categories,
- series: _self.Area.series,
- animation: true,
- padding: [20, 10, 10, 10],
- xAxis: {
- type: 'grid',
- gridColor: '#CCCCCC',
- gridType: 'solid',
- dashLength: 8,
- disableGrid: true,
- rotateLabel:true,
- rotateAngle:-50,
- },
- yAxis: {
- gridType: 'dash',
- gridColor: '#CCCCCC',
- dashLength: 8,
- splitNumber: 5,
- min: 0,
- // max: 180,
- },
- width: _self.cWidth * _self.pixelRatio,
- height: _self.cHeight * _self.pixelRatio,
- extra: {
- area: {
- type: 'straight',
- opacity: 0.2,
- addLine: true,
- width: 2
- }
- }
- });
- },
- touchArea(e) {
- canvaArea.showToolTip(e, {
- format: function(item, category) {
- return item.name + ' ' + category + ' ' + ':' + item.data
- }
- });
- },
- }
- };
- </script>
- <style lang="scss" scoped>
- ::v-deep .van-calendar{
- z-index: 15 !important;
- }
- .top-box {
- padding: 28rpx 32rpx 19rpx;
- background-color: #fff;
- .container-top {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 28rpx;
- .top-left {
- .word {
- font-size: 36rpx;
- font-weight: 500;
- color: #000000;
- }
- text {
- font-size: 24rpx;
- font-weight: 500;
- color: #777777;
- line-height: 33rpx;
- }
- }
- .top-right {
- width: 32rpx;
- height: 32rpx;
- image {
- width: 32rpx;
- height: 32rpx;
- }
- }
- }
- .chartsMain {
- width: 100%;
- // height: 450rpx;
- // box-sizing: border-box;
- background: #fff;
- border-top: 2rpx solid #f2f2f2;
- text-align: center;
- image {
- width: 70%;
- // height: 100%;
- }
- .charts {
- width: 680rpx;
- height: 400rpx;
- box-sizing: border-box;
- z-index: 10;
- }
- }
- }
- .content-box {
- background-color: #F7F7F7;
- // height: 100vh;
- .number-box {
- height: 131rpx;
- background-color: #fff;
- display: flex;
- margin-top: 16rpx;
- padding: 16rpx 32rpx;
- justify-content: space-around;
- .box-item {
- width: 218rpx;
- padding: 10rpx 16rpx;
- box-sizing: border-box;
- border-radius: 12rpx;
- border: 2rpx solid rgba(119, 119, 119, 0.3);
- text {
- font-size: 24rpx;
- font-weight: 400;
- color: #777777;
- }
- .item-under {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-top: 12rpx;
- .item-under-left {
- image {
- width: 32rpx;
- height: 32rpx;
- }
- text {
- margin-left: 15rpx;
- font-size: 32rpx;
- font-weight: 400;
- color: #000000;
- }
- }
- text {
- font-size: 24rpx;
- font-weight: 400;
- color: #777777;
- }
- }
- }
- }
- .word-box {
- margin-top: 16rpx;
- background-color: #fff;
- padding: 32rpx;
- font-size: 32rpx;
- font-weight: 600;
- color: #000000;
- }
- .list-box {
- margin-top: 16rpx;
- background-color: #fff;
- padding: 0 32rpx;
- .list-box-item {
- height: 88rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .list-box-left {
- display: flex;
- align-items: center;
- image {
- width: 48rpx;
- height: 48rpx;
- }
- text {
- margin-left: 32rpx;
- font-size: 32rpx;
- font-weight: 400;
- color: #000000;
- }
- }
- .list-box-right {
- display: flex;
- font-size: 32rpx;
- font-weight: 600;
- color: #000000;
- .num {
- margin-right: 30rpx;
- }
- }
- }
- }
- }
- </style>
|