206 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			206 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
import * as apis from '@/services/apis'
 | 
						|
import { orderBy } from 'lodash'
 | 
						|
import moment from "moment";
 | 
						|
import {generateUUID} from "ant-design-vue/lib/vc-select/util";
 | 
						|
 | 
						|
const colors = [
 | 
						|
  '#00FEF6',
 | 
						|
  '#FF9811',
 | 
						|
  '#FF4D11',
 | 
						|
  '#529a58',
 | 
						|
  '#D58FFF',
 | 
						|
  '#0395F6',
 | 
						|
  '#d5b11e',
 | 
						|
  '#03f634',
 | 
						|
  '#d5391e',
 | 
						|
  '#f6ce03'
 | 
						|
]
 | 
						|
export default {
 | 
						|
  created() {
 | 
						|
    this.getData()
 | 
						|
    if (this.timer) {
 | 
						|
      clearInterval(this.timer)
 | 
						|
      this.timer = null
 | 
						|
    }
 | 
						|
    this.timer = setInterval(() => {
 | 
						|
      this.getData()
 | 
						|
    }, 5000)
 | 
						|
  },
 | 
						|
  beforeDestroy() {
 | 
						|
    if (this.timer) {
 | 
						|
      clearInterval(this.timer)
 | 
						|
      this.timer = null
 | 
						|
    }
 | 
						|
  },
 | 
						|
  data () {
 | 
						|
    return {
 | 
						|
      resourcesStatistics: {},
 | 
						|
      studentGradStatistics: [],
 | 
						|
      deviceStatistics: {},
 | 
						|
      accessStatistics: {},
 | 
						|
      classBrandStatistics: {},
 | 
						|
      studentAttendanceStatistics: {},
 | 
						|
      studentAttendanceStatisticsPie: [],
 | 
						|
      leaveStatistics: [],
 | 
						|
      gradeStatistics: [],
 | 
						|
      gradeStatisticsData: [],
 | 
						|
      accessInfo: [],
 | 
						|
      studentSexStatistics: {
 | 
						|
        men: {
 | 
						|
          total: 0,
 | 
						|
          percent: 0
 | 
						|
        },
 | 
						|
        women: {
 | 
						|
          total: 0,
 | 
						|
          percent: 0
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
  },
 | 
						|
  methods: {
 | 
						|
    getData () {
 | 
						|
      this.getResourcesStatistics()
 | 
						|
      this.getStudentGradStatistics()
 | 
						|
      this.getStudentSexStatistics()
 | 
						|
      this.getDeviceStatistics()
 | 
						|
      this.getAccessStatistics()
 | 
						|
      this.getClassBrandStatistics()
 | 
						|
      this.getAccessInfo()
 | 
						|
      this.getStudentAttendanceStatistics()
 | 
						|
      this.getGradeStatistics()
 | 
						|
      this.getLeaveStatistics()
 | 
						|
    },
 | 
						|
 | 
						|
    getPercent (num, total) {
 | 
						|
      if (num === 0) return 0
 | 
						|
      if (total === 0) return 100
 | 
						|
      return (num * 100 / total).toFixed(2)
 | 
						|
    },
 | 
						|
    // 获取教育资源
 | 
						|
    async getResourcesStatistics () {
 | 
						|
      const { data } = await apis.getResourcesStatistics()
 | 
						|
      this.resourcesStatistics = data || {}
 | 
						|
    },
 | 
						|
    // 各年级学生分布信息
 | 
						|
    async getStudentGradStatistics () {
 | 
						|
      const {data} = await apis.getStudentGradStatistics()
 | 
						|
 | 
						|
      this.studentGradStatistics = (data || []).map((item, index) => {
 | 
						|
        return {
 | 
						|
          attr: '年级分布',
 | 
						|
          name: `${item.gradeIndex}年级`,
 | 
						|
          value: item.studentNumber,
 | 
						|
          color: colors[index]
 | 
						|
        }
 | 
						|
      })
 | 
						|
 | 
						|
    },
 | 
						|
    // 性别分布
 | 
						|
    async getStudentSexStatistics () {
 | 
						|
      const { data } = await apis.getStudentSexStatistics()
 | 
						|
      const total = (data || []).reduce((a, b) => a + b.studentNumber || 0, 0)
 | 
						|
      const men =  (data || []).filter(item => `${item.studentSex}` === '1').reduce((a, b) => a + b.studentNumber || 0, 0)
 | 
						|
      const women =  (data || []).filter(item => `${item.studentSex}` === '2').reduce((a, b) => a + b.studentNumber || 0, 0)
 | 
						|
      this.studentSexStatistics = {
 | 
						|
        men: {
 | 
						|
          total: men,
 | 
						|
          percent: this.getPercent(men, total)
 | 
						|
        },
 | 
						|
        women: {
 | 
						|
          total: women,
 | 
						|
          percent: this.getPercent(women, total)
 | 
						|
        }
 | 
						|
      }
 | 
						|
    },
 | 
						|
    // 电子班牌概况
 | 
						|
    async getDeviceStatistics () {
 | 
						|
      const { data } = await apis.getDeviceStatistics()
 | 
						|
      this.deviceStatistics = data || {}
 | 
						|
    },
 | 
						|
    // 门禁出入人数
 | 
						|
    async getAccessStatistics () {
 | 
						|
      const { data } = await apis.getAccessStatistics()
 | 
						|
      this.accessStatistics = data || {}
 | 
						|
    },
 | 
						|
 | 
						|
    async getClassBrandStatistics () {
 | 
						|
      const { data } = await apis.getClassBrandStatistics()
 | 
						|
      this.classBrandStatistics = data || {}
 | 
						|
    },
 | 
						|
 | 
						|
 | 
						|
    async getAccessInfo () {
 | 
						|
      const { data } = await apis.getAccessInfo()
 | 
						|
      this.accessInfo  = (data || []).map(item => ({
 | 
						|
        ...item,
 | 
						|
        uuid: generateUUID()
 | 
						|
      }))
 | 
						|
    },
 | 
						|
 | 
						|
    async getStudentAttendanceStatistics () {
 | 
						|
      const { data } = await apis.getStudentAttendanceStatistics()
 | 
						|
      const _data =  data || {}
 | 
						|
      this.studentAttendanceStatistics =_data
 | 
						|
      this.studentAttendanceStatisticsPie = [
 | 
						|
        {
 | 
						|
          attr: '考勤',
 | 
						|
          name: '出勤',
 | 
						|
          value: _data.studentAttendanceNumber || 0,
 | 
						|
          color: colors[0]
 | 
						|
        },
 | 
						|
        {
 | 
						|
          attr: '考勤',
 | 
						|
          name: '迟到',
 | 
						|
          value: _data.studentAttendanceLaterNumber || 0,
 | 
						|
          color: colors[1]
 | 
						|
        },
 | 
						|
        {
 | 
						|
          attr: '考勤',
 | 
						|
          name: '缺勤',
 | 
						|
          value: _data.studentAttendanceLossNumber || 0,
 | 
						|
          color: colors[2]
 | 
						|
        },
 | 
						|
        {
 | 
						|
          attr: '考勤',
 | 
						|
          name: '请假',
 | 
						|
          value: _data.studentAttendanceLeaveNumber || 0,
 | 
						|
          color: colors[3]
 | 
						|
        }
 | 
						|
      ]
 | 
						|
    },
 | 
						|
 | 
						|
    async getGradeStatistics () {
 | 
						|
      const { data } = await apis.getGradeStatistics()
 | 
						|
      this.gradeStatisticsData = data || []
 | 
						|
      this.getGradeStatisticsPieData()
 | 
						|
    },
 | 
						|
    getGradeStatisticsPieData () {
 | 
						|
      const item = this.gradeStatisticsData.find(item => `${item && item.gradeIndex}` === `${this.cls}`) || {}
 | 
						|
      this.gradeStatistics = orderBy((item.classStatisticsList || []).map((item, index) => ({
 | 
						|
        attr: '班级',
 | 
						|
        name: `${item.className }`,
 | 
						|
        value: item.studentNumber || 0,
 | 
						|
        color: colors[index]
 | 
						|
      })), ['name'], ['asc'])
 | 
						|
    },
 | 
						|
 | 
						|
    async getLeaveStatistics () {
 | 
						|
      const { data } = await apis.getLeaveStatistics()
 | 
						|
      this.leaveStatistics = (data || []).map(item => {
 | 
						|
        return [
 | 
						|
          {
 | 
						|
            attr: '事假',
 | 
						|
            name: moment(item.leaveDate).format('MM/DD'),
 | 
						|
            value: item.businessLeavee || 0
 | 
						|
          },
 | 
						|
          {
 | 
						|
            attr: '病假',
 | 
						|
            name: moment(item.leaveDate).format('MM/DD'),
 | 
						|
            value: item.sickLeaveNumber || 0
 | 
						|
          }
 | 
						|
        ]
 | 
						|
      }).flat(Infinity)
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 |