teacher-attendance.tsx 4.4 KB

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