CONTROL.tsx.ftl 2.1 KB
import { Vue, Component, Provide, Prop } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { CreateElement } from 'vue';

@Component({})
export default class ${view.codeName} extends Vue {

    /**
     * 名称
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public name?: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public viewState!: Subject<ViewState>;

    /**
     * 视图参数
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public viewData: string = '';

    /**
     * 监听对象
     *
     * @type {*}
     * @memberof SPLBGridView
     */
    public viewStateEvent: any;

    /**
     * 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public created() {
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('load', action)) {
                    this.viewData = JSON.stringify(data);
                }
            });
        }
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public destroyed() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

    /**
     * 绘制内容
     *
     * @param {CreateElement} h
     * @returns
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public render(h: CreateElement) {
        <#if ctrl.getEmbeddedPSAppDEView()??>
        <#assign embedview = ctrl.getEmbeddedPSAppDEView()>
        return (<${srffilepath2(embedview.codeName)} viewdata={this.viewData}></${srffilepath2(embedview.codeName)}>);
        <#else>
        return (<div>无嵌入视图</div>);
        </#if>
    }
}