@uxda/appkit 1.2.8 → 1.2.12
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/.eslintrc.mjs +7 -7
- package/README.md +187 -187
- package/babel.config.js +12 -12
- package/dist/appkit.css +289 -71
- package/dist/index.js +862 -341
- package/dist/styles.css +1 -0
- package/package.json +78 -78
- package/project.config.json +15 -15
- package/project.tt.json +13 -13
- package/rollup.config.mjs +54 -54
- package/src/Appkit.ts +65 -65
- package/src/balance/api/endpoints.ts +125 -122
- package/src/balance/api/index.ts +82 -82
- package/src/balance/components/AccountView.vue +754 -649
- package/src/balance/components/BalanceCard.vue +209 -209
- package/src/balance/components/BalanceReminder.vue +83 -83
- package/src/balance/components/ConsumptionFilter.vue +218 -218
- package/src/balance/components/ConsumptionRules.vue +68 -68
- package/src/balance/components/DateFilter.vue +235 -235
- package/src/balance/components/SecondBalance.vue +71 -71
- package/src/balance/components/Tip.vue +46 -0
- package/src/balance/components/index.ts +9 -9
- package/src/balance/types.ts +90 -88
- package/src/components/dd-area/index.vue +222 -222
- package/src/components/dd-icon/doc.md +21 -21
- package/src/components/dd-icon/index.vue +23 -23
- package/src/components/dd-selector/index.vue +124 -124
- package/src/components/ocr-id/index.vue +110 -110
- package/src/components/ocr-id/types.d.ts +12 -12
- package/src/global.ts +6 -6
- package/src/index.ts +88 -86
- package/src/main.scss +1 -1
- package/src/payment/api/config.ts +7 -7
- package/src/payment/api/endpoints.ts +103 -78
- package/src/payment/api/index.ts +71 -71
- package/src/payment/components/AmountPicker.vue +93 -93
- package/src/payment/components/RechargeResult.vue +66 -54
- package/src/payment/components/RechargeView.vue +154 -154
- package/src/payment/components/RightsPicker.vue +106 -0
- package/src/payment/components/TradeView.vue +298 -0
- package/src/payment/components/UserAgreement.vue +141 -141
- package/src/payment/components/index.ts +22 -19
- package/src/payment/index.ts +5 -5
- package/src/payment/services/index.ts +16 -16
- package/src/payment/services/invoke-recharge.ts +25 -25
- package/src/payment/services/request-payment.ts +58 -31
- package/src/payment/types.ts +28 -23
- package/src/register/components/SelfRegistration.vue +227 -227
- package/src/register/components/index.ts +2 -2
- package/src/shared/components/AppDrawer.vue +58 -58
- package/src/shared/components/EmptyView.vue +33 -33
- package/src/shared/components/PageHeader.vue +79 -79
- package/src/shared/components/index.ts +6 -6
- package/src/shared/composables/index.ts +2 -2
- package/src/shared/composables/useSafeArea.ts +43 -43
- package/src/shared/composables/useTabbar.ts +24 -24
- package/src/shared/http/Http.ts +126 -126
- package/src/shared/http/index.ts +1 -1
- package/src/shared/http/types.ts +157 -157
- package/src/shared/index.ts +3 -3
- package/src/shared/weixin/payment.ts +38 -38
- package/src/styles/fonts.scss +2 -2
- package/src/styles/vars.scss +3 -3
- package/tsconfig.json +30 -30
- package/types/global.d.ts +21 -21
- package/types/vue.d.ts +10 -10
package/src/index.ts
CHANGED
|
@@ -1,86 +1,88 @@
|
|
|
1
|
-
import { App } from 'vue'
|
|
2
|
-
import { components as paymentComponents } from './payment/components'
|
|
3
|
-
import { services as paymentServices } from './payment'
|
|
4
|
-
import {
|
|
5
|
-
Grid,
|
|
6
|
-
GridItem,
|
|
7
|
-
Button,
|
|
8
|
-
Checkbox,
|
|
9
|
-
Popup,
|
|
10
|
-
OverLay,
|
|
11
|
-
DatePicker,
|
|
12
|
-
Form,
|
|
13
|
-
FormItem,
|
|
14
|
-
Cell,
|
|
15
|
-
CellGroup,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
import './
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
appKitOptions
|
|
67
|
-
appKitOptions.
|
|
68
|
-
appKitOptions.
|
|
69
|
-
appKitOptions
|
|
70
|
-
appKitOptions.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
export * from './
|
|
85
|
-
export * from './
|
|
86
|
-
export
|
|
1
|
+
import { App } from 'vue'
|
|
2
|
+
import { components as paymentComponents } from './payment/components'
|
|
3
|
+
import { services as paymentServices } from './payment'
|
|
4
|
+
import {
|
|
5
|
+
Grid,
|
|
6
|
+
GridItem,
|
|
7
|
+
Button,
|
|
8
|
+
Checkbox,
|
|
9
|
+
Popup,
|
|
10
|
+
OverLay,
|
|
11
|
+
DatePicker,
|
|
12
|
+
Form,
|
|
13
|
+
FormItem,
|
|
14
|
+
Cell,
|
|
15
|
+
CellGroup,
|
|
16
|
+
Dialog
|
|
17
|
+
} from '@nutui/nutui-taro'
|
|
18
|
+
import { type AppKitOptions, useAppKitOptions, DollarApp } from './Appkit'
|
|
19
|
+
import { PaymentParams, RechargeParams } from './payment/types'
|
|
20
|
+
import './main.scss'
|
|
21
|
+
|
|
22
|
+
const nutComponents = [
|
|
23
|
+
Grid,
|
|
24
|
+
GridItem,
|
|
25
|
+
Button,
|
|
26
|
+
Checkbox,
|
|
27
|
+
Popup,
|
|
28
|
+
OverLay,
|
|
29
|
+
DatePicker,
|
|
30
|
+
Form,
|
|
31
|
+
FormItem,
|
|
32
|
+
Cell,
|
|
33
|
+
CellGroup,
|
|
34
|
+
Dialog
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
const appComponents = {
|
|
38
|
+
...paymentComponents,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const services = [...paymentServices]
|
|
42
|
+
|
|
43
|
+
const $app: DollarApp = {
|
|
44
|
+
setToken: (token: () => string) => {
|
|
45
|
+
const appKitOptions = useAppKitOptions()
|
|
46
|
+
appKitOptions.token = token
|
|
47
|
+
},
|
|
48
|
+
setTempToken: (token: () => string) => {
|
|
49
|
+
const appKitOptions = useAppKitOptions()
|
|
50
|
+
appKitOptions.tempToken = token
|
|
51
|
+
},
|
|
52
|
+
requestPayment: (options: PaymentParams) => {},
|
|
53
|
+
invokeRecharge: (options: RechargeParams) => {},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
services.forEach((service) => {
|
|
57
|
+
service.install($app)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
export function useAppKit(): DollarApp {
|
|
61
|
+
return $app
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const AppKit = {
|
|
65
|
+
install(app: App, options: AppKitOptions) {
|
|
66
|
+
const appKitOptions = useAppKitOptions()
|
|
67
|
+
appKitOptions.app = options.app
|
|
68
|
+
appKitOptions.tenant = options.tenant
|
|
69
|
+
appKitOptions.token = options.token
|
|
70
|
+
appKitOptions.baseUrl = options.baseUrl
|
|
71
|
+
appKitOptions[401] = options[401]
|
|
72
|
+
appKitOptions.gray = options.gray
|
|
73
|
+
nutComponents.forEach((component) => {
|
|
74
|
+
app.use(component)
|
|
75
|
+
})
|
|
76
|
+
Object.entries(appComponents).forEach(([name, component]) => {
|
|
77
|
+
app.component(name, component)
|
|
78
|
+
})
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default AppKit
|
|
83
|
+
|
|
84
|
+
export * from './payment'
|
|
85
|
+
export * from './balance'
|
|
86
|
+
export * from './shared'
|
|
87
|
+
export * from './register'
|
|
88
|
+
export { type AppKitOptions }
|
package/src/main.scss
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
@import url(./styles/vars.scss);
|
|
1
|
+
@import url(./styles/vars.scss);
|
|
2
2
|
@import url(./styles/fonts.scss);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { HttpClientConfig } from '../../shared/http'
|
|
2
|
-
|
|
3
|
-
const clientConfig: HttpClientConfig = {
|
|
4
|
-
baseUrl: 'http://ytech.dev.ddjf.info',
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
1
|
+
import type { HttpClientConfig } from '../../shared/http'
|
|
2
|
+
|
|
3
|
+
const clientConfig: HttpClientConfig = {
|
|
4
|
+
baseUrl: 'http://ytech.dev.ddjf.info',
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
|
|
8
8
|
export default clientConfig
|
|
@@ -1,79 +1,104 @@
|
|
|
1
|
-
import { HttpEndpoints } from '../../shared/http'
|
|
2
|
-
import { PaymentParams } from '../types'
|
|
3
|
-
|
|
4
|
-
const endpointsList: HttpEndpoints = {
|
|
5
|
-
/**
|
|
6
|
-
* 获取充值套餐包列表
|
|
7
|
-
* (查询某应用某场景可充值的金额列表)
|
|
8
|
-
* http://ytech.dev.ddjf.info/payment/doc.html#/%E5%AE%A2%E6%88%B7%E5%9F%9FAPI/%E6%94%AF%E4%BB%98%E4%B8%AD%E5%BF%83-%E5%AF%B9%E5%A4%96%E6%8E%A5%E5%8F%A3/getRechargeListUsingGET
|
|
9
|
-
*/
|
|
10
|
-
获取充值金额列表: {
|
|
11
|
-
path: '/payment/outer/payment/getRechargeList',
|
|
12
|
-
translate: (data: any) => ({
|
|
13
|
-
appCode: data.app,
|
|
14
|
-
// caseCode: 'recharge', // 这个参数可以不要
|
|
15
|
-
tenantId: data.tenant
|
|
16
|
-
}),
|
|
17
|
-
transform: (data: any) => data.amountList.map((d: any) => ({
|
|
18
|
-
token: d.desc,
|
|
19
|
-
amount: d.amount
|
|
20
|
-
}))
|
|
21
|
-
},
|
|
22
|
-
/**
|
|
23
|
-
* 查询支付参数包
|
|
24
|
-
* (获取拉起微信支付用的JSON串)
|
|
25
|
-
* http://ytech.dev.ddjf.info/payment/doc.html#/%E5%AE%A2%E6%88%B7%E5%9F%9FAPI/%E6%94%AF%E4%BB%98%E4%B8%AD%E5%BF%83-%E5%AF%B9%E5%A4%96%E6%8E%A5%E5%8F%A3/rechargePayUsingPOST
|
|
26
|
-
*/
|
|
27
|
-
获取微信支付参数包: {
|
|
28
|
-
// {
|
|
29
|
-
// "amount": 100,
|
|
30
|
-
// "appCode": "crm",
|
|
31
|
-
// "caseCode": "aiApproveRecharge",
|
|
32
|
-
// "tenantId": "17454646",
|
|
33
|
-
// "transFlowNo": "4343244",
|
|
34
|
-
// "certificateNo": "o7k8L0QTqcwRIBKVUPzI7iPfghLM"
|
|
35
|
-
// }
|
|
36
|
-
path: '/payment/outer/payment/rechargePay',
|
|
37
|
-
translate: (params: PaymentParams) => ({
|
|
38
|
-
amount: params.amount,
|
|
39
|
-
appCode: params.app,
|
|
40
|
-
// caseCode: data.stage, 这个参数可以不传
|
|
41
|
-
tenantId: params.tenant,
|
|
42
|
-
// transFlowNo: '4343244', 这个参数可以不传
|
|
43
|
-
certificateNo: params.user,
|
|
44
|
-
}),
|
|
45
|
-
transform: (data: any) => {
|
|
46
|
-
let json = null
|
|
47
|
-
try {
|
|
48
|
-
json = JSON.parse(data.prePayStr)
|
|
49
|
-
} catch (e) {
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
json, // 拉起微信支付用的JSON串
|
|
53
|
-
paymentId: data.payId // 查询用支付ID
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
import { HttpEndpoints } from '../../shared/http'
|
|
2
|
+
import { PaymentParams } from '../types'
|
|
3
|
+
|
|
4
|
+
const endpointsList: HttpEndpoints = {
|
|
5
|
+
/**
|
|
6
|
+
* 获取充值套餐包列表
|
|
7
|
+
* (查询某应用某场景可充值的金额列表)
|
|
8
|
+
* http://ytech.dev.ddjf.info/payment/doc.html#/%E5%AE%A2%E6%88%B7%E5%9F%9FAPI/%E6%94%AF%E4%BB%98%E4%B8%AD%E5%BF%83-%E5%AF%B9%E5%A4%96%E6%8E%A5%E5%8F%A3/getRechargeListUsingGET
|
|
9
|
+
*/
|
|
10
|
+
获取充值金额列表: {
|
|
11
|
+
path: '/payment/outer/payment/getRechargeList',
|
|
12
|
+
translate: (data: any) => ({
|
|
13
|
+
appCode: data.app,
|
|
14
|
+
// caseCode: 'recharge', // 这个参数可以不要
|
|
15
|
+
tenantId: data.tenant
|
|
16
|
+
}),
|
|
17
|
+
transform: (data: any) => data.amountList.map((d: any) => ({
|
|
18
|
+
token: d.desc,
|
|
19
|
+
amount: d.amount
|
|
20
|
+
}))
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* 查询支付参数包
|
|
24
|
+
* (获取拉起微信支付用的JSON串)
|
|
25
|
+
* http://ytech.dev.ddjf.info/payment/doc.html#/%E5%AE%A2%E6%88%B7%E5%9F%9FAPI/%E6%94%AF%E4%BB%98%E4%B8%AD%E5%BF%83-%E5%AF%B9%E5%A4%96%E6%8E%A5%E5%8F%A3/rechargePayUsingPOST
|
|
26
|
+
*/
|
|
27
|
+
获取微信支付参数包: {
|
|
28
|
+
// {
|
|
29
|
+
// "amount": 100,
|
|
30
|
+
// "appCode": "crm",
|
|
31
|
+
// "caseCode": "aiApproveRecharge",
|
|
32
|
+
// "tenantId": "17454646",
|
|
33
|
+
// "transFlowNo": "4343244",
|
|
34
|
+
// "certificateNo": "o7k8L0QTqcwRIBKVUPzI7iPfghLM"
|
|
35
|
+
// }
|
|
36
|
+
path: '/payment/outer/payment/rechargePay',
|
|
37
|
+
translate: (params: PaymentParams) => ({
|
|
38
|
+
amount: params.amount,
|
|
39
|
+
appCode: params.app,
|
|
40
|
+
// caseCode: data.stage, 这个参数可以不传
|
|
41
|
+
tenantId: params.tenant,
|
|
42
|
+
// transFlowNo: '4343244', 这个参数可以不传
|
|
43
|
+
certificateNo: params.user,
|
|
44
|
+
}),
|
|
45
|
+
transform: (data: any) => {
|
|
46
|
+
let json = null
|
|
47
|
+
try {
|
|
48
|
+
json = JSON.parse(data.prePayStr)
|
|
49
|
+
} catch (e) {
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
json, // 拉起微信支付用的JSON串
|
|
53
|
+
paymentId: data.payId // 查询用支付ID
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
获取权益微信支付: {
|
|
58
|
+
path: '/payment/outer/payment/valueExchangePay',
|
|
59
|
+
translate: (params: PaymentParams) => ({
|
|
60
|
+
caseConfigId: params.caseConfigId,
|
|
61
|
+
appCode: params.app,
|
|
62
|
+
tenantId: params.tenant,
|
|
63
|
+
amount: params.amount,
|
|
64
|
+
certificateNo: params.user,
|
|
65
|
+
}),
|
|
66
|
+
transform: (data: any) => {
|
|
67
|
+
let json = null
|
|
68
|
+
try {
|
|
69
|
+
json = JSON.parse(data.prePayStr)
|
|
70
|
+
} catch (e) {
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
json, // 拉起微信支付用的JSON串
|
|
74
|
+
paymentId: data.payId // 查询用支付ID
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
获取增值权益类目: {
|
|
79
|
+
path: "/payment/paymentCaseConfig/getBalanceAndRiskQueryPriceConfig",
|
|
80
|
+
transform: (data: any) => data
|
|
81
|
+
},
|
|
82
|
+
} as const
|
|
83
|
+
|
|
84
|
+
const keys = Object.keys(endpointsList as any)
|
|
85
|
+
|
|
86
|
+
type Keys = typeof keys[number]
|
|
87
|
+
|
|
88
|
+
const endpoints: Record<Keys, string> = Object.fromEntries(
|
|
89
|
+
Object.entries(endpointsList).map(([name, def]) => [name, def.path])
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const translates = Object.fromEntries(
|
|
93
|
+
Object.entries(endpointsList).map(([, def]) => [def.path, def.translate])
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
const transforms = Object.fromEntries(
|
|
97
|
+
Object.entries(endpointsList).map(([, def]) => [def.path, def.transform])
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
endpoints,
|
|
102
|
+
translates,
|
|
103
|
+
transforms,
|
|
79
104
|
}
|
package/src/payment/api/index.ts
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
2
|
-
import { HttpRequestConfig, ResponseRaw, createHttp } from '../../shared'
|
|
3
|
-
import { translates, transforms } from './endpoints'
|
|
4
|
-
import { useAppKitOptions } from '../../Appkit'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 小程序端 Http
|
|
8
|
-
* 使用 Taro.request 实现
|
|
9
|
-
*/
|
|
10
|
-
const vendor = {
|
|
11
|
-
async request<T>(config: HttpRequestConfig) {
|
|
12
|
-
return new Promise<ResponseRaw<T>>((resolve, reject) => {
|
|
13
|
-
Taro.request({
|
|
14
|
-
url: config.url,
|
|
15
|
-
method: config.method,
|
|
16
|
-
header: config.headers,
|
|
17
|
-
data: config.data,
|
|
18
|
-
})
|
|
19
|
-
.then(({ data }) => {
|
|
20
|
-
resolve({
|
|
21
|
-
status: data.code,
|
|
22
|
-
message: data.msg,
|
|
23
|
-
data: data.result as T,
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
.catch((e: any) => {
|
|
27
|
-
reject(e)
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function useHttp() {
|
|
34
|
-
const appkitOptions = useAppKitOptions()
|
|
35
|
-
const headers = {
|
|
36
|
-
Token: appkitOptions.tempToken() || appkitOptions.token(),
|
|
37
|
-
Appcode: appkitOptions.app(),
|
|
38
|
-
cookie: `tid=${appkitOptions.tenant()}`,
|
|
39
|
-
gray: appkitOptions.gray ? appkitOptions.gray() : '0',
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 传入配置获取 Http instanse
|
|
43
|
-
*/
|
|
44
|
-
const $http = createHttp({
|
|
45
|
-
vendor,
|
|
46
|
-
baseUrl: appkitOptions.baseUrl(),
|
|
47
|
-
headers,
|
|
48
|
-
interceptors: [
|
|
49
|
-
(raw) => {
|
|
50
|
-
if (raw.status == 401) {
|
|
51
|
-
appkitOptions[401]()
|
|
52
|
-
return true
|
|
53
|
-
}
|
|
54
|
-
return false
|
|
55
|
-
},
|
|
56
|
-
(raw) => {
|
|
57
|
-
if (raw.status > 500) {
|
|
58
|
-
return true
|
|
59
|
-
}
|
|
60
|
-
return false
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
translates,
|
|
64
|
-
transforms,
|
|
65
|
-
})
|
|
66
|
-
return $http
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export { useHttp }
|
|
70
|
-
|
|
71
|
-
export * from './endpoints'
|
|
1
|
+
import Taro from '@tarojs/taro'
|
|
2
|
+
import { HttpRequestConfig, ResponseRaw, createHttp } from '../../shared'
|
|
3
|
+
import { translates, transforms } from './endpoints'
|
|
4
|
+
import { useAppKitOptions } from '../../Appkit'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 小程序端 Http
|
|
8
|
+
* 使用 Taro.request 实现
|
|
9
|
+
*/
|
|
10
|
+
const vendor = {
|
|
11
|
+
async request<T>(config: HttpRequestConfig) {
|
|
12
|
+
return new Promise<ResponseRaw<T>>((resolve, reject) => {
|
|
13
|
+
Taro.request({
|
|
14
|
+
url: config.url,
|
|
15
|
+
method: config.method,
|
|
16
|
+
header: config.headers,
|
|
17
|
+
data: config.data,
|
|
18
|
+
})
|
|
19
|
+
.then(({ data }) => {
|
|
20
|
+
resolve({
|
|
21
|
+
status: data.code,
|
|
22
|
+
message: data.msg,
|
|
23
|
+
data: data.result as T,
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
.catch((e: any) => {
|
|
27
|
+
reject(e)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function useHttp() {
|
|
34
|
+
const appkitOptions = useAppKitOptions()
|
|
35
|
+
const headers = {
|
|
36
|
+
Token: appkitOptions.tempToken() || appkitOptions.token(),
|
|
37
|
+
Appcode: appkitOptions.app(),
|
|
38
|
+
cookie: `tid=${appkitOptions.tenant()}`,
|
|
39
|
+
gray: appkitOptions.gray ? appkitOptions.gray() : '0',
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 传入配置获取 Http instanse
|
|
43
|
+
*/
|
|
44
|
+
const $http = createHttp({
|
|
45
|
+
vendor,
|
|
46
|
+
baseUrl: appkitOptions.baseUrl(),
|
|
47
|
+
headers,
|
|
48
|
+
interceptors: [
|
|
49
|
+
(raw) => {
|
|
50
|
+
if (raw.status == 401) {
|
|
51
|
+
appkitOptions[401]()
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
return false
|
|
55
|
+
},
|
|
56
|
+
(raw) => {
|
|
57
|
+
if (raw.status > 500 && raw.status != 1100028) {
|
|
58
|
+
return true
|
|
59
|
+
}
|
|
60
|
+
return false
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
translates,
|
|
64
|
+
transforms,
|
|
65
|
+
})
|
|
66
|
+
return $http
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { useHttp }
|
|
70
|
+
|
|
71
|
+
export * from './endpoints'
|