// index.ts // 获取应用实例 let { getChannel } = require('../../utils/api') Page({ data: { userInfo: {}, onInitChart: undefined, array_act: 0, channelList_act: 0, array: [ { text: "", startDate: "", endDate: "" } ], channelList: [ { channelId: -1, channelName: "", localIndex: -1 } ] }, dateFommat(clearDay = 0): (string | number)[] { // 格式化日期 【年,月,日】 const nowTime = new Date(); let nowDate = new Date(nowTime.getTime() - clearDay * 86400000), month = nowDate.getMonth() + 1 > 9 ? nowDate.getMonth() + 1 : "0" + (nowDate.getMonth() + 1), day = nowDate.getDate() > 9 ? nowDate.getDate() : "0" + nowDate.getDate(); return [nowDate.getFullYear(), month, day]; }, timeList(): { text: string; startDate: string; endDate: string; }[] { let o = this.dateFommat(1), oldT = this.dateFommat(7), timeSelect = [ { text: "最近7天", startDate: oldT.join("-"), endDate: o.join("-"), }, ]; for (let i = 1; i <= 3; i++) { let T = this.dateFommat(30 * i), lastDay = new Date(Number(T[0]), Number(T[1]), 0); timeSelect.push({ text: `${T[0]}年${T[1]}月`, startDate: `${T[0]}-${T[1]}-01`, endDate: `${T[0]}-${T[1]}-${lastDay.getDate()}`, }); } return timeSelect; }, bindPickerChange(event: wxPicker) { // const item = this.data.array[Number(event.detail.value)]; this.setData({ array_act: Number(event.detail.value) }) }, channelChange(event: wxPicker) { this.setData({ channelList_act: Number(event.detail.value) }) }, onLoad() { const user = wx.getStorageSync("userInfo") || {}; let p = { userInfo: {}, array: this.timeList(), channelList: [ { channelId: -1, channelName: "", localIndex: -1 } ] }; user.signature && (p.userInfo = user) getChannel().then((li: { channelId: number, channelName: string }[]) => { p.channelList = (li || []).map((v, i) => { return { channelId: v.channelId, channelName: v.channelName, localIndex: i } }) this.setData(p); }) }, })