CONTROL-BASE.vue.ftl 10.2 KB
Newer Older
1 2 3 4 5 6
<template>
  <div class='dashboard'>
    <row v-if="isEnableCustomized">
      <app-build @handleClick="handleClick"></app-build>
    </row>
    <row v-if="!isHasCustomized">
7 8
<#--  BEGIN:看板Flex布局-前  -->
<#if ctrl.getLayoutMode?? && ctrl.getLayoutMode() == 'FLEX'>
9
    <div style = 'display : flex; <#if ctrl.getFlexAlign()??> justify-content :${ctrl.getFlexAlign()};</#if> <#if ctrl.getFlexDir()??> flex-direction:${ctrl.getFlexDir()};</#if> <#if ctrl.getFlexVAlign()??>align-items:${ctrl.getFlexVAlign()};</#if> '>
10 11
</#if>
<#--  END:看板Flex布局-前  -->
12 13
<#list ctrl.getPSPortlets() as portlet><#t>
  <#if portlet.getPortletType?? && portlet.getPortletType()??><#t>
14
    <#--  BEGIN:获取父的layout,自己的LayoutPos  -->
15 16
    <#assign layout=ctrl.getLayoutMode()>
    <#assign LayoutPos = portlet.getPSLayoutPos()>
17
    <#--  END:获取父的layout,自己的LayoutPos  -->
18
    <#--  BEGIN:门户部件绘制,栅格布局  -->
WodahsOrez's avatar
WodahsOrez committed
19 20 21 22 23
    <#if layout == 'TABLE_12COL'>
      <#assign multiple = 2/>
    <#else>
      <#assign multiple = 1/>
    </#if>
24
    <#macro format_numer num>
25
      <#if num lt 0 >
26
        0<#t>
27
      <#elseif num gt 24>
28
        24<#t>
29 30
      <#else>
        ${num}<#t>
31 32
      </#if>
    </#macro>
WodahsOrez's avatar
WodahsOrez committed
33
    <#if (layout == 'TABLE_24COL' || layout == 'TABLE_12COL') && LayoutPos??><#t>
34
      <i-col<#if LayoutPos.getColXS() != -1> :xs="{ span: <@format_numer LayoutPos.getColXS()*multiple/>, offset: <#if LayoutPos.getColXSOffset() != -1><@format_numer LayoutPos.getColXSOffset()*multiple /><#else>0</#if> }"</#if><#if LayoutPos.getColSM() != -1> :sm="{ span: <@format_numer LayoutPos.getColSM()*multiple />, offset: <#if LayoutPos.getColSMOffset() != -1><@format_numer LayoutPos.getColSMOffset()*multiple /><#else>0</#if> }"</#if><#if LayoutPos.getColMD() != -1> :md="{ span: <@format_numer LayoutPos.getColMD()*multiple />, offset: <#if LayoutPos.getColMDOffset() != -1><@format_numer LayoutPos.getColMDOffset()*multiple /><#else>0</#if> }"</#if><#if LayoutPos.getColLG() != -1> :lg="{ span: <@format_numer LayoutPos.getColLG()*multiple />, offset: <#if LayoutPos.getColLGOffset() != -1><@format_numer LayoutPos.getColLGOffset()*multiple /><#else>0</#if> }"</#if>>
35
          <#if portlet.getPortletType() == 'CONTAINER' && portlet.isShowTitleBar() && portlet.getTitle()?has_content>
36 37 38 39 40 41 42
          <p slot='title'>
            ${portlet.getTitle()}
            <span class="line"></span>
          </p>
          <a slot='extra'></a>
          </#if> 
          <span>
43 44 45
            <@ibizindent blank=10><#t>
            ${P.getCtrlCode(portlet, 'CONTROL.html').code}
            </@ibizindent>
46 47 48
          </span>
        </card>
      </i-col>
49
    <#--  ELSE:门户部件绘制,Flex  -->
50
    <#else>
51
      <card class="portlet-card" :bordered="false" dis-hover :padding="0">
52
        <#if portlet.getPortletType() == 'CONTAINER' && portlet.isShowTitleBar() && portlet.getTitle()?has_content>
53 54
        <p slot='title'>
          ${portlet.getTitle()}
55
          <span class="line"></span>
56 57 58 59
        </p>
        <a slot='extra'></a>
        </#if> 
        <span>
60 61 62
          <@ibizindent blank=10><#t>
          ${P.getCtrlCode(portlet, 'CONTROL.html').code}
          </@ibizindent>
63 64
        </span>
      </card>
65
    </#if>
66
    <#--  END:门户部件绘制  -->
67 68
  </#if>
</#list>
69 70 71 72 73
    <#--  BEGIN:看板Flex布局-后  -->
    <#if ctrl.getLayoutMode?? && ctrl.getLayoutMode() == 'FLEX'>
    </div>
    </#if>
    <#--  END:看板Flex布局-后  -->
74 75
    </row>
    <row v-if="isHasCustomized" style="width: 100%;min-height: calc(100% - 40px);">
76
      <div class="portlet-container" style="position: relative;width:100%;">
77
        <template v-for="(item, index) of modelDta">
78
        <#noparse><div :key="index" :style="{zIndex: 10, position: 'absolute', height: item.h*layoutRowH + 'px', width: `calc(100% / ${layoutColNum} * ${item.w})`,top: item.y*layoutRowH + 'px', left: `calc(100% / ${layoutColNum} * ${item.x})`}"></#noparse>
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
          <component :key="$util.createUUID()" :is="item.componentName" :name="item.portletCodeName" :context="JSON.parse(JSON.stringify(context))" :viewDefaultUsage="false" :isAdaptiveSize="true" :viewState="viewState"></component>
        </div>
        </template>
    </div>
    </row>
  </div>
</template>
<#assign import_block>
import UtilService from '@/utilservice/util-service';
</#assign>
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>
    /**
     * 是否支持看板定制
     *
95
     * @public
96 97 98
     * @type {(boolean)}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
99
    @Prop() public isEnableCustomized!:boolean;
100 101 102 103

    /**
     * 是否已有看板定制
     *
104
     * @public
105 106 107
     * @type {(boolean)}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
108
    public isHasCustomized:boolean = false;
109 110 111 112

    /**
     * 模型数据
     *
113
     * @public
114 115 116
     * @type {(*)}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
117
    public modelDta:any;
118 119 120 121 122 123 124

    /**
     * modleId
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
125
    public modelId:string = "dashboard_<#if ctrl.getPSAppDataEntity()??>${ctrl.getPSAppDataEntity().getCodeName()?lower_case}<#else>app</#if>_${ctrl.getCodeName()?lower_case}";
126 127 128 129 130 131 132

    /**
     * 建构功能服务对象
     *
     * @type {UtilService}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
133
    public utilService:UtilService = new UtilService();
134 135 136 137 138 139 140

    /**
     * 功能服务名称
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
141
    public utilServiceName:string = "<#if ctrl.getPSAppDynaDashboardUtil?? && ctrl.getPSAppDynaDashboardUtil()??>${ctrl.getPSAppDynaDashboardUtil().getCodeName()?lower_case}</#if>";
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

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

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

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
168
    public created() {
169 170 171 172 173 174 175 176
        this.afterCreated();
    }

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

    /**
     * 动态设计水平列数
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */   
    public layoutColNum:number = 12;

    /**
     * 动态设计单元格高度,80px
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */ 
    public layoutRowH:number = 80;

    /**
     *  通知状态
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */    
    public notifyState(){
      this.$nextTick(() =>{
        if (this.isHasCustomized) {
          if (this.modelDta && this.modelDta.length > 0) {
            this.modelDta.forEach((item: any) => {
              this.viewState.next({
                tag: item.portletCodeName,
                action: "load",
                data: JSON.parse(JSON.stringify(this.viewparams))
              });
            });
          }
        } else {
          if (this.viewState) {
            const refs: any = this.$refs;
            Object.keys(refs).forEach((name: string) => {
              this.viewState.next({
                tag: name,
                action: "load",
                data: JSON.parse(JSON.stringify(this.viewparams))
              });
            });
          }
        }
      })
    }

    /**
     * 加载布局与数据模型
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
241
    public loadModel(){
242 243
        if(this.isEnableCustomized){
          this.utilService.getService(this.utilServiceName).then((service:any) =>{
244
            service.loadModelData(JSON.parse(JSON.stringify(this.context)),{modelid:this.modelId,utilServiceName:this.utilServiceName}).then((res:any) =>{
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
              if(res && res.status == 200){
                const data:any = res.data;
                if(data && data.length >0){
                  this.isHasCustomized = true;
                  this.modelDta = data;
                  this.$forceUpdate();
                }else{
                  this.isHasCustomized = false;
                }
                this.notifyState();
              }else{
                console.error("加载面板模型异常");
                this.isHasCustomized = false;
                this.notifyState();
              }
            })
          })
        }else{
          this.notifyState();
        }
    }

    /**
     * 处理私人定制按钮
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
272
    public handleClick(){
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
      const view:any ={
        viewname: 'app-portal-design',
        title: '面板设计',
        width: 1600,
        placement: 'DRAWER_RIGHT'
      }
      const viewparam:any ={
        modelid:this.modelId,
        utilServiceName:this.utilServiceName,
        appdeName:<#if ctrl.getPSAppDataEntity?? && ctrl.getPSAppDataEntity()??>'${ctrl.getPSAppDataEntity().getCodeName()}'<#else>'app'</#if>
      }
      const appdrawer = this.$appdrawer.openDrawer(view, JSON.parse(JSON.stringify(this.context)), viewparam);
      appdrawer.subscribe((result: any) => {
          if(Object.is(result.ret,'OK')){
            this.loadModel();
          }
      });
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
297
    public destroyed() {
298 299 300 301 302 303 304 305
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
306
    public afterDestroy() {
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

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

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