@freelog/tools-lib 0.1.185 → 0.1.187
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/dist/service-API/index.d.ts +2 -0
- package/dist/service-API/payment.d.ts +35 -0
- package/dist/service-API/policies.d.ts +1 -1
- package/dist/tools-lib.cjs.development.js +180 -120
- package/dist/tools-lib.cjs.development.js.map +1 -1
- package/dist/tools-lib.cjs.production.min.js +1 -1
- package/dist/tools-lib.cjs.production.min.js.map +1 -1
- package/dist/tools-lib.esm.js +180 -120
- package/dist/tools-lib.esm.js.map +1 -1
- package/dist/utils/linkTo.d.ts +6 -0
- package/package.json +4 -3
- package/src/service-API/index.ts +45 -43
- package/src/service-API/payment.ts +82 -0
- package/src/service-API/policies.ts +93 -93
- package/src/utils/axios.ts +141 -141
- package/src/utils/linkTo.ts +697 -683
package/dist/utils/linkTo.d.ts
CHANGED
|
@@ -59,6 +59,12 @@ export declare function myCollections({}?: MyCollectionsParamsType): TReturnType
|
|
|
59
59
|
interface MyCollectsParamsType {
|
|
60
60
|
}
|
|
61
61
|
export declare function myCollects({}?: MyCollectsParamsType): TReturnType;
|
|
62
|
+
interface MyResourceIncomeParamsType {
|
|
63
|
+
}
|
|
64
|
+
export declare function myResourceIncome({}?: MyResourceIncomeParamsType): TReturnType;
|
|
65
|
+
interface MyResourceTransactionParamsType {
|
|
66
|
+
}
|
|
67
|
+
export declare function myResourceTransaction({}?: MyResourceTransactionParamsType): TReturnType;
|
|
62
68
|
interface ResourceVersionInfoParamsType {
|
|
63
69
|
resourceID: string;
|
|
64
70
|
version?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@freelog/tools-lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.187",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
"prepare": "tsdx build",
|
|
20
20
|
"size": "size-limit",
|
|
21
21
|
"analyze": "size-limit --why",
|
|
22
|
-
"publish": "npm publish --access=public",
|
|
23
|
-
"resetRegistry": "npm config set registry https://registry.npmjs.org/"
|
|
22
|
+
"publish": "npm publish --access=public --registry=https://registry.npmjs.org/",
|
|
23
|
+
"resetRegistry": "npm config set registry https://registry.npmjs.org/",
|
|
24
|
+
"setRegistry": "npm config set registry https://registry.npmmirror.com/"
|
|
24
25
|
},
|
|
25
26
|
"husky": {
|
|
26
27
|
"hooks": {}
|
package/src/service-API/index.ts
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
import * as Node from './nodes';
|
|
2
|
-
import * as Exhibit from './presentables';
|
|
3
|
-
import * as Storage from './storages';
|
|
4
|
-
import * as Collection from './collections';
|
|
5
|
-
import * as Resource from './resources';
|
|
6
|
-
import * as User from './user';
|
|
7
|
-
import * as InformalNode from './informalNodes';
|
|
8
|
-
import * as Contract from './contracts';
|
|
9
|
-
import * as Transaction from './transactions';
|
|
10
|
-
import * as Captcha from './captcha';
|
|
11
|
-
import * as Event from './events';
|
|
12
|
-
import * as Activity from './activities';
|
|
13
|
-
import * as TestQualification from './testQualifications';
|
|
14
|
-
import * as Statistic from './statistics';
|
|
15
|
-
import * as I18n from './i18n';
|
|
16
|
-
import * as Policy from './policies';
|
|
17
|
-
import * as recombination from './recombinations';
|
|
18
|
-
import * as Operation from './operation';
|
|
19
|
-
import * as ResourceType from './resourceType';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
import * as Node from './nodes';
|
|
2
|
+
import * as Exhibit from './presentables';
|
|
3
|
+
import * as Storage from './storages';
|
|
4
|
+
import * as Collection from './collections';
|
|
5
|
+
import * as Resource from './resources';
|
|
6
|
+
import * as User from './user';
|
|
7
|
+
import * as InformalNode from './informalNodes';
|
|
8
|
+
import * as Contract from './contracts';
|
|
9
|
+
import * as Transaction from './transactions';
|
|
10
|
+
import * as Captcha from './captcha';
|
|
11
|
+
import * as Event from './events';
|
|
12
|
+
import * as Activity from './activities';
|
|
13
|
+
import * as TestQualification from './testQualifications';
|
|
14
|
+
import * as Statistic from './statistics';
|
|
15
|
+
import * as I18n from './i18n';
|
|
16
|
+
import * as Policy from './policies';
|
|
17
|
+
import * as recombination from './recombinations';
|
|
18
|
+
import * as Operation from './operation';
|
|
19
|
+
import * as ResourceType from './resourceType';
|
|
20
|
+
import * as Payment from './payment';
|
|
21
|
+
|
|
22
|
+
const FServiceAPI = {
|
|
23
|
+
Node,
|
|
24
|
+
Exhibit,
|
|
25
|
+
Storage,
|
|
26
|
+
Collection,
|
|
27
|
+
Resource,
|
|
28
|
+
User,
|
|
29
|
+
InformalNode,
|
|
30
|
+
Contract,
|
|
31
|
+
Transaction,
|
|
32
|
+
Captcha,
|
|
33
|
+
Event,
|
|
34
|
+
Activity,
|
|
35
|
+
TestQualification,
|
|
36
|
+
Statistic,
|
|
37
|
+
I18n,
|
|
38
|
+
Policy,
|
|
39
|
+
recombination,
|
|
40
|
+
Operation,
|
|
41
|
+
ResourceType,
|
|
42
|
+
Payment,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default FServiceAPI;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import FUtil from '../utils';
|
|
3
|
+
|
|
4
|
+
// 证件上传与识别
|
|
5
|
+
interface UploadIDCardParamsType {
|
|
6
|
+
file: File;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function uploadIDCard(params: UploadIDCardParamsType, config?: AxiosRequestConfig) {
|
|
10
|
+
const formData = new FormData();
|
|
11
|
+
for (const [key, value] of Object.entries(params)) {
|
|
12
|
+
if (value) {
|
|
13
|
+
formData.append(key, value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return FUtil.Request({
|
|
17
|
+
method: 'POST',
|
|
18
|
+
url: `/v3/transactions/accounts/idCardUploadAndOcr`,
|
|
19
|
+
data: formData,
|
|
20
|
+
...config,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// 开通金融账户
|
|
26
|
+
interface OpenFinancialAccountParamsType {
|
|
27
|
+
accountType: 1 | 2; // 账户类型(1:个人账户 2:节点账户)
|
|
28
|
+
ownerId: number; // 账户所有者ID; 根据账户类型动态赋值userId或nodeId
|
|
29
|
+
certType: '00'; // 证件类型(00:身份证)
|
|
30
|
+
certNo: string; // 证件号码;例如身份证号
|
|
31
|
+
name: string; // 证件上的名称;例如身份证上的姓名
|
|
32
|
+
certValidityType: 0 | 1; // 证件有效期是否是长期; 0:非长期有效 1:长期有效
|
|
33
|
+
certBeginDate: string; // 证件有效期开始日期
|
|
34
|
+
certEndDate?: string; // 证件有效期结束日期(长期有效时此处不传)
|
|
35
|
+
mobile: string; // 开户人真实手机号;
|
|
36
|
+
certImagePaths: string[]; // 证件照保密存放的path部分; 身份证号码识别接口会返回
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function openFinancialAccount(params: OpenFinancialAccountParamsType, config?: AxiosRequestConfig) {
|
|
40
|
+
return FUtil.Request({
|
|
41
|
+
method: 'POST',
|
|
42
|
+
url: `/v3/transactions/accounts`,
|
|
43
|
+
data: params,
|
|
44
|
+
...config,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 金融账户绑定提现卡
|
|
49
|
+
interface BindWithdrawCardParamsType {
|
|
50
|
+
accountId: string; // 金融账户ID
|
|
51
|
+
cardType: 0 | 1 | 2 | 4; // 0:对公,1:对私法人,2:对私非法人,4:对公非同名;个人商户/用户不支持对公类型,对私非法人类型;
|
|
52
|
+
bankName: string; // 开户行名称
|
|
53
|
+
cardName: string; // 持卡人姓名
|
|
54
|
+
cardNo: string; // 卡号
|
|
55
|
+
provId: string; // 银行所在省ID
|
|
56
|
+
areaId: string; // 银行所在城市ID
|
|
57
|
+
branchCode?: string; // 银行支行联行号; 当card_type=0时必填
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function bindWithdrawCard({accountId, ...params}: BindWithdrawCardParamsType, config?: AxiosRequestConfig) {
|
|
61
|
+
return FUtil.Request({
|
|
62
|
+
method: 'POST',
|
|
63
|
+
url: `/v3/transactions/accounts/${accountId}/bindCashCard`,
|
|
64
|
+
data: params,
|
|
65
|
+
...config,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 登录用户关联金融登账户信息查询
|
|
70
|
+
interface QueryFinancialAccountInfoParamsType {
|
|
71
|
+
accountType: 1 | 2; // 账户类型(1:个人账户 2:节点账户)
|
|
72
|
+
ownerId: number; // 账户所有者ID; 根据账户类型动态赋值userId或nodeId
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function queryFinancialAccountInfo(params: QueryFinancialAccountInfoParamsType, config?: AxiosRequestConfig) {
|
|
76
|
+
return FUtil.Request({
|
|
77
|
+
method: 'GET',
|
|
78
|
+
url: `/v3/transactions/accounts/query`,
|
|
79
|
+
params: params,
|
|
80
|
+
...config,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
// import {Base64} from 'js-base64';
|
|
2
|
-
import FUtil from '../utils';
|
|
3
|
-
|
|
4
|
-
// 批量获取授权策略列表
|
|
5
|
-
interface PoliciesParamsType {
|
|
6
|
-
page?: number;
|
|
7
|
-
pageSize?: number;
|
|
8
|
-
subjectType?: 1 | 2 | 3; // 1:资源 2:展品 3:用户组
|
|
9
|
-
projection?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function policies(params: PoliciesParamsType) {
|
|
13
|
-
return FUtil.Request({
|
|
14
|
-
method: 'GET',
|
|
15
|
-
url: `/v2/policies`,
|
|
16
|
-
params: params,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// 批量获取授权策略列表
|
|
21
|
-
interface PoliciesListParamsType {
|
|
22
|
-
policyIds: string;
|
|
23
|
-
subjectType?: number;
|
|
24
|
-
userId?: number;
|
|
25
|
-
projection?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function policiesList(params: PoliciesListParamsType) {
|
|
29
|
-
return FUtil.Request({
|
|
30
|
-
method: 'GET',
|
|
31
|
-
url: `/v2/policies/list`,
|
|
32
|
-
params: params,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 策略模板
|
|
37
|
-
interface PolicyTemplatesParamsType {
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function policyTemplates(params: PolicyTemplatesParamsType = {}) {
|
|
41
|
-
return FUtil.Request({
|
|
42
|
-
method: 'GET',
|
|
43
|
-
url: `/v2/translate/translate-config/list4Client`,
|
|
44
|
-
params: params,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 重新编译
|
|
49
|
-
interface PolicyReCompileParamsType {
|
|
50
|
-
_id?: string;
|
|
51
|
-
contract?: string;
|
|
52
|
-
fillArgs: {
|
|
53
|
-
name: string;
|
|
54
|
-
value: string;
|
|
55
|
-
}[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function policyReCompile(data: PolicyReCompileParamsType) {
|
|
59
|
-
return FUtil.Request({
|
|
60
|
-
method: 'POST',
|
|
61
|
-
url: `/v2/translate/reCompile`,
|
|
62
|
-
data: data,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 模板策略翻译
|
|
67
|
-
interface PolicyTranslationParamsType {
|
|
68
|
-
contract: string;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function policyTranslation({contract}: PolicyTranslationParamsType) {
|
|
72
|
-
return FUtil.Request({
|
|
73
|
-
method: 'POST',
|
|
74
|
-
url: `/v2/translate/translate`,
|
|
75
|
-
data: {
|
|
76
|
-
contract: contract,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 模板策略翻译
|
|
82
|
-
interface PolicyTransferTranslationParamsType {
|
|
83
|
-
contract: string;
|
|
84
|
-
fsmTransfers: any;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function policyTransferTranslation(params: PolicyTransferTranslationParamsType) {
|
|
88
|
-
return FUtil.Request({
|
|
89
|
-
method: 'POST',
|
|
90
|
-
url: `/v2/translate/transfer`,
|
|
91
|
-
data: params,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
1
|
+
// import {Base64} from 'js-base64';
|
|
2
|
+
import FUtil from '../utils';
|
|
3
|
+
|
|
4
|
+
// 批量获取授权策略列表
|
|
5
|
+
interface PoliciesParamsType {
|
|
6
|
+
page?: number;
|
|
7
|
+
pageSize?: number;
|
|
8
|
+
subjectType?: 1 | 2 | 3; // 1:资源 2:展品 3:用户组
|
|
9
|
+
projection?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function policies(params: PoliciesParamsType) {
|
|
13
|
+
return FUtil.Request({
|
|
14
|
+
method: 'GET',
|
|
15
|
+
url: `/v2/policies`,
|
|
16
|
+
params: params,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 批量获取授权策略列表
|
|
21
|
+
interface PoliciesListParamsType {
|
|
22
|
+
policyIds: string;
|
|
23
|
+
subjectType?: number;
|
|
24
|
+
userId?: number;
|
|
25
|
+
projection?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function policiesList(params: PoliciesListParamsType) {
|
|
29
|
+
return FUtil.Request({
|
|
30
|
+
method: 'GET',
|
|
31
|
+
url: `/v2/policies/list`,
|
|
32
|
+
params: params,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 策略模板
|
|
37
|
+
interface PolicyTemplatesParamsType {
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function policyTemplates(params: PolicyTemplatesParamsType = {}) {
|
|
41
|
+
return FUtil.Request({
|
|
42
|
+
method: 'GET',
|
|
43
|
+
url: `/v2/translate/translate-config/list4Client`,
|
|
44
|
+
params: params,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 重新编译
|
|
49
|
+
interface PolicyReCompileParamsType {
|
|
50
|
+
_id?: string;
|
|
51
|
+
contract?: string;
|
|
52
|
+
fillArgs: {
|
|
53
|
+
name: string;
|
|
54
|
+
value: string | number;
|
|
55
|
+
}[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function policyReCompile(data: PolicyReCompileParamsType) {
|
|
59
|
+
return FUtil.Request({
|
|
60
|
+
method: 'POST',
|
|
61
|
+
url: `/v2/translate/reCompile`,
|
|
62
|
+
data: data,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 模板策略翻译
|
|
67
|
+
interface PolicyTranslationParamsType {
|
|
68
|
+
contract: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function policyTranslation({contract}: PolicyTranslationParamsType) {
|
|
72
|
+
return FUtil.Request({
|
|
73
|
+
method: 'POST',
|
|
74
|
+
url: `/v2/translate/translate`,
|
|
75
|
+
data: {
|
|
76
|
+
contract: contract,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 模板策略翻译
|
|
82
|
+
interface PolicyTransferTranslationParamsType {
|
|
83
|
+
contract: string;
|
|
84
|
+
fsmTransfers: any;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function policyTransferTranslation(params: PolicyTransferTranslationParamsType) {
|
|
88
|
+
return FUtil.Request({
|
|
89
|
+
method: 'POST',
|
|
90
|
+
url: `/v2/translate/transfer`,
|
|
91
|
+
data: params,
|
|
92
|
+
});
|
|
93
|
+
}
|
package/src/utils/axios.ts
CHANGED
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import axios, {AxiosRequestConfig} from 'axios';
|
|
2
|
-
// import NProgress from 'nprogress';
|
|
3
|
-
// import "nprogress/nprogress.css";
|
|
4
|
-
import {completeUrlByDomain} from "./format";
|
|
5
|
-
import * as LinkTo from './linkTo';
|
|
6
|
-
// import {CommonReturn, RequestParamsType} from "../service-API/tools";
|
|
7
|
-
import FServiceAPI from "../service-API";
|
|
8
|
-
// import from '../service-API';
|
|
9
|
-
|
|
10
|
-
const codeMessage: any = {
|
|
11
|
-
200: '服务器成功返回请求的数据。',
|
|
12
|
-
201: '新建或修改数据成功。',
|
|
13
|
-
202: '一个请求已经进入后台排队(异步任务)。',
|
|
14
|
-
204: '删除数据成功。',
|
|
15
|
-
400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
|
|
16
|
-
401: '用户没有权限(令牌、用户名、密码错误)。',
|
|
17
|
-
403: '用户得到授权,但是访问是被禁止的。',
|
|
18
|
-
404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
|
|
19
|
-
406: '请求的格式不可得。',
|
|
20
|
-
410: '请求的资源被永久删除,且不会再得到的。',
|
|
21
|
-
422: '当创建一个对象时,发生一个验证错误。',
|
|
22
|
-
500: '服务器发生错误,请检查服务器。',
|
|
23
|
-
502: '网关错误。',
|
|
24
|
-
503: '服务不可用,服务器暂时过载或维护。',
|
|
25
|
-
504: '网关超时。',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// export let apiHost: string = '';
|
|
29
|
-
if (window.location.hostname.includes('.com')) {
|
|
30
|
-
// apiHost = `${window.location.protocol}//qi.${(window.location.host.match(/(?<=\.).*/) || [''])[0]}`;
|
|
31
|
-
// apiHost = window.location.origin.replace('console', 'qi');
|
|
32
|
-
axios.defaults.withCredentials = true;
|
|
33
|
-
axios.defaults.baseURL = completeUrlByDomain('api');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 异常处理程序
|
|
38
|
-
*/
|
|
39
|
-
// const errorHandler = (error: { response: Response }): Response => {
|
|
40
|
-
// const {response} = error;
|
|
41
|
-
// if (response && response.status) {
|
|
42
|
-
// const errorText = codeMessage[response.status] || response.statusText;
|
|
43
|
-
// const {status, url} = response;
|
|
44
|
-
//
|
|
45
|
-
// // notification.error({
|
|
46
|
-
// // message: `请求错误 ${status}: ${url}`,
|
|
47
|
-
// // description: errorText,
|
|
48
|
-
// // });
|
|
49
|
-
// } else if (!response) {
|
|
50
|
-
// // notification.error({
|
|
51
|
-
// // description: '您的网络发生异常,无法连接服务器',
|
|
52
|
-
// // message: '网络异常',
|
|
53
|
-
// // });
|
|
54
|
-
// }
|
|
55
|
-
// return response;
|
|
56
|
-
// };
|
|
57
|
-
//
|
|
58
|
-
// // Add a request interceptor
|
|
59
|
-
axios.interceptors.request.use(
|
|
60
|
-
(config) => {
|
|
61
|
-
// Do something before request is sent
|
|
62
|
-
// NProgress.start();
|
|
63
|
-
return config;
|
|
64
|
-
},
|
|
65
|
-
(error) => {
|
|
66
|
-
// Do something with request error
|
|
67
|
-
// NProgress.done();
|
|
68
|
-
return Promise.reject(error);
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 配置request请求时的默认参数
|
|
74
|
-
*/
|
|
75
|
-
axios.interceptors.response.use(
|
|
76
|
-
(response) => {
|
|
77
|
-
// Do something with response data
|
|
78
|
-
// console.log(response, 'response!!!!!!');
|
|
79
|
-
// NProgress.done();
|
|
80
|
-
if (response.status !== 200) {
|
|
81
|
-
|
|
82
|
-
const error = {
|
|
83
|
-
description: codeMessage[response.status],
|
|
84
|
-
message: response.status,
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// notification.error(error);
|
|
88
|
-
throw new Error(JSON.stringify(error));
|
|
89
|
-
}
|
|
90
|
-
const {data, headers} = response;
|
|
91
|
-
if (headers['content-disposition']?.includes('attachment;')) {
|
|
92
|
-
// downloadFile(response);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// console.log(data, 'data2390jasdflkf');
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// if ((data.errcode === undefined
|
|
100
|
-
// ? (data.errCode !== 0 && data.errCode !== 2)
|
|
101
|
-
// : (data.errcode !== 0 && data.errcode !== 2))
|
|
102
|
-
// || data.ret !== 0) {
|
|
103
|
-
//
|
|
104
|
-
// // notification.error({
|
|
105
|
-
// // message: data.msg,
|
|
106
|
-
// // });
|
|
107
|
-
// throw new Error(JSON.stringify(data));
|
|
108
|
-
// }
|
|
109
|
-
return data;
|
|
110
|
-
},
|
|
111
|
-
(error) => {
|
|
112
|
-
// Do something with response error
|
|
113
|
-
// NProgress.done();
|
|
114
|
-
return Promise.reject(error);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
export default axios;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
export async function request(config: AxiosRequestConfig, {
|
|
121
|
-
// export async function request(config: any, {
|
|
122
|
-
noRedirect = false,
|
|
123
|
-
noErrorAlert = false,
|
|
124
|
-
// }: RequestParamsType = {}): Promise<CommonReturn & { data: any } | void> {
|
|
125
|
-
}: any = {}): Promise<any> {
|
|
126
|
-
const result: any = await axios.request(config);
|
|
127
|
-
// console.log(result, 'response');
|
|
128
|
-
// const {data} = response;
|
|
129
|
-
// console.log(result, 'result90iowjksdfjlsdkj')
|
|
130
|
-
if (result.errCode=== 30 && !noRedirect) {
|
|
131
|
-
await FServiceAPI.User.logout();
|
|
132
|
-
window.location.replace(`${completeUrlByDomain('user')}${LinkTo.login({goTo: window.location.href})}`);
|
|
133
|
-
} else if (result.ret === 4 && result.errCode === 10 && !noRedirect) {
|
|
134
|
-
window.location.replace(`${completeUrlByDomain('user')}${LinkTo.userFreeze({goTo: window.location.href})}`);
|
|
135
|
-
} else if ((result.errcode !== 0 || result.errCode !== 0) && !noErrorAlert) {
|
|
136
|
-
// window.alert(result.msg);
|
|
137
|
-
// return;
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
1
|
+
import axios, {AxiosRequestConfig} from 'axios';
|
|
2
|
+
// import NProgress from 'nprogress';
|
|
3
|
+
// import "nprogress/nprogress.css";
|
|
4
|
+
import {completeUrlByDomain} from "./format";
|
|
5
|
+
import * as LinkTo from './linkTo';
|
|
6
|
+
// import {CommonReturn, RequestParamsType} from "../service-API/tools";
|
|
7
|
+
import FServiceAPI from "../service-API";
|
|
8
|
+
// import from '../service-API';
|
|
9
|
+
|
|
10
|
+
const codeMessage: any = {
|
|
11
|
+
200: '服务器成功返回请求的数据。',
|
|
12
|
+
201: '新建或修改数据成功。',
|
|
13
|
+
202: '一个请求已经进入后台排队(异步任务)。',
|
|
14
|
+
204: '删除数据成功。',
|
|
15
|
+
400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
|
|
16
|
+
401: '用户没有权限(令牌、用户名、密码错误)。',
|
|
17
|
+
403: '用户得到授权,但是访问是被禁止的。',
|
|
18
|
+
404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
|
|
19
|
+
406: '请求的格式不可得。',
|
|
20
|
+
410: '请求的资源被永久删除,且不会再得到的。',
|
|
21
|
+
422: '当创建一个对象时,发生一个验证错误。',
|
|
22
|
+
500: '服务器发生错误,请检查服务器。',
|
|
23
|
+
502: '网关错误。',
|
|
24
|
+
503: '服务不可用,服务器暂时过载或维护。',
|
|
25
|
+
504: '网关超时。',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// export let apiHost: string = '';
|
|
29
|
+
if (window.location.hostname.includes('.com')) {
|
|
30
|
+
// apiHost = `${window.location.protocol}//qi.${(window.location.host.match(/(?<=\.).*/) || [''])[0]}`;
|
|
31
|
+
// apiHost = window.location.origin.replace('console', 'qi');
|
|
32
|
+
axios.defaults.withCredentials = true;
|
|
33
|
+
axios.defaults.baseURL = completeUrlByDomain('api');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 异常处理程序
|
|
38
|
+
*/
|
|
39
|
+
// const errorHandler = (error: { response: Response }): Response => {
|
|
40
|
+
// const {response} = error;
|
|
41
|
+
// if (response && response.status) {
|
|
42
|
+
// const errorText = codeMessage[response.status] || response.statusText;
|
|
43
|
+
// const {status, url} = response;
|
|
44
|
+
//
|
|
45
|
+
// // notification.error({
|
|
46
|
+
// // message: `请求错误 ${status}: ${url}`,
|
|
47
|
+
// // description: errorText,
|
|
48
|
+
// // });
|
|
49
|
+
// } else if (!response) {
|
|
50
|
+
// // notification.error({
|
|
51
|
+
// // description: '您的网络发生异常,无法连接服务器',
|
|
52
|
+
// // message: '网络异常',
|
|
53
|
+
// // });
|
|
54
|
+
// }
|
|
55
|
+
// return response;
|
|
56
|
+
// };
|
|
57
|
+
//
|
|
58
|
+
// // Add a request interceptor
|
|
59
|
+
axios.interceptors.request.use(
|
|
60
|
+
(config) => {
|
|
61
|
+
// Do something before request is sent
|
|
62
|
+
// NProgress.start();
|
|
63
|
+
return config;
|
|
64
|
+
},
|
|
65
|
+
(error) => {
|
|
66
|
+
// Do something with request error
|
|
67
|
+
// NProgress.done();
|
|
68
|
+
return Promise.reject(error);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 配置request请求时的默认参数
|
|
74
|
+
*/
|
|
75
|
+
axios.interceptors.response.use(
|
|
76
|
+
(response) => {
|
|
77
|
+
// Do something with response data
|
|
78
|
+
// console.log(response, 'response!!!!!!');
|
|
79
|
+
// NProgress.done();
|
|
80
|
+
if (response.status !== 200 && response.status !== 201) {
|
|
81
|
+
|
|
82
|
+
const error = {
|
|
83
|
+
description: codeMessage[response.status],
|
|
84
|
+
message: response.status,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// notification.error(error);
|
|
88
|
+
throw new Error(JSON.stringify(error));
|
|
89
|
+
}
|
|
90
|
+
const {data, headers} = response;
|
|
91
|
+
if (headers['content-disposition']?.includes('attachment;')) {
|
|
92
|
+
// downloadFile(response);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// console.log(data, 'data2390jasdflkf');
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
// if ((data.errcode === undefined
|
|
100
|
+
// ? (data.errCode !== 0 && data.errCode !== 2)
|
|
101
|
+
// : (data.errcode !== 0 && data.errcode !== 2))
|
|
102
|
+
// || data.ret !== 0) {
|
|
103
|
+
//
|
|
104
|
+
// // notification.error({
|
|
105
|
+
// // message: data.msg,
|
|
106
|
+
// // });
|
|
107
|
+
// throw new Error(JSON.stringify(data));
|
|
108
|
+
// }
|
|
109
|
+
return data;
|
|
110
|
+
},
|
|
111
|
+
(error) => {
|
|
112
|
+
// Do something with response error
|
|
113
|
+
// NProgress.done();
|
|
114
|
+
return Promise.reject(error);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export default axios;
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
export async function request(config: AxiosRequestConfig, {
|
|
121
|
+
// export async function request(config: any, {
|
|
122
|
+
noRedirect = false,
|
|
123
|
+
noErrorAlert = false,
|
|
124
|
+
// }: RequestParamsType = {}): Promise<CommonReturn & { data: any } | void> {
|
|
125
|
+
}: any = {}): Promise<any> {
|
|
126
|
+
const result: any = await axios.request(config);
|
|
127
|
+
// console.log(result, 'response');
|
|
128
|
+
// const {data} = response;
|
|
129
|
+
// console.log(result, 'result90iowjksdfjlsdkj')
|
|
130
|
+
if (result.errCode=== 30 && !noRedirect) {
|
|
131
|
+
await FServiceAPI.User.logout();
|
|
132
|
+
window.location.replace(`${completeUrlByDomain('user')}${LinkTo.login({goTo: window.location.href})}`);
|
|
133
|
+
} else if (result.ret === 4 && result.errCode === 10 && !noRedirect) {
|
|
134
|
+
window.location.replace(`${completeUrlByDomain('user')}${LinkTo.userFreeze({goTo: window.location.href})}`);
|
|
135
|
+
} else if ((result.errcode !== 0 || result.errCode !== 0) && !noErrorAlert) {
|
|
136
|
+
// window.alert(result.msg);
|
|
137
|
+
// return;
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|