UNPKG

fx-form-widget

Version:
83 lines (82 loc) 2.86 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import httpClient from '../../../config/httpClient'; ; var isFunction = function isFunction(value) { return typeof value === 'function'; }; export function catchRequestError() { return function (target, methodName, description) { var originMethod = description.value; description.value = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var _len, rest, _key, arg, callback, othersArg, _callback, _args = arguments; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: for (_len = _args.length, rest = new Array(_len), _key = 0; _key < _len; _key++) { rest[_key] = _args[_key]; } arg = rest[rest.length - 1]; callback = null; // 如果是对象取出callback参数,返回剩余接口需要的参数 if (typeof arg === 'object' && arg !== null) { callback = arg.callback; delete arg.callback; // 如果是函数直接就默认为callback } else if (isFunction(arg)) { callback = arg; } ; // 上述条件不满足默认不作任何回调处理 othersArg = rest.slice(0, rest.length - 1); _context.prev = 6; if (!(originMethod.length === 0)) { _context.next = 11; break; } return _context.abrupt("return", originMethod()); case 11: return _context.abrupt("return", originMethod.apply(void 0, [arg].concat(othersArg))); case 12: _context.next = 17; break; case 14: _context.prev = 14; _context.t0 = _context["catch"](6); console.error(_context.t0.message); case 17: _context.prev = 17; (_callback = callback) === null || _callback === void 0 ? void 0 : _callback(); return _context.finish(17); case 20: ; case 21: case "end": return _context.stop(); } }, _callee, null, [[6, 14, 17, 20]]); })); }; } ; ; var FormRelatedStore = /*#__PURE__*/function () { function FormRelatedStore() {} var _proto = FormRelatedStore.prototype; // @catchRequestError() _proto.submit = function submit(url, data) { return httpClient.post(url, data); }; _proto.getOptionsByUrl = function getOptionsByUrl(url, data) { return httpClient.post(url, data); }; return FormRelatedStore; }(); ; export default new FormRelatedStore();