UNPKG

@choerodon/master

Version:
81 lines (66 loc) 2.4 kB
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } import axios from "../components/axios"; import { getProjectId, getOrganizationId } from "../utils/getId"; var Api = /*#__PURE__*/function () { function Api() { var isConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; _classCallCheck(this, Api); this.isConfig = isConfig; } _createClass(Api, [{ key: "request", value: function request(AxiosConfig) { if (this.isConfig) { return AxiosConfig; } return axios(AxiosConfig); } }, { key: "projectId", get: function get() { return getProjectId(); } }, { key: "orgId", get: function get() { return getOrganizationId(); } /** * 目的:达到api.project(2).getList()中getList获取的projectId为2,而不是当前projectId * @param Property 要覆盖的key * @param value 要覆盖的值 */ }, { key: "overwrite", value: function overwrite(Property, value) { // 以当前this为模板,创建一个新对象 var temp = Object.create(this); // 不直接temp[Property] = value;的原因是,如果这个属性只有getter,会报错 Object.defineProperty(temp, Property, { get: function get() { return value; } }); // 返回新对象 return temp; } }, { key: "project", value: function project(projectId) { if (projectId) { return this.overwrite('projectId', projectId); } return this; } }, { key: "org", value: function org(orgId) { if (orgId) { return this.overwrite('orgId', orgId); } return this; } }]); return Api; }(); export default Api;