student-attendance.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import { defineComponent, onMounted, reactive, watch } from 'vue'
  2. import { Image } from 'vant'
  3. import styles from './index.module.less'
  4. import arrowLine from '../images/week/icon-arrow-line.png'
  5. import arrowPoint from '../images/icon-arrow-point.png'
  6. import teacherArrowLine from '../images/month/teacher-icon-arrow-line.png'
  7. import * as echarts from 'echarts/core'
  8. import {
  9. TitleComponent,
  10. // 组件类型的定义后缀都为 ComponentOption
  11. TooltipComponent,
  12. GridComponent,
  13. // 数据集组件
  14. DatasetComponent,
  15. // 内置数据转换器组件 (filter, sort)
  16. TransformComponent,
  17. LegendComponent,
  18. ToolboxComponent,
  19. DataZoomComponent
  20. } from 'echarts/components'
  21. import { LineChart } from 'echarts/charts'
  22. import { LabelLayout, UniversalTransition } from 'echarts/features'
  23. import { CanvasRenderer } from 'echarts/renderers'
  24. import { reportCourseType } from '../week-report'
  25. // type EChartsOption = echarts.EChartsOption
  26. // 注册必须的组件
  27. echarts.use([
  28. TitleComponent,
  29. TooltipComponent,
  30. GridComponent,
  31. DatasetComponent,
  32. TransformComponent,
  33. LabelLayout,
  34. UniversalTransition,
  35. CanvasRenderer,
  36. ToolboxComponent,
  37. LegendComponent,
  38. DataZoomComponent,
  39. LineChart
  40. ])
  41. export default defineComponent({
  42. name: 'orchestra-num',
  43. props: {
  44. type: {
  45. type: String,
  46. default: 'week'
  47. },
  48. reportData: {
  49. type: Object,
  50. default: () => ({})
  51. }
  52. },
  53. setup(props) {
  54. const forms = reactive({
  55. total: 0
  56. })
  57. watch(
  58. () => props.reportData,
  59. () => {
  60. handleInit()
  61. }
  62. )
  63. let myChart: any
  64. const handleInit = () => {
  65. if (myChart) {
  66. myChart.dispose()
  67. }
  68. const data = props.reportData || {}
  69. const titleList: any = []
  70. const valueList: any = []
  71. let lineColor = '#356BF7'
  72. let textColor = '#1B4FD7'
  73. for (const i in data) {
  74. if (i === 'TOTAL') {
  75. forms.total = data[i] * 100
  76. if (forms.total <= 59) {
  77. lineColor = '#FF8057'
  78. textColor = '#F67146'
  79. }
  80. } else {
  81. titleList.push(reportCourseType[i])
  82. valueList.push(data[i] * 100)
  83. }
  84. }
  85. const chartDom = document.getElementById('studentEcharts')
  86. myChart = echarts.init(chartDom as HTMLDivElement)
  87. const option = {
  88. xAxis: {
  89. type: 'category',
  90. data: titleList,
  91. axisLabel: {
  92. rotate: 45,
  93. fontSize: 10,
  94. color: '#333'
  95. }
  96. },
  97. yAxis: {
  98. type: 'value'
  99. },
  100. grid: {
  101. left: 0,
  102. top: 22,
  103. right: 0,
  104. bottom: 12,
  105. containLabel: true
  106. },
  107. series: [
  108. {
  109. type: 'line',
  110. showBackground: false,
  111. itemStyle: {
  112. color: lineColor
  113. },
  114. label: {
  115. show: true,
  116. position: 'top',
  117. fontSize: 10,
  118. color: textColor
  119. },
  120. data: valueList
  121. }
  122. ]
  123. }
  124. option && myChart.setOption(option)
  125. }
  126. onMounted(() => {
  127. handleInit()
  128. })
  129. return () => (
  130. <div
  131. class={[
  132. styles.trainSection,
  133. props.type === 'month' ? styles.teacherTrainSection : '',
  134. styles.studentSection
  135. ]}
  136. >
  137. <div class={styles.trainTitle}>
  138. <div class={styles.name}>
  139. <Image
  140. src={props.type === 'month' ? teacherArrowLine : arrowLine}
  141. class={styles.allowLine}
  142. />
  143. 本{props.type === 'month' ? '月' : '周'}学生出勤
  144. </div>
  145. <div class={styles.countNums}>
  146. <Image src={arrowPoint} class={styles.arrowPoint} />
  147. 总出勤率
  148. <span
  149. style={{
  150. color: forms.total > 59 ? '#42FFE2' : '#FF7C88'
  151. }}
  152. >
  153. {forms.total}
  154. </span>
  155. %
  156. </div>
  157. </div>
  158. <div class={styles.trainSectionContent}>
  159. <div class={styles.tContent}>
  160. <div class={styles.calssEchartTitle}>
  161. <span class={styles.unit}>单位:%</span>
  162. </div>
  163. <div id="studentEcharts" class={styles.classEcharts}></div>
  164. </div>
  165. </div>
  166. </div>
  167. )
  168. }
  169. })