123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- const app = getApp()
- import * as echarts from '../../../commpents/ec-canvas/echarts'
- Page({
- data: {
- frameStyle: { useTop: true, name: '出勤情况', leftArrow: true, useBar: false },
- // 学校
- zhSchool: '',
- school_id: '',
- schoolList: [],
- },
- // 返回
- back(e) {
- wx.navigateBack({ delta: 1 })
- },
- // 选择学校
- schoolChange: function (e) {
- const that = this;
- let data = that.data.schoolList[e.detail.value];
- if (data) {
- that.setData({ school_id: data.school_id });
- that.setData({ zhSchool: data.school_id_name });
- }
- that.watchLogin();
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- that.setData({
- ec: {
- onInit: that.initChart
- }
- })
- // 学校
- const school = await app.$get(`/rss`, { student_id: res.data.info.id });
- if (school.errcode == '0' && school.total > 0) {
- that.setData({ schoolList: school.data })
- }
- // 模拟请求
- var times = setTimeout(async function () {
- if (that.data.school_id) {
- const arr = await app.$get(`/statistics/studentLearning`, { school_id: that.data.school_id, student_id: res.data.info.id });
- if (arr.errcode == '0') {
- that.data.data1 = arr.data.signs;
- that.data.data2 = arr.data.minutes;
- }
- }
- clearTimeout(times);
- }, 1000)
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- // 折线图
- initChart(canvas, width, height, dpr) {
- let that = this;
- // 由于请求数据有延迟所以写一个时间函数,当数据存在的时候再执行绘制
- var times = setInterval(function () {
- var data1 = that.data.data1;
- var data2 = that.data.data2;
- if (data1 && data2) {
- clearInterval(times)
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- var option = {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'cross',
- label: {
- backgroundColor: '#6a7985'
- }
- }
- ,
- formatter: function (params) {
- let html = params[0].name + "<br>";
- for (let i = 0; i < params.length; i++) {
- html += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' + params[i].color + ';"></span>'
- if (params[i].seriesName == "签到数") {
- html += params[i].seriesName + ":" + params[i].value + "%<br>";
- }
- if (params[i].seriesName == "时长") {
- html += params[i].seriesName + ":" + params[i].value + "小时<br>";
- }
- }
- return html;
- }
- },
- legend: {
- textStyle: { color: '#4CA6A3' },
- x: 'right',
- data: [{ name: '签到数', icon: 'rect' }, { name: '时长', icon: 'rect' }]
- },
- grid: {
- left: '2%',
- right: '2%',
- containLabel: true
- },
- xAxis: [
- {
- type: 'category',
- boundaryGap: false,
- // 设置x轴线的属性
- axisLabel: {
- //x轴文字的配置
- show: true,
- interval: 0,//使x轴文字显示全
- },
- axisLine: {
- lineStyle: {
- color: '#4CA6A3', // 设置x轴字体颜色
- width: 2, // 设置x轴字体宽度
- }
- },
- data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
- }
- ],
- yAxis: [
- {
- type: 'value',
- name: '时长',
- position: 'left',
- alignTicks: true,
- axisLine: {
- show: true,
- lineStyle: {
- fontSize: 16,
- color: '#293C55'
- }
- },
- axisLabel: {
- formatter: '{value} 小时'
- }
- },
- {
- type: 'value',
- alignTicks: true,
- nameGap: 10,
- nameRotate: 0,
- nameTextStyle: {
- fontSize: 16,
- color: '#293C55'
- },
- splitLine: { show: false },//去除网格线
- min: 0,
- max: 100,
- interval: 10,
- // 设置轴线的属性
- axisLine: {
- show: true,
- lineStyle: {
- color: '#293C55',
- }
- }
- }
- ],
- series: [
- {
- name: '签到数',
- type: 'line',
- stack: '总量',
- areaStyle: {},
- itemStyle: {
- normal: {
- color: "#25DEDB",//折线点的颜色
- lineStyle: {
- color: "#25DEDB"//折线的颜色
- }
- }
- },
- areaStyle: { // 该属性设置可以使这下图区域颜色达到渐变的效果
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: '#25DEDB'
- }, {
- offset: 1,
- color: '#ffe'
- }])
- },
- data: data1
- },
- {
- name: '时长',
- type: 'line',
- stack: '总量',
- areaStyle: {},
- itemStyle: {
- normal: {
- color: "#E96C44",//折线点的颜色
- lineStyle: {
- color: "#E96C44"//折线的颜色
- }
- }
- },
- areaStyle: { // 该属性设置可以使这下图区域颜色达到渐变的效果
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: '#E96C44'
- }, {
- offset: 1,
- color: '#ffe'
- }])
- },
- data: data2
- }
- ]
- };
- chart.setOption(option, true);
- return chart;
- }
- }, 100)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () { },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- const that = this;
- // 监听用户是否登录
- that.watchLogin();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (res) {
- },
- })
|