08335 / hivui-platform-template
hivui平台项目模板
Newer
Older
hivui-platform-template / project / hivuiBirt / templates / compose / org-tree-edit.js
/**
 * 树型组件编辑:新增、修改、删除,根据名称过滤节点操作
 * @param {*} dlgId 对话框随机id,防止id冲突与数据集id统一命名引用
 * @param {*} dsId 绑定过滤数据集ID
 * @param {*} option 扩展选项
 * @returns 
 */
 import pinyin from "pinyin";


export function treeEditFilter(dlgId, dsId, option) {
    let filterField = option.hcTree.labelField;
    let lazy = option.hcTree.lazy;
    let fireAction = lazy ? "" : "keyup";
    let treeId = "HcTree_org";
    // 过滤编辑器
    let inputFilter = {
        controlName: "HcInputFilter",
        controlId: "HcInputFilter_" + dlgId,
        size: "small",
        fireAction: fireAction,
        events: {
            filterChange: function (filterKey) {
                this.getRefCompt(treeId).filter(
                    filterKey
                );
            },
        }
    };
     // 编辑树组件
     let hcTree = {
         controlName: "HcTree",
         controlId: treeId,
         dataset: dsId,
         labelField: filterField,
         // defaultExpandAll: true,
         // accordion: true,
         highlightCurrent: true,
         expandOnClickNode: false,
         lazy: false,
         filterNodeMethod:function(value, data,node) {
             if (!value){
                 return true
             }else{
                 let key =node.label +"_" + pinyin.getCamelChars(node.label);
                 return key.indexOf(value.toUpperCase()) !== -1;
             }
         },
         height: function (parentHeight) {
             return parentHeight - 80;
         },
         renderContent(h, { node, data, store}) {
             var _this = this
             var iconClass = ''
             switch (data.FORGKIND) {
                 case '.ROOT':
                     iconClass = 'iconfont icon-root'
                     break;
                 case '.ORG':
                     iconClass = 'iconfont icon-org'
                     break;
                 case '.DPT':
                     iconClass = 'iconfont icon-dpt'
                     break;
                 case '.PTM':
                     iconClass = 'iconfont icon-ptm'
                     break;
             
                 default:
                     iconClass = ''
                     break;
             }
             return (
               <span class="custom-tree-node">
                 <span title={data.FORGKINDNAME}>
                    <i class={iconClass}></i>
                    {node.label}
                 </span>
               </span>);
           }
     };
     // 应用树个性化配置
     Object.assign(hcTree, option.hcTree);
 
    // 返回布局结构
    return [
        inputFilter,
        hcTree
    ]

}