Files
FreeERP.Applet/miniprogram/pages/base/workload/workload.ts
2026-03-12 15:16:49 +08:00

187 lines
4.9 KiB
TypeScript

import { onPageLoadInitAuth, post } from '@/utils/https';
import { toArray, toNumber } from '@/utils/util';
// import uCharts from '@/uCharts/u-charts.min.js';
// const uChartsInstance: any = {};
// console.log(uCharts);
Page({
/**
* 页面的初始数据
*/
data: {
process_count: [] as any[],
seven_process_count: [] as any[],
isLogin: false,
// cWidth: 750,
// cHeight: 500,
// pixelRatio: 2,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {},
// drawCharts(id: string, data: any) {
// const query = wx.createSelectorQuery().in(this);
// query
// .select('#' + id)
// .fields({ node: true, size: true })
// .exec((res) => {
// if (res[0]) {
// const canvas = res[0].node;
// const ctx = canvas.getContext('2d');
// canvas.width = res[0].width * this.data.pixelRatio;
// canvas.height = res[0].height * this.data.pixelRatio;
// uChartsInstance[id] = new uCharts({
// animation: true,
// background: '#FFFFFF',
// canvas2d: true,
// categories: data.categories,
// color: [
// '#1890FF',
// '#91CB74',
// '#FAC858',
// '#EE6666',
// '#73C0DE',
// '#3CA272',
// '#FC8452',
// '#9A60B4',
// '#ea7ccc',
// ],
// context: ctx,
// extra: {
// column: { type: 'group', width: 30, activeBgColor: '#000000', activeBgOpacity: 0.08 },
// },
// height: this.data.cHeight * this.data.pixelRatio,
// legend: {},
// padding: [15, 15, 0, 5],
// pixelRatio: this.data.pixelRatio,
// series: data.series,
// type: 'column',
// width: this.data.cWidth * this.data.pixelRatio,
// xAxis: { disableGrid: true },
// yAxis: {
// data: [{ min: 0 }],
// },
// });
// } else {
// console.error('[uCharts]: 未获取到 context');
// }
// });
// },
// tap(e: any) {
// uChartsInstance[e.target.id].touchLegend(e);
// uChartsInstance[e.target.id].showToolTip(e);
// },
getList() {
// let res = {
// categories: ['2016', '2017', '2018', '2019', '2020', '2021'],
// series: [
// {
// name: '目标值',
// data: [35, 36, 31, 33, 13, 34],
// },
// {
// name: '完成量',
// data: [18, 27, 21, 24, 6, 28],
// },
// ],
// };
// this.drawCharts('afMCYQMEmXXVAjNQFJvvfxbLSHuxNEOL', res);
return new Promise<void>((resolve, reject) => {
post('Index/index')
.then((res: any) => {
const process_count = toArray(res.process_count).filter((el) => {
el.count = toNumber(el.count);
return el.count > 0;
});
const arr = toArray(res.seven_process_count).filter((el) => {
el.count = toNumber(el.count);
return el.count > 0;
});
const map = new Map<string, any>();
arr.forEach((el) => {
if (!map.has(el.date)) {
map.set(el.date, []);
}
map.get(el.date).push(el);
});
// console.log([...map.values()]);
this.setData({
seven_process_count: [...map.values()],
process_count: process_count,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
})
.finally(() => {
wx.stopPullDownRefresh();
});
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(_options) {},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
// //这里的第一个 750 对应 css .charts 的 width
// const cWidth = wx.getWindowInfo().windowWidth - 24;
// //这里的 500 对应 css .charts 的 height
// const cHeight = wx.getWindowInfo().windowWidth * 0.68;
// const pixelRatio = wx.getWindowInfo().pixelRatio;
// this.setData({ cWidth, cHeight, pixelRatio });
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
onPageLoadInitAuth(this, () => this.getList());
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
if (this.data.isLogin) {
this.init();
}
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {},
});