@fle-ui/plus-table 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -11,7 +11,7 @@ var _antd = require("antd");
11
11
  var _index = _interopRequireDefault(require("./FormSearch/index"));
12
12
  var _icons = require("@ant-design/icons");
13
13
  require("./FormSearch/index.less");
14
- var _excluded = ["mode", "columns", "search", "hasShowFull", "request", "pagination", "formRef", "actionRef", "defaultColumnsState"];
14
+ var _excluded = ["mode", "columns", "hasShowFull", "request", "pagination", "formRef", "actionRef", "defaultColumnsState", "options"];
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
17
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -33,10 +33,9 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
33
33
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
34
34
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
35
35
  var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
36
- var _otherProps$scroll, _document$getElements;
36
+ var _otherProps$scroll;
37
37
  var mode = props.mode,
38
38
  columns = props.columns,
39
- search = props.search,
40
39
  _props$hasShowFull = props.hasShowFull,
41
40
  hasShowFull = _props$hasShowFull === void 0 ? true : _props$hasShowFull,
42
41
  request = props.request,
@@ -44,6 +43,8 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
44
43
  formRef = props.formRef,
45
44
  actionRef = props.actionRef,
46
45
  defaultColumnsState = props.defaultColumnsState,
46
+ _props$options = props.options,
47
+ options = _props$options === void 0 ? {} : _props$options,
47
48
  otherProps = _objectWithoutProperties(props, _excluded);
48
49
  var searchRef = (0, _react.useRef)(null);
49
50
  var _useState = (0, _react.useState)(false),
@@ -69,7 +70,7 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
69
70
  var _useState9 = (0, _react.useState)({}),
70
71
  _useState10 = _slicedToArray(_useState9, 2),
71
72
  columnsStateContainId = _useState10[0],
72
- setColumnsStateContainId = _useState10[1]; // 上传时候的对数组
73
+ setColumnsStateContainId = _useState10[1]; // 上传时 候的对数组
73
74
  var _Form$useForm = _antd.Form.useForm(),
74
75
  _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
75
76
  form = _Form$useForm2[0];
@@ -141,12 +142,13 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
141
142
  }();
142
143
  var handleReset = /*#__PURE__*/function () {
143
144
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
145
+ var _props$fetchSetting;
144
146
  var res;
145
147
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
146
148
  while (1) switch (_context3.prev = _context3.next) {
147
149
  case 0:
148
150
  _context3.next = 2;
149
- return props.fetchSetting();
151
+ return (_props$fetchSetting = props.fetchSetting) === null || _props$fetchSetting === void 0 ? void 0 : _props$fetchSetting.call(props);
150
152
  case 2:
151
153
  res = _context3.sent;
152
154
  setColumnsStateMap(res);
@@ -163,7 +165,7 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
163
165
  }();
164
166
  var init = /*#__PURE__*/function () {
165
167
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
166
- var res;
168
+ var _props$fetchSetting2, res;
167
169
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
168
170
  while (1) switch (_context4.prev = _context4.next) {
169
171
  case 0:
@@ -172,7 +174,7 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
172
174
  break;
173
175
  }
174
176
  _context4.next = 3;
175
- return props.fetchSetting();
177
+ return (_props$fetchSetting2 = props.fetchSetting) === null || _props$fetchSetting2 === void 0 ? void 0 : _props$fetchSetting2.call(props);
176
178
  case 3:
177
179
  res = _context4.sent;
178
180
  setColumnsStateContainId(res);
@@ -187,7 +189,7 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
187
189
  return _ref3.apply(this, arguments);
188
190
  };
189
191
  }();
190
- var onValuesChange = function onValuesChange() {
192
+ var onValuesChange = function onValuesChange(changeValue, allValue) {
191
193
  var _searchRef$current2;
192
194
  searchRef === null || searchRef === void 0 ? void 0 : (_searchRef$current2 = searchRef.current) === null || _searchRef$current2 === void 0 ? void 0 : _searchRef$current2.setFieldValue(drawFormRef.current.getFieldsValue());
193
195
  };
@@ -222,7 +224,6 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
222
224
  var fetchParams = {};
223
225
  columns.forEach(function (item) {
224
226
  var _item$search;
225
- // 如果存在映射函数则执行映射函数
226
227
  if ((item === null || item === void 0 ? void 0 : (_item$search = item.search) === null || _item$search === void 0 ? void 0 : _item$search.transform) && params[item.dataIndex]) {
227
228
  fetchParams = _objectSpread(_objectSpread({}, fetchParams), item.search.transform(params[item.dataIndex]));
228
229
  } else {
@@ -231,6 +232,33 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
231
232
  });
232
233
  return fetchParams;
233
234
  };
235
+ var columnsState = {
236
+ //列设置
237
+ defaultValue: defaultColumnsState,
238
+ value: columnsStateMap,
239
+ onChange: handleOnChangeColumn //列状态的值发生改变之后触发
240
+ };
241
+ var _options = Object.prototype.toString.call(options) === '[object Object]' ? _objectSpread({
242
+ density: false,
243
+ reloadIcon: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_icons.ReloadOutlined, {
244
+ onClick: function onClick() {
245
+ return actionRef.current.reload();
246
+ }
247
+ })),
248
+ setting: {
249
+ checkedReset: false,
250
+ extra: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("a", {
251
+ onClick: function onClick() {
252
+ return handleSave();
253
+ }
254
+ }, "\u4FDD\u5B58"), /*#__PURE__*/_react.default.createElement("a", {
255
+ onClick: function onClick() {
256
+ return handleReset();
257
+ }
258
+ }, "\u91CD\u7F6E")),
259
+ showListItemOption: true
260
+ }
261
+ }, options) : options;
234
262
  return /*#__PURE__*/_react.default.createElement("div", {
235
263
  className: !searchDrawer ? 'page_plustable__body' : 'page_plustable__body turn-left'
236
264
  },
@@ -246,13 +274,13 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
246
274
  xxl: 6
247
275
  },
248
276
  labelWidth: 80,
249
- onCollapse: function onCollapse(e) {
277
+ onCollapse: function onCollapse() {
250
278
  // 执行展开和关闭动作
251
279
  },
252
- collapseRender: function collapseRender(collapsed) {
280
+ collapseRender: function collapseRender() {
253
281
  return null;
254
282
  },
255
- optionRender: function optionRender(searchConfig, formProps, dom) {
283
+ optionRender: function optionRender(searchConfig) {
256
284
  return [/*#__PURE__*/_react.default.createElement(_antd.Button, {
257
285
  size: "middle",
258
286
  type: "primary",
@@ -291,12 +319,7 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
291
319
  }, /*#__PURE__*/_react.default.createElement(_icons.BarsOutlined, null), "\u9AD8\u7EA7\u7B5B\u9009") : null];
292
320
  }
293
321
  },
294
- columnsState: {
295
- //列设置
296
- defaultValue: defaultColumnsState,
297
- value: columnsStateMap,
298
- onChange: handleOnChangeColumn //列状态的值发生改变之后触发
299
- },
322
+ columnsState: columnsState,
300
323
  pagination: pagination,
301
324
  actionRef: actionRef,
302
325
  formRef: searchRef,
@@ -370,34 +393,15 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
370
393
  x: (otherProps === null || otherProps === void 0 ? void 0 : (_otherProps$scroll = otherProps.scroll) === null || _otherProps$scroll === void 0 ? void 0 : _otherProps$scroll.x) || 1300
371
394
  },
372
395
  onChange: onTableChange,
373
- options: {
374
- // 这里还要再处理一下 接口不应该调用
375
- density: false,
376
- reloadIcon: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_icons.ReloadOutlined, {
377
- onClick: function onClick() {
378
- return actionRef.current.reload();
379
- }
380
- })),
381
- setting: {
382
- checkedReset: false,
383
- extra: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("a", {
384
- onClick: function onClick() {
385
- return handleSave();
386
- }
387
- }, "\u4FDD\u5B58"), /*#__PURE__*/_react.default.createElement("a", {
388
- onClick: function onClick() {
389
- return handleReset();
390
- }
391
- }, "\u91CD\u7F6E")),
392
- showListItemOption: true
393
- }
394
- }
396
+ options: _options
395
397
  })) : /*#__PURE__*/_react.default.createElement(_proComponents.ProTable // 普通模式
396
398
  , _extends({
397
399
  columns: columns,
398
400
  request: request,
399
401
  actionRef: actionRef,
400
- formRef: formRef
402
+ formRef: formRef,
403
+ columnsState: columnsState,
404
+ options: _options
401
405
  }, otherProps)), /*#__PURE__*/_react.default.createElement(_antd.Drawer, {
402
406
  onClose: function onClose() {
403
407
  return setSearchDrawer(false);
@@ -406,9 +410,9 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
406
410
  width: 380,
407
411
  rootStyle: {
408
412
  position: 'fixed',
409
- top: props.top || 64
413
+ top: props.top || 0
410
414
  },
411
- getContainer: (otherProps === null || otherProps === void 0 ? void 0 : otherProps.getContainer) || ((_document$getElements = document.getElementsByClassName('page_plustable__body')[0]) === null || _document$getElements === void 0 ? void 0 : _document$getElements.parentElement),
415
+ getContainer: (otherProps === null || otherProps === void 0 ? void 0 : otherProps.getContainer) || document.getElementsByTagName('body')[0],
412
416
  className: "search-drawer",
413
417
  open: searchDrawer,
414
418
  maskClosable: false,
@@ -416,8 +420,8 @@ var PlusTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
416
420
  }, /*#__PURE__*/_react.default.createElement(_index.default, {
417
421
  columns: columns,
418
422
  loading: false,
419
- changeValue: function changeValue() {
420
- return onValuesChange();
423
+ changeValue: function changeValue(_changeValue, allValue) {
424
+ return onValuesChange(_changeValue, allValue);
421
425
  },
422
426
  onFormSearchSubmit: function onFormSearchSubmit() {
423
427
  var _searchRef$current5;
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ getJDGoodsStock: string;
3
+ getCategoryAllList: string;
4
+ getSelfGoodsFlag: string;
5
+ getSelfGoodsFlagCategory: string;
6
+ getDgssCityAllList: string;
7
+ getGoodsList: string;
8
+ };
9
+ export default _default;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = exports.default = {
8
+ // getGoodsList: '/fleshopy/merchant/site/site-goods/pageList', // 查询站点商品
9
+ getJDGoodsStock: '/fleshopy/stock/getStockBatch',
10
+ getCategoryAllList: '/fleshopy/category/getTreeList',
11
+ getSelfGoodsFlag: '/fleshopy/goods/flag/allList',
12
+ getSelfGoodsFlagCategory: '/elebuys/goodsCategory/tree',
13
+ getDgssCityAllList: '/supplier/dgss/city/allList',
14
+ getGoodsList: '/bestgift/goods/goods/search/getMemberGoodsList'
15
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 金额格式化
3
+ * @param data
4
+ */
5
+ type moneyType = number | string;
6
+ interface ShowMoneyType {
7
+ (data: moneyType): string;
8
+ }
9
+ export declare const showMoney: ShowMoneyType;
10
+ /**
11
+ * 时间格式化
12
+ * @param data
13
+ * @param fmtType
14
+ */
15
+ type timeType = Date | number | string;
16
+ interface ShowTimeType {
17
+ (data: timeType, fmtType: string): string;
18
+ }
19
+ export declare const showTime: ShowTimeType;
20
+ /**
21
+ * 格式化url参数
22
+ */
23
+ export declare const parseQueryString: () => {
24
+ [key: string]: string;
25
+ };
26
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.showTime = exports.showMoney = exports.parseQueryString = void 0;
7
+ var _dayjs = _interopRequireDefault(require("dayjs"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
+ 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); }
11
+ 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; }
12
+ var showMoney = exports.showMoney = function showMoney(data) {
13
+ return (+data / 100).toFixed(2);
14
+ };
15
+ var showTime = exports.showTime = function showTime(data) {
16
+ var fmtType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD HH:mm:ss';
17
+ return data ? (0, _dayjs.default)(data).format(fmtType) : '';
18
+ };
19
+ /**
20
+ * 格式化url参数
21
+ */
22
+ var parseQueryString = exports.parseQueryString = function parseQueryString() {
23
+ var urlParams = new URLSearchParams(window.location.search);
24
+ var params = {};
25
+ var _iterator = _createForOfIteratorHelper(urlParams),
26
+ _step;
27
+ try {
28
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
29
+ var param = _step.value;
30
+ params[param[0]] = param[1];
31
+ }
32
+ } catch (err) {
33
+ _iterator.e(err);
34
+ } finally {
35
+ _iterator.f();
36
+ }
37
+ return params;
38
+ };
@@ -0,0 +1,25 @@
1
+ export declare const tabs: {
2
+ label: string;
3
+ key: string;
4
+ }[];
5
+ export declare const tabsSearchParamsMap: any;
6
+ export declare const priceRangeForOnce: {
7
+ label: string;
8
+ value: string;
9
+ }[];
10
+ export declare const priceRangeForPurchase: {
11
+ label: string;
12
+ value: string;
13
+ }[];
14
+ export declare const profitRangeForOnce: {
15
+ label: string;
16
+ value: string;
17
+ }[];
18
+ export declare const profitRangeForPurchase: {
19
+ label: string;
20
+ value: string;
21
+ }[];
22
+ export declare const sortOptions: {
23
+ label: string;
24
+ value: string;
25
+ }[];
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.tabsSearchParamsMap = exports.tabs = exports.sortOptions = exports.profitRangeForPurchase = exports.profitRangeForOnce = exports.priceRangeForPurchase = exports.priceRangeForOnce = void 0;
7
+ var tabs = exports.tabs = [{
8
+ label: '京东商品',
9
+ key: 'jd'
10
+ }, {
11
+ label: '精选商品',
12
+ key: 'jx'
13
+ }, {
14
+ label: '自有商品',
15
+ key: 'zy'
16
+ }, {
17
+ label: '鲜花蛋糕',
18
+ key: 'xhdg'
19
+ }, {
20
+ label: '猫超商品',
21
+ key: 'mc'
22
+ }];
23
+ var tabsSearchParamsMap = exports.tabsSearchParamsMap = {
24
+ jd: {
25
+ thirdType: 10,
26
+ isSelf: 0
27
+ },
28
+ jx: {
29
+ thirdType: 0,
30
+ isSelf: 0
31
+ },
32
+ zy: {
33
+ isSelf: 1
34
+ },
35
+ xhdg: {
36
+ thirdType: 40,
37
+ isSelf: 0
38
+ },
39
+ mc: {
40
+ thirdType: 50,
41
+ isSelf: 0
42
+ }
43
+ };
44
+ // 一件代发价格筛选配置 - 非营销云
45
+ var priceRangeForOnce = exports.priceRangeForOnce = [{
46
+ label: '市场价',
47
+ value: 'onceMarketPrice'
48
+ }, {
49
+ label: '代发价',
50
+ value: 'onceSalePrice'
51
+ }, {
52
+ label: '销售价',
53
+ value: 'onceSitePrice'
54
+ }];
55
+ // 集采价格筛选配置 - 营销云
56
+ var priceRangeForPurchase = exports.priceRangeForPurchase = [{
57
+ label: '集采市场价',
58
+ value: 'purchaseMarketPrice'
59
+ }, {
60
+ label: '代发市场价',
61
+ value: 'onceMarketPrice'
62
+ }, {
63
+ label: '集采价',
64
+ value: 'purchaseSalePrice'
65
+ }, {
66
+ label: '代发价',
67
+ value: 'onceSalePrice'
68
+ }, {
69
+ label: '集采销售价',
70
+ value: 'purchaseSitePrice'
71
+ }, {
72
+ label: '代发销售价',
73
+ value: 'onceSitePrice'
74
+ }];
75
+ // 一件代发利润率筛选配置 - 非营销云
76
+ var profitRangeForOnce = exports.profitRangeForOnce = [{
77
+ label: '利润率',
78
+ value: 'onceSiteProfit'
79
+ }];
80
+ // 集采利润率筛选配置 - 营销云
81
+ var profitRangeForPurchase = exports.profitRangeForPurchase = [{
82
+ label: '集采利润率',
83
+ value: 'purchaseSiteProfit'
84
+ }, {
85
+ label: '代发利润率',
86
+ value: 'onceSiteProfit'
87
+ }];
88
+ // 排序规则
89
+ var sortOptions = exports.sortOptions = [{
90
+ label: '推荐',
91
+ value: 'pool_saas_search_site_profit_max' // 销售利润率(站点利润率)
92
+ }, {
93
+ label: '上架时间',
94
+ value: 'pool_saas_putaway_time'
95
+ }, {
96
+ label: '会员价',
97
+ value: 'search_sale_price_max'
98
+ }, {
99
+ label: '销售价',
100
+ value: 'pool_saas_search_site_price_max'
101
+ }];
@@ -0,0 +1,26 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ interface RequestConfig extends AxiosRequestConfig {
3
+ notice?: boolean;
4
+ }
5
+ declare module 'axios' {
6
+ interface AxiosInstance {
7
+ (config: RequestConfig): Promise<any>;
8
+ }
9
+ }
10
+ interface AxiosConfig {
11
+ baseUrl?: string;
12
+ timeout?: number;
13
+ tokenKey?: string;
14
+ token?: string | undefined;
15
+ loginErrUrl?: string;
16
+ loginErrFn?: Function | undefined;
17
+ noNotificationCodes?: Array<string | number>;
18
+ errUrlFn?: Function | undefined;
19
+ formDataUrls?: Array<string>;
20
+ exceptionErrFn?: {
21
+ notification?: Function | undefined;
22
+ };
23
+ }
24
+ declare const Request: (configParams: AxiosConfig) => import("axios").AxiosInstance;
25
+ export declare const request: import("axios").AxiosInstance;
26
+ export default Request;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.request = exports.default = void 0;
7
+ var _jsCookie = _interopRequireDefault(require("js-cookie"));
8
+ var _axios = _interopRequireDefault(require("axios"));
9
+ var _antd = require("antd");
10
+ var _env = require("@fle-tools/env");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
+ var DATA_CODE = new Map([['SUCCESS', '2000'], ['LOGIN_ERROR', '100003']]);
19
+ // 登录失效
20
+ var CancelToken = _axios.default.CancelToken;
21
+ var source = CancelToken.source();
22
+ var pending = [];
23
+ // 移除重复请求
24
+ var removePending = function removePending(config) {
25
+ for (var key in pending) {
26
+ var item = +key;
27
+ var list = pending[key];
28
+ // 当前请求在数组中存在时执行函数体
29
+ if (list.url === config.url && list.method === config.method && JSON.stringify(list.params) === JSON.stringify(config.params) && JSON.stringify(list.data) === JSON.stringify(config.data)) {
30
+ // 执行取消操作
31
+ list.cancel('操作太频繁,请稍后再试');
32
+ // 从数组中移除记录
33
+ pending.splice(item, 1);
34
+ }
35
+ }
36
+ };
37
+ // 默认配置
38
+ var initAxiosConfig = {
39
+ baseUrl: undefined,
40
+ timeout: 10000,
41
+ tokenKey: 'token',
42
+ token: undefined,
43
+ loginErrUrl: undefined,
44
+ loginErrFn: undefined,
45
+ noNotificationCodes: [],
46
+ errUrlFn: undefined,
47
+ formDataUrls: [] // 需要用formData提交的接口列表
48
+ };
49
+ var Request = function Request(configParams) {
50
+ configParams = _objectSpread(_objectSpread({}, initAxiosConfig), configParams);
51
+ // console.log(configParams, 'config')
52
+ var service = _axios.default.create({
53
+ baseURL: configParams.baseUrl,
54
+ timeout: configParams.timeout
55
+ });
56
+ service.interceptors.request.use(function (config) {
57
+ var _configParams$formDat;
58
+ removePending(config);
59
+ config.headers['authority_token'] = configParams.token || _jsCookie.default.get(configParams.tokenKey);
60
+ config.url = "".concat(config.url);
61
+ if ((_configParams$formDat = configParams.formDataUrls) === null || _configParams$formDat === void 0 ? void 0 : _configParams$formDat.includes(config.url)) {
62
+ config.headers['Content-Type'] = 'multipart/form-data';
63
+ config.headers['Accept'] = '*/*';
64
+ }
65
+ return _objectSpread(_objectSpread({}, config), {}, {
66
+ cancelToken: source.token
67
+ });
68
+ }, function (err) {
69
+ var _configParams$excepti;
70
+ if ((_configParams$excepti = configParams.exceptionErrFn) === null || _configParams$excepti === void 0 ? void 0 : _configParams$excepti.notification) {
71
+ var _configParams$excepti2;
72
+ (_configParams$excepti2 = configParams.exceptionErrFn) === null || _configParams$excepti2 === void 0 ? void 0 : _configParams$excepti2.notification('提示', err.toString());
73
+ } else {
74
+ _antd.notification.error({
75
+ message: '提示',
76
+ description: err.toString()
77
+ });
78
+ }
79
+ return Promise.reject(_objectSpread(_objectSpread({}, err), {}, {
80
+ data: null
81
+ }));
82
+ });
83
+ service.interceptors.response.use(function (res) {
84
+ var status = res.status,
85
+ data = res.data,
86
+ statusText = res.statusText,
87
+ config = res.config;
88
+ removePending(config);
89
+ return new Promise(function (resolve, reject) {
90
+ if (status < 200 || status > 300) {
91
+ var _configParams$excepti3;
92
+ if ((_configParams$excepti3 = configParams.exceptionErrFn) === null || _configParams$excepti3 === void 0 ? void 0 : _configParams$excepti3.notification) {
93
+ var _configParams$excepti4;
94
+ (_configParams$excepti4 = configParams.exceptionErrFn) === null || _configParams$excepti4 === void 0 ? void 0 : _configParams$excepti4.notification("\u8BF7\u6C42\u9519\u8BEF: ".concat(status), statusText);
95
+ } else {
96
+ _antd.notification.error({
97
+ message: "\u8BF7\u6C42\u9519\u8BEF: ".concat(status),
98
+ description: statusText
99
+ });
100
+ }
101
+ reject(data);
102
+ } else if (!data.success) {
103
+ if (data.code === DATA_CODE.get('LOGIN_ERROR')) {
104
+ // 登录失效后,取消后续的http请求
105
+ source.cancel('登录失效');
106
+ if (configParams.loginErrFn) {
107
+ configParams.loginErrFn();
108
+ } else if (configParams.loginErrUrl) {
109
+ _antd.Modal.warning({
110
+ title: '登录失效',
111
+ content: '点击确定重新登录',
112
+ okText: '确定',
113
+ onOk: function onOk() {
114
+ var _getAppInfo;
115
+ window.location.href = configParams.loginErrUrl || ((_getAppInfo = (0, _env.getAppInfo)()) === null || _getAppInfo === void 0 ? void 0 : _getAppInfo.__fle_loginErrUrl__);
116
+ }
117
+ });
118
+ }
119
+ } else {
120
+ var _configParams$noNotif;
121
+ if (!((_configParams$noNotif = configParams.noNotificationCodes) === null || _configParams$noNotif === void 0 ? void 0 : _configParams$noNotif.includes(data.code))) {
122
+ var _configParams$excepti5;
123
+ if ((_configParams$excepti5 = configParams.exceptionErrFn) === null || _configParams$excepti5 === void 0 ? void 0 : _configParams$excepti5.notification) {
124
+ var _configParams$excepti6;
125
+ (_configParams$excepti6 = configParams.exceptionErrFn) === null || _configParams$excepti6 === void 0 ? void 0 : _configParams$excepti6.notification('提示', data.message);
126
+ } else {
127
+ _antd.notification.error({
128
+ message: '提示',
129
+ description: data.message
130
+ });
131
+ }
132
+ }
133
+ }
134
+ reject(data);
135
+ } else {
136
+ resolve(data);
137
+ }
138
+ });
139
+ }, function (err) {
140
+ var _err$message;
141
+ if (err.message === 'Request failed with status code 404') {
142
+ if (configParams.errUrlFn) {
143
+ configParams.errUrlFn();
144
+ return;
145
+ }
146
+ }
147
+ if (err.message === '登录失效') {
148
+ return;
149
+ }
150
+ if ((_err$message = err.message) === null || _err$message === void 0 ? void 0 : _err$message.includes('timeout')) {
151
+ var _configParams$excepti7;
152
+ if ((_configParams$excepti7 = configParams.exceptionErrFn) === null || _configParams$excepti7 === void 0 ? void 0 : _configParams$excepti7.notification) {
153
+ var _configParams$excepti8;
154
+ (_configParams$excepti8 = configParams.exceptionErrFn) === null || _configParams$excepti8 === void 0 ? void 0 : _configParams$excepti8.notification('提示', '请求超时~');
155
+ } else {
156
+ _antd.notification.error({
157
+ message: '提示',
158
+ description: '请求超时~'
159
+ });
160
+ }
161
+ } else {
162
+ var _configParams$excepti9;
163
+ if ((_configParams$excepti9 = configParams.exceptionErrFn) === null || _configParams$excepti9 === void 0 ? void 0 : _configParams$excepti9.notification) {
164
+ var _configParams$excepti10;
165
+ (_configParams$excepti10 = configParams.exceptionErrFn) === null || _configParams$excepti10 === void 0 ? void 0 : _configParams$excepti10.notification('提示', err.toString());
166
+ } else {
167
+ _antd.notification.error({
168
+ message: '提示',
169
+ description: err.toString()
170
+ });
171
+ }
172
+ }
173
+ return Promise.reject(err);
174
+ });
175
+ return service;
176
+ };
177
+ var request = exports.request = Request({
178
+ baseUrl: (0, _env.getAePrefix)()
179
+ });
180
+ var _default = exports.default = Request;
@@ -0,0 +1,6 @@
1
+ export type EnvType = 'dev' | 'test' | 'qa' | 'prod';
2
+ export declare const baseURLMap: {
3
+ [key in EnvType]: string;
4
+ };
5
+ export declare const getApiHost: (env: EnvType) => string;
6
+ export declare const getApiUrl: (env: EnvType, url: string) => string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getApiUrl = exports.getApiHost = exports.baseURLMap = void 0;
7
+ var baseURLMap = exports.baseURLMap = {
8
+ dev: 'https://dev-gateway.fxqifu.net/pangu',
9
+ test: 'https://qa-gateway.fxqifu.net/pangu',
10
+ qa: 'https://qa-gateway.fxqifu.net/pangu',
11
+ prod: 'https://gateway.fxqifu.net/pangu'
12
+ };
13
+ var getApiHost = exports.getApiHost = function getApiHost(env) {
14
+ return baseURLMap[env];
15
+ };
16
+ var getApiUrl = exports.getApiUrl = function getApiUrl(env, url) {
17
+ return baseURLMap[env] + url;
18
+ };