Pārlūkot izejas kodu

增加 洞悉首页最近7天/30天数据展示

test
chenJinxu pirms 10 mēnešiem
vecāks
revīzija
cf0289f56c
3 mainītis faili ar 51 papildinājumiem un 23 dzēšanām
  1. +19
    -0
      src/filters/filter.js
  2. +1
    -0
      src/filters/index.js
  3. +31
    -23
      src/views/insight/index.vue

+ 19
- 0
src/filters/filter.js Parādīt failu

@@ -58,3 +58,22 @@ export function calcBMI(height, weight) {
}
return bmiObj;
}

/**
*
* @param {*} numDays
*/
export function getRangeStartAndEnd(numDays) {
// 获取当前日期对象
const currentDate = new Date();
const startDate = new Date(currentDate);
startDate.setDate(currentDate.getDate() - numDays + 1); // 减去numDays-1天以得到numDays天前的日期作为开始日期

const endDate = new Date(currentDate);
endDate.setDate(currentDate.getDate()); // 当前日期为结束日期

return {
start: startDate,
end: endDate
};
}

+ 1
- 0
src/filters/index.js Parādīt failu

@@ -6,3 +6,4 @@ Object.keys(filter).forEach(k => Vue.filter(k, filter[k]));
Vue.prototype.$formatDate = Vue.filter('formatDate');
Vue.prototype.$hidePhone = Vue.filter('hidePhone');
Vue.prototype.$calcBMI = Vue.filter('calcBMI');
Vue.prototype.$getRangeStartAndEnd = Vue.filter('getRangeStartAndEnd');

+ 31
- 23
src/views/insight/index.vue Parādīt failu

@@ -5,7 +5,7 @@
<div class="periodItem week" :class="{ active: active == 0 }" @click="active = 0">周</div>
<div class="periodItem month" :class="{ active: active == 1 }" @click="active = 1">月</div>
</div>
<DateSwitch :dateType="active == 0 ? 'week' : 'month'" @updateDate="updateDate"></DateSwitch>
<DateSwitch :dateType="active == 0 ? 'week' : 'month'" @updateDate="updateDate" v-if="false"></DateSwitch>
<!-- <div class="periodSwitch">
<div class="arrow arrowLeft">
<van-icon name="arrow-left"></van-icon>
@@ -306,12 +306,21 @@ export default {
},
mounted() {
this.initData();
this.getPsychologiclData();
},
watch: {
/* active(val) {
active(val) {
console.log(val);
let currentDate = new Date();
}, */
console.log('最近7天开始时间和结束时间', this.$getRangeStartAndEnd(7));
let days = val === 0 ? 7 : 30;
let startAndEndDate = this.$getRangeStartAndEnd(days);
let date = {
start: this.$dayjs(startAndEndDate.start).format('YYYY-MM-DD'),
end: this.$dayjs(startAndEndDate.end).format('YYYY-MM-DD')
};

this.updateDate(date);
},
emotionActive(val) {
console.log(val);
/* this.$nextTick(() => {
@@ -539,19 +548,22 @@ export default {
data: ''
}
];
let days = this.active === 0 ? 7 : 30;
let startAndEndDate = this.$getRangeStartAndEnd(days);
this.date = {
start: this.$dayjs(startAndEndDate.start).format('YYYY-MM-DD'),
end: this.$dayjs(startAndEndDate.end).format('YYYY-MM-DD')
};
},
// 获取情绪数据
getPsychologiclData(date, startDate, endDate) {
ToastService.loading({
message: '数据加载中'
});
let reqDate = date
? this.$dayjs(date).format('YYYY-MM-DD')
: this.routeDate || this.$dayjs(this.defaultDate).format('YYYY-MM-DD'); /* "2023-05-23" */
let reqParams = {
uid: this.uid,
startDate: startDate || reqDate,
endDate: endDate || reqDate,
startDate: startDate || this.date.start,
endDate: endDate || this.date.end,
type: this.emoType
};
console.log('请求参数', reqParams);
@@ -835,16 +847,10 @@ export default {
return list;
},
updateDate(value) {
console.log('组件原始值', value);
this.date = value;
console.log('this.date', this.date);
if (this.active == 1) {
this.getMonthStaEnd(this.date);
this.getPsychologiclData('', this.monthDate.start, this.monthDate.end);
} else {
this.getPsychologiclData('', value.start, value.end);
}
console.log('接口所需要的值', this.date, '如果是月', this.monthDate);
this.getPsychologiclData('', value.start, value.end);
this.getReportData('', value.start, value.end);
},
formateDate(time) {
let year = time.getFullYear();
@@ -904,7 +910,7 @@ export default {
/* if (!this.emotionChart) {
this.emotionChart = this.$echarts.init(document.getElementById('emotionChart'));
} */
if (!this.signChart) {
this.signChart = this.$echarts.init(document.getElementById('signChart'));
}
@@ -959,7 +965,8 @@ export default {
},
async initSignChart() {
let option = this.getOption();
let data = await this.getReportData();

let data = await this.getReportData('', this.date.start, this.date.end);
if (this.signActive == 0) {
//测试
this.formateHeartRateData(option, data.day);
@@ -971,7 +978,7 @@ export default {
} else if (this.signActive == 2) {
option = this.getOption(false);
let option2 = this.getOption(false);
let data2 = await this.getReportData(3);
let data2 = await this.getReportData(3, this.date.start, this.date.end);
this.stepsData = { ...data };
this.calorieData = { ...data2 };

@@ -1364,13 +1371,14 @@ export default {
return color;
},
// 获取体征历史数据
getReportData(value) {
getReportData(value, startDate, endDate) {
let reqDate = this.date;
let reqBody = {
personId: this.$store.getters.personId,
dateType: 1,
healthyType: value || this.signActive,
startTime: '2024-01-28',
endTime: '2024-02-03'
startTime: startDate || reqDate.start,
endTime: endDate || reqDate.end
};
return new Promise(resolve => {
APIHealthUser.getReportData(reqBody).then(res => {


Notiek ielāde…
Atcelt
Saglabāt