UNPKG

@jecloud/ui

Version:

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

1 lines 3.08 kB
import{mitt as t,isString as e,cloneDeep as r,isEmpty as o,isNotEmpty as a,uuid as i,get as n,isNumber as s,isEqual as p}from"@jecloud/utils";import{nextTick as u,toRaw as l}from"vue";import{useProxy as c}from"../proxy";var d=function(){function d(e){var r,o;this.$table=null,this.idProperty="id",this.data=[],this.dataMap=new Map,this.sourceMap=new Map,this.emitter=t(),this.loading=!1,this.autoLoad=!1,this.fields=e.fields,this.autoLoad=null!==(r=e.autoLoad)&&void 0!==r&&r,this.data=null!==(o=e.data)&&void 0!==o?o:[],e.proxy&&(this.proxy=c(e.proxy,this))}return Object.defineProperty(d.prototype,"isStore",{get:function(){return!0},enumerable:!1,configurable:!0}),d.prototype.setup=function(t){var e;this.$table=t,this.fields=null!==(e=this.fields)&&void 0!==e?e:t.props.fieldConfig},d.prototype.on=function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];(t=this.emitter).on.apply(t,e)},d.prototype.emit=function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];(t=this.emitter).emit.apply(t,e)},d.prototype.getRecordById=function(t){return this.dataMap.get(t)},d.prototype.getRecordId=function(t){return e(t)?t:null==t?void 0:t[this.idProperty]},d.prototype.isInsertRecord=function(t){return"doInsert"===t.__action__},d.prototype.isChange=function(t,e){var r=l(t);if(e){var o=this.getRecordId(r),a=l(this.sourceMap.get(o));return!this.eqCellValue(r,a,e)}var i=this.getChanges(r,!1)[0];return!!(null==i?void 0:i[e])},d.prototype.eqCellValue=function(t,r,a){var i=n(t,a),u=n(r,a);return!(!o(i)||!o(u))||(e(i)||s(i)?i==u:p(i,u))},d.prototype.getChanges=function(t,e){var r=this,o=[];return(t?[t]:Array.from(this.dataMap.values())).forEach((function(t){var i;r.fields||(r.fields=Object.keys(t).map((function(t){return{name:t}})));var n={},s=l(t),p=r.getRecordId(s),u=null!==(i=l(r.sourceMap.get(p)))&&void 0!==i?i:{};e&&r.isInsertRecord(s)?Object.keys(s).forEach((function(t){n[t]={field:t,oldValue:s[t],newValue:s[t]}})):r.fields.forEach((function(t){var e,o=null!==(e=t.name)&&void 0!==e?e:t,a=u[o],i=s[o];r.eqCellValue(u,s,o)||(n[o]={field:o,oldValue:a,newValue:i})})),a(n)&&(n._record=s,o.push(n))})),o},d.prototype.commitRecord=function(t){var e=this.getRecordId(t),o=this.dataMap.get(e),a=this.sourceMap.get(e);this.isInsertRecord(t)&&(a=r(t),this.sourceMap.set(e,a)),a&&o&&t&&(Object.assign(o,t),Object.assign(a,t),this._clearInsertMark(o),this._clearInsertMark(a),this.refresh())},d.prototype.refresh=function(){var t=this.$table.$plugin.value.reactData.tableData;return this.$table.$plugin.value.reactData.tableData=t.slice(0),u()},d.prototype._setInsertMark=function(t){t.__action__="doInsert"},d.prototype._clearInsertMark=function(t){delete t.__action__},d.prototype._addCache=function(t){var e=this.getRecordId(t);o(e)&&(e=i(),t[this.idProperty]=e,this._setInsertMark(t)),this.dataMap.set(e,t),this.sourceMap.set(e,r(l(t)))},d.prototype._removeCache=function(t){var e=this.getRecordId(t);this.dataMap.delete(e),this.sourceMap.delete(e)},d.prototype._clearCache=function(){this.dataMap.clear(),this.sourceMap.clear()},d}();export default d;