@freelog/tools-lib 0.1.87 → 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.
Files changed (36) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +103 -103
  3. package/dist/service-API/informalNodes.d.ts +15 -45
  4. package/dist/service-API/policies.d.ts +2 -6
  5. package/dist/tools-lib.cjs.development.js +342 -330
  6. package/dist/tools-lib.cjs.development.js.map +1 -1
  7. package/dist/tools-lib.cjs.production.min.js +1 -1
  8. package/dist/tools-lib.cjs.production.min.js.map +1 -1
  9. package/dist/tools-lib.esm.js +342 -330
  10. package/dist/tools-lib.esm.js.map +1 -1
  11. package/dist/utils/axios.d.ts +1 -4
  12. package/dist/utils/linkTo.d.ts +3 -0
  13. package/package.json +1 -1
  14. package/src/index.ts +7 -7
  15. package/src/service-API/activities.ts +28 -28
  16. package/src/service-API/captcha.ts +30 -30
  17. package/src/service-API/collections.ts +81 -81
  18. package/src/service-API/contracts.ts +84 -84
  19. package/src/service-API/events.ts +18 -18
  20. package/src/service-API/index.ts +29 -29
  21. package/src/service-API/informalNodes.ts +238 -238
  22. package/src/service-API/nodes.ts +65 -65
  23. package/src/service-API/policies.ts +39 -39
  24. package/src/service-API/presentables.ts +282 -282
  25. package/src/service-API/resources.ts +496 -496
  26. package/src/service-API/storages.ts +345 -345
  27. package/src/service-API/tools/index.ts +10 -10
  28. package/src/service-API/transactions.ts +109 -109
  29. package/src/service-API/user.ts +188 -188
  30. package/src/utils/axios.ts +8 -3
  31. package/src/utils/format.ts +89 -89
  32. package/src/utils/index.ts +18 -18
  33. package/src/utils/linkTo.ts +332 -324
  34. package/src/utils/predefined.ts +37 -37
  35. package/src/utils/regexp.ts +52 -52
  36. package/src/utils/tools.ts +72 -72
@@ -1042,106 +1042,113 @@ function market(_temp4) {
1042
1042
 
1043
1043
  return "/market";
1044
1044
  }
1045
- function resourceDetails(_ref6) {
1046
- var resourceID = _ref6.resourceID,
1047
- params = _objectWithoutPropertiesLoose(_ref6, _excluded);
1045
+ function exampleNodes(_temp5) {
1046
+ var _ref6 = _temp5 === void 0 ? {} : _temp5;
1048
1047
 
1049
- return "/resource/details/" + resourceID + handleQuery(params);
1050
- }
1051
- function resourceCreator(_temp5) {
1052
- var _ref7 = _temp5 === void 0 ? {} : _temp5;
1048
+ _objectDestructuringEmpty(_ref6);
1053
1049
 
1054
- _objectDestructuringEmpty(_ref7);
1050
+ return "/examples";
1051
+ }
1052
+ function resourceDetails(_ref7) {
1053
+ var resourceID = _ref7.resourceID,
1054
+ params = _objectWithoutPropertiesLoose(_ref7, _excluded);
1055
1055
 
1056
- return "/resource/creator";
1056
+ return "/resource/details/" + resourceID + handleQuery(params);
1057
1057
  }
1058
- function myResources(_temp6) {
1058
+ function resourceCreator(_temp6) {
1059
1059
  var _ref8 = _temp6 === void 0 ? {} : _temp6;
1060
1060
 
1061
1061
  _objectDestructuringEmpty(_ref8);
1062
1062
 
1063
- return "/resource/list";
1063
+ return "/resource/creator";
1064
1064
  }
1065
- function myCollects(_temp7) {
1065
+ function myResources(_temp7) {
1066
1066
  var _ref9 = _temp7 === void 0 ? {} : _temp7;
1067
1067
 
1068
1068
  _objectDestructuringEmpty(_ref9);
1069
1069
 
1070
+ return "/resource/list";
1071
+ }
1072
+ function myCollects(_temp8) {
1073
+ var _ref10 = _temp8 === void 0 ? {} : _temp8;
1074
+
1075
+ _objectDestructuringEmpty(_ref10);
1076
+
1070
1077
  return "/resource/collect";
1071
1078
  }
1072
- function resourceInfo(_ref10) {
1073
- var resourceID = _ref10.resourceID;
1079
+ function resourceInfo(_ref11) {
1080
+ var resourceID = _ref11.resourceID;
1074
1081
  return "/resource/info/" + resourceID;
1075
1082
  }
1076
- function resourceAuth(_ref11) {
1077
- var resourceID = _ref11.resourceID;
1083
+ function resourceAuth(_ref12) {
1084
+ var resourceID = _ref12.resourceID;
1078
1085
  return "/resource/auth/" + resourceID;
1079
1086
  }
1080
- function resourceCreateVersion(_ref12) {
1081
- var resourceID = _ref12.resourceID;
1087
+ function resourceCreateVersion(_ref13) {
1088
+ var resourceID = _ref13.resourceID;
1082
1089
  return "/resource/version/creator/" + resourceID;
1083
1090
  }
1084
- function resourceVersion(_ref13) {
1085
- var resourceID = _ref13.resourceID,
1086
- version = _ref13.version;
1091
+ function resourceVersion(_ref14) {
1092
+ var resourceID = _ref14.resourceID,
1093
+ version = _ref14.version;
1087
1094
  return "/resource/version/info/" + resourceID + "/" + version;
1088
1095
  }
1089
- function nodeCreator(_temp8) {
1090
- var _ref14 = _temp8 === void 0 ? {} : _temp8;
1096
+ function nodeCreator(_temp9) {
1097
+ var _ref15 = _temp9 === void 0 ? {} : _temp9;
1091
1098
 
1092
- _objectDestructuringEmpty(_ref14);
1099
+ _objectDestructuringEmpty(_ref15);
1093
1100
 
1094
1101
  return "/node/creator";
1095
1102
  }
1096
- function nodeManagement(_ref15) {
1097
- var nodeID = _ref15.nodeID;
1103
+ function nodeManagement(_ref16) {
1104
+ var nodeID = _ref16.nodeID;
1098
1105
  return "/node/formal/" + nodeID;
1099
1106
  }
1100
- function exhibitManagement(_ref16) {
1101
- var exhibitID = _ref16.exhibitID;
1107
+ function exhibitManagement(_ref17) {
1108
+ var exhibitID = _ref17.exhibitID;
1102
1109
  return "/node/exhibit/formal/" + exhibitID;
1103
1110
  }
1104
- function informNodeManagement(_ref17) {
1105
- var nodeID = _ref17.nodeID,
1106
- _ref17$showPage = _ref17.showPage,
1107
- showPage = _ref17$showPage === void 0 ? 'exhibit' : _ref17$showPage,
1108
- params = _objectWithoutPropertiesLoose(_ref17, _excluded2);
1111
+ function informNodeManagement(_ref18) {
1112
+ var nodeID = _ref18.nodeID,
1113
+ _ref18$showPage = _ref18.showPage,
1114
+ showPage = _ref18$showPage === void 0 ? 'exhibit' : _ref18$showPage,
1115
+ params = _objectWithoutPropertiesLoose(_ref18, _excluded2);
1109
1116
 
1110
1117
  return "/node/informal/" + nodeID + handleQuery(_extends({
1111
1118
  showPage: showPage
1112
1119
  }, params));
1113
1120
  }
1114
- function informExhibitManagement(_ref18) {
1115
- var exhibitID = _ref18.exhibitID;
1121
+ function informExhibitManagement(_ref19) {
1122
+ var exhibitID = _ref19.exhibitID;
1116
1123
  return "/node/exhibit/informal/" + exhibitID;
1117
1124
  }
1118
- function storageSpace(_temp9) {
1119
- var _ref19 = _temp9 === void 0 ? {} : _temp9,
1120
- params = _extends({}, _ref19);
1125
+ function storageSpace(_temp10) {
1126
+ var _ref20 = _temp10 === void 0 ? {} : _temp10,
1127
+ params = _extends({}, _ref20);
1121
1128
 
1122
1129
  return "/storage" + handleQuery(params);
1123
1130
  }
1124
- function objectDetails(_ref20) {
1125
- var params = _extends({}, _ref20);
1131
+ function objectDetails(_ref21) {
1132
+ var params = _extends({}, _ref21);
1126
1133
 
1127
1134
  return "/storage" + handleQuery(params);
1128
1135
  }
1129
- function resourceCreateSuccess(_ref21) {
1130
- var resourceID = _ref21.resourceID;
1136
+ function resourceCreateSuccess(_ref22) {
1137
+ var resourceID = _ref22.resourceID;
1131
1138
  return "/result/resource/create/success/" + resourceID;
1132
1139
  }
1133
- function resourceVersionCreateSuccess(_ref22) {
1134
- var resourceID = _ref22.resourceID,
1135
- version = _ref22.version;
1140
+ function resourceVersionCreateSuccess(_ref23) {
1141
+ var resourceID = _ref23.resourceID,
1142
+ version = _ref23.version;
1136
1143
  return "/result/resource/version/create/success/" + resourceID + "/" + version;
1137
1144
  }
1138
- function nodeCreateSuccess(_ref23) {
1139
- var nodeID = _ref23.nodeID;
1145
+ function nodeCreateSuccess(_ref24) {
1146
+ var nodeID = _ref24.nodeID;
1140
1147
  return "/result/node/create/success/" + nodeID;
1141
1148
  }
1142
- function exception403(_temp10) {
1143
- var _ref24 = _temp10 === void 0 ? {} : _temp10,
1144
- params = _extends({}, _ref24);
1149
+ function exception403(_temp11) {
1150
+ var _ref25 = _temp11 === void 0 ? {} : _temp11,
1151
+ params = _extends({}, _ref25);
1145
1152
 
1146
1153
  var fromUrl = params.from || '';
1147
1154
 
@@ -1156,56 +1163,56 @@ function exception403(_temp10) {
1156
1163
  from: fromUrl
1157
1164
  });
1158
1165
  }
1159
- function login(_temp11) {
1160
- var _ref25 = _temp11 === void 0 ? {} : _temp11,
1161
- goTo = _ref25.goTo;
1166
+ function login(_temp12) {
1167
+ var _ref26 = _temp12 === void 0 ? {} : _temp12,
1168
+ goTo = _ref26.goTo;
1162
1169
 
1163
1170
  return "/login" + handleQuery({
1164
1171
  goTo: goTo ? encodeURIComponent(goTo) : undefined
1165
1172
  });
1166
1173
  }
1167
- function logon(_temp12) {
1168
- var _ref26 = _temp12 === void 0 ? {} : _temp12,
1169
- goTo = _ref26.goTo;
1174
+ function logon(_temp13) {
1175
+ var _ref27 = _temp13 === void 0 ? {} : _temp13,
1176
+ goTo = _ref27.goTo;
1170
1177
 
1171
1178
  return "/logon" + handleQuery({
1172
1179
  goTo: goTo ? encodeURIComponent(goTo) : undefined
1173
1180
  });
1174
1181
  }
1175
- function retrieveUserPassword(_temp13) {
1176
- var _ref27 = _temp13 === void 0 ? {} : _temp13,
1177
- goTo = _ref27.goTo;
1182
+ function retrieveUserPassword(_temp14) {
1183
+ var _ref28 = _temp14 === void 0 ? {} : _temp14,
1184
+ goTo = _ref28.goTo;
1178
1185
 
1179
1186
  return "/retrieve" + handleQuery({
1180
1187
  goTo: goTo ? encodeURIComponent(goTo) : undefined
1181
1188
  });
1182
1189
  }
1183
- function retrievePayPassword(_temp14) {
1184
- var _ref28 = _temp14 === void 0 ? {} : _temp14;
1185
-
1186
- _objectDestructuringEmpty(_ref28);
1187
-
1188
- return "/retrievePayPassword";
1189
- }
1190
- function wallet(_temp15) {
1190
+ function retrievePayPassword(_temp15) {
1191
1191
  var _ref29 = _temp15 === void 0 ? {} : _temp15;
1192
1192
 
1193
1193
  _objectDestructuringEmpty(_ref29);
1194
1194
 
1195
- return "/logged/wallet";
1195
+ return "/retrievePayPassword";
1196
1196
  }
1197
- function contract(_temp16) {
1197
+ function wallet(_temp16) {
1198
1198
  var _ref30 = _temp16 === void 0 ? {} : _temp16;
1199
1199
 
1200
1200
  _objectDestructuringEmpty(_ref30);
1201
1201
 
1202
- return "/logged/contract";
1202
+ return "/logged/wallet";
1203
1203
  }
1204
- function setting(_temp17) {
1204
+ function contract(_temp17) {
1205
1205
  var _ref31 = _temp17 === void 0 ? {} : _temp17;
1206
1206
 
1207
1207
  _objectDestructuringEmpty(_ref31);
1208
1208
 
1209
+ return "/logged/contract";
1210
+ }
1211
+ function setting(_temp18) {
1212
+ var _ref32 = _temp18 === void 0 ? {} : _temp18;
1213
+
1214
+ _objectDestructuringEmpty(_ref32);
1215
+
1209
1216
  return "/logged/setting";
1210
1217
  }
1211
1218
  /************** user End ******************************************************/
@@ -1234,6 +1241,7 @@ var LinkTo = {
1234
1241
  activity: activity,
1235
1242
  dashboard: dashboard,
1236
1243
  market: market,
1244
+ exampleNodes: exampleNodes,
1237
1245
  resourceDetails: resourceDetails,
1238
1246
  resourceCreator: resourceCreator,
1239
1247
  myResources: myResources,
@@ -1296,265 +1304,19 @@ var EnumContractStatus;
1296
1304
  EnumContractStatus[EnumContractStatus["authorized"] = 1] = "authorized";
1297
1305
  EnumContractStatus[EnumContractStatus["stopped"] = 2] = "stopped";
1298
1306
  })(EnumContractStatus || (EnumContractStatus = {})); // 合约授权状态定义
1299
- // export enum ContractAuthStatus {
1300
- //
1301
- // }
1302
-
1303
- var Predefined = {
1304
- __proto__: null,
1305
- resourceTypes: resourceTypes,
1306
- pageSize: pageSize,
1307
- momentDateFormat: momentDateFormat,
1308
- momentDateTimeFormat: momentDateTimeFormat,
1309
- get EnumContractPartyIdentityType () { return EnumContractPartyIdentityType; },
1310
- get EnumSubjectType () { return EnumSubjectType; },
1311
- get EnumContractStatus () { return EnumContractStatus; }
1312
- };
1313
-
1314
- var codeMessage = {
1315
- 200: '服务器成功返回请求的数据。',
1316
- 201: '新建或修改数据成功。',
1317
- 202: '一个请求已经进入后台排队(异步任务)。',
1318
- 204: '删除数据成功。',
1319
- 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
1320
- 401: '用户没有权限(令牌、用户名、密码错误)。',
1321
- 403: '用户得到授权,但是访问是被禁止的。',
1322
- 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
1323
- 406: '请求的格式不可得。',
1324
- 410: '请求的资源被永久删除,且不会再得到的。',
1325
- 422: '当创建一个对象时,发生一个验证错误。',
1326
- 500: '服务器发生错误,请检查服务器。',
1327
- 502: '网关错误。',
1328
- 503: '服务不可用,服务器暂时过载或维护。',
1329
- 504: '网关超时。'
1330
- }; // export let apiHost: string = '';
1331
-
1332
- if (window.location.hostname.includes('.com')) {
1333
- // apiHost = `${window.location.protocol}//qi.${(window.location.host.match(/(?<=\.).*/) || [''])[0]}`;
1334
- // apiHost = window.location.origin.replace('console', 'qi');
1335
- axios.defaults.withCredentials = true;
1336
- axios.defaults.baseURL = /*#__PURE__*/completeUrlByDomain('qi');
1337
- }
1338
- /**
1339
- * 异常处理程序
1340
- */
1341
- // const errorHandler = (error: { response: Response }): Response => {
1342
- // const {response} = error;
1343
- // if (response && response.status) {
1344
- // const errorText = codeMessage[response.status] || response.statusText;
1345
- // const {status, url} = response;
1346
- //
1347
- // // notification.error({
1348
- // // message: `请求错误 ${status}: ${url}`,
1349
- // // description: errorText,
1350
- // // });
1351
- // } else if (!response) {
1352
- // // notification.error({
1353
- // // description: '您的网络发生异常,无法连接服务器',
1354
- // // message: '网络异常',
1355
- // // });
1356
- // }
1357
- // return response;
1358
- // };
1359
- //
1360
- // // Add a request interceptor
1361
-
1362
-
1363
- axios.interceptors.request.use(function (config) {
1364
- // Do something before request is sent
1365
- NProgress.start();
1366
- return config;
1367
- }, function (error) {
1368
- // Do something with request error
1369
- NProgress.done();
1370
- return Promise.reject(error);
1371
- });
1372
- /**
1373
- * 配置request请求时的默认参数
1374
- */
1375
-
1376
- axios.interceptors.response.use(function (response) {
1377
- var _headers$contentDisp;
1378
-
1379
- // Do something with response data
1380
- // console.log(response, 'response!!!!!!');
1381
- NProgress.done();
1382
-
1383
- if (response.status !== 200) {
1384
- var error = {
1385
- description: codeMessage[response.status],
1386
- message: response.status
1387
- }; // notification.error(error);
1388
-
1389
- throw new Error(JSON.stringify(error));
1390
- }
1391
-
1392
- var data = response.data,
1393
- headers = response.headers;
1394
-
1395
- if ((_headers$contentDisp = headers['content-disposition']) != null && _headers$contentDisp.includes('attachment;')) {
1396
- // downloadFile(response);
1397
- return;
1398
- } // console.log(data, 'data2390jasdflkf');
1399
- // if ((data.errcode === undefined
1400
- // ? (data.errCode !== 0 && data.errCode !== 2)
1401
- // : (data.errcode !== 0 && data.errcode !== 2))
1402
- // || data.ret !== 0) {
1403
- //
1404
- // // notification.error({
1405
- // // message: data.msg,
1406
- // // });
1407
- // throw new Error(JSON.stringify(data));
1408
- // }
1409
-
1410
-
1411
- return data;
1412
- }, function (error) {
1413
- // Do something with response error
1414
- NProgress.done();
1415
- return Promise.reject(error);
1416
- });
1417
- function request(_x, _x2) {
1418
- return _request.apply(this, arguments);
1419
- } // export function downloadFile(res: AxiosResponse) {
1420
- // const {data, headers} = res;
1421
- // // const fileName = headers['content-disposition'].replace(/attachment; filename="(.*)"/, '$1');
1422
- // const fileName = headers['content-disposition'].replace(/attachment; filename="(.*)"/, '$1');
1423
- // const blob = new Blob([data], {});
1424
- // FileSaver.saveAs(blob, fileName);
1425
- // }
1426
-
1427
- function _request() {
1428
- _request = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(config, _temp) {
1429
- var _ref, _ref$noRedirect, noRedirect, _ref$noErrorAlert, noErrorAlert, result;
1430
-
1431
- return runtime_1.wrap(function _callee$(_context) {
1432
- while (1) {
1433
- switch (_context.prev = _context.next) {
1434
- case 0:
1435
- _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;
1436
- _context.next = 3;
1437
- return axios.request(config);
1438
-
1439
- case 3:
1440
- result = _context.sent;
1441
-
1442
- if (!((result.errCode === 30 || result.errCode === 30) && !noRedirect)) {
1443
- _context.next = 6;
1444
- break;
1445
- }
1446
-
1447
- return _context.abrupt("return", window.location.replace("" + completeUrlByDomain('user') + login({
1448
- goTo: window.location.href
1449
- })));
1450
-
1451
- case 6:
1452
-
1453
- return _context.abrupt("return", result);
1454
-
1455
- case 8:
1456
- case "end":
1457
- return _context.stop();
1458
- }
1459
- }
1460
- }, _callee);
1461
- }));
1462
- return _request.apply(this, arguments);
1463
- }
1464
-
1465
- /**
1466
- * 根据 File 获取 SHA1 Hash 字符串
1467
- * @param file
1468
- * @return {Promise<string>}
1469
- */
1470
-
1471
- function getSHA1Hash(file) {
1472
- return new Promise(function (resolve) {
1473
- var reader = new FileReader();
1474
-
1475
- reader.onload = function () {
1476
- var wordArray = lib.WordArray.create(reader.result);
1477
- var hash = SHA1(wordArray).toString();
1478
- resolve(hash);
1479
- };
1480
-
1481
- reader.readAsArrayBuffer(file);
1482
- });
1483
- }
1484
- /**
1485
- * 生成随机码
1486
- */
1487
-
1488
- function generateRandomCode(strLen) {
1489
- if (strLen === void 0) {
1490
- strLen = 5;
1491
- }
1492
-
1493
- var allStr = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
1494
- var newStrArr = [];
1495
-
1496
- for (var i = 0; i < strLen; i++) {
1497
- newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
1498
- }
1499
-
1500
- return newStrArr.join('');
1501
- }
1502
- /**
1503
- * 通过读取 cookies 获取用户 ID
1504
- */
1505
-
1506
- function getUserIDByCookies() {
1507
- var uid = document.cookie.split('; ').find(function (co) {
1508
- return co.startsWith('uid=');
1509
- });
1510
-
1511
- if (!uid) {
1512
- return -1;
1513
- }
1514
-
1515
- return Number(uid.replace('uid=', ''));
1516
- }
1517
- function transformServerAPIContractState(_ref) {
1518
- var status = _ref.status,
1519
- authStatus = _ref.authStatus;
1520
-
1521
- if (status === 0) {
1522
- if (authStatus === 1 || authStatus === 3) {
1523
- return 'active';
1524
- }
1525
-
1526
- if (authStatus === 2) {
1527
- return 'testActive';
1528
- }
1529
-
1530
- if (authStatus === 128) {
1531
- return 'inactive';
1532
- }
1533
- }
1534
-
1535
- if (status === 1) {
1536
- return 'terminal';
1537
- }
1538
-
1539
- return 'exception';
1540
- }
1541
-
1542
- var Tool = {
1543
- __proto__: null,
1544
- getSHA1Hash: getSHA1Hash,
1545
- generateRandomCode: generateRandomCode,
1546
- getUserIDByCookies: getUserIDByCookies,
1547
- transformServerAPIContractState: transformServerAPIContractState
1548
- };
1549
-
1550
- var FUtil = {
1551
- Format: Format,
1552
- Regexp: Regexp,
1553
- LinkTo: LinkTo,
1554
- Predefined: Predefined,
1555
- Axios: axios,
1556
- Request: request,
1557
- Tool: Tool
1307
+ // export enum ContractAuthStatus {
1308
+ //
1309
+ // }
1310
+
1311
+ var Predefined = {
1312
+ __proto__: null,
1313
+ resourceTypes: resourceTypes,
1314
+ pageSize: pageSize,
1315
+ momentDateFormat: momentDateFormat,
1316
+ momentDateTimeFormat: momentDateTimeFormat,
1317
+ get EnumContractPartyIdentityType () { return EnumContractPartyIdentityType; },
1318
+ get EnumSubjectType () { return EnumSubjectType; },
1319
+ get EnumContractStatus () { return EnumContractStatus; }
1558
1320
  };
1559
1321
 
1560
1322
  function create(params) {
@@ -2851,5 +2613,255 @@ var FServiceAPI = {
2851
2613
  Activity: Activity
2852
2614
  };
2853
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
+
2854
2866
  export { FServiceAPI, FUtil };
2855
2867
  //# sourceMappingURL=tools-lib.esm.js.map