UNPKG

yw-common-list

Version:

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

817 lines (718 loc) 40.6 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _button = require("../../button"); var _list = _interopRequireDefault(require("../../a-common-list/src/list")); var _query = _interopRequireDefault(require("../../advanced-query/src/query")); var _pager = _interopRequireDefault(require("../../pager/src/pager")); var _options = _interopRequireDefault(require("./options")); var _request = require("./request"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } // 监听尺寸变化 // import resize from './resize' var _default2 = { name: 'ya-wei-list', inheritAttrs: false, // mixins: [resize], data: function data() { return { // 表格数据 tableData: [], // 表格列 columns: [], // 表格加载状态 loading: false, // 表格配置 tableOption: {}, // 表格分页数据 tablePage: { // 当前页 pageNo: 1, // 每页数据量 pageSize: _options.default.pageSize, // 列表总量 totalResult: 0 }, // 排序所需数据 tableSort: {}, // 是否显示高级查询 showQuery: false, // 高级查询页面渲染所需数据 queryOption: [], // 列表高级查询查询条件 listQuery: {}, // 错误信息 errorMessage: null, // 记录最后一次的查询方式,手动触发 reload / 高级查询 superQuery searchType: null, // 监听传值 query 是否变更 updatePropQuery: false }; }, props: { // 表格配置key tableKey: { type: String, require: true }, // 是否显示分页 showTablePage: { type: Boolean, default: true }, // 是否显示表格上方区域 showTop: { type: Boolean, default: true }, // 是否显示高级查询 showAdvancedQuery: { type: Boolean, default: true }, // 高级查询页面弹窗用的数据回显 advancedPopupData: { type: Object, default: function _default() { return {}; } }, // 自定义分页参数 customPage: { type: Object, default: function _default() { return { // 当前页 pageNo: _options.default.pageNo, // 每页数据量 pageSize: _options.default.pageSize, // 列表总量 totalResult: 0 }; } }, // 列表高级查询查询条件 superParams: { type: Array, default: function _default() { return []; } }, // 查询条件,会被高级查询覆盖 query: { type: Object, default: function _default() { return {}; } }, // 高级查询选中与 query 独立 superQueryAlone: { type: Boolean, default: true }, // 高级查询选中与 query 独立的参数名 superQueryAloneParams: { type: Array, default: function _default() { return ['id', 'column', 'order']; } }, // 初始化默认加载数据 defaultReload: { type: Boolean, default: false } }, // 监听属性 类似于data概念", computed: {}, // 监控data中的数据变化", watch: { // 监听表格key tableKey: function tableKey() { this.initTable(); }, query: { deep: true, handler: function handler(val, old) { this.updatePropQuery = JSON.stringify(this.removeEmptyData(val)) !== JSON.stringify(this.removeEmptyData(old)); } }, advancedPopupData: { deep: true, handler: function handler(val) { if (this.showAdvancedQuery) { this.$refs.refAdvancedQuery.updateData(val); } } } /* , // 深度监听自定义分页 customPage: { deep: true, // 深度监听 immediate: true, // 立即触发 handler (val) { if (val) this.initTablePage() } } */ }, methods: { // 获取表格当前选中数据 getCheckboxRecords: function getCheckboxRecords() { var _this$$refs$ref, _this$$refs$ref$$refs; var ref = this.tableKey; return ((_this$$refs$ref = this.$refs[ref]) === null || _this$$refs$ref === void 0 ? void 0 : (_this$$refs$ref$$refs = _this$$refs$ref.$refs[ref]) === null || _this$$refs$ref$$refs === void 0 ? void 0 : _this$$refs$ref$$refs.getCheckboxRecords()) || []; }, // 分页触发方法 handlePageChange: function handlePageChange(_ref) { var currentPage = _ref.currentPage, pageSize = _ref.pageSize; this.tablePage.pageNo = currentPage; this.tablePage.pageSize = pageSize; this.initData(); }, // 清空数据 clearData: function clearData() { this.tableData = []; this.columns = []; this.loading = false; this.tableOption = {}; this.tablePage = { pageNo: _options.default.pageNo, pageSize: _options.default.pageSize, totalResult: 0 }; }, /** * 刷新表格 * @param e 所需查询参数 * @param back 是否为返回,返回不对searchType进行修改 * @returns {Promise<unknown>} 接口返回数据 */ reload: function reload(e) { var back = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (back) { this.tableData = []; this.loading = false; return this.initData(); } var searchType = 'reload'; if (e && Object.keys(e).length > 0) { if (this.isNotEmptyNumber(e.pageNo) && this.isNotEmptyNumber(e.pageSize)) { if (this.searchType === 'superQuery' && !this.updatePropQuery) { if (this.tablePage.pageNo !== e.pageNo || this.tablePage.pageSize !== e.pageSize) { searchType = 'superQuery'; } } this.tablePage = _objectSpread({}, e); } } this.searchType = searchType; this.tableData = []; this.loading = false; return this.initData(); }, // 清空对象中空数据 removeEmptyData: function removeEmptyData(data) { var keys = Object.keys(data); if (!data || data && keys.length < 0) return {}; var filter = {}; keys.forEach(function (key) { var value = data[key]; if (value !== null && value !== '' && typeof value !== 'undefined') { filter[key] = value; } }); return filter; }, // 判断不为空数字 isNotEmptyNumber: function isNotEmptyNumber(str) { return str !== '' && str !== null && typeof str !== 'undefined'; }, // 初始化表格 initTable: function initTable(str) { var _this = this; this.clearData(); this.initOption().then(function () { if (str === 'created' && _this.defaultReload) { _this.initData(); } }); }, // 初始化分页 initTablePage: function initTablePage(e) { // 自定义分页数据不存在或者开启分页,不使用自定义分页数据 if (this.showTablePage) { this.tablePage = { pageNo: e.pageNo || _options.default.pageNo, pageSize: e.pageSize || _options.default.pageSize, totalResult: e === null || e === void 0 ? void 0 : e.total }; } else if (this.customPage) { var page = _objectSpread({}, this.customPage); if (Object.keys(page).length > 0) { this.tablePage = page; } } }, // 初始化表格数据 initData: function initData() { var _this2 = this; return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { var _yield$_this2$getTabl, success, result; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _this2.loading = true; _context.next = 3; return _this2.getTableData(); case 3: _yield$_this2$getTabl = _context.sent; success = _yield$_this2$getTabl.success; result = _yield$_this2$getTabl.result; _this2.loading = false; if (!success) { _context.next = 15; break; } _this2.tableData = result.records || []; _this2.tablePage.totalResult = result.total || 0; result.pageNo = _this2.tablePage.pageNo; result.superQuery = _this2.listQuery; result.isSuperQuery = _this2.searchType === 'superQuery'; _this2.$emit('listLoaderSuccess', result); return _context.abrupt("return", new Promise(function (resolve) { return resolve(result); })); case 15: case "end": return _context.stop(); } } }, _callee); }))(); }, // 设置表格尺寸 initTableSize: function initTableSize() {// console.log('tableSize') // const { clientWidth, clientHeight } = this.$el // const option = { ...this.tableOption } // if (clientWidth && clientHeight && !option.width && !option.height) { // let height = clientHeight // const buttonHeight = this.$refs.yaWeiListVXEToolbar?.$el.clientHeight // const pageHeight = this.$refs.yaWeiListVXEPager?.$el.clientHeight // // 如果显示上方按钮区域 // if (this.showTop) height -= buttonHeight || 51 // if (this.showTablePage) height -= pageHeight || 48 // option.width = clientWidth // option.divHeight = height // // option.height = height - (this.showTop ? buttonHeight || 51 : 0) - (this.showTablePage ? pageHeight || 48 : 0) // option.height = 'auto' // this.tableOption = option // } }, // 格式化表格所需参数 formatTableOption: function formatTableOption(result) { var option = { align: result.columnTitleAlign, border: true, // 边框 stripe: true, // 斑马条纹 width: result.width, // 宽度 tableHeight: result.height || 'auto', // 高度 rowHeight: result.rowHeight // 行高 }; var _this$$el = this.$el, clientWidth = _this$$el.clientWidth, clientHeight = _this$$el.clientHeight; if (clientWidth && clientHeight && !result.width && !result.height) { var _this$$refs$yaWeiList, _this$$refs$yaWeiList2; var height = clientHeight; var buttonHeight = (_this$$refs$yaWeiList = this.$refs.yaWeiListVXEToolbar) === null || _this$$refs$yaWeiList === void 0 ? void 0 : _this$$refs$yaWeiList.$el.clientHeight; var pageHeight = (_this$$refs$yaWeiList2 = this.$refs.yaWeiListVXEPager) === null || _this$$refs$yaWeiList2 === void 0 ? void 0 : _this$$refs$yaWeiList2.$el.clientHeight; // 如果显示上方按钮区域 if (this.showTop) height -= buttonHeight || 51; if (this.showTablePage) height -= pageHeight || 48; option.width = clientWidth; option.divHeight = height; // option.height = height - (this.showTop ? buttonHeight || 51 : 0) - (this.showTablePage ? pageHeight || 48 : 0) option.tableHeight = 'auto'; } return option; }, // 格式化高级查询所需参数 formatQueryOption: function formatQueryOption(e) { var option = JSON.parse(JSON.stringify(e)); option.sort(function (a, b) { return (a.superSort || 0) - (b.superSort || 0); }); return option; }, // 初始化表格配置 initOption: function initOption() { var _this3 = this; return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { var _yield$_this3$getTabl, success, result, message, code, relFields, timeout; return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return _this3.getTableOption(); case 2: _yield$_this3$getTabl = _context2.sent; success = _yield$_this3$getTabl.success; result = _yield$_this3$getTabl.result; message = _yield$_this3$getTabl.message; code = _yield$_this3$getTabl.code; if (success) { relFields = result.relFields || []; _this3.queryOption = _this3.formatQueryOption(relFields); _this3.tableOption = _this3.formatTableOption(result); /* this.tableOption = { align: result.columnTitleAlign, border: true, // 边框 stripe: true, // 斑马条纹 width: result.width, // 宽度 height: result.height || 'auto', // 高度 rowHeight: result.rowHeight // 行高 } this.initTableSize() */ _this3.initTablePage(result); // 让columns最后赋值,避免出现意外情况 timeout = setTimeout(function () { _this3.initColumn(relFields); clearTimeout(timeout); }, 50); } else { _this3.errorMessage = "".concat(code, "-").concat(message); } case 8: case "end": return _context2.stop(); } } }, _callee2); }))(); }, // 初始化表格列 initColumn: function initColumn(list) { var columns = []; var list1 = _toConsumableArray(list); // list1.filter(item => item.field).map(item => { list1.map(function (item) { var _item$field; var column = Object.assign(item, { width: item.columnWidths, title: item.fieldCn, data: item.field, field: item.fieldCode || ((_item$field = item.field) === null || _item$field === void 0 ? void 0 : _item$field.fieldName) }); if (item.columnSort) column.sort = item.columnSort; columns.push(column); }); // columns = columns.filter(item => item.title) columns = columns.filter(function (item) { return item.title && item.field; }); /* columns.push({ columnAttributes: '-3', width: 100, title: '测试checkBox', field: 'checkBox' }) columns.push({ columnAttributes: '-2', width: 100, title: '操作', field: 'caoZuo' }) */ this.columns = columns || []; }, // 获取插槽所用数据 getScopedSlots: function getScopedSlots(columns, h) { var slots = {}; var $scopedSlots = this.$scopedSlots; if (columns && columns.length > 0) { // 为所有列增加头部插槽,插槽名=列字段+Header columns.map(function (item) { var header = "".concat(item.field, "Header"); if ($scopedSlots[header]) { slots[header] = function (props) { return h('div', $scopedSlots[header](props)); }; } // 判断当前列是否为自定义列,如果是增加与列字段同名的插槽 if (item.columnAttributes === -2 || item.columnAttributes === '-2') { if ($scopedSlots[item.field]) { slots[item.field] = function (props) { return h('div', $scopedSlots[item.field](props)); }; } } }); } return slots; }, // 通过接口调用获取表格配置 getTableOption: function getTableOption() { var _this4 = this; return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() { var configName, _this4$$YaWeiListUseO, res; return _regeneratorRuntime().wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: configName = _this4.tableKey; if (!configName) { _context3.next = 15; break; } res = {}; if (!((_this4$$YaWeiListUseO = _this4.$YaWeiListUseOption) !== null && _this4$$YaWeiListUseO !== void 0 && _this4$$YaWeiListUseO.axios)) { _context3.next = 10; break; } _this4.$YaWeiListUseOption.axios.defaults.baseURL = _options.default.baseUrl; _context3.next = 7; return _this4.$YaWeiListUseOption.axios.get('grid-config/queryAllByName', { params: { configName: configName } }); case 7: res = _context3.sent; _context3.next = 14; break; case 10: _request.axios.defaults.baseURL = _options.default.baseUrl; _context3.next = 13; return _request.axios.get('grid-config/queryAllByName', { params: { configName: configName } }); case 13: res = _context3.sent; case 14: return _context3.abrupt("return", Promise.resolve(res.data.data || res.data)); case 15: case "end": return _context3.stop(); } } }, _callee3); }))(); }, // 通过接口调用获取表格数据 getTableData: function getTableData() { var _this5 = this; return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() { var configName, _this5$$YaWeiListUseO, _this5$tablePage, pageNo, pageSize, superParams, tableSort, listQuery, res; return _regeneratorRuntime().wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: // console.log(this.searchType, this.query, this.listQuery) configName = _this5.tableKey; if (!configName) { _context4.next = 20; break; } _this5$tablePage = _this5.tablePage, pageNo = _this5$tablePage.pageNo, pageSize = _this5$tablePage.pageSize; superParams = _this5.superParams; tableSort = _this5.tableSort; listQuery = {}; if (_this5.superQueryAlone) { if (_this5.searchType === 'reload') listQuery = _objectSpread(_objectSpread({}, _this5.query), tableSort);else if (_this5.searchType === 'superQuery') { listQuery = _objectSpread(_objectSpread({}, _this5.listQuery), tableSort); if (_this5.query && Object.keys(_this5.query).length > 0 && _this5.superQueryAloneParams && _this5.superQueryAloneParams.length > 0) { Object.keys(_this5.query).map(function (item) { if (!_this5.superQueryAloneParams.includes(item)) listQuery[item] = _this5.query[item]; }); } } } else { listQuery = _objectSpread(_objectSpread(_objectSpread({}, _this5.query), _this5.listQuery), tableSort); } res = {}; if (!((_this5$$YaWeiListUseO = _this5.$YaWeiListUseOption) !== null && _this5$$YaWeiListUseO !== void 0 && _this5$$YaWeiListUseO.axios)) { _context4.next = 15; break; } _this5.$YaWeiListUseOption.axios.defaults.baseURL = _options.default.baseUrl; _context4.next = 12; return _this5.$YaWeiListUseOption.axios.post('list-common/queryCommonList', { superParams: superParams, listQuery: listQuery }, { params: { configName: configName, pageNo: pageNo, pageSize: pageSize } }); case 12: res = _context4.sent; _context4.next = 19; break; case 15: _request.axios.defaults.baseURL = _options.default.baseUrl; _context4.next = 18; return _request.axios.post('list-common/queryCommonList', { superParams: superParams, listQuery: listQuery }, { params: { configName: configName, pageNo: pageNo, pageSize: pageSize } }); case 18: res = _context4.sent; case 19: return _context4.abrupt("return", Promise.resolve(res.data.data || res.data)); case 20: case "end": return _context4.stop(); } } }, _callee4); }))(); }, // 排序变更出发方法 sortChange: function sortChange(e) { var _this6 = this; if (!e || Object.keys(e).length === 0 || !e.field) return; this.tableSort = e.order ? { column: e.field, order: e.order } : {}; this.$nextTick(function () { _this6.initData(); }); } }, // 生命周期 - 创建完成(可以访问当前this实例)",数据模型已加载,方法已加载,html模板已加载,html模板未渲染 created: function created() { this.initTable('created'); }, render: function render(h) { var _this7 = this; // eslint-disable-next-line @typescript-eslint/no-this-alias var that = this; var _this$$data = this.$data, tableOption = _this$$data.tableOption, loading = _this$$data.loading, tableData = _this$$data.tableData, columns = _this$$data.columns, tablePage = _this$$data.tablePage; var ref = this.tableKey; var aCommonListAttr = _objectSpread(_objectSpread({}, this.$attrs), {}, { tableKey: ref, tableOption: tableOption, loading: loading, tableData: tableData, columns: columns }); var scopedSlots = this.getScopedSlots(columns, h); var vxePagerAttr = { border: true, loading: loading, currentPage: tablePage.pageNo, pageSize: tablePage.pageSize, total: tablePage.totalResult, pageSizes: _options.default.pageSizes, layouts: ['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total'] }; // 是否显示分页 var showTablePage = this.showTablePage; // 是否显示高级查询 var showAdvancedQuery = this.showAdvancedQuery; var style = {}; if (tableOption.divHeight) style.height = "".concat(tableOption.divHeight, "px"); return h('div', { class: 'ya-wei-list', style: style }, this.errorMessage || [this.showTop && h('vxe-toolbar', { ref: 'yaWeiListVXEToolbar', scopedSlots: { buttons: function buttons() { return [that.$slots.buttons, h(_button.Button, { attrs: { content: '刷新', status: 'primary' }, on: { click: function click() { that.initData(); } } }), showAdvancedQuery && h(_button.Button, { attrs: { content: '高级查询', status: 'primary' }, on: { click: function click() { that.showQuery = true; } } })]; } } }), showAdvancedQuery && h(_query.default, { ref: 'refAdvancedQuery', attrs: { visible: this.showQuery, option: this.queryOption || [], tableKey: this.tableKey, data: _objectSpread(_objectSpread({}, this.listQuery || {}), this.advancedPopupData || {}) }, on: { updateVisible: function updateVisible(flag) { _this7.showQuery = flag; }, submit: function submit(e) { _this7.listQuery = e; _this7.tablePage.pageNo = 1; _this7.searchType = 'superQuery'; _this7.initData(); }, focusCustom: function focusCustom(str) { _this7.$emit('focusCustom', str); }, clearCustom: function clearCustom(str) { _this7.$emit('clearCustom', str); }, resetForm: function resetForm() { _this7.$emit('superQueryReset'); } } }), h(_list.default, { ref: ref, attrs: aCommonListAttr, scopedSlots: scopedSlots, on: _objectSpread({ 'sort-change': this.sortChange }, this.$listeners) }), showTablePage && h(_pager.default, { ref: 'yaWeiListVXEPager', attrs: vxePagerAttr, on: { 'page-change': this.handlePageChange } })]); } }; exports.default = _default2;