ls-pro-common 3.1.7 → 3.1.9

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.
@@ -50,10 +50,11 @@ export declare function httpDelete(url: string, data: any, needGateWay?: boolean
50
50
  * @param showValue 是否显示值
51
51
  * @param needGateWay 是否需要网关 默认为true
52
52
  * @param timeout 超时时间,默认60000毫秒
53
+ * @param isGet 是否Get请求
53
54
  * @param valueIsNumber 返回值是否为数字,默认false
54
55
  * @returns Promise<Record<string,string>[]>
55
56
  */
56
- export declare function getDict(dictCode: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, valueIsNumber?: boolean): Promise<any>;
57
+ export declare function getDict(dictCodes: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
57
58
  /**
58
59
  * 加载下拉框的数据源
59
60
  *
@@ -63,8 +64,10 @@ export declare function getDict(dictCode: string, showValue?: boolean, needGateW
63
64
  * @param labelField 显示字段
64
65
  * @param showValue 显示值
65
66
  * @param needGateWay 是否需要网关 默认为true
67
+ * @param timeout
68
+ * @param isGet = true 是否get请求,默认true
66
69
  * @param valueIsNumber 返回值是否为数字,默认false
67
70
  * @returns
68
71
  */
69
- export declare function fetchOptions(url: string, param: any, valueField: string, labelField: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, valueIsNumber?: boolean): Promise<any>;
72
+ export declare function fetchOptions(url: string, param: any, valueField: string, labelField: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
70
73
  export default request;
package/es/http/index.js CHANGED
@@ -53,7 +53,7 @@ export var isCrossDomain = function isCrossDomain(url) {
53
53
  };
54
54
  /** 请求拦截器,统一添加token */
55
55
  request.interceptors.request.use(function (url, options) {
56
- var _options$params;
56
+ var _window$crypto$random, _window$crypto, _options$params;
57
57
  options.headers = options.headers || {};
58
58
  // 处理浏览器指纹
59
59
  if (browserId) {
@@ -92,7 +92,8 @@ request.interceptors.request.use(function (url, options) {
92
92
  url = url.replace('&noToken=1', '').replace('noToken=1', '');
93
93
  var resCode = getUrlQuery('resCode', url) || getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId');
94
94
  var param = {
95
- _t1: Date.now()
95
+ _t1: Date.now(),
96
+ __r: ((_window$crypto$random = (_window$crypto = window.crypto)['randomUUID']) === null || _window$crypto$random === void 0 ? void 0 : _window$crypto$random.call(_window$crypto)) || Math.random()
96
97
  };
97
98
  // 当没有明文参数resCode的时候,添加resCode参数为资源Id
98
99
  //@ts-ignore
@@ -325,19 +326,21 @@ export function httpDelete(url, data) {
325
326
  * @param showValue 是否显示值
326
327
  * @param needGateWay 是否需要网关 默认为true
327
328
  * @param timeout 超时时间,默认60000毫秒
329
+ * @param isGet 是否Get请求
328
330
  * @param valueIsNumber 返回值是否为数字,默认false
329
331
  * @returns Promise<Record<string,string>[]>
330
332
  */
331
- export function getDict(dictCode) {
333
+ export function getDict(dictCodes) {
332
334
  var showValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
333
335
  var needGateWay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
334
336
  var timeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 60000;
335
- var valueIsNumber = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
337
+ var isGet = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
338
+ var valueIsNumber = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
336
339
  var api = '/lesoon-petrel-integration-api/sysDictDtl/listByProperties';
337
340
  var param = {
338
- dictCode: dictCode
341
+ dictCodes: (dictCodes || '').split(',')
339
342
  };
340
- return fetchOptions(api, param, 'dictValue', 'displayName', showValue, needGateWay, timeout, valueIsNumber);
343
+ return fetchOptions(api, param, 'dictValue', 'displayName', showValue, needGateWay, timeout, isGet, valueIsNumber);
341
344
  }
342
345
  /**
343
346
  * 加载下拉框的数据源
@@ -348,6 +351,8 @@ export function getDict(dictCode) {
348
351
  * @param labelField 显示字段
349
352
  * @param showValue 显示值
350
353
  * @param needGateWay 是否需要网关 默认为true
354
+ * @param timeout
355
+ * @param isGet = true 是否get请求,默认true
351
356
  * @param valueIsNumber 返回值是否为数字,默认false
352
357
  * @returns
353
358
  */
@@ -359,9 +364,8 @@ function _fetchOptions() {
359
364
  var showValue,
360
365
  needGateWay,
361
366
  timeout,
367
+ isGet,
362
368
  valueIsNumber,
363
- _yield$httpGet,
364
- _yield$httpGet$rows,
365
369
  rows,
366
370
  data,
367
371
  _args2 = arguments;
@@ -371,13 +375,38 @@ function _fetchOptions() {
371
375
  showValue = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : true;
372
376
  needGateWay = _args2.length > 5 && _args2[5] !== undefined ? _args2[5] : true;
373
377
  timeout = _args2.length > 6 && _args2[6] !== undefined ? _args2[6] : 60000;
374
- valueIsNumber = _args2.length > 7 && _args2[7] !== undefined ? _args2[7] : false;
375
- _context2.next = 6;
378
+ isGet = _args2.length > 7 && _args2[7] !== undefined ? _args2[7] : true;
379
+ valueIsNumber = _args2.length > 8 && _args2[8] !== undefined ? _args2[8] : false;
380
+ if (!isGet) {
381
+ _context2.next = 14;
382
+ break;
383
+ }
384
+ _context2.next = 8;
376
385
  return httpGet(url, param, needGateWay, timeout);
377
- case 6:
378
- _yield$httpGet = _context2.sent;
379
- _yield$httpGet$rows = _yield$httpGet.rows;
380
- rows = _yield$httpGet$rows === void 0 ? [] : _yield$httpGet$rows;
386
+ case 8:
387
+ _context2.t0 = _context2.sent.rows;
388
+ if (_context2.t0) {
389
+ _context2.next = 11;
390
+ break;
391
+ }
392
+ _context2.t0 = [];
393
+ case 11:
394
+ rows = _context2.t0;
395
+ _context2.next = 20;
396
+ break;
397
+ case 14:
398
+ _context2.next = 16;
399
+ return httpPost(url, param, true, needGateWay, timeout);
400
+ case 16:
401
+ _context2.t1 = _context2.sent.rows;
402
+ if (_context2.t1) {
403
+ _context2.next = 19;
404
+ break;
405
+ }
406
+ _context2.t1 = [];
407
+ case 19:
408
+ rows = _context2.t1;
409
+ case 20:
381
410
  data = (rows || []).map(function (o) {
382
411
  return _objectSpread(_objectSpread({}, o), {}, {
383
412
  value: valueIsNumber && !isNaN(o[valueField]) ? Number(o[valueField]) : o[valueField],
@@ -386,7 +415,7 @@ function _fetchOptions() {
386
415
  });
387
416
  });
388
417
  return _context2.abrupt("return", data);
389
- case 11:
418
+ case 22:
390
419
  case "end":
391
420
  return _context2.stop();
392
421
  }
@@ -3,6 +3,7 @@ export * from './modal';
3
3
  export * from './array';
4
4
  export * from './format';
5
5
  export * from './size';
6
+ export * from './promise';
6
7
  export { getBrowserId } from 'ls-pro-tools';
7
8
  /**
8
9
  * 获取 url 参数
package/es/utils/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './modal';
6
6
  export * from './array';
7
7
  export * from './format';
8
8
  export * from './size';
9
+ export * from './promise';
9
10
  export { getBrowserId } from 'ls-pro-tools';
10
11
  /**
11
12
  * 获取 url 参数
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 执行promise,返回结果和错误数组,结果在前,错误在后
3
+ *
4
+ * @example
5
+ * const [result, error] = await execPromise(httpGet('/api'));
6
+ * if (error) {
7
+ * console.error('请求数据异常', error);
8
+ * } else {
9
+ * console.log(result);
10
+ * }
11
+ *
12
+ * @param promise
13
+ * @returns Result, Error
14
+ */
15
+ export declare function execPromise<T>(promise: Promise<T>): Promise<[T | null, Error | null]>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 执行promise,返回结果和错误数组,结果在前,错误在后
3
+ *
4
+ * @example
5
+ * const [result, error] = await execPromise(httpGet('/api'));
6
+ * if (error) {
7
+ * console.error('请求数据异常', error);
8
+ * } else {
9
+ * console.log(result);
10
+ * }
11
+ *
12
+ * @param promise
13
+ * @returns Result, Error
14
+ */
15
+ export function execPromise(promise) {
16
+ return promise.then(function (res) {
17
+ return [res, null];
18
+ }).catch(function (err) {
19
+ return [null, err];
20
+ });
21
+ }
@@ -50,10 +50,11 @@ export declare function httpDelete(url: string, data: any, needGateWay?: boolean
50
50
  * @param showValue 是否显示值
51
51
  * @param needGateWay 是否需要网关 默认为true
52
52
  * @param timeout 超时时间,默认60000毫秒
53
+ * @param isGet 是否Get请求
53
54
  * @param valueIsNumber 返回值是否为数字,默认false
54
55
  * @returns Promise<Record<string,string>[]>
55
56
  */
56
- export declare function getDict(dictCode: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, valueIsNumber?: boolean): Promise<any>;
57
+ export declare function getDict(dictCodes: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
57
58
  /**
58
59
  * 加载下拉框的数据源
59
60
  *
@@ -63,8 +64,10 @@ export declare function getDict(dictCode: string, showValue?: boolean, needGateW
63
64
  * @param labelField 显示字段
64
65
  * @param showValue 显示值
65
66
  * @param needGateWay 是否需要网关 默认为true
67
+ * @param timeout
68
+ * @param isGet = true 是否get请求,默认true
66
69
  * @param valueIsNumber 返回值是否为数字,默认false
67
70
  * @returns
68
71
  */
69
- export declare function fetchOptions(url: string, param: any, valueField: string, labelField: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, valueIsNumber?: boolean): Promise<any>;
72
+ export declare function fetchOptions(url: string, param: any, valueField: string, labelField: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
70
73
  export default request;
package/lib/http/index.js CHANGED
@@ -53,7 +53,7 @@ export var isCrossDomain = function isCrossDomain(url) {
53
53
  };
54
54
  /** 请求拦截器,统一添加token */
55
55
  request.interceptors.request.use(function (url, options) {
56
- var _options$params;
56
+ var _window$crypto$random, _window$crypto, _options$params;
57
57
  options.headers = options.headers || {};
58
58
  // 处理浏览器指纹
59
59
  if (browserId) {
@@ -92,7 +92,8 @@ request.interceptors.request.use(function (url, options) {
92
92
  url = url.replace('&noToken=1', '').replace('noToken=1', '');
93
93
  var resCode = getUrlQuery('resCode', url) || getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId');
94
94
  var param = {
95
- _t1: Date.now()
95
+ _t1: Date.now(),
96
+ __r: ((_window$crypto$random = (_window$crypto = window.crypto)['randomUUID']) === null || _window$crypto$random === void 0 ? void 0 : _window$crypto$random.call(_window$crypto)) || Math.random()
96
97
  };
97
98
  // 当没有明文参数resCode的时候,添加resCode参数为资源Id
98
99
  //@ts-ignore
@@ -325,19 +326,21 @@ export function httpDelete(url, data) {
325
326
  * @param showValue 是否显示值
326
327
  * @param needGateWay 是否需要网关 默认为true
327
328
  * @param timeout 超时时间,默认60000毫秒
329
+ * @param isGet 是否Get请求
328
330
  * @param valueIsNumber 返回值是否为数字,默认false
329
331
  * @returns Promise<Record<string,string>[]>
330
332
  */
331
- export function getDict(dictCode) {
333
+ export function getDict(dictCodes) {
332
334
  var showValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
333
335
  var needGateWay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
334
336
  var timeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 60000;
335
- var valueIsNumber = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
337
+ var isGet = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
338
+ var valueIsNumber = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
336
339
  var api = '/lesoon-petrel-integration-api/sysDictDtl/listByProperties';
337
340
  var param = {
338
- dictCode: dictCode
341
+ dictCodes: (dictCodes || '').split(',')
339
342
  };
340
- return fetchOptions(api, param, 'dictValue', 'displayName', showValue, needGateWay, timeout, valueIsNumber);
343
+ return fetchOptions(api, param, 'dictValue', 'displayName', showValue, needGateWay, timeout, isGet, valueIsNumber);
341
344
  }
342
345
  /**
343
346
  * 加载下拉框的数据源
@@ -348,6 +351,8 @@ export function getDict(dictCode) {
348
351
  * @param labelField 显示字段
349
352
  * @param showValue 显示值
350
353
  * @param needGateWay 是否需要网关 默认为true
354
+ * @param timeout
355
+ * @param isGet = true 是否get请求,默认true
351
356
  * @param valueIsNumber 返回值是否为数字,默认false
352
357
  * @returns
353
358
  */
@@ -359,9 +364,8 @@ function _fetchOptions() {
359
364
  var showValue,
360
365
  needGateWay,
361
366
  timeout,
367
+ isGet,
362
368
  valueIsNumber,
363
- _yield$httpGet,
364
- _yield$httpGet$rows,
365
369
  rows,
366
370
  data,
367
371
  _args2 = arguments;
@@ -371,13 +375,38 @@ function _fetchOptions() {
371
375
  showValue = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : true;
372
376
  needGateWay = _args2.length > 5 && _args2[5] !== undefined ? _args2[5] : true;
373
377
  timeout = _args2.length > 6 && _args2[6] !== undefined ? _args2[6] : 60000;
374
- valueIsNumber = _args2.length > 7 && _args2[7] !== undefined ? _args2[7] : false;
375
- _context2.next = 6;
378
+ isGet = _args2.length > 7 && _args2[7] !== undefined ? _args2[7] : true;
379
+ valueIsNumber = _args2.length > 8 && _args2[8] !== undefined ? _args2[8] : false;
380
+ if (!isGet) {
381
+ _context2.next = 14;
382
+ break;
383
+ }
384
+ _context2.next = 8;
376
385
  return httpGet(url, param, needGateWay, timeout);
377
- case 6:
378
- _yield$httpGet = _context2.sent;
379
- _yield$httpGet$rows = _yield$httpGet.rows;
380
- rows = _yield$httpGet$rows === void 0 ? [] : _yield$httpGet$rows;
386
+ case 8:
387
+ _context2.t0 = _context2.sent.rows;
388
+ if (_context2.t0) {
389
+ _context2.next = 11;
390
+ break;
391
+ }
392
+ _context2.t0 = [];
393
+ case 11:
394
+ rows = _context2.t0;
395
+ _context2.next = 20;
396
+ break;
397
+ case 14:
398
+ _context2.next = 16;
399
+ return httpPost(url, param, true, needGateWay, timeout);
400
+ case 16:
401
+ _context2.t1 = _context2.sent.rows;
402
+ if (_context2.t1) {
403
+ _context2.next = 19;
404
+ break;
405
+ }
406
+ _context2.t1 = [];
407
+ case 19:
408
+ rows = _context2.t1;
409
+ case 20:
381
410
  data = (rows || []).map(function (o) {
382
411
  return _objectSpread(_objectSpread({}, o), {}, {
383
412
  value: valueIsNumber && !isNaN(o[valueField]) ? Number(o[valueField]) : o[valueField],
@@ -386,7 +415,7 @@ function _fetchOptions() {
386
415
  });
387
416
  });
388
417
  return _context2.abrupt("return", data);
389
- case 11:
418
+ case 22:
390
419
  case "end":
391
420
  return _context2.stop();
392
421
  }
@@ -3,6 +3,7 @@ export * from './modal';
3
3
  export * from './array';
4
4
  export * from './format';
5
5
  export * from './size';
6
+ export * from './promise';
6
7
  export { getBrowserId } from 'ls-pro-tools';
7
8
  /**
8
9
  * 获取 url 参数
@@ -6,6 +6,7 @@ export * from './modal';
6
6
  export * from './array';
7
7
  export * from './format';
8
8
  export * from './size';
9
+ export * from './promise';
9
10
  export { getBrowserId } from 'ls-pro-tools';
10
11
  /**
11
12
  * 获取 url 参数
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 执行promise,返回结果和错误数组,结果在前,错误在后
3
+ *
4
+ * @example
5
+ * const [result, error] = await execPromise(httpGet('/api'));
6
+ * if (error) {
7
+ * console.error('请求数据异常', error);
8
+ * } else {
9
+ * console.log(result);
10
+ * }
11
+ *
12
+ * @param promise
13
+ * @returns Result, Error
14
+ */
15
+ export declare function execPromise<T>(promise: Promise<T>): Promise<[T | null, Error | null]>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 执行promise,返回结果和错误数组,结果在前,错误在后
3
+ *
4
+ * @example
5
+ * const [result, error] = await execPromise(httpGet('/api'));
6
+ * if (error) {
7
+ * console.error('请求数据异常', error);
8
+ * } else {
9
+ * console.log(result);
10
+ * }
11
+ *
12
+ * @param promise
13
+ * @returns Result, Error
14
+ */
15
+ export function execPromise(promise) {
16
+ return promise.then(function (res) {
17
+ return [res, null];
18
+ }).catch(function (err) {
19
+ return [null, err];
20
+ });
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-pro-common",
3
- "version": "3.1.7",
3
+ "version": "3.1.9",
4
4
  "description": "ls-pro-common",
5
5
  "license": "MIT",
6
6
  "sideEffects": [