CONTROL.vue.ftl 5.4 KB
Newer Older
yanshaowei's avatar
yanshaowei 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 166 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
<template>
<#ibizinclude>
./CONTROL.html.ftl
</#ibizinclude>
</template>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_DEFAULT.vue.ftl
</#ibizinclude>

<#assign self_content>

    /**
      * 快捷菜单标题
      *
      * @type {string}
      * @memberof Menutwo
      */
    @Prop() public title?:string; 
    
    /**
      * 快捷菜单样式
      *
      * @type {string}
      * @memberof Menutwo
      */
    @Prop() public menuStyle?:string; 

    /**
     * api地址
     *
     * @private
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    private url: string = '${app.getPKGCodeName()?lower_case}/ctrl/${ctrl.codeName?lower_case}appmenu';

    /**
    * 菜单数据
    *
    * @protected
    * @type {Array<any>}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public menus:Array<any> =[];

    /**
    * 当前视图类型
    *
    * @protected
    * @type string
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public curViewType:string = "${view.getViewType()}";

    /**
    * 当前选中
    *
    * @protected
    * @type {string}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public currentSelected:string ="";

    /**
    * 视图状态事件
    *
    * @protected
    * @type {(Subscription | undefined)}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    protected viewStateEvent: Subscription | undefined;

    /**
     * 应用功能集合
     *
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public appFuncs: any[] = [
        <#list ctrl.getPSAppFuncs() as appFuncs>
        {
            appfunctag: '${appFuncs.getCodeName()}',
            appfuncyype: '${appFuncs.getAppFuncType()}',
            <#if appFuncs.getAppFuncType() == 'APPVIEW'>
            <#assign appview = appFuncs.getPSAppView()/>
            pathname: '${appview.getPSAppModule().getCodeName()?lower_case}_${appview.getCodeName()?lower_case}',
            </#if>
        },
        </#list>
    ];

    created() {
      this.handleCreated();
    }

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

    /**
    * 数据加载
    *
    * @param {*} data
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public load(data: any) {
      const get: Promise<any> = this.$http.get(this.url + "/get", {});
      get.then((response: any) => {
          if (!response || response.status !== 200) {
            console.error("错误" + response.info);
          }
          this.menus = response.data.items;
          if(this.menus.length >0){
               if(this.$route.meta.routetag){
                  this.currentSelected = this.$route.meta.routetag;
                  this.$store.commit('setIndexSelected', this.currentSelected);
                }
          }
        })
        .catch((response: any) => {
          if (response && response.status === 401) {
            return;
          }
          if (!response || !response.status || !response.data) {
            console.error("错误,系统异常!");
            return;
          }
        });
    }

    /**
    * 菜单点击事件
    *
    * @param {*} data
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public menuClick($event:any){
        if(this.menus.length >0){
            let curSelectObj=this.menus.filter((item:any) =>{
                return item.name == $event;
            })
            if(curSelectObj && curSelectObj.length >0 && curSelectObj[0].appfunctag){
                this.$store.commit('setIndexSelected', $event);
                this.openAppFuncPickupView(curSelectObj[0].appfunctag);
            }
        }
    }
    
    /**
      * 打开功能页
      *
      * @param {*} data
      * @memberof ${srfclassname('${ctrl.codeName}')}
      */
    public openAppFuncPickupView(value:any){
        if(this.appFuncs.length >0){
            let curSelectObj=this.appFuncs.filter((func:any) =>{
                return func.appfunctag === value;
            })
            if(curSelectObj && curSelectObj.length >0){
                 this.click(curSelectObj[0]);
            }
        }
    }

     /**
     * 菜单点击
     *
     * @private
     * @param {*} item 菜单数据
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    private click(item: any) {
        if (item) {
            switch (item.appfunctag) {
                <#if ctrl.getPSAppFuncs()??>
                <#assign appFuncs = ctrl.getPSAppFuncs()>
                <#list appFuncs as singFuncs>
                case '${singFuncs.getCodeName()}':
                    this.click${singFuncs.codeName}(item);
                    return;
                </#list>
                </#if>
                default:
                    console.warn('未指定应用功能');
            }
        }
    }

<#if ctrl.getPSAppFuncs()??>
<@ibizindent blank=4>
<#list ctrl.getPSAppFuncs() as singleFuncs>
${P.getLogicCode(singleFuncs,"LOGIC.vue").code}
</#list>
</@ibizindent>
</#if>

</#assign>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_CONTAINER.vue.ftl
</#ibizinclude>

<style lang="less">
     <#ibizinclude>
    ./CONTROL.less.ftl
    </#ibizinclude>
</style>