CONTROL-BASE.vue.ftl 7.3 KB
Newer Older
ibizdev's avatar
ibizdev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
<#ibizinclude>
./CONTROL-BASE.template.ftl
</#ibizinclude>

<#assign import_block>
import echarts from 'echarts';
</#assign>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getData(): any {
        return null;
    }

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof MOBILEENTITY3Canlen
     */
    @Prop({ default: true }) protected showBusyIndicator!: boolean;

    /**
     * 部件行为--fetch
     *
     * @type {string}
     * @memberof Mob
     */
    @Prop() protected fetchAction!: string;  

    /**
    * Vue声明周期(组件初始化完毕)
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public created() {
         this.afterCreated();     
    }

    /**
    * 执行created后的逻辑
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public afterCreated(){
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('load', action)) {
                    this.load(data);
                }
            });
        }  
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    protected destroyed() {
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    protected afterDestroy() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

    /**
     * 图表div绑定的id
     *
     * @type {}
     * @memberof ${srfclassname('${ctrl.name}')}
     */   
    public chartId:string = this.$util.createUUID();

    /**
     * echarts图表对象
     *
     * @type {}
     * @memberof ${srfclassname('${ctrl.name}')}
     */   
    public myChart:any;

    /**
     * 初始化图表所需参数
     *
     * @type {}
     * @memberof ${srfclassname('${ctrl.name}')}
     */   
    public chartOption:any = {};

    /**
     * 图表基础配置参数
     * 
     * @returns {*} 
     * @memberof ${srfclassname('${ctrl.name}')}Service
     */
    public defaultConfig: any = {
<#--  获取模板对象:BEGIN  -->
<#assign title=ctrl.getPSDEChartTitle()>
<#list ctrl.getPSDEChartSerieses() as series>
  <#--  暂只支持第一个序列  -->
  <#if series_index == 0>
    <#assign chartSeries = series/>
  </#if>
</#list>
<#--  获取模板对象:END  -->
<#--  公共配置:BEGIN  -->
        title: { 
          show: <#if title.isShowTitle()>true<#else>false</#if>,
<#if title.getTitle()??> 
          text: '${title.getTitle()}',
</#if>
<#if title.getSubTitle()??>
          subtext: '${title.getSubTitle()}'
</#if> 
        },
        legend: {top: 20},
        toolbox: { 
          show: true,  
          feature: { 
            dataView: { 
              show: false, 
              readOnly: true, 
              title: '数据视图' 
            }, 
            saveAsImage: { 
              show: false, 
              title: '保存为图片' 
            }
          }
        },
<#--  公共配置:END  -->
<#--  饼图配置:BEGIN  -->
KK's avatar
KK committed
166
<#if chartSeries.getSeriesType() == 'pie'>
ibizdev's avatar
ibizdev committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
        tooltip: { trigger: 'item' },
<#--  饼图配置:END  -->
<#--  折线图,柱状图配置:BEGIN  -->
<#elseif chartSeries.getSeriesType() == 'line' || chartSeries.getSeriesType() == 'bar'>
  <#assign xAxes = chartSeries.getXPSDEChartAxes() />
  <#assign yAxes = chartSeries.getYPSDEChartAxes() />
        tooltip: { trigger: 'axis' },
  <#if xAxes??>
        xAxis: {
    <#if xAxes.getAxesType?? && xAxes.getAxesType()??>
          type: '${xAxes.getAxesType()}', 
    </#if>
    <#if xAxes.getAxesPos?? && xAxes.getAxesPos()??>
          position: '${xAxes.getAxesPos()}', 
    </#if>
    <#if xAxes.getCaption?? && xAxes.getCaption()??>
          name: '${xAxes.getCaption()}', 
    </#if>
    <#if xAxes.getMaxValue?? && xAxes.getMaxValue()??>
          max: '${xAxes.getMaxValue()}', 
    </#if>
    <#if xAxes.getMinValue?? && xAxes.getMinValue()??>
          min: '${xAxes.getMinValue()}', 
    </#if>
        },
  </#if>
  <#if yAxes??>
        yAxis: {
    <#if yAxes.getAxesType?? && yAxes.getAxesType()??>
          type: '<#if yAxes.getAxesType() == 'numeric'>value<#else>${yAxes.getAxesType()}</#if>', 
    </#if>
    <#if yAxes.getAxesPos?? && yAxes.getAxesPos()??>
          position: '${yAxes.getAxesPos()}', 
    </#if>
    <#if yAxes.getCaption?? && yAxes.getCaption()??>
          name: '${yAxes.getCaption()}', 
    </#if>
    <#if yAxes.getMaxValue?? && yAxes.getMaxValue()??>
          max: '${yAxes.getMaxValue()}', 
    </#if>
    <#if yAxes.getMinValue?? && yAxes.getMinValue()??>
          min: '${yAxes.getMinValue()}', 
    </#if>
        },
  </#if>
</#if>
<#--  折线图,柱状图配置:BEGIN  -->
    }

    /**
     * 深度合并对象,把secondObj的内容合并给firstObj,返回合并后的firstObj
     * @param {} firstObj 被合并对象
     * @param {} secondObj 合并对象
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public deepObjectMerge(firstObj: any, secondObj: any) {
        for (let key in secondObj) {
            firstObj[key] =
                firstObj[key] && firstObj[key].toString() === "[object Object]"
                    ? this.deepObjectMerge(firstObj[key], secondObj[key])
                    : (firstObj[key] = secondObj[key]);
        }
        return firstObj;
    }

    /**
     * 刷新
     *
     * @param {*} [opt={}]
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    protected refresh(opt: any = {}) {
        this.load(opt);
    }

    /**
     * 获取图表数据
zcdtk's avatar
zcdtk committed
244 245 246
     *
     * @param {*} [opt]
     * @returns {Promise<any>}
ibizdev's avatar
ibizdev committed
247 248
     * @memberof ${srfclassname('${ctrl.name}')}
     */
zcdtk's avatar
zcdtk committed
249
    public async load(opt?: any): Promise<any> {
ibizdev's avatar
ibizdev committed
250 251 252 253 254
        let _this = this;
        const arg: any = { ...opt };
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);
zcdtk's avatar
zcdtk committed
255 256 257 258 259 260 261 262
        Object.assign(arg, { viewparams: this.viewparams });
        const response = await this.service.search(this.fetchAction, { ...this.context }, arg, this.showBusyIndicator);
        if (response && response.status === 200) {
            _this.chartOption = _this.deepObjectMerge(_this.defaultConfig, response.data);
            _this.drawCharts();
        } else {
            console.error(response);
        }
ibizdev's avatar
ibizdev committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    }

    /**
     * 绘制图表
     * 
     * @returns {*} 
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public drawCharts(){
        if(!this.myChart){
          let element:any =  document.getElementById(this.chartId);
          this.myChart = echarts.init(element);
        }
        this.myChart.setOption(this.chartOption);
        this.myChart.resize();
    }


<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL-BASE.style.ftl
</#ibizinclude>