UNPKG

a-common-list

Version:

基于vxe-table封装的自定义可配置表格

1 lines 14.6 kB
"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _button=require("../../button"),_list=_interopRequireDefault(require("../../a-common-list/src/list")),_query=_interopRequireDefault(require("../../advanced-query/src/query")),_pager=_interopRequireDefault(require("../../pager/src/pager")),_options=_interopRequireDefault(require("./options")),_request=require("./request");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_unsupportedIterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(t,e){if(t){if("string"==typeof t)return _arrayLikeToArray(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(r="Object"===r&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(t,e):void 0}}function _iterableToArray(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t))return _arrayLikeToArray(t)}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function _regeneratorRuntime(){_regeneratorRuntime=function(){return a};var a={},t=Object.prototype,s=t.hasOwnProperty,e="function"==typeof Symbol?Symbol:{},n=e.iterator||"@@iterator",r=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(t){i=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o,i,a,u,e=e&&e.prototype instanceof f?e:f,e=Object.create(e.prototype),n=new w(n||[]);return e._invoke=(o=t,i=r,a=n,u="suspendedStart",function(t,e){if("executing"===u)throw new Error("Generator is already running");if("completed"===u){if("throw"===t)throw e;return S()}for(a.method=t,a.arg=e;;){var r=a.delegate;if(r){r=function t(e,r){var n=e.iterator[r.method];if(void 0===n){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=void 0,t(e,r),"throw"===r.method))return l;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}n=c(n,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,l;n=n.arg;return n?n.done?(r[e.resultName]=n.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,l):n:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,l)}(r,a);if(r){if(r===l)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if("suspendedStart"===u)throw u="completed",a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);u="executing";r=c(o,i,a);if("normal"===r.type){if(u=a.done?"completed":"suspendedYield",r.arg===l)continue;return{value:r.arg,done:a.done}}"throw"===r.type&&(u="completed",a.method="throw",a.arg=r.arg)}}),e}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}a.wrap=u;var l={};function f(){}function p(){}function h(){}var e={},y=(i(e,n,function(){return this}),Object.getPrototypeOf),y=y&&y(y(_([]))),d=(y&&y!==t&&s.call(y,n)&&(e=y),h.prototype=f.prototype=Object.create(e));function g(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function m(a,u){var e;this._invoke=function(r,n){function t(){return new u(function(t,e){!function e(t,r,n,o){var i,t=c(a[t],a,r);if("throw"!==t.type)return(r=(i=t.arg).value)&&"object"==_typeof(r)&&s.call(r,"__await")?u.resolve(r.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):u.resolve(r).then(function(t){i.value=t,n(i)},function(t){return e("throw",t,n,o)});o(t.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function v(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function w(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function _(e){if(e){var r,t=e[n];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return r=-1,(t=function t(){for(;++r<e.length;)if(s.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t}).next=t}return{next:S}}function S(){return{value:void 0,done:!0}}return i(d,"constructor",p.prototype=h),i(h,"constructor",p),p.displayName=i(h,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,i(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t},a.awrap=function(t){return{__await:t}},g(m.prototype),i(m.prototype,r,function(){return this}),a.AsyncIterator=m,a.async=function(t,e,r,n,o){void 0===o&&(o=Promise);var i=new m(u(t,e,r,n),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},g(d),i(d,o,"Generator"),i(d,n,function(){return this}),i(d,"toString",function(){return"[object Generator]"}),a.keys=function(r){var t,n=[];for(t in r)n.push(t);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=_,w.prototype={constructor:w,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(v),!t)for(var e in this)"t"===e.charAt(0)&&s.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function t(t,e){return i.type="throw",i.arg=r,n.next=t,e&&(n.method="next",n.arg=void 0),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=s.call(o,"catchLoc"),u=s.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&s.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}var i=(o=o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc?null:o)?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),v(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r,n,o=this.tryEntries[e];if(o.tryLoc===t)return"throw"===(r=o.completion).type&&(n=r.arg,v(o)),n}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},a}function asyncGeneratorStep(t,e,r,n,o,i,a){try{var u=t[i](a),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,o)}function _asyncToGenerator(u){return function(){var t=this,a=arguments;return new Promise(function(e,r){var n=u.apply(t,a);function o(t){asyncGeneratorStep(n,e,r,o,i,"next",t)}function i(t){asyncGeneratorStep(n,e,r,o,i,"throw",t)}o(void 0)})}}function ownKeys(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach(function(t){_defineProperty(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function _defineProperty(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var _default2={name:"ya-wei-list",inheritAttrs:!1,data:function(){return{tableData:[],columns:[],loading:!1,tableOption:{},tablePage:{pageNo:1,pageSize:_options.default.pageSize,totalResult:0},showQuery:!1,queryOption:[],listQuery:{}}},props:{tableKey:{type:String,require:!0},showTablePage:{type:Boolean,default:!0},showTop:{type:Boolean,default:!0},showAdvancedQuery:{type:Boolean,default:!0},customPage:{type:Object,default:function(){return{pageNo:_options.default.pageNo,pageSize:_options.default.pageSize,totalResult:0}}},superParams:{type:Array,default:function(){return[]}}},computed:{},watch:{tableKey:function(){this.initTable()},customPage:{deep:!0,handler:function(t){t&&this.initTablePage()}}},methods:{getCheckboxRecords:function(){var t,e=this.tableKey;return(null==(t=this.$refs[e])||null==(t=t.$refs[e])?void 0:t.getCheckboxRecords())||[]},handlePageChange:function(t){var e=t.currentPage,t=t.pageSize;this.tablePage.pageNo=e,this.tablePage.pageSize=t,this.initData()},clearData:function(){this.tableData=[],this.columns=[],this.loading=!1,this.tableOption={},this.tablePage={pageNo:_options.default.pageNo,pageSize:_options.default.pageSize,totalResult:0}},reload:function(){this.tableData=[],this.loading=!1,this.initData()},initTable:function(){var t=this;this.clearData(),this.initOption().then(function(){t.initData()})},initTablePage:function(t){this.showTablePage?this.tablePage={pageNo:t.pageNo||_options.default.pageNo,pageSize:t.pageSize||_options.default.pageSize,totalResult:null==t?void 0:t.total}:this.customPage&&(t=_objectSpread({},this.customPage),0<Object.keys(t).length&&(this.tablePage=t))},initData:function(){var n=this;return _asyncToGenerator(_regeneratorRuntime().mark(function t(){var e,r;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n.loading=!0,t.next=3,n.getTableData();case 3:r=t.sent,e=r.success,r=r.result,e&&(n.tableData=r.records||[]),n.loading=!1;case 8:case"end":return t.stop()}},t)}))()},initOption:function(){var i=this;return _asyncToGenerator(_regeneratorRuntime().mark(function t(){var e,r,n,o;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i.getTableOption();case 2:e=t.sent,r=e.success,n=e.result,r&&(i.queryOption=JSON.parse(JSON.stringify(n.relFields)),i.tableOption={width:n.width,height:n.height,align:n.columnTitleAlign,border:!0},i.initTablePage(n),o=setTimeout(function(){i.initColumn(n.relFields),clearTimeout(o)},50));case 6:case"end":return t.stop()}},t)}))()},initColumn:function(t){var r=[];_toConsumableArray(t).filter(function(t){return t.field}).map(function(t){var e=Object.assign(t,{width:t.columnWidths,title:t.fieldCn,field:null==(e=t.field)?void 0:e.fieldName});t.columnSort&&(e.sort=t.columnSort),r.push(e)}),r=r.filter(function(t){return t.title&&t.field}),this.columns=r||[]},getScopedSlots:function(t,n){var o={},i=this.$scopedSlots;return t&&0<t.length&&t.map(function(e){var r="".concat(e.field,"Header");i[r]&&(o[r]=function(t){return n("div",i[r](t))}),-2!==e.columnAttributes&&"-2"!==e.columnAttributes||i[e.field]&&(o[e.field]=function(t){return n("div",i[e.field](t))})}),o},getTableOption:function(){var r=this;return _asyncToGenerator(_regeneratorRuntime().mark(function t(){var e;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e=r.tableKey)return t.next=4,_request.axios.request({url:"grid-config/queryAllByName",method:"GET",params:{configName:e}});t.next=6;break;case 4:return e=t.sent,t.abrupt("return",Promise.resolve(e.data));case 6:case"end":return t.stop()}},t)}))()},getTableData:function(){var a=this;return _asyncToGenerator(_regeneratorRuntime().mark(function t(){var e,r,n,o,i;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=a.tableKey)return r=a.tablePage,e=r.pageNo,r=r.pageSize,n=a.superParams,o=a.listQuery,t.next=7,_request.axios.request({url:"list-common/queryCommonList",method:"POST",params:{configName:i,pageNo:e,pageSize:r},data:{superParams:n,listQuery:o}});t.next=9;break;case 7:return i=t.sent,t.abrupt("return",Promise.resolve(i.data));case 9:case"end":return t.stop()}},t)}))()}},created:function(){this.initTable()},render:function(t){var e=this,r=this,n=this.$data,o=n.tableOption,i=n.loading,a=n.tableData,u=n.columns,n=n.tablePage,s=this.tableKey,o={tableKey:s,tableOption:o,loading:i,tableData:a,columns:u},a=this.getScopedSlots(u,t),u={border:!0,loading:i,currentPage:n.pageNo,pageSize:n.pageSize,total:n.totalResult,pageSizes:_options.default.pageSizes,layouts:["PrevPage","JumpNumber","NextPage","FullJump","Sizes","Total"]},i=this.showTablePage,c=this.showAdvancedQuery;return t("div",{class:"ya-wei-list"},[this.showTop&&t("vxe-toolbar",{scopedSlots:{buttons:function(){return[r.$slots.buttons,t(_button.Button,{attrs:{content:"刷新",status:"primary"},on:{click:function(){r.initData()}}}),c&&t(_button.Button,{attrs:{content:"高级查询",status:"primary"},on:{click:function(){r.showQuery=!0}}})]}}}),c&&t(_query.default,{attrs:{visible:this.showQuery,option:this.queryOption||[],tableKey:this.tableKey,data:this.listQuery},on:{updateVisible:function(t){e.showQuery=t},submit:function(t){e.listQuery=t,e.initData()}}}),t(_list.default,{ref:s,attrs:o,scopedSlots:a,on:this.$listeners}),i&&t(_pager.default,{attrs:u,on:{"page-change":this.handlePageChange}})])}};exports.default=_default2;