diff --git a/src/filters/filter.js b/src/filters/filter.js index f603ae4..a4d895d 100644 --- a/src/filters/filter.js +++ b/src/filters/filter.js @@ -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 + }; +} diff --git a/src/filters/index.js b/src/filters/index.js index 6f1f749..4238764 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -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'); diff --git a/src/views/insight/index.vue b/src/views/insight/index.vue index 8b0ba19..2c18678 100644 --- a/src/views/insight/index.vue +++ b/src/views/insight/index.vue @@ -5,7 +5,7 @@
- +