app-grid-column.tsx 11.3 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
import { Vue, Component, Prop } from 'vue-property-decorator';
import { DataTypes, ModelTool, Util } from 'ibiz-core';
import { IPSAppCodeList, IPSAppDataEntity, IPSAppDEField, IPSAppDEView, IPSAppView, IPSDEGrid, IPSDEGridColumn, IPSDEGridDataItem, IPSDEGridEditItem, IPSDEGridFieldColumn, IPSDEUIAction, IPSEditor } from '@ibiz/dynamic-model-api';

@Component({})
export class AppDefaultGridColumn extends Vue {

    /**
     * 表格列实例
     * 
     * @type {IBizGridColumnModel}
     * @memberof AppDefaultGridColumn
     */
    @Prop() public columnInstance!: IPSDEGridColumn;

    /**
     * 表格实例
     * 
     * @type {IBizGridColumnModel}
     * @memberof AppDefaultGridColumn
     */
    @Prop() public gridInstance!: IPSDEGrid;

    /**
     * 当前行
     * 
     * @type {*}
     * @memberof AppDefaultGridColumn
     */
    @Prop() public row!: any;

    /**
     * 当前行下标
     * 
     * @type {number}
     * @memberof AppDefaultGridColumn
     */
    @Prop() public index!: number;

    /**
     * 应用上下文
     * 
     * @type {*}
     * @memberof AppDefaultGridColumn
     */
    @Prop() public context!: any;

    /**
     * 视图参数
     * 
     * @type {*}
     * @memberof AppDefaultGridColumn
     */
    @Prop() public viewparams!: any;

    /**
     * 界面UI服务对象
     * 
     * @type {*}
     * @memberof AppDefaultGridColumn
     */
    @Prop() public appUIService!: any;

    /**
    * 模型服务对象
    * 
    * @memberof AppStyle2DefaultLayout
    */
    @Prop() public modelService!: any;

    /**
     * 绘制
     * 
     * @memberof AppDefaultGridColumn
     */
    public render() {
        const uiAction: IPSDEUIAction | null = (this.columnInstance as IPSDEGridFieldColumn).getPSDEUIAction();
        if (uiAction && uiAction.uIActionTag) {
            return (
                <a
                    v-show={this.row[uiAction.uIActionTag] && this.row[uiAction.uIActionTag].visabled === false ? false : true}
                    disabled={this.row[uiAction.uIActionTag]?.disabled}
                    style="{'display': 'block'}"
                    on-click={($event: any) => { this.onClick($event) }}>
                    {this.renderGridColumn()}
                </a>)
        } else {
            return this.renderGridColumn()
        }
    }

    /**
     * 绘制表格列
     * 
     * @memberof AppDefaultGridColumn
     */
    public renderGridColumn() {
        const columnModel: IPSDEGridFieldColumn = this.columnInstance as IPSDEGridFieldColumn;
        const { cLConvertMode, enableLinkView,  dataItemName } = columnModel;
        const codeList: IPSAppCodeList | null = columnModel.getPSAppCodeList();
        if (codeList && cLConvertMode == "FRONT") {   //  代码表
            return (
                <codelist
                    value={this.row[ModelTool.getGridDataColName(columnModel)]}
                    codeList={codeList}
                >
                </codelist>
            )
        } else if (enableLinkView && columnModel.getLinkPSAppView()) {   //  链接视图
            const linkView: IPSAppView = columnModel.getLinkPSAppView() as IPSAppView;
            let view: any = {
                viewname: 'app-view-shell',
                height: linkView.height,
                width: linkView.width,
                title: this.$tl(linkView.getTitlePSLanguageRes()?.lanResTag, linkView.title),
                isRedirectView: linkView.redirectView ? true : false,
                placement: linkView.openMode ? linkView.openMode : '',
                viewpath: linkView.modelFilePath
            }
            Object.defineProperty(view, 'viewModel', { enumerable: false, writable: true, value: linkView });
            this.handleLinkViewParams(linkView, view);
            return this.renderLinkView(linkView, view);
        } else {    //常规显示
            return this.renderDefault();
        }
    }


    /**
     * 计算路由参数
     * 
     * @param linkView 链接视图
     * @param view 模型
     * @param entity 链接视图实体
     */
    public handleLinkViewParams(linkView: IPSAppView, view: any) {
        const entity: IPSAppDataEntity = linkView.getPSAppDataEntity() as IPSAppDataEntity;
        //获取父关系路由参数
        let tempDeResParameters: any[] = [];
        //视图本身路由参数
        let tempParameters: any[] = [];
        if (entity && entity.codeName) {
            tempDeResParameters = Util.formatAppDERSPath(this.context, (linkView as IPSAppDEView).getPSAppDERSPaths());
            tempParameters.push({
                pathName: Util.srfpluralize(entity.codeName).toLowerCase(),
                parameterName: entity.codeName.toLowerCase()
            });
            tempParameters.push({
                pathName: (linkView as IPSAppDEView).getPSDEViewCodeName()?.toLowerCase(),
                parameterName: (linkView as IPSAppDEView).getPSDEViewCodeName()?.toLowerCase()
            });
        } else {
            tempParameters.push({
                pathName: linkView.codeName?.toLowerCase(),
                parameterName: linkView.codeName?.toLowerCase()
            });
        }
        Object.assign(view, {
            parameters: tempParameters,
            deResParameters: tempDeResParameters
        })
    }

    /**
     * 绘制常规显示内容
     * 
     * @memberof AppDefaultGridColumn
     */
    public renderDefault() {
        const editItem: IPSDEGridEditItem = ModelTool.getGridItemByCodeName(this.columnInstance.codeName, this.gridInstance) as IPSDEGridEditItem;
        const editor: IPSEditor | null = editItem?.getPSEditor();
        const appDEField: IPSAppDEField = (editItem ? editItem.getPSAppDEField() : (this.columnInstance as IPSDEGridFieldColumn).getPSAppDEField()) as IPSAppDEField;
        let stdDataType, precision, valueFormat;
174
        if (appDEField) {
175 176 177 178 179 180
            stdDataType = appDEField.stdDataType;
            precision = appDEField.precision;
            valueFormat = appDEField.valueFormat;
        }
        valueFormat = (this.columnInstance as IPSDEGridFieldColumn).valueFormat ? (this.columnInstance as IPSDEGridFieldColumn).valueFormat : valueFormat;
        const name: any = editor?.name ? editor.name : this.columnInstance.name;
181 182
        const dataItemName: any = this.columnInstance.dataItemName;
        if (stdDataType && DataTypes.toString(stdDataType) && (DataTypes.toString(stdDataType) == "FLOAT" || DataTypes.toString(stdDataType) == "CURRENCY" || DataTypes.toString(stdDataType) == "DECIMAL")) {
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
            return (<app-format-data
                dataType={DataTypes.toString(stdDataType)}
                precision={precision ? precision : 0}
                unitName={(this.columnInstance as any).unitName}
                data={this.row[dataItemName]}>
            </app-format-data>)
        } else {
            const dataItem: IPSDEGridDataItem | undefined = this.gridInstance.getPSDEGridDataItems()?.find((item: IPSDEGridDataItem) => { return item.name === this.columnInstance.dataItemName; });
            if (dataItem?.customCode) {
                return (
                    this.$createElement('div', {
                        domProps: {
                            innerHTML: this.row[dataItemName],
                        },
                    })
                )
            } else {
                if (Object.is('ADDRESSPICKUP', this.columnInstance?.userTag)) {
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
                    return (
                        <app-span
                            name={name}
                            valueType={this.columnInstance.M.valueType}
                            textSeparator={this.columnInstance.M.textSeparator}
                            valueSeparator={this.columnInstance.M.valueSeparator}
                            objectIdField={this.columnInstance.M.objectIdField?.toLowerCase()}
                            objectNameField={this.columnInstance.M.objectNameField?.toLowerCase()}
                            objectValueField={this.columnInstance.M.objectValueField?.toLowerCase()}
                            editorType={'ADDRESSPICKUP'}
                            value={dataItemName ? this.row[dataItemName] : ""}
                            dataType={stdDataType ? DataTypes.toString(stdDataType) : "text"}
                            valueFormat={valueFormat}
                            precision={precision || 0}>
                        </app-span>
                    )
                }
                return (
219 220
                    <app-span
                        name={name}
221 222 223 224 225 226 227
                        valueType={this.columnInstance.M.valueType}
                        textSeparator={this.columnInstance.M.textSeparator}
                        valueSeparator={this.columnInstance.M.valueSeparator}
                        objectIdField={this.columnInstance.M.objectIdField?.toLowerCase()}
                        objectNameField={this.columnInstance.M.objectNameField?.toLowerCase()}
                        objectValueField={this.columnInstance.M.objectValueField?.toLowerCase()}
                        editorType={editor?.editorType}
228 229 230
                        value={dataItemName ? this.row[dataItemName] : ""}
                        dataType={stdDataType ? DataTypes.toString(stdDataType) : "text"}
                        valueFormat={valueFormat}
231
                        unitName={(this.columnInstance as any).unitName}
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
                        precision={precision || 0}>
                    </app-span>
                )
            }
        }
    }

    /**
     * 绘制链接视图内容
     * 
     * @memberof AppDefaultGridColumn
     */
    public renderLinkView(linkView: IPSAppView, view: any) {
        const linkViewEntity: IPSAppDataEntity | null = linkView.getPSAppDataEntity();
        const editInstance: IPSEditor = (ModelTool.getGridItemByCodeName(this.columnInstance.codeName, this.gridInstance) as IPSDEGridEditItem)?.getPSEditor() as IPSEditor;
        const name = this.columnInstance.name.toLowerCase();
        const dataItemName = this.columnInstance.dataItemName;
        let tempContext: any = Util.deepCopy(this.context);
        if (view.viewpath) {
            Object.assign(tempContext, { viewpath: view.viewpath });
        }
        let tempViewParam: any = Util.deepCopy(this.viewparams);
        return (
            <app-column-link
                deKeyField={linkViewEntity && linkViewEntity.codeName ? linkViewEntity.codeName?.toLowerCase() : ""}
                context={tempContext}
                viewparams={tempViewParam}
                modelService={this.modelService}
                data={this.row}
                linkview={view}
                appUIService={this.appUIService}
                valueitem={(this.columnInstance as IPSDEGridFieldColumn).linkValueItem}
            >
                {editInstance && editInstance.editorType ?
                    <app-span
                        name={name}
                        editorType={editInstance.editorType}
                        value={this.row[dataItemName]}>
                    </app-span> :
                    <span>
                        {this.row[dataItemName]}
                    </span>}
            </app-column-link>
        )
    }

    /**
     * 链接点击
     * 
     * @param {*} row 当前行数据
     * @param {*} tag 标识
     * @param {*} $event 点击Event
     * @memberof AppDefaultGridColumn
     */
    public onClick($event: any) {
        this.$emit("uiAction", $event);
    }
}