nsn-service
Version:
NSN服务组件
116 lines (89 loc) • 3.75 kB
JavaScript
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; }
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); }); }; }
import { HttpMethod, MappingURI } from 'nsn-enum';
import { NType, NStr } from 'nsn-util';
import { request } from './request';
var exec = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(ctx, uri, method, params) {
var umiparam;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
umiparam = {
ctx: undefined,
uri: uri,
options: _defineProperty({
method: method
}, NStr.isEqual(method, HttpMethod.POST) ? 'data' : 'params', params)
};
if (NType.isString(ctx)) {
umiparam.ctx = ctx;
} else if (ctx) {
umiparam = Object.assign(umiparam, ctx);
}
return _context.abrupt("return", request(umiparam));
case 3:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function exec(_x, _x2, _x3, _x4) {
return _ref.apply(this, arguments);
};
}();
var page = function page(ctx, params) {
var _ref2 = params || {},
pageSize = _ref2.pageSize;
if (pageSize) {
var _params;
// 修改参数
(_params = params) === null || _params === void 0 ? void 0 : delete _params.pageSize;
params = Object.assign(params, {
page_size: pageSize
});
}
return exec(ctx, MappingURI.PAGE, HttpMethod.GET, params);
};
var save = function save(ctx, params) {
return exec(ctx, MappingURI.SAVE, HttpMethod.POST, params);
};
var remove = function remove(ctx, params) {
return exec(ctx, MappingURI.REMOVE, HttpMethod.POST, params);
};
var toggle = function toggle(ctx, params) {
return exec(ctx, MappingURI.TOGGLE, HttpMethod.POST, params);
};
var find = function find(ctx, params) {
return exec(ctx, MappingURI.FIND, HttpMethod.GET, params);
};
var list = function list(ctx, params) {
return exec(ctx, MappingURI.LIST, HttpMethod.GET, params);
};
var unique = function unique(ctx, params) {
return exec(ctx, MappingURI.UNIQUE, HttpMethod.GET, params);
};
var tree = function tree(ctx, params) {
return exec(ctx, MappingURI.TREE, HttpMethod.GET, params);
};
export var NRequest = {
/** GET /api/nsn/{ctx}/find | /api/{ctx}/find */
find: find,
/** GET /api/nsn/{ctx}/list | /api/{ctx}/list */
list: list,
/** GET /api/nsn/{ctx}/page | /api/{ctx}/page */
page: page,
/** POST /api/nsn/{ctx}/remove | /api/{ctx}/remove */
remove: remove,
/** POST /api/nsn/{ctx}/save | /api/{ctx}/save */
save: save,
/** POST /api/nsn/{ctx}/toggle | /api/{ctx}/toggle */
toggle: toggle,
/** GET /api/nsn/{ctx}/unique | /api/{ctx}/unique */
unique: unique,
/** GET /api/nsn/{ctx}/tree | /api/{ctx}/tree */
tree: tree
};