rank-list.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <el-drawer size='50%' title="排行榜" :visible.sync="show" direction="rtl">
  3. <view id="chart-bar" style="width: 100%;height: 100%;" class="">
  4. </view>
  5. </el-drawer>
  6. </template>
  7. <script>
  8. import * as echarts from "echarts";
  9. import {
  10. chartBar
  11. } from './chart.js'
  12. export default {
  13. data() {
  14. return {
  15. show: false,
  16. }
  17. },
  18. props: {
  19. chooseClassId: {
  20. type: Number | String,
  21. default: ""
  22. },
  23. },
  24. computed: {},
  25. methods: {
  26. open() {
  27. this.show = true;
  28. this.$api.sendRequest({
  29. url: '/mobile/studentTab/getStudentMonthRank',
  30. method: "post",
  31. data: {
  32. class_id: this.chooseClassId,
  33. },
  34. success: res => {
  35. let dom = document.getElementById('chart-bar')
  36. dom.style.height = `${res.data.length * 40}px`
  37. this.chart = echarts.init(dom);
  38. const myChart = this.chart;
  39. myChart.clear();
  40. let option = chartBar(res.data)
  41. res.data.forEach((item, index) => {
  42. option.yAxis.axisLabel.rich[index] = {
  43. height: 20, // 图片高度
  44. width: 20, // 图片宽度
  45. backgroundColor: {
  46. image: item.student.student_cartoon_photo, // 图片路径
  47. // 如果你使用的是模块化的方式(如 Vue),你可能需要使用 require 或 import 来引入图片
  48. // 例如:image: require('@/assets/image.png')
  49. }
  50. }
  51. if (item.score_total < 0) {
  52. option.yAxis.splitArea.areaStyle.color.push('rgba(231,79,176,0.2)')
  53. } else {
  54. option.yAxis.splitArea.areaStyle.color.push('rgba(0,0,0,0)')
  55. }
  56. })
  57. myChart.setOption(option);
  58. // setTimeout(() => {
  59. // myChart.setOption({
  60. // series: [
  61. // {
  62. // type: 'bar',
  63. // data:[5000,6000,1000,4000,58000,8000]
  64. // }
  65. // ]
  66. // });
  67. // },2000)
  68. }
  69. })
  70. }
  71. }
  72. }
  73. </script>
  74. <style>
  75. </style>