@web-utils/component 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -27
- package/dist/chunks/163eed3b.js +16 -1
- package/dist/chunks/2bd4e340.js +184 -0
- package/dist/chunks/6499de3a.js +30 -1
- package/dist/chunks/7af3ceb1.js +75 -0
- package/dist/chunks/86bcadec.js +24 -0
- package/dist/chunks/8bbde9bf.js +81 -1
- package/dist/chunks/90bd3d52.js +26 -1
- package/dist/chunks/92404ceb.js +126 -0
- package/dist/chunks/a73fe8ee.js +11 -0
- package/dist/chunks/df803484.js +60 -0
- package/dist/components/address-input/index.js +113 -1
- package/dist/components/aside-menu/index.js +58 -1
- package/dist/components/awesome-button/index.js +82 -1
- package/dist/components/capsule-tab/index.js +52 -1
- package/dist/components/chunk-file-uploader/index.js +119 -1
- package/dist/components/chunk-file-uploader-button/index.js +60 -1
- package/dist/components/chunk-file-uploader-drop/index.js +65 -1
- package/dist/components/chunk-file-uploader-file/index.js +311 -1
- package/dist/components/chunk-file-uploader-files/index.js +49 -1
- package/dist/components/chunk-file-uploader-list/index.js +50 -1
- package/dist/components/chunk-file-uploader-un-support/index.js +51 -1
- package/dist/components/code-mirror-editor/index.js +310 -6
- package/dist/components/color-picker/index.js +110 -1
- package/dist/components/confirm-button/index.js +57 -1
- package/dist/components/confirmable/index.js +28 -1
- package/dist/components/context-menu/index.js +236 -1
- package/dist/components/custom-scrollbar/index.js +150 -1
- package/dist/components/data-table-picker/index.js +137 -1
- package/dist/components/dynamic-table/index.js +195 -1
- package/dist/components/e-charts/index.js +229 -1
- package/dist/components/editable-progress/index.js +141 -1
- package/dist/components/editable-tree/index.js +789 -1
- package/dist/components/egd-collapse/index.js +79 -1
- package/dist/components/egd-collapse-item/index.js +132 -1
- package/dist/components/el-color-picker-dropdown/index.js +170 -1
- package/dist/components/element-dialog/index.js +242 -1
- package/dist/components/empty-view/index.js +69 -1
- package/dist/components/error-view/index.js +61 -1
- package/dist/components/flex-column/index.js +50 -1
- package/dist/components/flex-item/index.js +66 -1
- package/dist/components/flex-row/index.js +50 -1
- package/dist/components/flex-scroller/index.js +47 -1
- package/dist/components/form-button/index.js +80 -1
- package/dist/components/form-cascader/index.js +151 -1
- package/dist/components/form-checkbox-group/index.js +192 -1
- package/dist/components/form-date-picker/index.js +182 -1
- package/dist/components/form-holder/index.js +90 -1
- package/dist/components/form-input/index.js +106 -1
- package/dist/components/form-input-email/index.js +97 -1
- package/dist/components/form-input-id-card/index.js +104 -1
- package/dist/components/form-input-number/index.js +123 -1
- package/dist/components/form-input-phone-number/index.js +98 -1
- package/dist/components/form-input-time/index.js +124 -1
- package/dist/components/form-item/index.js +120 -1
- package/dist/components/form-item-config-provider/index.js +63 -1
- package/dist/components/form-item-group/index.js +169 -1
- package/dist/components/form-radio-group/index.js +170 -1
- package/dist/components/form-select/index.js +154 -1
- package/dist/components/form-switch/index.js +97 -1
- package/dist/components/form-textarea/index.js +102 -1
- package/dist/components/form-view/index.js +343 -1
- package/dist/components/guide-steps/index.js +94 -1
- package/dist/components/icon-card/index.js +62 -1
- package/dist/components/iframe-window/index.js +99 -1
- package/dist/components/input-number/index.js +274 -1
- package/dist/components/input-number-range/index.js +110 -1
- package/dist/components/j-s-x-component/index.js +16 -1
- package/dist/components/keep-view-alive/index.js +119 -1
- package/dist/components/loading-view/index.js +61 -1
- package/dist/components/nav-bar/index.js +52 -1
- package/dist/components/not-implement/index.js +35 -1
- package/dist/components/page/index.js +40 -1
- package/dist/components/page-header/index.js +56 -1
- package/dist/components/page-index/index.js +151 -1
- package/dist/components/page-index-top/index.js +119 -1
- package/dist/components/page-skeleton/index.js +56 -1
- package/dist/components/page-skeleton-new/index.js +98 -1
- package/dist/components/pageable-table/index.js +429 -1
- package/dist/components/pageable-view/index.js +328 -2
- package/dist/components/photo-swipe/index.js +187 -1
- package/dist/components/resize-observer/index.js +62 -1
- package/dist/components/search-popover/index.js +391 -2
- package/dist/components/sign-panel/index.js +242 -1
- package/dist/components/split-pane/index.js +209 -1
- package/dist/components/stateful/index.js +84 -1
- package/dist/components/static-pageable-table/index.js +92 -1
- package/dist/components/swiper/index.js +158 -1
- package/dist/components/tab/index.js +145 -1
- package/dist/components/tab-item/index.js +73 -1
- package/dist/components/table-column/index.js +89 -1
- package/dist/components/table-view/index.js +363 -1
- package/dist/components/tag-render/index.js +97 -1
- package/dist/components/tinymce-editor/index.js +173 -1
- package/dist/components/tinymce-wrapper/index.js +618 -1
- package/dist/components/toolbar/index.js +217 -1
- package/dist/components/toolbar-button/index.js +90 -1
- package/dist/components/trigger/index.js +71 -1
- package/dist/components/vue-tags-input/index.js +439 -1
- package/dist/components/watermark/index.js +63 -1
- package/dist/components/x-dialog/index.js +173 -1
- package/dist/index.css +2102 -1
- package/dist/index.es.js +2992 -2075
- package/package.json +29 -29
- package/web-types.json +22 -16
- package/dist/chunks/23bd3525.js +0 -1
- package/dist/chunks/65f4f4f2.js +0 -1
- package/dist/chunks/8473fc69.js +0 -1
- package/dist/chunks/a125d16c.js +0 -1
- package/dist/chunks/addb6ed5.js +0 -1
- package/dist/chunks/f15477c7.js +0 -1
|
@@ -1 +1,789 @@
|
|
|
1
|
-
var C=Object.defineProperty,v=Object.defineProperties;var $=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var m=(e,t,i)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,l=(e,t)=>{for(var i in t||(t={}))b.call(t,i)&&m(e,i,t[i]);if(f)for(var i of f(t))_.call(t,i)&&m(e,i,t[i]);return e},d=(e,t)=>v(e,$(t));import{hasOwn as u,addResizeListener as x,removeResizeListener as y,isVerticalScrollbarVisible as k,scrollbarWidth as B,computePosition as T,isPlainObject as c,cloneDeep as w,isFunction as g,isUndefined as h,isNotEmpty as M,fastClone as K,delay as P,findTreeChildren as E}from"@web-utils/core";import{a as D,b as z,c as p}from"../../chunks/8473fc69.js";import{n as L}from"../../chunks/6499de3a.js";var R=function(){var e=this,t=e.$createElement,i=e._self._c||t;return i("div",{staticClass:"editable-tree"},[!e.readonly&&e.addRootNodeButtonStyle==="top-right"?i("ElButton",{staticStyle:{position:"absolute",top:"4px","z-index":"1"},style:{right:`${e.right}px`},attrs:{type:"primary",size:"mini",icon:"el-icon-plus",circle:"",plain:""},on:{click:function(s){return s.stopPropagation(),e.$emit("add-root-node")}}}):e._e(),i("div",{ref:"treeWrapper",staticClass:"et-tree-wrapper"},[!e.readonly&&e.addRootNodeButtonStyle==="top"?i("div",{staticStyle:{"padding-left":"24px"}},[i("ElButton",{attrs:{disabled:e.loading,size:"mini",type:"text"},on:{click:e.appendRootNode}},[i("i",{staticClass:"el-icon-lx-add"}),e._v(" "+e._s(e.addRootNodeLabel?e.addRootNodeLabel:`\u6DFB\u52A0${e.label}`)+" ")])],1):e._e(),i("ElTree",e._g(e._b({key:e.treeKey,ref:"tree",staticClass:"flex-item",attrs:{"default-expanded-keys":e.expandedKeys,"expand-on-click-node":!1,"highlight-current":"",load:e.loadNode,data:e.innerTreeData,props:e.treeProps,lazy:e.lazy,"node-key":e.nodeKey},on:{"node-click":e.nodeClick,"node-contextmenu":e.showContextMenu,"node-expand":e.addExpandKey,"node-collapse":e.removeExpandKey},scopedSlots:e._u([{key:"default",fn:function(s){var o=s.node,n=s.data;return[e._t("default",function(){return[n.edit?[i("span",{staticClass:"custom-tree-node flex-box flex-1 oh",attrs:{"data-id":n.id}},[e.icon?i("i",{staticClass:"node-icon shrink-0",class:n.loading?"el-icon-loading":"el-icon-edit-outline"}):e._e(),i("ElInput",{ref:"labelTxt",staticClass:"node-input flex-1",attrs:{size:"mini",placeholder:e.defaultOptions.inputPlaceholder},on:{blur:function(a){return e.inputBlur(a,o,n)}},nativeOn:{keyup:function(a){return function(r){return e.inputKeyup(r,o,n)}.apply(null,arguments)},click:function(a){a.stopPropagation()}},model:{value:e.text,callback:function(a){e.text=a},expression:"text"}}),e.confirmButton?[i("ElButton",{directives:[{name:"show",rawName:"v-show",value:!n.loading,expression:"!data.loading"}],staticClass:"shrink-0",attrs:{size:"mini",type:"text"},on:{click:function(a){return a.stopPropagation(),e.onConfirm(o,n)}}},[e._v("\u786E\u5B9A")]),i("ElButton",{directives:[{name:"show",rawName:"v-show",value:!n.loading,expression:"!data.loading"}],staticClass:"shrink-0",attrs:{size:"mini",type:"text"},on:{click:function(a){return a.stopPropagation(),e.onCancel(o,n)}}},[e._v("\u53D6\u6D88")])]:e._e()],2)]:[i("span",{staticClass:"custom-tree-node",attrs:{"data-id":n.id}},[i("span",{staticClass:"node-label flex-box flex-1 oh ellipsis-1"},[e.icon?i("i",{staticClass:"node-icon",class:n.loading?"el-icon-loading":e.icon(n,o)}):e._e(),i("span",{staticClass:"flex-1-relative",staticStyle:{height:"21px"}},[i("span",{staticClass:"ellipsis-1 absolute-box et-tree-label",attrs:{title:o.label}},[e._t("label",function(){return[e._v(e._s(o.label))]},{data:n,node:o})],2)]),e._t("label-suffix",null,{node:o,data:n})],2),!e.contextMenu&&!e.readonly?i("span",{directives:[{name:"show",rawName:"v-show",value:!n.loading&&!e.loading,expression:"!data.loading && !loading"}],staticClass:"handle-actions"},[i("ElButton",{attrs:{size:"mini",type:"text"},on:{click:function(a){return a.stopPropagation(),e.appendChildNode(o,n)}}},[e._v("\u6DFB\u52A0")]),i("ElButton",{attrs:{size:"mini",type:"text"},on:{click:function(a){return a.stopPropagation(),e.editNode(o,n)}}},[e._v("\u4FEE\u6539")]),i("ElPopconfirm",{staticClass:"pop-confirm",attrs:{"icon-color":"red",title:"\u4F60\u786E\u5B9A\u8981\u5220\u9664\u5417\uFF1F"},on:{confirm:function(a){return e.removeNode(o,n)}},scopedSlots:e._u([{key:"reference",fn:function(){return[i("ElButton",{directives:[{name:"show",rawName:"v-show",value:o.isLeaf,expression:"node.isLeaf"}],staticStyle:{"margin-left":"4px"},attrs:{size:"mini",type:"text"},on:{click:function(a){a.stopPropagation()}}},[e._v("\u5220\u9664")])]},proxy:!0}],null,!0)})],1):e._e(),e.contextMenuIcon&&e.contextMenu&&!e.readonly?i("span",{directives:[{name:"show",rawName:"v-show",value:!n.loading&&!e.loading,expression:"!data.loading && !loading"}],staticClass:"handle-actions",staticStyle:{display:"inline-block"}},[i("ElButton",{staticStyle:{padding:"6px 10px 0"},attrs:{size:"mini",type:"text"},on:{click:function(a){return a.stopPropagation(),e.showContextMenu(a,n,o)}}},[e._v(". . .")])],1):e._e()])]]},{node:o,data:n})]}}],null,!0)},"ElTree",e.filterTreeProperties(e.$attrs),!1),e.filterTreeEvents(e.$listeners))),e.contextMenu&&!e.readonly?i("div",{directives:[{name:"show",rawName:"v-show",value:e.showMenu,expression:"showMenu"}],ref:"contextMenu",staticClass:"menu",style:e.position},[i("ul",{staticClass:"menu-list"},[e._t("context-menu",function(){return[i("li",{directives:[{name:"show",rawName:"v-show",value:e.curData.id>-1,expression:"curData.id > -1"}],staticClass:"menu-item",on:{click:function(s){return e.appendPeerNode(e.curNode,e.curData)}}},[i("i",{staticClass:"menu-item-icon el-icon-lx-add",staticStyle:{color:"#228b22"}}),e._v(e._s(e.menuLabel.appendPeer)+" ")]),i("li",{staticClass:"menu-item",on:{click:function(s){return e.appendChildNode(e.curNode,e.curData)}}},[i("i",{staticClass:"menu-item-icon el-icon-lx-add",staticStyle:{color:"#228b22"}}),e._v(e._s(e.menuLabel.appendChild)+" ")]),i("li",{directives:[{name:"show",rawName:"v-show",value:e.curData.id>-1,expression:"curData.id > -1"}],staticClass:"menu-item",on:{click:function(s){return e.editNode(e.curNode,e.curData)}}},[i("i",{staticClass:"menu-item-icon el-icon-edit-outline",staticStyle:{color:"#ffa500"}}),e._v(e._s(e.menuLabel.editNode)+" ")]),i("li",{directives:[{name:"show",rawName:"v-show",value:e.curNode.isLeaf,expression:"curNode.isLeaf"}],staticClass:"menu-item",on:{click:function(s){return e.removeNodeModal(e.curNode,e.curData)}}},[i("i",{staticClass:"menu-item-icon el-icon-delete",staticStyle:{color:"#f00"}}),e._v(e._s(e.menuLabel.removeNode)+" ")])]},{curNode:e.curNode,curData:e.curData})],2)]):e._e()],1)],1)},S=[];const I={name:"EditableTree",props:{label:{type:String,default:"\u4E66\u7B7E"},addRootNodeLabel:{type:String},defaultExpandedKeys:{type:Array,default:()=>[]},newNodeBuilder:{type:Function,default:(e,t)=>({name:e,parentId:t.id})},contextMenu:Boolean,lazy:{type:Boolean,default:!0},expandFirstNode:{type:Boolean,default:!0},readonly:Boolean,saveApi:{type:Function},updateApi:{type:Function},deleteApi:{type:Function},fetchApi:{type:Function},customRootNode:{type:{type:Object,default:void 0}},rootNode:{type:Object},contextMenuIcon:Boolean,contextMenuInline:Boolean,treeProps:{type:Object,default:()=>({children:"children",label:"name",isLeaf:e=>u(e,"hasChildren")?!e.hasChildren:u(e,"hasChild")?!e.hasChild:u(e,"children")&&e.children?e.children.length===0:!0})},menuLabel:{type:Object,default:()=>({appendPeer:"\u6DFB\u52A0\u540C\u7EA7\u8282\u70B9",appendChild:"\u6DFB\u52A0",removeNode:"\u5220\u9664",editNode:"\u4FEE\u6539"})},icon:{type:[Function,Boolean],default:(e,t)=>"el-icon-collection-tag"},confirmButton:{type:Boolean,default:!0},addRootNodeButtonStyle:{type:String,default:"top"},reserveExpandKey:Boolean,nodeKey:{type:String,default:"id"}},data(){return{loading:!1,showMenu:!1,empty:!0,expandedKeys:this.lazy?[]:this.defaultExpandedKeys,treeData:[],curNode:{},curData:{},position:{},text:"",right:4,treeKey:Date.now()}},computed:{defaultOptions(){return{confirmButtonText:"\u786E\u5B9A",cancelButtonText:"\u53D6\u6D88",closeOnClickModal:!1,modal:!0,inputErrorMessage:`${this.label}\u540D\u4E0D\u80FD\u4E3A\u7A7A\uFF01`,inputPlaceholder:`\u8BF7\u8F93\u5165${this.label}\u540D...`,inputValidator:e=>e!=null&&e.trim().length>0}},innerTreeData(){var e;return(e=this.$attrs.data)!=null&&e.length?this.$attrs.data:this.treeData}},watch:{defaultExpandedKeys:{immediate:!0,handler(e){this.expandedKeys=[...e]}}},created(){this.tryFetch()},mounted(){x(this.$refs.tree.$el,this.resize),x(this.$refs.treeWrapper,this.resize)},beforeDestroy(){y(this.$refs.tree.$el,this.resize),y(this.$refs.treeWrapper,this.resize)},methods:{filterTreeProperties:D,filterTreeEvents:z,addExpandKey(e){this.reserveExpandKey&&this.expandedKeys.push(e[this.nodeKey])},removeExpandKey(e){this.reserveExpandKey&&(this.expandedKeys=this.expandedKeys.filter(t=>t!==e[this.nodeKey]))},resize(){k(this.$refs.treeWrapper)?this.right=4+B:this.right=4},async showContextMenu(e,t,i){t.contextmenu===!1||t.id===-1||t.id===0||t.edit===!0||this.contextMenu&&(this.curNode=i,this.curData=t,this.showMenu=!0,this.$refs.tree.setCurrentKey(t.id),await this.$nextTick(),this.position=T(e,this.$refs.contextMenu),window.addEventListener("click",this.hideContextMenu))},hideContextMenu(){this.showMenu=!1,window.removeEventListener("click",this.hideContextMenu)},async tryFetch(){var e,t;if(this.lazy===!1&&this.fetchApi){const i=await this.fetchApi((t=(e=this.rootNode)==null?void 0:e.id)!=null?t:-1,{});if(c(i.data)&&(i.data=[i.data]),i.data=i.data||[],this.empty=i.data.length===0,c(this.customRootNode)){const s=w(this.customRootNode);s[this.treeProps.children||"children"]=i.data,this.treeData=[s]}else if(g(this.customRootNode)){const s=this.customRootNode(i.data);s[this.treeProps.children||"children"]=i.data,this.treeData=c(s)?[s]:s}else this.treeData=i.data}},async loadNode(e,t){var i,s,o,n;if(e.level===0){const a=await this.fetchApi((s=(i=this.rootNode)==null?void 0:i.id)!=null?s:-1,e);if(this.empty=a.data.length===0,c(this.customRootNode)){const r=w(this.customRootNode);r[this.treeProps.children||"children"]=a.data,t([r])}else if(g(this.customRootNode)){const r=this.customRootNode(a.data);r[this.treeProps.children||"children"]=a.data,this.treeData=c(r)?[r]:r}else t(a.data);await this.$nextTick(),this.$emit("root-node-loaded",a.data),this.defaultExpandedKeys?this.expandedKeys=[(o=a==null?void 0:a.data[0])==null?void 0:o.id,...this.defaultExpandedKeys]:this.expandFirstNode&&(this.expandedKeys=[(n=a==null?void 0:a.data[0])==null?void 0:n.id])}else{if(e.leaf||e.data.isTempNode)return t([]);const a=await this.fetchApi(e.data.id,e);t(a.data),await this.$nextTick(),this.$emit("node-loaded",a.data)}},clear(){this.cancelEdit(),this.removeNewNode()},clearChecked(){this.$refs.tree.setCheckedKeys([])},removeNewNode(){this.newChild&&this.newChild.id===-1&&(console.log(this.newChild),this.$refs.tree.remove(this.newChild),this.$emit("remove-new-node"))},cancelEdit(){this.editData&&(h(this.editData.edit)?this.$set(this.editData,"edit",!0):this.editData.edit=!1)},async editNode(e,t){!this.contextMenu||this.contextMenuIcon||this.contextMenuInline?(this.clear(),this.editData=t,this.text=t[this.treeProps.label],h(t.edit)?this.$set(t,"edit",!0):t.edit=!0,await this.$nextTick(),this.$refs.labelTxt.focus()):await this.$prompt(`\u8BF7\u8F93\u5165\u65B0\u7684${this.label}\u540D\uFF1A`,d(l({},this.defaultOptions),{inputValue:t[this.treeProps.label],beforeClose:async(i,s,o)=>{if(i==="confirm"){try{s.confirmButtonLoading=!0,s.confirmButtonText="\u5904\u7406\u4E2D...",this.text=s.inputValue,await this.onConfirm(this.curNode,this.curData),o()}catch{s.confirmButtonText="\u786E\u5B9A"}s.confirmButtonLoading=!1}else o()}})).catch(i=>i)},async appendRootNode(){this.text="",!this.contextMenu||this.contextMenuIcon||this.contextMenuInline?(this.clear(),this.createNewChild(void 0),this.$refs.tree.root.insertChild({data:this.newChild},void 0,!0),await this.scrollIntoView(!0)):await this.$prompt(`\u8BF7\u8F93\u5165${this.label}\u540D\uFF1A`,d(l({},this.defaultOptions),{beforeClose:async(e,t,i)=>{if(e==="confirm"){try{this.createNewChild(-1),t.confirmButtonLoading=!0,t.confirmButtonText="\u5904\u7406\u4E2D...";const s=await this.saveApi(this.newNodeBuilder(t.inputValue,{id:-1}));this.newChild[this.treeProps.label]=t.inputValue,this.newChild.edit=!1,p(this.newChild,s.data),this.$refs.tree.root.insertChild({data:this.newChild},void 0,!0),await this.locateView(),i()}catch{t.confirmButtonText="\u786E\u5B9A"}t.confirmButtonLoading=!1}else i()}})).catch(e=>e)},appendChildNode(e){this.text="";const t=e.expanded;e.expand(async()=>{!this.contextMenu||this.contextMenuIcon||this.contextMenuInline?(this.clear(),this.createNewChild(e.data.id),this.$refs.tree.append(this.newChild,e),await this.scrollIntoView(t)):await this.$prompt(`\u8BF7\u8F93\u5165${this.label}\u540D\uFF1A`,d(l({},this.defaultOptions),{beforeClose:async(i,s,o)=>{if(i==="confirm"){try{this.createNewChild(e.data.id),s.confirmButtonLoading=!0,s.confirmButtonText="\u5904\u7406\u4E2D...";const n=await this.saveApi(this.newNodeBuilder(s.inputValue,e.data));this.newChild[this.treeProps.label]=s.inputValue,this.newChild.edit=!1,p(this.newChild,n.data),this.$refs.tree.append(this.newChild,e),await this.locateView(),o()}catch{s.confirmButtonText="\u786E\u5B9A"}s.confirmButtonLoading=!1}else o()}})).catch(i=>i)})},appendChildNodeWithData(e,t,i){this.text="";const s=e.expanded;e.expand(async()=>{this.clear(),this.newChild={id:-1,parentId:t,[this.treeProps.label]:i,edit:!1,isTempNode:!0,hasChildren:!1},this.$refs.tree.append(this.newChild,e),await this.scrollIntoView(s)})},appendPeerNode(e){e.parent&&e.parent.level!==0?this.appendChildNode(e.parent):this.appendRootNode()},async addRootNode(e){this.$refs.tree.remove(e),await this.$nextTick(),this.$refs.tree.root.insertChild({data:e},void 0,!0)},async addChildNode(e){this.curNode&&this.curNode.level!==0?this.curNode.expand(async()=>{this.$refs.tree.remove(e),await this.$nextTick(),this.$refs.tree.append(e,this.curNode)}):await this.addRootNode(e)},async addPeerNode(e){this.curNode&&this.curNode.parent&&this.curNode.parent.level!==0?this.curNode.parent.expand(async()=>{this.$refs.tree.remove(e),await this.$nextTick(),this.$refs.tree.append(e,this.curNode.parent)}):await this.addRootNode(e)},updateNode(e){const t=this.$refs.tree.getNode(e);t&&(t.data=e)},setCurrentKey(e){this.$refs.tree&&this.$refs.tree.setCurrentKey(e)},createNewChild(e){this.newChild={id:-1,parentId:e,[this.treeProps.label]:"",edit:!0,isTempNode:!0,hasChildren:!1},this.$emit("create-new-node",this.newChild)},async removeNodeModal(e){await this.$confirm(`\u4F60\u786E\u5B9A\u8981\u5220\u9664${this.label}[<span class="break-word" style="color: orange">${e.data[this.treeProps.label]}</span>]\u5417\uFF1F`,"\u7CFB\u7EDF\u63D0\u793A",{type:"warning",modal:!0,dangerouslyUseHTMLString:!0,iconClass:"el-icon-question",closeOnClickModal:!1,confirmButtonClass:"el-button--danger",cancelButtonClass:"el-button--primary is-plain",beforeClose:async(t,i,s)=>{if(t==="confirm"){try{i.confirmButtonLoading=!0,i.confirmButtonText="\u5220\u9664...";const o=e.parent,n=await this.deleteApi(e.data.id);n.code===0?(this.$message.success("\u5220\u9664\u6210\u529F!"),this.$refs.tree.remove(e),this.$emit("node-deleted",o,e.data),s()):this.$message.error(n.message)}catch{}i.confirmButtonText="\u786E\u5B9A",i.confirmButtonLoading=!1}else s()}}).catch(t=>t)},async removeNode(e){try{const t=e.parent;if(this.deleteApi){const i=await this.deleteApi(e.data.id);i.code===0?(this.$message.success("\u5220\u9664\u6210\u529F!"),this.$refs.tree.remove(e),this.$emit("node-deleted",t,e.data)):this.$message.error(i.message)}else this.$refs.tree.remove(e)}catch{}},async onConfirm(e,t){if(t[this.treeProps.label]===this.text||!M(this.text)){this.clear();return}h(t.loading)?this.$set(t,"loading",!0):t.loading=!0;try{if(this.loading=!0,t.id===-1){const i=await this.saveApi(this.newNodeBuilder(this.text,e.parent.data||{id:-1})),s=K(t);p(t,d(l({},i.data),{isTempNode:!1})),this.$emit("node-added",t,s,e),this.registerNode(e)}else await this.updateApi(d(l({},t),{[this.treeProps.label]:this.text}));t[this.treeProps.label]=this.text,t.edit=!1,this.$emit("node-updated",t,e),this.text=""}catch{}t.loading=!1,this.loading=!1},onCancel(e,t){t.id===-1?this.$refs.tree.remove(e):t.edit=!1,this.text=""},nodeClick(e,t,i){this.hideContextMenu(),(h(e.loading)||!e.loading)&&(this.curNode=t,this.curData=e,this.$emit("on-node-click",e,t,i))},getCurrentNode(){return this.$refs.tree.getCurrentNode()},async locateView(){await this.$nextTick();const e=this.$el.querySelector(`[data-id="${this.newChild.id}"]`);e&&e.scrollIntoView()},async scrollIntoView(e){var t,i;await this.$nextTick(),e||await P(300),(i=(t=this.$refs)==null?void 0:t.labelTxt)==null||i.focus()},inputKeyup(e,t,i){e.keyCode===13&&this.onConfirm(t,i),e.keyCode===27&&this.clear()},inputBlur(e,t,i){this.confirmButton||this.onConfirm(t,i)},getCheckedKeys(){return this.$refs.tree.getCheckedKeys()},setCheckedKeys(e){this.$refs.tree.setCheckedKeys(e)},getCheckedNodes(){return this.$refs.tree.getCheckedNodes()},setCheckedNodes(e){this.$refs.tree.setCheckedNodes(e)},getNode(e){return this.$refs.tree.getNode(e)},getRootNode(){return this.$refs.tree.root},findTreeNode(e){return E(this.$refs.tree.root.childNodes,t=>t.data===e||t.data.id===e,"childNodes")},registerNode(e){e.store.registerNode(e),delete e.store.nodesMap[-1]},async reloadTree(){this.lazy?this.treeKey=Date.now():await this.tryFetch()}}},N={};var V=L(I,R,S,!1,A,null,null,null);function A(e){for(let t in N)this[t]=N[t]}var O=function(){return V.exports}();export{O as default};
|
|
1
|
+
import { hasOwn as c, addResizeListener as u, removeResizeListener as p, isVerticalScrollbarVisible as x, scrollbarWidth as w, computePosition as N, isPlainObject as l, cloneDeep as f, isFunction as m, isUndefined as d, isNotEmpty as C, fastClone as v, delay as g, findTreeChildren as $ } from "@web-utils/core";
|
|
2
|
+
import { a as b, b as _, c as h } from "../../chunks/2bd4e340.js";
|
|
3
|
+
import { n as k } from "../../chunks/6499de3a.js";
|
|
4
|
+
var B = function() {
|
|
5
|
+
var e = this, i = e.$createElement, t = e._self._c || i;
|
|
6
|
+
return t("div", {
|
|
7
|
+
staticClass: "editable-tree"
|
|
8
|
+
}, [!e.readonly && e.addRootNodeButtonStyle === "top-right" ? t("ElButton", {
|
|
9
|
+
staticStyle: {
|
|
10
|
+
position: "absolute",
|
|
11
|
+
top: "4px",
|
|
12
|
+
"z-index": "1"
|
|
13
|
+
},
|
|
14
|
+
style: {
|
|
15
|
+
right: `${e.right}px`
|
|
16
|
+
},
|
|
17
|
+
attrs: {
|
|
18
|
+
type: "primary",
|
|
19
|
+
size: "mini",
|
|
20
|
+
icon: "el-icon-plus",
|
|
21
|
+
circle: "",
|
|
22
|
+
plain: ""
|
|
23
|
+
},
|
|
24
|
+
on: {
|
|
25
|
+
click: function(s) {
|
|
26
|
+
return s.stopPropagation(), e.$emit("add-root-node");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}) : e._e(), t("div", {
|
|
30
|
+
ref: "treeWrapper",
|
|
31
|
+
staticClass: "et-tree-wrapper"
|
|
32
|
+
}, [!e.readonly && e.addRootNodeButtonStyle === "top" ? t("div", {
|
|
33
|
+
staticStyle: {
|
|
34
|
+
"padding-left": "24px"
|
|
35
|
+
}
|
|
36
|
+
}, [t("ElButton", {
|
|
37
|
+
attrs: {
|
|
38
|
+
disabled: e.loading,
|
|
39
|
+
size: "mini",
|
|
40
|
+
type: "text"
|
|
41
|
+
},
|
|
42
|
+
on: {
|
|
43
|
+
click: e.appendRootNode
|
|
44
|
+
}
|
|
45
|
+
}, [t("i", {
|
|
46
|
+
staticClass: "el-icon-lx-add"
|
|
47
|
+
}), e._v(" " + e._s(e.addRootNodeLabel ? e.addRootNodeLabel : `\u6DFB\u52A0${e.label}`) + " ")])], 1) : e._e(), t("ElTree", e._g(e._b({
|
|
48
|
+
key: e.treeKey,
|
|
49
|
+
ref: "tree",
|
|
50
|
+
staticClass: "flex-item",
|
|
51
|
+
attrs: {
|
|
52
|
+
"default-expanded-keys": e.expandedKeys,
|
|
53
|
+
"expand-on-click-node": !1,
|
|
54
|
+
"highlight-current": "",
|
|
55
|
+
load: e.loadNode,
|
|
56
|
+
data: e.innerTreeData,
|
|
57
|
+
props: e.treeProps,
|
|
58
|
+
lazy: e.lazy,
|
|
59
|
+
"node-key": e.nodeKey
|
|
60
|
+
},
|
|
61
|
+
on: {
|
|
62
|
+
"node-click": e.nodeClick,
|
|
63
|
+
"node-contextmenu": e.showContextMenu,
|
|
64
|
+
"node-expand": e.addExpandKey,
|
|
65
|
+
"node-collapse": e.removeExpandKey
|
|
66
|
+
},
|
|
67
|
+
scopedSlots: e._u([{
|
|
68
|
+
key: "default",
|
|
69
|
+
fn: function(s) {
|
|
70
|
+
var o = s.node, n = s.data;
|
|
71
|
+
return [e._t("default", function() {
|
|
72
|
+
return [n.edit ? [t("span", {
|
|
73
|
+
staticClass: "custom-tree-node flex-box flex-1 oh",
|
|
74
|
+
attrs: {
|
|
75
|
+
"data-id": n.id
|
|
76
|
+
}
|
|
77
|
+
}, [e.icon ? t("i", {
|
|
78
|
+
staticClass: "node-icon shrink-0",
|
|
79
|
+
class: n.loading ? "el-icon-loading" : "el-icon-edit-outline"
|
|
80
|
+
}) : e._e(), t("ElInput", {
|
|
81
|
+
ref: "labelTxt",
|
|
82
|
+
staticClass: "node-input flex-1",
|
|
83
|
+
attrs: {
|
|
84
|
+
size: "mini",
|
|
85
|
+
placeholder: e.defaultOptions.inputPlaceholder
|
|
86
|
+
},
|
|
87
|
+
on: {
|
|
88
|
+
blur: function(a) {
|
|
89
|
+
return e.inputBlur(a, o, n);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
nativeOn: {
|
|
93
|
+
keyup: function(a) {
|
|
94
|
+
return function(r) {
|
|
95
|
+
return e.inputKeyup(r, o, n);
|
|
96
|
+
}.apply(null, arguments);
|
|
97
|
+
},
|
|
98
|
+
click: function(a) {
|
|
99
|
+
a.stopPropagation();
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
model: {
|
|
103
|
+
value: e.text,
|
|
104
|
+
callback: function(a) {
|
|
105
|
+
e.text = a;
|
|
106
|
+
},
|
|
107
|
+
expression: "text"
|
|
108
|
+
}
|
|
109
|
+
}), e.confirmButton ? [t("ElButton", {
|
|
110
|
+
directives: [{
|
|
111
|
+
name: "show",
|
|
112
|
+
rawName: "v-show",
|
|
113
|
+
value: !n.loading,
|
|
114
|
+
expression: "!data.loading"
|
|
115
|
+
}],
|
|
116
|
+
staticClass: "shrink-0",
|
|
117
|
+
attrs: {
|
|
118
|
+
size: "mini",
|
|
119
|
+
type: "text"
|
|
120
|
+
},
|
|
121
|
+
on: {
|
|
122
|
+
click: function(a) {
|
|
123
|
+
return a.stopPropagation(), e.onConfirm(o, n);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}, [e._v("\u786E\u5B9A")]), t("ElButton", {
|
|
127
|
+
directives: [{
|
|
128
|
+
name: "show",
|
|
129
|
+
rawName: "v-show",
|
|
130
|
+
value: !n.loading,
|
|
131
|
+
expression: "!data.loading"
|
|
132
|
+
}],
|
|
133
|
+
staticClass: "shrink-0",
|
|
134
|
+
attrs: {
|
|
135
|
+
size: "mini",
|
|
136
|
+
type: "text"
|
|
137
|
+
},
|
|
138
|
+
on: {
|
|
139
|
+
click: function(a) {
|
|
140
|
+
return a.stopPropagation(), e.onCancel(o, n);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, [e._v("\u53D6\u6D88")])] : e._e()], 2)] : [t("span", {
|
|
144
|
+
staticClass: "custom-tree-node",
|
|
145
|
+
attrs: {
|
|
146
|
+
"data-id": n.id
|
|
147
|
+
}
|
|
148
|
+
}, [t("span", {
|
|
149
|
+
staticClass: "node-label flex-box flex-1 oh ellipsis-1"
|
|
150
|
+
}, [e.icon ? t("i", {
|
|
151
|
+
staticClass: "node-icon",
|
|
152
|
+
class: n.loading ? "el-icon-loading" : e.icon(n, o)
|
|
153
|
+
}) : e._e(), t("span", {
|
|
154
|
+
staticClass: "flex-1-relative",
|
|
155
|
+
staticStyle: {
|
|
156
|
+
height: "21px"
|
|
157
|
+
}
|
|
158
|
+
}, [t("span", {
|
|
159
|
+
staticClass: "ellipsis-1 absolute-box et-tree-label",
|
|
160
|
+
attrs: {
|
|
161
|
+
title: o.label
|
|
162
|
+
}
|
|
163
|
+
}, [e._t("label", function() {
|
|
164
|
+
return [e._v(e._s(o.label))];
|
|
165
|
+
}, {
|
|
166
|
+
data: n,
|
|
167
|
+
node: o
|
|
168
|
+
})], 2)]), e._t("label-suffix", null, {
|
|
169
|
+
node: o,
|
|
170
|
+
data: n
|
|
171
|
+
})], 2), !e.contextMenu && !e.readonly ? t("span", {
|
|
172
|
+
directives: [{
|
|
173
|
+
name: "show",
|
|
174
|
+
rawName: "v-show",
|
|
175
|
+
value: !n.loading && !e.loading,
|
|
176
|
+
expression: "!data.loading && !loading"
|
|
177
|
+
}],
|
|
178
|
+
staticClass: "handle-actions"
|
|
179
|
+
}, [t("ElButton", {
|
|
180
|
+
attrs: {
|
|
181
|
+
size: "mini",
|
|
182
|
+
type: "text"
|
|
183
|
+
},
|
|
184
|
+
on: {
|
|
185
|
+
click: function(a) {
|
|
186
|
+
return a.stopPropagation(), e.appendChildNode(o, n);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}, [e._v("\u6DFB\u52A0")]), t("ElButton", {
|
|
190
|
+
attrs: {
|
|
191
|
+
size: "mini",
|
|
192
|
+
type: "text"
|
|
193
|
+
},
|
|
194
|
+
on: {
|
|
195
|
+
click: function(a) {
|
|
196
|
+
return a.stopPropagation(), e.editNode(o, n);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}, [e._v("\u4FEE\u6539")]), t("ElPopconfirm", {
|
|
200
|
+
staticClass: "pop-confirm",
|
|
201
|
+
attrs: {
|
|
202
|
+
"icon-color": "red",
|
|
203
|
+
title: "\u4F60\u786E\u5B9A\u8981\u5220\u9664\u5417\uFF1F"
|
|
204
|
+
},
|
|
205
|
+
on: {
|
|
206
|
+
confirm: function(a) {
|
|
207
|
+
return e.removeNode(o, n);
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
scopedSlots: e._u([{
|
|
211
|
+
key: "reference",
|
|
212
|
+
fn: function() {
|
|
213
|
+
return [t("ElButton", {
|
|
214
|
+
directives: [{
|
|
215
|
+
name: "show",
|
|
216
|
+
rawName: "v-show",
|
|
217
|
+
value: o.isLeaf,
|
|
218
|
+
expression: "node.isLeaf"
|
|
219
|
+
}],
|
|
220
|
+
staticStyle: {
|
|
221
|
+
"margin-left": "4px"
|
|
222
|
+
},
|
|
223
|
+
attrs: {
|
|
224
|
+
size: "mini",
|
|
225
|
+
type: "text"
|
|
226
|
+
},
|
|
227
|
+
on: {
|
|
228
|
+
click: function(a) {
|
|
229
|
+
a.stopPropagation();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}, [e._v("\u5220\u9664")])];
|
|
233
|
+
},
|
|
234
|
+
proxy: !0
|
|
235
|
+
}], null, !0)
|
|
236
|
+
})], 1) : e._e(), e.contextMenuIcon && e.contextMenu && !e.readonly ? t("span", {
|
|
237
|
+
directives: [{
|
|
238
|
+
name: "show",
|
|
239
|
+
rawName: "v-show",
|
|
240
|
+
value: !n.loading && !e.loading,
|
|
241
|
+
expression: "!data.loading && !loading"
|
|
242
|
+
}],
|
|
243
|
+
staticClass: "handle-actions",
|
|
244
|
+
staticStyle: {
|
|
245
|
+
display: "inline-block"
|
|
246
|
+
}
|
|
247
|
+
}, [t("ElButton", {
|
|
248
|
+
staticStyle: {
|
|
249
|
+
padding: "6px 10px 0"
|
|
250
|
+
},
|
|
251
|
+
attrs: {
|
|
252
|
+
size: "mini",
|
|
253
|
+
type: "text"
|
|
254
|
+
},
|
|
255
|
+
on: {
|
|
256
|
+
click: function(a) {
|
|
257
|
+
return a.stopPropagation(), e.showContextMenu(a, n, o);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}, [e._v(". . .")])], 1) : e._e()])]];
|
|
261
|
+
}, {
|
|
262
|
+
node: o,
|
|
263
|
+
data: n
|
|
264
|
+
})];
|
|
265
|
+
}
|
|
266
|
+
}], null, !0)
|
|
267
|
+
}, "ElTree", e.filterTreeProperties(e.$attrs), !1), e.filterTreeEvents(e.$listeners))), e.contextMenu && !e.readonly ? t("div", {
|
|
268
|
+
directives: [{
|
|
269
|
+
name: "show",
|
|
270
|
+
rawName: "v-show",
|
|
271
|
+
value: e.showMenu,
|
|
272
|
+
expression: "showMenu"
|
|
273
|
+
}],
|
|
274
|
+
ref: "contextMenu",
|
|
275
|
+
staticClass: "menu",
|
|
276
|
+
style: e.position
|
|
277
|
+
}, [t("ul", {
|
|
278
|
+
staticClass: "menu-list"
|
|
279
|
+
}, [e._t("context-menu", function() {
|
|
280
|
+
return [t("li", {
|
|
281
|
+
directives: [{
|
|
282
|
+
name: "show",
|
|
283
|
+
rawName: "v-show",
|
|
284
|
+
value: e.curData.id > -1,
|
|
285
|
+
expression: "curData.id > -1"
|
|
286
|
+
}],
|
|
287
|
+
staticClass: "menu-item",
|
|
288
|
+
on: {
|
|
289
|
+
click: function(s) {
|
|
290
|
+
return e.appendPeerNode(e.curNode, e.curData);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}, [t("i", {
|
|
294
|
+
staticClass: "menu-item-icon el-icon-lx-add",
|
|
295
|
+
staticStyle: {
|
|
296
|
+
color: "#228b22"
|
|
297
|
+
}
|
|
298
|
+
}), e._v(e._s(e.menuLabel.appendPeer) + " ")]), t("li", {
|
|
299
|
+
staticClass: "menu-item",
|
|
300
|
+
on: {
|
|
301
|
+
click: function(s) {
|
|
302
|
+
return e.appendChildNode(e.curNode, e.curData);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}, [t("i", {
|
|
306
|
+
staticClass: "menu-item-icon el-icon-lx-add",
|
|
307
|
+
staticStyle: {
|
|
308
|
+
color: "#228b22"
|
|
309
|
+
}
|
|
310
|
+
}), e._v(e._s(e.menuLabel.appendChild) + " ")]), t("li", {
|
|
311
|
+
directives: [{
|
|
312
|
+
name: "show",
|
|
313
|
+
rawName: "v-show",
|
|
314
|
+
value: e.curData.id > -1,
|
|
315
|
+
expression: "curData.id > -1"
|
|
316
|
+
}],
|
|
317
|
+
staticClass: "menu-item",
|
|
318
|
+
on: {
|
|
319
|
+
click: function(s) {
|
|
320
|
+
return e.editNode(e.curNode, e.curData);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}, [t("i", {
|
|
324
|
+
staticClass: "menu-item-icon el-icon-edit-outline",
|
|
325
|
+
staticStyle: {
|
|
326
|
+
color: "#ffa500"
|
|
327
|
+
}
|
|
328
|
+
}), e._v(e._s(e.menuLabel.editNode) + " ")]), t("li", {
|
|
329
|
+
directives: [{
|
|
330
|
+
name: "show",
|
|
331
|
+
rawName: "v-show",
|
|
332
|
+
value: e.curNode.isLeaf,
|
|
333
|
+
expression: "curNode.isLeaf"
|
|
334
|
+
}],
|
|
335
|
+
staticClass: "menu-item",
|
|
336
|
+
on: {
|
|
337
|
+
click: function(s) {
|
|
338
|
+
return e.removeNodeModal(e.curNode, e.curData);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}, [t("i", {
|
|
342
|
+
staticClass: "menu-item-icon el-icon-delete",
|
|
343
|
+
staticStyle: {
|
|
344
|
+
color: "#f00"
|
|
345
|
+
}
|
|
346
|
+
}), e._v(e._s(e.menuLabel.removeNode) + " ")])];
|
|
347
|
+
}, {
|
|
348
|
+
curNode: e.curNode,
|
|
349
|
+
curData: e.curData
|
|
350
|
+
})], 2)]) : e._e()], 1)], 1);
|
|
351
|
+
}, T = [];
|
|
352
|
+
const M = {
|
|
353
|
+
name: "EditableTree",
|
|
354
|
+
props: {
|
|
355
|
+
label: {
|
|
356
|
+
type: String,
|
|
357
|
+
default: "\u4E66\u7B7E"
|
|
358
|
+
},
|
|
359
|
+
addRootNodeLabel: {
|
|
360
|
+
type: String
|
|
361
|
+
},
|
|
362
|
+
defaultExpandedKeys: {
|
|
363
|
+
type: Array,
|
|
364
|
+
default: () => []
|
|
365
|
+
},
|
|
366
|
+
newNodeBuilder: {
|
|
367
|
+
type: Function,
|
|
368
|
+
default: (e, i) => ({
|
|
369
|
+
name: e,
|
|
370
|
+
parentId: i.id
|
|
371
|
+
})
|
|
372
|
+
},
|
|
373
|
+
contextMenu: Boolean,
|
|
374
|
+
lazy: {
|
|
375
|
+
type: Boolean,
|
|
376
|
+
default: !0
|
|
377
|
+
},
|
|
378
|
+
expandFirstNode: {
|
|
379
|
+
type: Boolean,
|
|
380
|
+
default: !0
|
|
381
|
+
},
|
|
382
|
+
readonly: Boolean,
|
|
383
|
+
saveApi: {
|
|
384
|
+
type: Function
|
|
385
|
+
},
|
|
386
|
+
updateApi: {
|
|
387
|
+
type: Function
|
|
388
|
+
},
|
|
389
|
+
deleteApi: {
|
|
390
|
+
type: Function
|
|
391
|
+
},
|
|
392
|
+
fetchApi: {
|
|
393
|
+
type: Function
|
|
394
|
+
},
|
|
395
|
+
customRootNode: {
|
|
396
|
+
type: {
|
|
397
|
+
type: Object,
|
|
398
|
+
default: void 0
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
rootNode: {
|
|
402
|
+
type: Object
|
|
403
|
+
},
|
|
404
|
+
contextMenuIcon: Boolean,
|
|
405
|
+
contextMenuInline: Boolean,
|
|
406
|
+
treeProps: {
|
|
407
|
+
type: Object,
|
|
408
|
+
default: () => ({
|
|
409
|
+
children: "children",
|
|
410
|
+
label: "name",
|
|
411
|
+
isLeaf: (e) => c(e, "hasChildren") ? !e.hasChildren : c(e, "hasChild") ? !e.hasChild : c(e, "children") && e.children ? e.children.length === 0 : !0
|
|
412
|
+
})
|
|
413
|
+
},
|
|
414
|
+
menuLabel: {
|
|
415
|
+
type: Object,
|
|
416
|
+
default: () => ({
|
|
417
|
+
appendPeer: "\u6DFB\u52A0\u540C\u7EA7\u8282\u70B9",
|
|
418
|
+
appendChild: "\u6DFB\u52A0",
|
|
419
|
+
removeNode: "\u5220\u9664",
|
|
420
|
+
editNode: "\u4FEE\u6539"
|
|
421
|
+
})
|
|
422
|
+
},
|
|
423
|
+
icon: {
|
|
424
|
+
type: [Function, Boolean],
|
|
425
|
+
default: () => "el-icon-collection-tag"
|
|
426
|
+
},
|
|
427
|
+
confirmButton: {
|
|
428
|
+
type: Boolean,
|
|
429
|
+
default: !0
|
|
430
|
+
},
|
|
431
|
+
addRootNodeButtonStyle: {
|
|
432
|
+
type: String,
|
|
433
|
+
default: "top"
|
|
434
|
+
},
|
|
435
|
+
reserveExpandKey: Boolean,
|
|
436
|
+
nodeKey: {
|
|
437
|
+
type: String,
|
|
438
|
+
default: "id"
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
data() {
|
|
442
|
+
return {
|
|
443
|
+
loading: !1,
|
|
444
|
+
showMenu: !1,
|
|
445
|
+
empty: !0,
|
|
446
|
+
expandedKeys: this.lazy ? [] : this.defaultExpandedKeys,
|
|
447
|
+
treeData: [],
|
|
448
|
+
curNode: {},
|
|
449
|
+
curData: {},
|
|
450
|
+
position: {},
|
|
451
|
+
text: "",
|
|
452
|
+
right: 4,
|
|
453
|
+
treeKey: Date.now()
|
|
454
|
+
};
|
|
455
|
+
},
|
|
456
|
+
computed: {
|
|
457
|
+
defaultOptions() {
|
|
458
|
+
return {
|
|
459
|
+
confirmButtonText: "\u786E\u5B9A",
|
|
460
|
+
cancelButtonText: "\u53D6\u6D88",
|
|
461
|
+
closeOnClickModal: !1,
|
|
462
|
+
modal: !0,
|
|
463
|
+
inputErrorMessage: `${this.label}\u540D\u4E0D\u80FD\u4E3A\u7A7A\uFF01`,
|
|
464
|
+
inputPlaceholder: `\u8BF7\u8F93\u5165${this.label}\u540D...`,
|
|
465
|
+
inputValidator: (e) => e != null && e.trim().length > 0
|
|
466
|
+
};
|
|
467
|
+
},
|
|
468
|
+
innerTreeData() {
|
|
469
|
+
var e;
|
|
470
|
+
return (e = this.$attrs.data) != null && e.length ? this.$attrs.data : this.treeData;
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
watch: {
|
|
474
|
+
defaultExpandedKeys: {
|
|
475
|
+
immediate: !0,
|
|
476
|
+
handler(e) {
|
|
477
|
+
this.expandedKeys = [...e];
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
created() {
|
|
482
|
+
this.tryFetch();
|
|
483
|
+
},
|
|
484
|
+
mounted() {
|
|
485
|
+
u(this.$refs.tree.$el, this.resize), u(this.$refs.treeWrapper, this.resize);
|
|
486
|
+
},
|
|
487
|
+
beforeDestroy() {
|
|
488
|
+
p(this.$refs.tree.$el, this.resize), p(this.$refs.treeWrapper, this.resize);
|
|
489
|
+
},
|
|
490
|
+
methods: {
|
|
491
|
+
filterTreeProperties: b,
|
|
492
|
+
filterTreeEvents: _,
|
|
493
|
+
addExpandKey(e) {
|
|
494
|
+
this.reserveExpandKey && this.expandedKeys.push(e[this.nodeKey]);
|
|
495
|
+
},
|
|
496
|
+
removeExpandKey(e) {
|
|
497
|
+
this.reserveExpandKey && (this.expandedKeys = this.expandedKeys.filter((i) => i !== e[this.nodeKey]));
|
|
498
|
+
},
|
|
499
|
+
resize() {
|
|
500
|
+
x(this.$refs.treeWrapper) ? this.right = 4 + w : this.right = 4;
|
|
501
|
+
},
|
|
502
|
+
async showContextMenu(e, i, t) {
|
|
503
|
+
i.contextmenu === !1 || i.id === -1 || i.id === 0 || i.edit === !0 || this.contextMenu && (this.curNode = t, this.curData = i, this.showMenu = !0, this.$refs.tree.setCurrentKey(i.id), await this.$nextTick(), this.position = N(e, this.$refs.contextMenu), window.addEventListener("click", this.hideContextMenu));
|
|
504
|
+
},
|
|
505
|
+
hideContextMenu() {
|
|
506
|
+
this.showMenu = !1, window.removeEventListener("click", this.hideContextMenu);
|
|
507
|
+
},
|
|
508
|
+
async tryFetch() {
|
|
509
|
+
var e, i;
|
|
510
|
+
if (this.lazy === !1 && this.fetchApi) {
|
|
511
|
+
const t = await this.fetchApi((i = (e = this.rootNode) == null ? void 0 : e.id) != null ? i : -1, {});
|
|
512
|
+
if (l(t.data) && (t.data = [t.data]), t.data = t.data || [], this.empty = t.data.length === 0, l(this.customRootNode)) {
|
|
513
|
+
const s = f(this.customRootNode);
|
|
514
|
+
s[this.treeProps.children || "children"] = t.data, this.treeData = [s];
|
|
515
|
+
} else if (m(this.customRootNode)) {
|
|
516
|
+
const s = this.customRootNode(t.data);
|
|
517
|
+
s[this.treeProps.children || "children"] = t.data, this.treeData = l(s) ? [s] : s;
|
|
518
|
+
} else
|
|
519
|
+
this.treeData = t.data;
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
async loadNode(e, i) {
|
|
523
|
+
var t, s, o, n;
|
|
524
|
+
if (e.level === 0) {
|
|
525
|
+
const a = await this.fetchApi((s = (t = this.rootNode) == null ? void 0 : t.id) != null ? s : -1, e);
|
|
526
|
+
if (this.empty = a.data.length === 0, l(this.customRootNode)) {
|
|
527
|
+
const r = f(this.customRootNode);
|
|
528
|
+
r[this.treeProps.children || "children"] = a.data, i([r]);
|
|
529
|
+
} else if (m(this.customRootNode)) {
|
|
530
|
+
const r = this.customRootNode(a.data);
|
|
531
|
+
r[this.treeProps.children || "children"] = a.data, this.treeData = l(r) ? [r] : r;
|
|
532
|
+
} else
|
|
533
|
+
i(a.data);
|
|
534
|
+
await this.$nextTick(), this.$emit("root-node-loaded", a.data), this.defaultExpandedKeys ? this.expandedKeys = [(o = a == null ? void 0 : a.data[0]) == null ? void 0 : o.id, ...this.defaultExpandedKeys] : this.expandFirstNode && (this.expandedKeys = [(n = a == null ? void 0 : a.data[0]) == null ? void 0 : n.id]);
|
|
535
|
+
} else {
|
|
536
|
+
if (e.leaf || e.data.isTempNode)
|
|
537
|
+
return i([]);
|
|
538
|
+
const a = await this.fetchApi(e.data.id, e);
|
|
539
|
+
i(a.data), await this.$nextTick(), this.$emit("node-loaded", a.data);
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
clear() {
|
|
543
|
+
this.cancelEdit(), this.removeNewNode();
|
|
544
|
+
},
|
|
545
|
+
clearChecked() {
|
|
546
|
+
this.$refs.tree.setCheckedKeys([]);
|
|
547
|
+
},
|
|
548
|
+
removeNewNode() {
|
|
549
|
+
this.newChild && this.newChild.id === -1 && (console.log(this.newChild), this.$refs.tree.remove(this.newChild), this.$emit("remove-new-node"));
|
|
550
|
+
},
|
|
551
|
+
cancelEdit() {
|
|
552
|
+
this.editData && (d(this.editData.edit) ? this.$set(this.editData, "edit", !0) : this.editData.edit = !1);
|
|
553
|
+
},
|
|
554
|
+
async editNode(e, i) {
|
|
555
|
+
!this.contextMenu || this.contextMenuIcon || this.contextMenuInline ? (this.clear(), this.editData = i, this.text = i[this.treeProps.label], d(i.edit) ? this.$set(i, "edit", !0) : i.edit = !0, await this.$nextTick(), this.$refs.labelTxt.focus()) : await this.$prompt(`\u8BF7\u8F93\u5165\u65B0\u7684${this.label}\u540D\uFF1A`, {
|
|
556
|
+
...this.defaultOptions,
|
|
557
|
+
inputValue: i[this.treeProps.label],
|
|
558
|
+
beforeClose: async (t, s, o) => {
|
|
559
|
+
if (t === "confirm") {
|
|
560
|
+
try {
|
|
561
|
+
s.confirmButtonLoading = !0, s.confirmButtonText = "\u5904\u7406\u4E2D...", this.text = s.inputValue, await this.onConfirm(this.curNode, this.curData), o();
|
|
562
|
+
} catch {
|
|
563
|
+
s.confirmButtonText = "\u786E\u5B9A";
|
|
564
|
+
}
|
|
565
|
+
s.confirmButtonLoading = !1;
|
|
566
|
+
} else
|
|
567
|
+
o();
|
|
568
|
+
}
|
|
569
|
+
}).catch((t) => t);
|
|
570
|
+
},
|
|
571
|
+
async appendRootNode() {
|
|
572
|
+
this.text = "", !this.contextMenu || this.contextMenuIcon || this.contextMenuInline ? (this.clear(), this.createNewChild(void 0), this.$refs.tree.root.insertChild({ data: this.newChild }, void 0, !0), await this.scrollIntoView(!0)) : await this.$prompt(`\u8BF7\u8F93\u5165${this.label}\u540D\uFF1A`, {
|
|
573
|
+
...this.defaultOptions,
|
|
574
|
+
beforeClose: async (e, i, t) => {
|
|
575
|
+
if (e === "confirm") {
|
|
576
|
+
try {
|
|
577
|
+
this.createNewChild(-1), i.confirmButtonLoading = !0, i.confirmButtonText = "\u5904\u7406\u4E2D...";
|
|
578
|
+
const s = await this.saveApi(this.newNodeBuilder(i.inputValue, { id: -1 }));
|
|
579
|
+
this.newChild[this.treeProps.label] = i.inputValue, this.newChild.edit = !1, h(this.newChild, s.data), this.$refs.tree.root.insertChild({ data: this.newChild }, void 0, !0), await this.locateView(), t();
|
|
580
|
+
} catch {
|
|
581
|
+
i.confirmButtonText = "\u786E\u5B9A";
|
|
582
|
+
}
|
|
583
|
+
i.confirmButtonLoading = !1;
|
|
584
|
+
} else
|
|
585
|
+
t();
|
|
586
|
+
}
|
|
587
|
+
}).catch((e) => e);
|
|
588
|
+
},
|
|
589
|
+
appendChildNode(e) {
|
|
590
|
+
this.text = "";
|
|
591
|
+
const i = e.expanded;
|
|
592
|
+
e.expand(async () => {
|
|
593
|
+
!this.contextMenu || this.contextMenuIcon || this.contextMenuInline ? (this.clear(), this.createNewChild(e.data.id), this.$refs.tree.append(this.newChild, e), await this.scrollIntoView(i)) : await this.$prompt(`\u8BF7\u8F93\u5165${this.label}\u540D\uFF1A`, {
|
|
594
|
+
...this.defaultOptions,
|
|
595
|
+
beforeClose: async (t, s, o) => {
|
|
596
|
+
if (t === "confirm") {
|
|
597
|
+
try {
|
|
598
|
+
this.createNewChild(e.data.id), s.confirmButtonLoading = !0, s.confirmButtonText = "\u5904\u7406\u4E2D...";
|
|
599
|
+
const n = await this.saveApi(this.newNodeBuilder(s.inputValue, e.data));
|
|
600
|
+
this.newChild[this.treeProps.label] = s.inputValue, this.newChild.edit = !1, h(this.newChild, n.data), this.$refs.tree.append(this.newChild, e), await this.locateView(), o();
|
|
601
|
+
} catch {
|
|
602
|
+
s.confirmButtonText = "\u786E\u5B9A";
|
|
603
|
+
}
|
|
604
|
+
s.confirmButtonLoading = !1;
|
|
605
|
+
} else
|
|
606
|
+
o();
|
|
607
|
+
}
|
|
608
|
+
}).catch((t) => t);
|
|
609
|
+
});
|
|
610
|
+
},
|
|
611
|
+
appendChildNodeWithData(e, i, t) {
|
|
612
|
+
this.text = "";
|
|
613
|
+
const s = e.expanded;
|
|
614
|
+
e.expand(async () => {
|
|
615
|
+
this.clear(), this.newChild = {
|
|
616
|
+
id: -1,
|
|
617
|
+
parentId: i,
|
|
618
|
+
[this.treeProps.label]: t,
|
|
619
|
+
edit: !1,
|
|
620
|
+
isTempNode: !0,
|
|
621
|
+
hasChildren: !1
|
|
622
|
+
}, this.$refs.tree.append(this.newChild, e), await this.scrollIntoView(s);
|
|
623
|
+
});
|
|
624
|
+
},
|
|
625
|
+
appendPeerNode(e) {
|
|
626
|
+
e.parent && e.parent.level !== 0 ? this.appendChildNode(e.parent) : this.appendRootNode();
|
|
627
|
+
},
|
|
628
|
+
async addRootNode(e) {
|
|
629
|
+
this.$refs.tree.remove(e), await this.$nextTick(), this.$refs.tree.root.insertChild({ data: e }, void 0, !0);
|
|
630
|
+
},
|
|
631
|
+
async addChildNode(e) {
|
|
632
|
+
this.curNode && this.curNode.level !== 0 ? this.curNode.expand(async () => {
|
|
633
|
+
this.$refs.tree.remove(e), await this.$nextTick(), this.$refs.tree.append(e, this.curNode);
|
|
634
|
+
}) : await this.addRootNode(e);
|
|
635
|
+
},
|
|
636
|
+
async addPeerNode(e) {
|
|
637
|
+
this.curNode && this.curNode.parent && this.curNode.parent.level !== 0 ? this.curNode.parent.expand(async () => {
|
|
638
|
+
this.$refs.tree.remove(e), await this.$nextTick(), this.$refs.tree.append(e, this.curNode.parent);
|
|
639
|
+
}) : await this.addRootNode(e);
|
|
640
|
+
},
|
|
641
|
+
updateNode(e) {
|
|
642
|
+
const i = this.$refs.tree.getNode(e);
|
|
643
|
+
i && (i.data = e);
|
|
644
|
+
},
|
|
645
|
+
setCurrentKey(e) {
|
|
646
|
+
this.$refs.tree && this.$refs.tree.setCurrentKey(e);
|
|
647
|
+
},
|
|
648
|
+
createNewChild(e) {
|
|
649
|
+
this.newChild = {
|
|
650
|
+
id: -1,
|
|
651
|
+
parentId: e,
|
|
652
|
+
[this.treeProps.label]: "",
|
|
653
|
+
edit: !0,
|
|
654
|
+
isTempNode: !0,
|
|
655
|
+
hasChildren: !1
|
|
656
|
+
}, this.$emit("create-new-node", this.newChild);
|
|
657
|
+
},
|
|
658
|
+
async removeNodeModal(e) {
|
|
659
|
+
await this.$confirm(
|
|
660
|
+
`\u4F60\u786E\u5B9A\u8981\u5220\u9664${this.label}[<span class="break-word" style="color: orange">${e.data[this.treeProps.label]}</span>]\u5417\uFF1F`,
|
|
661
|
+
"\u7CFB\u7EDF\u63D0\u793A",
|
|
662
|
+
{
|
|
663
|
+
type: "warning",
|
|
664
|
+
modal: !0,
|
|
665
|
+
dangerouslyUseHTMLString: !0,
|
|
666
|
+
iconClass: "el-icon-question",
|
|
667
|
+
closeOnClickModal: !1,
|
|
668
|
+
confirmButtonClass: "el-button--danger",
|
|
669
|
+
cancelButtonClass: "el-button--primary is-plain",
|
|
670
|
+
beforeClose: async (i, t, s) => {
|
|
671
|
+
if (i === "confirm") {
|
|
672
|
+
try {
|
|
673
|
+
t.confirmButtonLoading = !0, t.confirmButtonText = "\u5220\u9664...";
|
|
674
|
+
const o = e.parent, n = await this.deleteApi(e.data.id);
|
|
675
|
+
n.code === 0 ? (this.$message.success("\u5220\u9664\u6210\u529F!"), this.$refs.tree.remove(e), this.$emit("node-deleted", o, e.data), s()) : this.$message.error(n.message);
|
|
676
|
+
} catch {
|
|
677
|
+
}
|
|
678
|
+
t.confirmButtonText = "\u786E\u5B9A", t.confirmButtonLoading = !1;
|
|
679
|
+
} else
|
|
680
|
+
s();
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
).catch((i) => i);
|
|
684
|
+
},
|
|
685
|
+
async removeNode(e) {
|
|
686
|
+
try {
|
|
687
|
+
const i = e.parent;
|
|
688
|
+
if (this.deleteApi) {
|
|
689
|
+
const t = await this.deleteApi(e.data.id);
|
|
690
|
+
t.code === 0 ? (this.$message.success("\u5220\u9664\u6210\u529F!"), this.$refs.tree.remove(e), this.$emit("node-deleted", i, e.data)) : this.$message.error(t.message);
|
|
691
|
+
} else
|
|
692
|
+
this.$refs.tree.remove(e);
|
|
693
|
+
} catch {
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
async onConfirm(e, i) {
|
|
697
|
+
if (i[this.treeProps.label] === this.text || !C(this.text)) {
|
|
698
|
+
this.clear();
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
d(i.loading) ? this.$set(i, "loading", !0) : i.loading = !0;
|
|
702
|
+
try {
|
|
703
|
+
if (this.loading = !0, i.id === -1) {
|
|
704
|
+
const t = await this.saveApi(this.newNodeBuilder(this.text, e.parent.data || { id: -1 })), s = v(i);
|
|
705
|
+
h(i, { ...t.data, isTempNode: !1 }), this.$emit("node-added", i, s, e), this.registerNode(e);
|
|
706
|
+
} else
|
|
707
|
+
await this.updateApi({ ...i, [this.treeProps.label]: this.text });
|
|
708
|
+
i[this.treeProps.label] = this.text, i.edit = !1, this.$emit("node-updated", i, e), this.text = "";
|
|
709
|
+
} catch {
|
|
710
|
+
}
|
|
711
|
+
i.loading = !1, this.loading = !1;
|
|
712
|
+
},
|
|
713
|
+
onCancel(e, i) {
|
|
714
|
+
i.id === -1 ? this.$refs.tree.remove(e) : i.edit = !1, this.text = "";
|
|
715
|
+
},
|
|
716
|
+
nodeClick(e, i, t) {
|
|
717
|
+
this.hideContextMenu(), (d(e.loading) || !e.loading) && (this.curNode = i, this.curData = e, this.$emit("on-node-click", e, i, t));
|
|
718
|
+
},
|
|
719
|
+
getCurrentNode() {
|
|
720
|
+
return this.$refs.tree.getCurrentNode();
|
|
721
|
+
},
|
|
722
|
+
async locateView() {
|
|
723
|
+
await this.$nextTick();
|
|
724
|
+
const e = this.$el.querySelector(`[data-id="${this.newChild.id}"]`);
|
|
725
|
+
e && e.scrollIntoView();
|
|
726
|
+
},
|
|
727
|
+
async scrollIntoView(e) {
|
|
728
|
+
var i, t;
|
|
729
|
+
await this.$nextTick(), e || await g(300), (t = (i = this.$refs) == null ? void 0 : i.labelTxt) == null || t.focus();
|
|
730
|
+
},
|
|
731
|
+
inputKeyup(e, i, t) {
|
|
732
|
+
e.keyCode === 13 && this.onConfirm(i, t), e.keyCode === 27 && this.clear();
|
|
733
|
+
},
|
|
734
|
+
inputBlur(e, i, t) {
|
|
735
|
+
this.confirmButton || this.onConfirm(i, t);
|
|
736
|
+
},
|
|
737
|
+
getCheckedKeys() {
|
|
738
|
+
return this.$refs.tree.getCheckedKeys();
|
|
739
|
+
},
|
|
740
|
+
setCheckedKeys(e) {
|
|
741
|
+
this.$refs.tree.setCheckedKeys(e);
|
|
742
|
+
},
|
|
743
|
+
getCheckedNodes() {
|
|
744
|
+
return this.$refs.tree.getCheckedNodes();
|
|
745
|
+
},
|
|
746
|
+
setCheckedNodes(e) {
|
|
747
|
+
this.$refs.tree.setCheckedNodes(e);
|
|
748
|
+
},
|
|
749
|
+
getNode(e) {
|
|
750
|
+
return this.$refs.tree.getNode(e);
|
|
751
|
+
},
|
|
752
|
+
getRootNode() {
|
|
753
|
+
return this.$refs.tree.root;
|
|
754
|
+
},
|
|
755
|
+
findTreeNode(e) {
|
|
756
|
+
return $(
|
|
757
|
+
this.$refs.tree.root.childNodes,
|
|
758
|
+
(i) => i.data === e || i.data.id === e,
|
|
759
|
+
"childNodes"
|
|
760
|
+
);
|
|
761
|
+
},
|
|
762
|
+
registerNode(e) {
|
|
763
|
+
e.store.registerNode(e), delete e.store.nodesMap[-1];
|
|
764
|
+
},
|
|
765
|
+
async reloadTree() {
|
|
766
|
+
this.lazy ? this.treeKey = Date.now() : await this.tryFetch();
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}, y = {};
|
|
770
|
+
var K = /* @__PURE__ */ k(
|
|
771
|
+
M,
|
|
772
|
+
B,
|
|
773
|
+
T,
|
|
774
|
+
!1,
|
|
775
|
+
P,
|
|
776
|
+
null,
|
|
777
|
+
null,
|
|
778
|
+
null
|
|
779
|
+
);
|
|
780
|
+
function P(e) {
|
|
781
|
+
for (let i in y)
|
|
782
|
+
this[i] = y[i];
|
|
783
|
+
}
|
|
784
|
+
const R = /* @__PURE__ */ function() {
|
|
785
|
+
return K.exports;
|
|
786
|
+
}();
|
|
787
|
+
export {
|
|
788
|
+
R as default
|
|
789
|
+
};
|