123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- // 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)];
- console.log(item)
- 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);
- })
- },
- getUserProfile() {
- // 获取用户信息,妥善保管用户快速填写的头像昵称,避免重复弹窗
- wx.getUserProfile({
- desc: '大数据平台账户信息完善', // 声明获取用户个人信息后的用途,后续会展示在弹窗中
- success: (res) => {
- if (!res.signature) return
- wx.setStorageSync("userInfo", res)
- this.setData({
- userInfo: res,
- })
- }
- })
- },
- })
|