@uxda/appkit 1.0.66 → 1.0.70

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxda/appkit",
3
- "version": "1.0.66",
3
+ "version": "1.0.70",
4
4
  "description": "小程序应用开发包",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.ts",
@@ -39,6 +39,7 @@
39
39
  "@tarojs/taro": "^3.5.6",
40
40
  "@tarojs/taro-h5": "^3.5.6",
41
41
  "@types/wechat-miniprogram": "^3.4.7",
42
+ "dayjs": "^1.11.10",
42
43
  "vue": "^3.3.0"
43
44
  },
44
45
  "devDependencies": {
@@ -1,6 +1,9 @@
1
1
  import { HttpEndpoints } from '../../shared/http'
2
- import { ConsumptionFiltering, ConsumptionGroups, ConsumptionType } from '../types'
2
+ import { 账户流水筛选项, ConsumptionType } from '../types'
3
3
 
4
+ /**
5
+ * 流水交易类型映射
6
+ */
4
7
  const typeMappings: Record<string, ConsumptionType> = {
5
8
  'CZ': '充值',
6
9
  'JF': '缴费',
@@ -11,6 +14,9 @@ const typeMappings: Record<string, ConsumptionType> = {
11
14
  'TH': '退回',
12
15
  }
13
16
 
17
+ /**
18
+ * 映射还能反过来
19
+ */
14
20
  const typeMappingsReversed = Object.fromEntries(
15
21
  Object.entries(typeMappings).map(([x, y]) => [y, x])
16
22
  )
@@ -34,56 +40,54 @@ const directionMappingsReversed = Object.fromEntries(
34
40
  )
35
41
 
36
42
  const endpointsList: HttpEndpoints = {
37
- /**
38
- * 余额明细
39
- */
40
- getBalance: {
43
+ 获取余额明细: {
41
44
  path: '/ac-app/account/info/detail/app', // /app
42
- translate: (data: any) => ({
43
- }),
44
45
  transform (result: any) {
45
46
  return {
46
47
  total: result.commonAccount,
47
48
  privileges: result.rightsAccountBalList.map((r: any) => ({
48
49
  title: r.rightsName,
49
- amount: r.rightsAccount
50
+ count: r.rightsAccount
50
51
  }))
51
52
  }
52
53
  }
53
54
  },
54
- /**
55
- * 账户流水明细
56
- */
57
- getOperations: {
55
+ 获取账户流水: {
58
56
  path: '/ac-app/account/record/detail/mobile',
59
- translate: (data: ConsumptionFiltering) => {
57
+ translate: (data: 账户流水筛选项) => {
60
58
  return {
61
- accountType: positionMappingsReversed[data.position] || '',
62
- inOrOut: directionMappingsReversed[data.direction] || '',
63
- changeType: typeMappingsReversed[data.type] || '',
59
+ accountType: positionMappingsReversed[data.账户类型] || '',
60
+ inOrOut: directionMappingsReversed[data.收入还是支出] || '',
61
+ changeType: typeMappingsReversed[data.交易类型] || '',
64
62
  operateTimeStart: data.dateFrom || '',
65
63
  operateTimeEnd: data.dateTo || '',
64
+ rightsCode: data.权益类目,
65
+ pageNum: data.page,
66
+ pageSize: 10,
66
67
  }
67
68
  },
68
- transform (result: any) {
69
- if (!result.accountRecordDetailDailyList) return []
70
- const data: ConsumptionGroups = {
71
- from: result.operateTimeStart,
72
- to: result.operateTimeEnd,
73
- list: result.accountRecordDetailDailyList.map((r: any) => ({
74
- date: r.operateTime,
75
- consumptions: r.accountRecordDetailList.map((d: any) => ({
76
- position: positionMappings[d.accountType],
77
- type: typeMappings[d.changeType],
78
- direction: directionMappings[d.inOrOut],
79
- amount: d.changeValue,
80
- title: d.rightsName,
81
- description: d.remark,
82
- }))
83
- }))
84
- }
69
+ transform (response: any) {
70
+ const data = response.list.map((d: any) => ({
71
+ 账户类型: positionMappings[d.accountType],
72
+ 交易类型: typeMappings[d.changeType],
73
+ 收入还是支出: directionMappings[d.inOrOut],
74
+ amount: d.changeValue,
75
+ title: d.rightsName,
76
+ time: Date.parse(d.operateTime), // 后台返回的是日期字符串,这里格式化成 timestamp
77
+ description: d.remark,
78
+ }))
85
79
  return data
86
80
  }
81
+ },
82
+ 获取权益类目: {
83
+ path: '/ac-app/rights/item/list',
84
+ // translate (data: ConsumptionFiltering) {
85
+ // // return { appCode: data.appCode }
86
+ // },
87
+ transform: (data: any[]) => data.map(d => ({
88
+ name: d.rightsName,
89
+ code: d.rightsCode,
90
+ }))
87
91
  }
88
92
  }
89
93
 
@@ -103,4 +107,4 @@ export {
103
107
  endpoints,
104
108
  translates,
105
109
  transforms,
106
- }
110
+ }
@@ -1,21 +1,73 @@
1
- import { useHttp } from '../../shared'
1
+ import Taro from '@tarojs/taro'
2
+ import { HttpRequestConfig, PagingData, PagingParams, ResponseRaw, createHttp } from '../../shared'
2
3
  import { translates, transforms } from './endpoints'
3
4
  import { useAppKitOptions } from '../../Appkit'
4
5
 
5
- const makeHttp = () => {
6
- const appkitOptions = useAppKitOptions()
7
6
 
8
- const header = {
7
+ /**
8
+ * 小程序端 Http
9
+ * 使用 Taro.request 实现
10
+ */
11
+ const vendor = {
12
+ async request <T>(config: HttpRequestConfig) {
13
+ return new Promise<ResponseRaw<T>>((resolve, reject) => {
14
+ Taro.request({
15
+ url: config.url,
16
+ method: config.method,
17
+ header: config.headers,
18
+ data: config.data
19
+ }).then(({data}) => {
20
+ resolve({
21
+ status: +data.code,
22
+ message: data.msg,
23
+ data: data.result as T
24
+ })
25
+ }).catch((e: any) => {
26
+ reject(e)
27
+ })
28
+ })
29
+ }
30
+ }
31
+
32
+ function useHttp () {
33
+ const appkitOptions = useAppKitOptions()
34
+ const headers = {
9
35
  Token: appkitOptions.token(),
10
36
  Appcode: appkitOptions.app(),
11
37
  cookie: `tid=${appkitOptions.tenant()}`
12
38
  }
13
-
14
- const $http = useHttp({
39
+ /**
40
+ * 传入配置获取 Http instanse
41
+ */
42
+ const $http = createHttp({
43
+ vendor,
15
44
  baseUrl: appkitOptions.baseUrl(),
16
- header,
17
- onAuthError () {
18
- appkitOptions[401]()
45
+ headers,
46
+ interceptors: [
47
+ raw => {
48
+ if (raw.status == 401) {
49
+ appkitOptions[401]()
50
+ return true
51
+ }
52
+ return false
53
+ },
54
+ raw => {
55
+ if (raw.status > 500) {
56
+ return true
57
+ }
58
+ return false
59
+ }
60
+ ],
61
+ paging: {
62
+ translate: (params: PagingParams) => ({
63
+ pageNum: params.page,
64
+ pageSize: params.pageSize
65
+ }),
66
+ transform (data: any): PagingData {
67
+ return {
68
+ totalPages: data.pages
69
+ }
70
+ }
19
71
  },
20
72
  translates,
21
73
  transforms,
@@ -24,7 +76,7 @@ const makeHttp = () => {
24
76
  }
25
77
 
26
78
  export {
27
- makeHttp
79
+ useHttp
28
80
  }
29
81
 
30
82
  export * from './endpoints'