08335 / hivui-platform-template
hivui平台项目模板
Newer
Older
hivui-platform-template / project / hivuiBirt / templates / pages / form-single-save.js
/**
 * 单一表单保存,页面模板
 * @param {*} saveDataset 保存数据集,命名规范 ds_[数组下标]_[对话框id]
 * @param {*} conf 组件定义配置项
 * @returns 
 */
import { StringUtil } from "@birt/funclib/StringUtil.js";
import { editTable } from "../compose/table/edit-table"

export function newInstance(saveDataset, conf) {
    const dlgId = StringUtil.randomString(6);
    // 设置数据集id
    // saveDataset.controlId += "_" + dlgId;
    // 表单操作工具条
    var hcFormToolbar = {
        controlName: "HcFormToolbar",
        controlId: "HcFormToolbar_" + dlgId,
        dataset: saveDataset.controlId,
        layout: ["cancel", "save"],
        addOne: true,
        size: "small",
        style: "padding:15px;"
    }
    // 应用工具条个性化配置
    Object.assign(hcFormToolbar, conf.hcFormToolbar || {});
    // 表单内容
    var hcForm = {
        controlName: "HcForm",
        controlId: "HcForm_" + dlgId,
        dataset: saveDataset.controlId,
        labelWidth: "80px",
        rules: {
        },
        children: [],
    };
    // 应用表单个性化配置
    Object.assign(hcForm, conf.hcForm || {});

    // 冗余表格
    var hcTable = false;
    if (conf.hcTable) {
        // 表单网格明细
        hcTable = editTable(dlgId, saveDataset.controlId, conf);
    }

    // 系统表单自动填充字段
    var hcSysForm = false;
    if (conf.hcSysForm) {
        var hcSysForm = {
            controlName: "HcForm",
            controlId: "HcForm_sys_" + dlgId,
            dataset: saveDataset.controlId,
            labelWidth: "80px",
            rules: {
            },
            children: [],
        };
        // 应用系统字段表单个性化配置
        Object.assign(hcSysForm, conf.hcSysForm || {});
    }

    // 应用报表模型
    var birtWorkBook = Object.assign({
        controlName: "BirtWorkBook",
        controlId: "BirtWorkBook_" + dlgId,
        showToolBar: false,
        totalPage: 1,
        renderType: "pages",
        height: function (parentHeight) {
            return parentHeight;
        },
    }, conf.birtWorkBook || {})
    birtWorkBook.children = [
        {
            controlName: "BirtSheet",
            controlId: "BirtSheet_" + dlgId,
            name: "sheet_" + dlgId,
            pageIndex: 0,
            dataSets: [saveDataset],
            children: [
                {
                    controlName: "BirtFormSheet",
                    controlId: "BirtFormSheet_" + dlgId,
                    children: [
                        hcFormToolbar,
                        hcForm
                    ]
                        .concat(hcTable ? hcTable : [])
                        .concat(hcSysForm ? hcSysForm : [])
                }
            ]
        }
    ];
    // 返回布局结构
    return birtWorkBook
}