CONTROL-BASE.vue.ftl 11.3 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">
tony001's avatar
tony001 committed
7 8 9 10 11
<#--  BEGIN:看板Flex布局-前  -->
<#if ctrl.getLayoutMode?? && ctrl.getLayoutMode() == 'FLEX'>
    <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> '>
</#if>
<#--  END:看板Flex布局-前  -->
12 13
<#list ctrl.getPSPortlets() as portlet><#t>
  <#if portlet.getPortletType?? && portlet.getPortletType()??><#t>
tony001's avatar
tony001 committed
14 15 16 17
    <#--  BEGIN:获取父的layout,自己的LayoutPos  -->
    <#assign layout=ctrl.getLayoutMode()>
    <#assign LayoutPos = portlet.getPSLayoutPos()>
    <#--  END:获取父的layout,自己的LayoutPos  -->
18
    <#--  BEGIN:门户部件绘制,栅格布局  -->
tony001's avatar
tony001 committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
    <#if layout == 'TABLE_12COL'>
      <#assign multiple = 2/>
    <#else>
      <#assign multiple = 1/>
    </#if>
    <#macro format_numer num>
      <#if num lt 0 >
        0<#t>
      <#elseif num gt 24>
        24<#t>
      <#else>
        ${num}<#t>
      </#if>
    </#macro>
    <#if (layout == 'TABLE_24COL' || layout == 'TABLE_12COL') && LayoutPos??><#t>
      <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.getPSPortlets?? && portlet.getPSPortlets()??>
tony001's avatar
tony001 committed
36
        <card class="portlet-card" :bordered="false" dis-hover :padding="0">
37 38 39
        <#else>
        <card class="portlet-card custom-card" :bordered="false" dis-hover :padding="10">
        </#if>
tony001's avatar
tony001 committed
40
          <#if portlet.getPortletType() == 'CONTAINER' && portlet.isShowTitleBar() && portlet.getTitle()?has_content>
41
          <#if ctrl.getViewStyle?? && ctrl.getViewStyle()?? && ctrl.getViewStyle() != 'DEFAULT'>
42 43
          <a slot='extra'></a>
          <#else>
44 45 46 47 48
          <p slot='title'>
            ${portlet.getTitle()}
            <span class="line"></span>
          </p>
          <a slot='extra'></a>
49
          </#if>
50 51
          </#if> 
          <span>
52 53 54
            <@ibizindent blank=10><#t>
            ${P.getCtrlCode(portlet, 'CONTROL.html').code}
            </@ibizindent>
55 56 57
          </span>
        </card>
      </i-col>
tony001's avatar
tony001 committed
58
    <#--  ELSE:门户部件绘制,Flex  -->
59
    <#else>
60 61 62 63 64
      <#if portlet.getPSPortlets?? && portlet.getPSPortlets()??>
        <card class="portlet-card" :bordered="false" dis-hover :padding="0">
        <#else>
        <card class="portlet-card custom-card" :bordered="false" dis-hover :padding="10">
        </#if>
tony001's avatar
tony001 committed
65
        <#if portlet.getPortletType() == 'CONTAINER' && portlet.isShowTitleBar() && portlet.getTitle()?has_content>
66
        <#if ctrl.getViewStyle?? && ctrl.getViewStyle()?? && ctrl.getViewStyle() != 'DEFAULT'>
67 68
        <a slot='extra'></a>
        <#else>
69 70
        <p slot='title'>
          ${portlet.getTitle()}
tony001's avatar
tony001 committed
71
          <span class="line"></span>
72 73
        </p>
        <a slot='extra'></a>
74
        </#if>
75 76
        </#if> 
        <span>
77 78 79
          <@ibizindent blank=10><#t>
          ${P.getCtrlCode(portlet, 'CONTROL.html').code}
          </@ibizindent>
80 81
        </span>
      </card>
82
    </#if>
tony001's avatar
tony001 committed
83
    <#--  END:门户部件绘制  -->
84 85
  </#if>
</#list>
tony001's avatar
tony001 committed
86 87 88 89 90
    <#--  BEGIN:看板Flex布局-后  -->
    <#if ctrl.getLayoutMode?? && ctrl.getLayoutMode() == 'FLEX'>
    </div>
    </#if>
    <#--  END:看板Flex布局-后  -->
91 92
    </row>
    <row v-if="isHasCustomized" style="width: 100%;min-height: calc(100% - 40px);">
93
      <div class="portlet-container" style="position: relative;width:100%;">
94
        <template v-for="(item, index) of modelDta">
95
        <#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>
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
          <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>
    /**
     * 是否支持看板定制
     *
112
     * @public
113
     * @type {(boolean)}
KK's avatar
KK committed
114
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
115
     */
116
    @Prop() public isEnableCustomized!:boolean;
117 118 119 120

    /**
     * 是否已有看板定制
     *
121
     * @public
122
     * @type {(boolean)}
KK's avatar
KK committed
123
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
124
     */
125
    public isHasCustomized:boolean = false;
126 127 128 129

    /**
     * 模型数据
     *
130
     * @public
131
     * @type {(*)}
KK's avatar
KK committed
132
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
133
     */
134
    public modelDta:any;
135 136 137 138 139

    /**
     * modleId
     *
     * @type {string}
KK's avatar
KK committed
140
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
141
     */
142
    public modelId:string = "dashboard_<#if ctrl.getPSAppDataEntity()??>${ctrl.getPSAppDataEntity().getCodeName()?lower_case}<#else>app</#if>_${ctrl.getCodeName()?lower_case}";
143 144 145 146 147

    /**
     * 建构功能服务对象
     *
     * @type {UtilService}
KK's avatar
KK committed
148
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
149
     */
150
    public utilService:UtilService = new UtilService();
151 152 153 154 155

    /**
     * 功能服务名称
     *
     * @type {string}
KK's avatar
KK committed
156
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
157
     */
JunZai's avatar
JunZai committed
158
    public utilServiceName:string = "<#if ctrl.getPSAppDynaDashboardUtil?? && ctrl.getPSAppDynaDashboardUtil()??>${ctrl.getPSAppDynaDashboardUtil().getCodeName()?lower_case}</#if>";
159 160 161 162 163

    /**
     * 获取多项数据
     *
     * @returns {any[]}
KK's avatar
KK committed
164
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
165 166 167 168 169 170 171 172 173
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
KK's avatar
KK committed
174
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
175 176 177 178 179 180 181 182
     */
    public getData(): any {
        return {};
    }

    /**
     * vue 生命周期
     *
KK's avatar
KK committed
183
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
184
     */
185
    public created() {
186 187 188 189 190 191
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
KK's avatar
KK committed
192
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
193
     */    
194
    public afterCreated(){
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
      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();
              }
          });
      }
    }

    /**
     * 动态设计水平列数
     *
KK's avatar
KK committed
210
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
211 212 213 214 215 216
     */   
    public layoutColNum:number = 12;

    /**
     * 动态设计单元格高度,80px
     *
KK's avatar
KK committed
217
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
218 219 220 221 222 223
     */ 
    public layoutRowH:number = 80;

    /**
     *  通知状态
     *
KK's avatar
KK committed
224
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
     */    
    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))
              });
            });
          }
        }
      })
    }

    /**
     * 加载布局与数据模型
     *
KK's avatar
KK committed
256
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
257
     */
258
    public loadModel(){
259 260
        if(this.isEnableCustomized){
          this.utilService.getService(this.utilServiceName).then((service:any) =>{
tony001's avatar
tony001 committed
261
            service.loadModelData(JSON.parse(JSON.stringify(this.context)),{modelid:this.modelId,utilServiceName:this.utilServiceName}).then((res:any) =>{
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
              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();
              }
tony001's avatar
tony001 committed
277 278 279 280 281 282
            }).catch((error:any)=>{
                console.error("加载面板模型异常");
                console.error(error);
                this.isHasCustomized = false;
                this.notifyState();
            });
283 284 285 286 287 288 289 290 291
          })
        }else{
          this.notifyState();
        }
    }

    /**
     * 处理私人定制按钮
     *
KK's avatar
KK committed
292
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
293
     */
294
    public handleClick(){
295 296
      const view:any ={
        viewname: 'app-portal-design',
297
        title: (this.$t('app.dashBoard.handleClick.title')),
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
        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 生命周期
     *
KK's avatar
KK committed
317
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
318
     */
319
    public destroyed() {
320 321 322 323 324 325
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
KK's avatar
KK committed
326
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
327
     */
328
    public afterDestroy() {
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
        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>