app-portal-design.vue 3.9 KB
Newer Older
ibizdev's avatar
ibizdev 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
<template>
    <card class="app-portal-design" :dis-hover="true" :padding="0" :bordered="false">
        <p slot="title">
            自定义门户
        </p>
        <div class="design-toolbar" slot="extra">
            <i-button @click="click">保存</i-button>
        </div>
        <div class="design-container">
            <app-dashboard-design :viewState="viewState" :context="context" :viewparams="viewparams" :utilServiceName="utilServiceName" @save="onSaved"></app-dashboard-design>
        </div>
    </card>
</template>

<script lang="ts">
import { Vue, Component, Prop, Model, Emit,Watch } from "vue-property-decorator";
import { Subject } from "rxjs";
import AppDashboardDesign from '@components/app-dashboard-design/app-dashboard-design.vue';

@Component({
    components: {
        AppDashboardDesign
    }
})
export default class AppPortalDesign extends Vue {

      /**
     * 传入视图上下文
     *
     * @type {string}
     * @memberof AppPortalDesign
     */
    @Prop() protected viewdata!: string;

    /**
     * 传入视图参数
     *
     * @type {string}
     * @memberof AppPortalDesign
     */
    @Prop() protected viewparam!: string;

    /**
     * 视图默认使用
     *
     * @type {boolean}
     * @memberof AppPortalDesign
     */
    @Prop({ default: true }) protected viewDefaultUsage!: boolean;

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof AppPortalDesign
     */
    protected context:any = {};

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof AppPortalDesign
     */
    protected viewparams:any = {};

    /**
     * modelId
     *
     * @type {*}
     * @memberof AppPortalDesign
     */
    protected modelId:string = "";

    /**
     * 功能服务名称
     *
     * @type {*}
     * @memberof AppPortalDesign
     */
    protected utilServiceName:string = "";

    /**
     * 视图状态订阅对象
     *
     * @private
     * @type {Subject<{action: string, data: any}>}
     * @memberof AppPortalDesign
     */
    protected viewState: Subject<ViewState> = new Subject();

    /**
     * 视图参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof AppPortalDesign
     */
    @Watch('viewparam',{immediate: true, deep: true})
    onParamData(newVal: any, oldVal: any) {
        this.prepareViewparam();
    }

    /**
     * 处理应用上下文变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof AppPortalDesign
     */
    @Watch('viewdata')
    onViewData(newVal: any, oldVal: any) {
        this.prepareContext();
    }

    /**
     * 生命周期
     *
     * @memberof AppPortalDesign
     */
    public created() {
        this.prepareViewparam();
        this.prepareContext();
    }

    /**
     * 准备视图参数
     *
     * @memberof AppPortalDesign
     */
    public prepareViewparam() {
        if(this.viewparam){
            Object.assign(this.viewparams, JSON.parse(this.viewparam));
            if(this.viewparams && this.viewparams.modelid){
                this.modelId = this.viewparams.modelid;
            }
            if(this.viewparams && this.viewparams.utilServiceName){
                this.utilServiceName = this.viewparams.utilServiceName;
            }
        } 
    }

    /**
     * 准备视图上下文参数
     *
     * @memberof AppPortalDesign
     */
    public prepareContext() {
        if (!this.viewDefaultUsage && this.viewdata && !Object.is(this.viewdata, '')) {
            Object.assign(this.context, JSON.parse(this.viewdata));
            return;
        } 
    }

     
    /**
     * 点击保存
     *
     * @memberof AppPortalDesign
     */
    public click() {
        this.viewState.next({ tag: "", action: "save", data: {} })
    }

     /**
     * 保存完成
     *
     * @memberof AppPortalDesign
     */
    public onSaved($event: any) {
        this.$emit("close", $event);
    }

}
</script>

<style lang='less'>
@import "./app-portal-design.less";
</style>