index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div :id="id" :class="className" :style="{ height: height, width: width }" />
  3. </template>
  4. <script>
  5. import tdTheme from './theme.json' // 引入默认主题
  6. import themeCopy from './themeCopy.json' // 引入默认主题
  7. import '../map/fujian.js'
  8. export default {
  9. name: 'echart',
  10. props: {
  11. className: {
  12. type: String,
  13. default: 'chart'
  14. },
  15. id: {
  16. type: String,
  17. default: 'chart'
  18. },
  19. width: {
  20. type: String,
  21. default: '100%'
  22. },
  23. height: {
  24. type: String,
  25. default: '2.5rem'
  26. },
  27. options: {
  28. type: Object,
  29. default: ()=>({})
  30. }
  31. },
  32. data () {
  33. return {
  34. chart: null
  35. }
  36. },
  37. watch: {
  38. options: {
  39. handler (options) {
  40. // 设置true清空echart缓存
  41. this.chart.setOption(options, true)
  42. },
  43. deep: true
  44. }
  45. },
  46. mounted () {
  47. console.log(this.$route.name == "newDatavScr")
  48. //由于现在开发新的数据大屏、主题冲突了,暂时判断以下路由来源、作为主题切换
  49. if(this.$route.name == "newDatavScr"){
  50. this.$echarts.registerTheme('tdTheme', themeCopy); // 修改默认主题
  51. this.initChart();
  52. return;
  53. }
  54. this.$echarts.registerTheme('tdTheme', tdTheme); // 覆盖默认主题
  55. this.initChart();
  56. },
  57. beforeDestroy () {
  58. this.chart.dispose()
  59. this.chart = null
  60. window.removeEventListener('resize', this.$_handleResizeChart)
  61. },
  62. methods: {
  63. initChart () {
  64. // console.log(this.$router)
  65. // 初始化echart
  66. this.chart = this.$echarts.init(this.$el, 'tdTheme')
  67. this.chart.setOption(this.options, true)
  68. window.addEventListener("resize", this.$_handleResizeChart);
  69. },
  70. $_handleResizeChart(){
  71. this.chart.resize();
  72. }
  73. }
  74. }
  75. </script>
  76. <style>
  77. </style>