widgetConicalColumnChart.vue 4.41 KB
<!--
锥形柱图
-->
<template>
<!--  <div id="widget-scroll-ranking-board" :style="styleObj">-->
    <dv-conical-column-chart :config="options" :style="styleObj"/>
<!--  </div>-->
</template>
<script>
import Vue from "vue";
import conicalColumnChart from "@jiaminghi/data-view/lib/components/conicalColumnChart";
Vue.use(conicalColumnChart)
export default {
  name: "WidgetScrollRankingBoard",
  props: {
    value: Object,
    ispreview: Boolean,
  },
  data() {
    return {
      //返回图标数据
      options: {
        data:[],//柱数据
        img:[],//柱顶图片url
        fontSize: 12,//文字大小
        imgSideLength: 30,//图片边长
        columnColor: 'rgba(0, 194, 255, 0.4)',//柱颜色
        textColor: '#fff',//文字颜色
        showValue: false//显示数值
      },
      optionsStyle: {}, // 样式
      optionsData: {}, // 数据
      optionsCollapse: {}, // 图标属性
      optionsSetup: {},
      defImgArray:[
        '/static/images/conicalColumnChart/1st.png',
        '/static/images/conicalColumnChart/2st.png',
        '/static/images/conicalColumnChart/3st.png',
        '/static/images/conicalColumnChart/4st.png',
        '/static/images/conicalColumnChart/5st.png',
        '/static/images/conicalColumnChart/6st.png',
        '/static/images/conicalColumnChart/7st.png'
      ],
    };
  },
  computed: {
    styleObj() {
      return {
        position: this.ispreview ? "absolute" : "static",
        width: this.optionsStyle.width + "px",
        height: this.optionsStyle.height + "px",
        left: this.optionsStyle.left + "px",
        top: this.optionsStyle.top + "px",
        background: this.optionsSetup.background
      };
    },
  },
  watch: {
    value: {
      handler(val) {
        this.optionsStyle = val.position;
        this.optionsData = val.data;
        this.optionsSetup = val.setup;
        this.editorOptions();
      },
      deep: true
    }
  },
  created() {
    this.optionsStyle = this.value.position;
    this.optionsData = this.value.data;
    this.optionsSetup = this.value.setup;
    this.editorOptions();
  },
  methods: {
    // 修改图标options属性
    editorOptions() {
      //数据修改
      this.setOptionsData();
      //配置修改
      this.setOptionsConfig();
    },
    // 配置修改
    setOptionsConfig() {
      const optionsSetup = this.optionsSetup;
      this.options.fontSize =optionsSetup.fontSize;
      this.options.imgSideLength =optionsSetup.imgSideLength;
      this.options.columnColor =optionsSetup.columnColor;
      this.options.textColor =optionsSetup.textColor;
      this.options.showValue =optionsSetup.showValue;
      this.options.showImg =optionsSetup.showImg;
      this.options={...this.options};
    },
    //数据类型
    setOptionsData() {
      const optionsData = this.optionsData; // 数据类型 静态 or 动态
      optionsData.dataType == "staticData"
        ? this.staticDataFn(optionsData.staticData)
        : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
    },
    getImgs(data){
      const imgArray =[];
      const key="img";
      for (let i = 0; i < data.length; i++) {
        const cloneVal= data[i];
        if (Object.hasOwn(cloneVal, key) && cloneVal[key]) {
          imgArray.push(cloneVal[key]);
        }
      }
      const showImg = this.isBlank(this.optionsSetup.showImg)?true:this.optionsSetup.showImg;
      if(showImg){
        return imgArray.length>0?imgArray:this.defImgArray;
      }else{
        return [];
      }
    },
    staticDataFn(val) {
      // console.log("设置静态数据",this.options)
      const staticData = typeof val == "string" ? JSON.parse(val) : val;
      const staticImg = this.getImgs(staticData);
      this.options.data=staticData;
      this.options.img=staticImg;
    },
    dynamicDataFn(val, refreshTime) {
      if (!val) return;
      if (this.ispreview) {
        this.getEchartData(val);
        this.flagInter = setInterval(() => {
          this.getEchartData(val);
        }, refreshTime);
      } else {
        this.getEchartData(val);
      }
    },
    getEchartData(val) {
      const data = this.queryEchartsData(val);
      data.then(res => {
        this.renderingFn(res);
      });
    },
    renderingFn(val) {
      const staticImg = this.getImgs(val);
      this.options.data = val;
      this.options.img = staticImg;
    },
  }
};

</script>
<style scoped lang="scss">
.echarts {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>