context-menu-drag.vue 4.7 KB
Newer Older
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
<template>
    <Drawer
        class="sider-drawer"
        :class-name="getClass()"
        placement="left"
        :closable="false"
        :mask="false"
        width="200"
        v-model="leftDrawerVisiable"
    >
        <div class="context-menu-drag">
            <div class="context-menu__list">
                <div class="context-menu__list__header">
                    <div class="header__menuicon">
                        <Icon type="md-apps" />
                    </div>
                    <div class="header__content">
                        <span>{{ $t('components.contextmenudrag.allapp') }}</span>
                    </div>
                    <div class="header__forward">
                        <Icon type="ios-arrow-forward" />
                    </div>
                </div>
                <div class="context-menu__list__content">
                    <div @click="skipTo(item)" class="content__item" v-for="item in list" :key="item.id">
                        <span class="icon">
                            <Icon type="ios-star" />
                        </span>
                        <span class="caption">{{ item.fullName ? item.fullName : item.label }}</span>
                    </div>
                </div>
            </div>
        </div>
    </Drawer>
</template>

<script lang="ts">
import draggable from 'vuedraggable';
import { Vue, Component, Watch, Prop, Model } from 'vue-property-decorator';
import { AppServiceBase, DataEntityService, LogUtil } from 'ibiz-core';

// tslint:disable-next-line:max-classes-per-file
@Component({
    components: {
        draggable,
    },
})
export default class ContextMenuDrag extends Vue {
    public panelShow: boolean = true;

    /**
     * 抽屉菜单状态
     *
     * @memberof ContextMenuDrag
     */
    @Prop() public contextMenuDragVisiable?: boolean;

    /**
     * 视图样式
     *
     * @memberof ContextMenuDrag
     */
    @Prop() public viewStyle!: string;

    /**
     * 拖拽列表配置对象
     *
     * @returns
     * @memberof ContextMenuDrag
     */
    @Model('change') public dragOptions: any;

    /**
     * 左侧飘窗状态
     *
     * @returns
     * @memberof ContextMenuDrag
     */
    public leftDrawerVisiable: boolean = false;

    /**
     * 全部应用数据
     *
     * @returns
     * @memberof ContextMenuDrag
     */
    public list: Array<any> = [];

    /**
     * 拖拽列表
     *
     * @returns
     * @memberof ContextMenuDrag
     */
    public drag: boolean = false;

    /**
     * 拖拽列表配置项
     *
     * @returns
     * @memberof ContextMenuDrag
     */
    get dragOptionsVal() {
        return {
            animation: 200,
            group: 'description',
            disabled: false,
            ghostClass: 'ghost',
        };
    }

    /**
     * 获取绑定样式
     *
     * @memberof ContextMenuDrag
     */
    getClass() {
        if (this.viewStyle === 'STYLE2' || this.viewStyle === 'STYLE3') {
            return 'style-top';
        } else {
            return 'default-top';
        }
    }

    /**
     * 实体服务对象
     *
     * @protected
     * @type {DataEntityService}
     * @memberof ContextMenuDrag
     */
    protected entityService: DataEntityService = new DataEntityService();

    /**
     * 监听抽屉菜单状态
     *
     * @returns
     * @memberof ContextMenuDrag
     */
    @Watch('contextMenuDragVisiable')
    public onVisiableChange(newVal: any, oldVal: any) {
        this.leftDrawerVisiable = newVal;
    }

    /**
     * 跳转到应用
     *
     * @returns
     * @memberof ContextMenuDrag
     */
    public skipTo(item: any) {
        if (item.addr) {
            window.location.href = item.addr;
        } else {
            this.$info(this.$t('components.contextmenudrag.nofind') as string,'skipTo');
        }
    }

    /**
     * vue 生命周期
     *
     * @returns
     * @memberof ContextMenuDrag
     */
    mounted() {
        const get: Promise<any> = this.entityService.getAllApp(null, {});
        get.then((response: any) => {
            if (response) {
                this.handleAppList(response?.data?.model);
            }
        }).catch((error: any) => {
            LogUtil.warn(this.$t('components.contextmenudrag.error'));
        });
    }

    /**
     * 处理应用列表
     *
     * @memberof ContextMenuDrag
     */
    public handleAppList(data:any){
      if(!data && data.length === 0){
        this.list = [];
      }
      const Environment: any = AppServiceBase.getInstance().getAppEnvironment();
      let protalData:any = {fullName:this.$t('components.contextmenudrag.portlet'),addr:Environment.portalUrl};
      this.list.push(protalData);
      this.list.push(...data);
    }
}
</script>