app-actionbar.vue 2.9 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
<template>
    <div class="app-actionbar">
        <div class="app-actionbar-item" v-for="(item,index) in Object.values(items)" :key="index">
            <Badge v-if="item.counterService&&item.counterService.counterData" v-show="item.visabled"
                :count="item.counterService.counterData[item.counterId]" type="primary">
                <i-button :disabled="item.disabled" @click="handleClick(item, $event)">
                    <i v-if="item.icon" style="margin-right: 5px;" :class="item.icon"></i>
                    {{item.actionName}}
                </i-button>
            </Badge>
            <i-button v-show="item.visabled" :disabled="item.disabled" v-else @click="handleClick(item, $event)">
                <i v-if="item.icon" style="margin-right: 5px;" :class="item.icon"></i>
                {{item.actionName}}
            </i-button>
        </div>
    </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { Subject, Subscription } from "rxjs";
import { ViewState, ViewTool } from 'ibiz-core';

@Component({})
export default class AppActionBar extends Vue {

    /**
     * 传入操作栏模型数据
     * 
     * @type {any}
     * @memberof AppActionBar
     */
    @Prop() public items!: any;

    /**
     * 注入的UI服务
     *
     * @type {*}
     * @memberof AppActionBar
     */
    @Prop() public uiService!: any;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof AppActionBar
     */
    @Prop() public viewState!: Subject<ViewState>;

    /**
     * 视图状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     * @memberof ActionlinetestBase
     */
    public viewStateEvent: Subscription | undefined;

    /**
     * 部件数据
     *
     * @type {*}
     * @memberof AppActionBar
     */
    public data: any;

    /**
     * 组件初始化
     *
     * @memberof AppActionBar
     */
    public created() {
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, "all-portlet")) {
                    return;
                }
                if (Object.is(action, 'loadmodel')) {
                    this.data = data;
                    ViewTool.calcActionItemAuthState(data, this.items, this.uiService);
                    this.$forceUpdate();
                }
            });
        }
    }

    /**
     * 触发界面行为
     * 
     * @memberof AppActionBar
     */
    public handleClick(item: any, $event: any) {
        let _data = {
            tag: item.viewlogicname,
            params: this.data,
            event: $event
        };
        this.$emit('itemClick', _data);
    }

    /**
     * 组件销毁
     * 
     * @memberof AppActionBar
     */
    public destroyed() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
    }

}
</script>