UNPKG

@jecloud/ui

Version:

JECloud UI库,基于ant-design-vue封装

1 lines 3.33 kB
var t=this&&this.__extends||function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){function r(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}}(),e=this&&this.__spreadArrays||function(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;var r=Array(t),i=0;for(e=0;e<o;e++)for(var n=arguments[e],a=0,d=n.length;a<d;a++,i++)r[i]=n[a];return r};import{isPlainObject as o,forEach as r}from"@jecloud/utils";import{reactive as i}from"vue";import n from"../model/tree-node";import a from"./base-store";var d=function(a){function d(t){var e,o,r,i,d,c,p=a.call(this,t)||this;return p._rootNode=new n({text:"ROOT",id:"ROOT",code:"ROOT"}),p.rootVisible=null!==(e=t.rootVisible)&&void 0!==e&&e,p.idProperty=null!==(o=t.idProperty)&&void 0!==o?o:"id",p.textProperty=null!==(r=t.textProperty)&&void 0!==r?r:"text",p.codeProperty=null!==(i=t.codeProperty)&&void 0!==i?i:"code",p.parentProperty=null!==(d=t.parentProperty)&&void 0!==d?d:"parent",p.childrenProperty=null!==(c=t.childrenProperty)&&void 0!==c?c:"children",p._loadoptionsCache={},p}return t(d,a),Object.defineProperty(d.prototype,"rootNode",{get:function(){return this._rootNode},set:function(t){this._rootNode=new n(t)},enumerable:!1,configurable:!0}),d.prototype.load=function(t){var e=this;void 0===t&&(t={});var o=this;return o.loading=!0,!1!==this.emitter.emit("before-load",{options:t,store:o})?(this._loadoptionsCache=t,this.proxy.read(t).then((function(t){return o.loading=!1,e.loadData(t),e.emitter.emit("load",{store:o}),{store:o}})).catch((function(){o.loading=!1}))):(o.loading=!1,Promise.resolve({store:o}))},d.prototype.reload=function(){this.load(this._loadoptionsCache)},d.prototype.loadData=function(t){var e,r=this;void 0===t&&(t=[]);var i=[];o(t)?(this.rootVisible?i.push(t):i=null!==(e=t[this.childrenProperty])&&void 0!==e?e:[],this.rootNode=t):i=t,this._clearCache(),this.data=i.map((function(t){return new n(t)})),this.data.forEach((function(t){t.cascade((function(t){r._addCache(t)}))}))},d.prototype.cascade=function(t,e){r(null!=e?e:this.data,(function(e){return e.cascade(t)}))},d.prototype.findChild=function(t,e){var o;return this.cascade((function(e){if(t(e))return o=e,!1}),e),o},d.prototype.appendChild=function(t,e){var r=this;void 0===t&&(t=[]),o(t)&&(t=[t]),t=t.map((function(t){var e=i(new n(t));return r._addCache(e),e}));var a=this.data.slice(0);return e?e.appendChild(t):a.push.apply(a,t),this.data=a,t},d.prototype.insert=function(t,r){var a=this;o(t)&&(t=[t]),t=t.map((function(t){var e=i(new n(t));return a._addCache(e),e}));var d=this.data.slice(0);if(-1===r)d.push.apply(d,t);else if(r){var c=d,p=c.indexOf(r);if(-1===p)p=(c=this.getRecordById(r.parent).children).indexOf(r);c.splice.apply(c,e([p,0],t))}else d.unshift.apply(d,t);return this.data=d,t},d.prototype.remove=function(t){var e=this;o(t)&&(t=[t]);var r=this.data.slice(0);t.forEach((function(t){var o=e.getRecordById(e.getRecordId(t));if(o){var i=r.indexOf(o);if(-1===i){var n=e.getRecordById(o.parent);n&&(i=n.children.indexOf(o),n.children.splice(i,1))}else r.splice(i,1);e._removeCache(o)}})),this.data=r},d}(a);export default d;