moment 近30天 近1年 近7天

 

 

if (i == 1) {
                            //近30天
                            let d30 = [...new Array(30)].map((i, idx) => this.moment().startOf("day").subtract(idx, "days").format('MM-DD')).reverse();
                            //随机数
                            let randomArr1 = [];
                            let randomArr2 = [];
                            for (let i = 0; i < 30; i++) {
                                randomArr1.push(Math.round(Math.random() * (d2 - d1) + d1));
                                randomArr2.push(Math.round(Math.random() * (d4 - d3) + d3));
                            }
                            this.datalistdd = [['用水', '用电'], d30, randomArr1, randomArr2]
                        } else {
                            //近1年
                            let dyear = [...new Array(12)].map((i, idx) => this.moment().startOf("month").subtract(idx, "months").format('YYYY-MM')).reverse();
                            //随机数
                            let randomArr1 = [];
                            let randomArr2 = [];
                            for (let i = 0; i < 12; i++) {
                                randomArr1.push(Math.round(Math.random() * (d2 - d1) + d1));
                                randomArr2.push(Math.round(Math.random() * (d4 - d3) + d3));
                            }
                            this.datalistdd = [['用水', '用电'], dyear, randomArr1, randomArr2]
                        }
let ds = [...new Array(7)].map((i, idx) => this.$moment().startOf("day").subtract(idx, "days").format("MM-DD"));
    this.dataList[0] = ds.reverse();

 

posted @ 2023-07-31 14:56  abcByme  阅读(207)  评论(1编辑  收藏  举报