@freelog/tools-lib 0.1.89 → 0.1.91

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.
@@ -1319,252 +1319,6 @@ var Predefined = {
1319
1319
  get EnumContractStatus () { return EnumContractStatus; }
1320
1320
  };
1321
1321
 
1322
- var codeMessage = {
1323
- 200: '服务器成功返回请求的数据。',
1324
- 201: '新建或修改数据成功。',
1325
- 202: '一个请求已经进入后台排队(异步任务)。',
1326
- 204: '删除数据成功。',
1327
- 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
1328
- 401: '用户没有权限(令牌、用户名、密码错误)。',
1329
- 403: '用户得到授权,但是访问是被禁止的。',
1330
- 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
1331
- 406: '请求的格式不可得。',
1332
- 410: '请求的资源被永久删除,且不会再得到的。',
1333
- 422: '当创建一个对象时,发生一个验证错误。',
1334
- 500: '服务器发生错误,请检查服务器。',
1335
- 502: '网关错误。',
1336
- 503: '服务不可用,服务器暂时过载或维护。',
1337
- 504: '网关超时。'
1338
- }; // export let apiHost: string = '';
1339
-
1340
- if (window.location.hostname.includes('.com')) {
1341
- // apiHost = `${window.location.protocol}//qi.${(window.location.host.match(/(?<=\.).*/) || [''])[0]}`;
1342
- // apiHost = window.location.origin.replace('console', 'qi');
1343
- axios.defaults.withCredentials = true;
1344
- axios.defaults.baseURL = /*#__PURE__*/completeUrlByDomain('qi');
1345
- }
1346
- /**
1347
- * 异常处理程序
1348
- */
1349
- // const errorHandler = (error: { response: Response }): Response => {
1350
- // const {response} = error;
1351
- // if (response && response.status) {
1352
- // const errorText = codeMessage[response.status] || response.statusText;
1353
- // const {status, url} = response;
1354
- //
1355
- // // notification.error({
1356
- // // message: `请求错误 ${status}: ${url}`,
1357
- // // description: errorText,
1358
- // // });
1359
- // } else if (!response) {
1360
- // // notification.error({
1361
- // // description: '您的网络发生异常,无法连接服务器',
1362
- // // message: '网络异常',
1363
- // // });
1364
- // }
1365
- // return response;
1366
- // };
1367
- //
1368
- // // Add a request interceptor
1369
-
1370
-
1371
- axios.interceptors.request.use(function (config) {
1372
- // Do something before request is sent
1373
- NProgress.start();
1374
- return config;
1375
- }, function (error) {
1376
- // Do something with request error
1377
- NProgress.done();
1378
- return Promise.reject(error);
1379
- });
1380
- /**
1381
- * 配置request请求时的默认参数
1382
- */
1383
-
1384
- axios.interceptors.response.use(function (response) {
1385
- var _headers$contentDisp;
1386
-
1387
- // Do something with response data
1388
- // console.log(response, 'response!!!!!!');
1389
- NProgress.done();
1390
-
1391
- if (response.status !== 200) {
1392
- var error = {
1393
- description: codeMessage[response.status],
1394
- message: response.status
1395
- }; // notification.error(error);
1396
-
1397
- throw new Error(JSON.stringify(error));
1398
- }
1399
-
1400
- var data = response.data,
1401
- headers = response.headers;
1402
-
1403
- if ((_headers$contentDisp = headers['content-disposition']) != null && _headers$contentDisp.includes('attachment;')) {
1404
- // downloadFile(response);
1405
- return;
1406
- } // console.log(data, 'data2390jasdflkf');
1407
- // if ((data.errcode === undefined
1408
- // ? (data.errCode !== 0 && data.errCode !== 2)
1409
- // : (data.errcode !== 0 && data.errcode !== 2))
1410
- // || data.ret !== 0) {
1411
- //
1412
- // // notification.error({
1413
- // // message: data.msg,
1414
- // // });
1415
- // throw new Error(JSON.stringify(data));
1416
- // }
1417
-
1418
-
1419
- return data;
1420
- }, function (error) {
1421
- // Do something with response error
1422
- NProgress.done();
1423
- return Promise.reject(error);
1424
- });
1425
- function request(_x, _x2) {
1426
- return _request.apply(this, arguments);
1427
- } // export function downloadFile(res: AxiosResponse) {
1428
- // const {data, headers} = res;
1429
- // // const fileName = headers['content-disposition'].replace(/attachment; filename="(.*)"/, '$1');
1430
- // const fileName = headers['content-disposition'].replace(/attachment; filename="(.*)"/, '$1');
1431
- // const blob = new Blob([data], {});
1432
- // FileSaver.saveAs(blob, fileName);
1433
- // }
1434
-
1435
- function _request() {
1436
- _request = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(config, _temp) {
1437
- var _ref, _ref$noRedirect, noRedirect, _ref$noErrorAlert, noErrorAlert, result;
1438
-
1439
- return runtime_1.wrap(function _callee$(_context) {
1440
- while (1) {
1441
- switch (_context.prev = _context.next) {
1442
- case 0:
1443
- _ref = _temp === void 0 ? {} : _temp, _ref$noRedirect = _ref.noRedirect, noRedirect = _ref$noRedirect === void 0 ? false : _ref$noRedirect, _ref$noErrorAlert = _ref.noErrorAlert, noErrorAlert = _ref$noErrorAlert === void 0 ? false : _ref$noErrorAlert;
1444
- _context.next = 3;
1445
- return axios.request(config);
1446
-
1447
- case 3:
1448
- result = _context.sent;
1449
-
1450
- if (!((result.errCode === 30 || result.errCode === 30) && !noRedirect)) {
1451
- _context.next = 6;
1452
- break;
1453
- }
1454
-
1455
- return _context.abrupt("return", window.location.replace("" + completeUrlByDomain('user') + login({
1456
- goTo: window.location.href
1457
- })));
1458
-
1459
- case 6:
1460
-
1461
- return _context.abrupt("return", result);
1462
-
1463
- case 8:
1464
- case "end":
1465
- return _context.stop();
1466
- }
1467
- }
1468
- }, _callee);
1469
- }));
1470
- return _request.apply(this, arguments);
1471
- }
1472
-
1473
- /**
1474
- * 根据 File 获取 SHA1 Hash 字符串
1475
- * @param file
1476
- * @return {Promise<string>}
1477
- */
1478
-
1479
- function getSHA1Hash(file) {
1480
- return new Promise(function (resolve) {
1481
- var reader = new FileReader();
1482
-
1483
- reader.onload = function () {
1484
- var wordArray = lib.WordArray.create(reader.result);
1485
- var hash = SHA1(wordArray).toString();
1486
- resolve(hash);
1487
- };
1488
-
1489
- reader.readAsArrayBuffer(file);
1490
- });
1491
- }
1492
- /**
1493
- * 生成随机码
1494
- */
1495
-
1496
- function generateRandomCode(strLen) {
1497
- if (strLen === void 0) {
1498
- strLen = 5;
1499
- }
1500
-
1501
- var allStr = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
1502
- var newStrArr = [];
1503
-
1504
- for (var i = 0; i < strLen; i++) {
1505
- newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
1506
- }
1507
-
1508
- return newStrArr.join('');
1509
- }
1510
- /**
1511
- * 通过读取 cookies 获取用户 ID
1512
- */
1513
-
1514
- function getUserIDByCookies() {
1515
- var uid = document.cookie.split('; ').find(function (co) {
1516
- return co.startsWith('uid=');
1517
- });
1518
-
1519
- if (!uid) {
1520
- return -1;
1521
- }
1522
-
1523
- return Number(uid.replace('uid=', ''));
1524
- }
1525
- function transformServerAPIContractState(_ref) {
1526
- var status = _ref.status,
1527
- authStatus = _ref.authStatus;
1528
-
1529
- if (status === 0) {
1530
- if (authStatus === 1 || authStatus === 3) {
1531
- return 'active';
1532
- }
1533
-
1534
- if (authStatus === 2) {
1535
- return 'testActive';
1536
- }
1537
-
1538
- if (authStatus === 128) {
1539
- return 'inactive';
1540
- }
1541
- }
1542
-
1543
- if (status === 1) {
1544
- return 'terminal';
1545
- }
1546
-
1547
- return 'exception';
1548
- }
1549
-
1550
- var Tool = {
1551
- __proto__: null,
1552
- getSHA1Hash: getSHA1Hash,
1553
- generateRandomCode: generateRandomCode,
1554
- getUserIDByCookies: getUserIDByCookies,
1555
- transformServerAPIContractState: transformServerAPIContractState
1556
- };
1557
-
1558
- var FUtil = {
1559
- Format: Format,
1560
- Regexp: Regexp,
1561
- LinkTo: LinkTo,
1562
- Predefined: Predefined,
1563
- Axios: axios,
1564
- Request: request,
1565
- Tool: Tool
1566
- };
1567
-
1568
1322
  function create(params) {
1569
1323
  // return FUtil.Axios.post('/v2/nodes', params);
1570
1324
  return FUtil.Request({
@@ -2859,5 +2613,255 @@ var FServiceAPI = {
2859
2613
  Activity: Activity
2860
2614
  };
2861
2615
 
2616
+ var codeMessage = {
2617
+ 200: '服务器成功返回请求的数据。',
2618
+ 201: '新建或修改数据成功。',
2619
+ 202: '一个请求已经进入后台排队(异步任务)。',
2620
+ 204: '删除数据成功。',
2621
+ 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
2622
+ 401: '用户没有权限(令牌、用户名、密码错误)。',
2623
+ 403: '用户得到授权,但是访问是被禁止的。',
2624
+ 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
2625
+ 406: '请求的格式不可得。',
2626
+ 410: '请求的资源被永久删除,且不会再得到的。',
2627
+ 422: '当创建一个对象时,发生一个验证错误。',
2628
+ 500: '服务器发生错误,请检查服务器。',
2629
+ 502: '网关错误。',
2630
+ 503: '服务不可用,服务器暂时过载或维护。',
2631
+ 504: '网关超时。'
2632
+ }; // export let apiHost: string = '';
2633
+
2634
+ if (window.location.hostname.includes('.com')) {
2635
+ // apiHost = `${window.location.protocol}//qi.${(window.location.host.match(/(?<=\.).*/) || [''])[0]}`;
2636
+ // apiHost = window.location.origin.replace('console', 'qi');
2637
+ axios.defaults.withCredentials = true;
2638
+ axios.defaults.baseURL = /*#__PURE__*/completeUrlByDomain('qi');
2639
+ }
2640
+ /**
2641
+ * 异常处理程序
2642
+ */
2643
+ // const errorHandler = (error: { response: Response }): Response => {
2644
+ // const {response} = error;
2645
+ // if (response && response.status) {
2646
+ // const errorText = codeMessage[response.status] || response.statusText;
2647
+ // const {status, url} = response;
2648
+ //
2649
+ // // notification.error({
2650
+ // // message: `请求错误 ${status}: ${url}`,
2651
+ // // description: errorText,
2652
+ // // });
2653
+ // } else if (!response) {
2654
+ // // notification.error({
2655
+ // // description: '您的网络发生异常,无法连接服务器',
2656
+ // // message: '网络异常',
2657
+ // // });
2658
+ // }
2659
+ // return response;
2660
+ // };
2661
+ //
2662
+ // // Add a request interceptor
2663
+
2664
+
2665
+ axios.interceptors.request.use(function (config) {
2666
+ // Do something before request is sent
2667
+ NProgress.start();
2668
+ return config;
2669
+ }, function (error) {
2670
+ // Do something with request error
2671
+ NProgress.done();
2672
+ return Promise.reject(error);
2673
+ });
2674
+ /**
2675
+ * 配置request请求时的默认参数
2676
+ */
2677
+
2678
+ axios.interceptors.response.use(function (response) {
2679
+ var _headers$contentDisp;
2680
+
2681
+ // Do something with response data
2682
+ // console.log(response, 'response!!!!!!');
2683
+ NProgress.done();
2684
+
2685
+ if (response.status !== 200) {
2686
+ var error = {
2687
+ description: codeMessage[response.status],
2688
+ message: response.status
2689
+ }; // notification.error(error);
2690
+
2691
+ throw new Error(JSON.stringify(error));
2692
+ }
2693
+
2694
+ var data = response.data,
2695
+ headers = response.headers;
2696
+
2697
+ if ((_headers$contentDisp = headers['content-disposition']) != null && _headers$contentDisp.includes('attachment;')) {
2698
+ // downloadFile(response);
2699
+ return;
2700
+ } // console.log(data, 'data2390jasdflkf');
2701
+ // if ((data.errcode === undefined
2702
+ // ? (data.errCode !== 0 && data.errCode !== 2)
2703
+ // : (data.errcode !== 0 && data.errcode !== 2))
2704
+ // || data.ret !== 0) {
2705
+ //
2706
+ // // notification.error({
2707
+ // // message: data.msg,
2708
+ // // });
2709
+ // throw new Error(JSON.stringify(data));
2710
+ // }
2711
+
2712
+
2713
+ return data;
2714
+ }, function (error) {
2715
+ // Do something with response error
2716
+ NProgress.done();
2717
+ return Promise.reject(error);
2718
+ });
2719
+ function request(_x, _x2) {
2720
+ return _request.apply(this, arguments);
2721
+ } // export function downloadFile(res: AxiosResponse) {
2722
+ // const {data, headers} = res;
2723
+ // // const fileName = headers['content-disposition'].replace(/attachment; filename="(.*)"/, '$1');
2724
+ // const fileName = headers['content-disposition'].replace(/attachment; filename="(.*)"/, '$1');
2725
+ // const blob = new Blob([data], {});
2726
+ // FileSaver.saveAs(blob, fileName);
2727
+ // }
2728
+
2729
+ function _request() {
2730
+ _request = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(config, _temp) {
2731
+ var _ref, _ref$noRedirect, noRedirect, _ref$noErrorAlert, noErrorAlert, result;
2732
+
2733
+ return runtime_1.wrap(function _callee$(_context) {
2734
+ while (1) {
2735
+ switch (_context.prev = _context.next) {
2736
+ case 0:
2737
+ _ref = _temp === void 0 ? {} : _temp, _ref$noRedirect = _ref.noRedirect, noRedirect = _ref$noRedirect === void 0 ? false : _ref$noRedirect, _ref$noErrorAlert = _ref.noErrorAlert, noErrorAlert = _ref$noErrorAlert === void 0 ? false : _ref$noErrorAlert;
2738
+ _context.next = 3;
2739
+ return axios.request(config);
2740
+
2741
+ case 3:
2742
+ result = _context.sent;
2743
+
2744
+ if (!((result.errCode === 30 || result.errCode === 30) && !noRedirect)) {
2745
+ _context.next = 8;
2746
+ break;
2747
+ }
2748
+
2749
+ _context.next = 7;
2750
+ return FServiceAPI.User.logout();
2751
+
2752
+ case 7:
2753
+ window.location.replace("" + completeUrlByDomain('user') + login({
2754
+ goTo: window.location.href
2755
+ }));
2756
+
2757
+ case 8:
2758
+
2759
+ return _context.abrupt("return", result);
2760
+
2761
+ case 10:
2762
+ case "end":
2763
+ return _context.stop();
2764
+ }
2765
+ }
2766
+ }, _callee);
2767
+ }));
2768
+ return _request.apply(this, arguments);
2769
+ }
2770
+
2771
+ /**
2772
+ * 根据 File 获取 SHA1 Hash 字符串
2773
+ * @param file
2774
+ * @return {Promise<string>}
2775
+ */
2776
+
2777
+ function getSHA1Hash(file) {
2778
+ return new Promise(function (resolve) {
2779
+ var reader = new FileReader();
2780
+
2781
+ reader.onload = function () {
2782
+ var wordArray = lib.WordArray.create(reader.result);
2783
+ var hash = SHA1(wordArray).toString();
2784
+ resolve(hash);
2785
+ };
2786
+
2787
+ reader.readAsArrayBuffer(file);
2788
+ });
2789
+ }
2790
+ /**
2791
+ * 生成随机码
2792
+ */
2793
+
2794
+ function generateRandomCode(strLen) {
2795
+ if (strLen === void 0) {
2796
+ strLen = 5;
2797
+ }
2798
+
2799
+ var allStr = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
2800
+ var newStrArr = [];
2801
+
2802
+ for (var i = 0; i < strLen; i++) {
2803
+ newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
2804
+ }
2805
+
2806
+ return newStrArr.join('');
2807
+ }
2808
+ /**
2809
+ * 通过读取 cookies 获取用户 ID
2810
+ */
2811
+
2812
+ function getUserIDByCookies() {
2813
+ var uid = document.cookie.split('; ').find(function (co) {
2814
+ return co.startsWith('uid=');
2815
+ });
2816
+
2817
+ if (!uid) {
2818
+ return -1;
2819
+ }
2820
+
2821
+ return Number(uid.replace('uid=', ''));
2822
+ }
2823
+ function transformServerAPIContractState(_ref) {
2824
+ var status = _ref.status,
2825
+ authStatus = _ref.authStatus;
2826
+
2827
+ if (status === 0) {
2828
+ if (authStatus === 1 || authStatus === 3) {
2829
+ return 'active';
2830
+ }
2831
+
2832
+ if (authStatus === 2) {
2833
+ return 'testActive';
2834
+ }
2835
+
2836
+ if (authStatus === 128) {
2837
+ return 'inactive';
2838
+ }
2839
+ }
2840
+
2841
+ if (status === 1) {
2842
+ return 'terminal';
2843
+ }
2844
+
2845
+ return 'exception';
2846
+ }
2847
+
2848
+ var Tool = {
2849
+ __proto__: null,
2850
+ getSHA1Hash: getSHA1Hash,
2851
+ generateRandomCode: generateRandomCode,
2852
+ getUserIDByCookies: getUserIDByCookies,
2853
+ transformServerAPIContractState: transformServerAPIContractState
2854
+ };
2855
+
2856
+ var FUtil = {
2857
+ Format: Format,
2858
+ Regexp: Regexp,
2859
+ LinkTo: LinkTo,
2860
+ Predefined: Predefined,
2861
+ Axios: axios,
2862
+ Request: request,
2863
+ Tool: Tool
2864
+ };
2865
+
2862
2866
  export { FServiceAPI, FUtil };
2863
2867
  //# sourceMappingURL=tools-lib.esm.js.map