@uxda/appkit 1.2.60 → 1.2.61

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/index.js CHANGED
@@ -554,9 +554,9 @@ const request = (config) => {
554
554
  ...config
555
555
  };
556
556
  return new Promise((resolve, reject) => {
557
- const data = config.data && clientConfig.translates && clientConfig.translates[c.url] ? clientConfig.translates[c.url]?.(c.data || {}) : c.data;
557
+ const data = config.data && clientConfig.translates && clientConfig.translates[c.url] ? clientConfig.translates[c.url](c.data || {}) : c.data;
558
558
  console.log(`[][][][][]HTTP.${c.method}, ${c.baseUrl}${c.url}`, data);
559
- clientConfig.vendor?.request({
559
+ clientConfig.vendor && clientConfig.vendor.request({
560
560
  url: `${c.baseUrl}${c.url}`,
561
561
  data,
562
562
  headers: c.headers,
@@ -570,8 +570,8 @@ const request = (config) => {
570
570
  }
571
571
  }
572
572
  if (raw.data) {
573
- const response = clientConfig.transforms && clientConfig.transforms[c.url] ? clientConfig.transforms[c.url]?.(raw.data) : raw.data;
574
- const paging = config.data?.page ? clientConfig.paging?.transform(raw.data) : void 0;
573
+ const response = clientConfig.transforms && clientConfig.transforms[c.url] ? clientConfig.transforms[c.url](raw.data) : raw.data;
574
+ const paging = config.data.page ? clientConfig.paging.transform(raw.data) : void 0;
575
575
  resolve(
576
576
  paging ? {
577
577
  ...paging,
@@ -602,9 +602,7 @@ const post = (url, data) => {
602
602
  };
603
603
  const defaultClientConfig = {
604
604
  baseUrl: "/",
605
- interceptors: [
606
- (raw) => raw.status == 401
607
- ]
605
+ interceptors: [(raw) => raw.status == 401]
608
606
  };
609
607
  let clientConfig = {
610
608
  ...defaultClientConfig
@@ -3681,8 +3679,10 @@ var script$1 = /* @__PURE__ */ defineComponent({
3681
3679
  appCode: props.app || appkitOptions.app(),
3682
3680
  tenantId: appkitOptions.tenant()
3683
3681
  }).then((result) => {
3684
- bannerMessages.value = (result || []).filter((item) => item.noticeType !== void 0);
3685
- popMessages.value = (result || []).filter((item) => item.isPop);
3682
+ if (!Array.isArray(result))
3683
+ return;
3684
+ bannerMessages.value = result.filter((item) => item.noticeType !== void 0);
3685
+ popMessages.value = result.filter((item) => item.isPop);
3686
3686
  startMessageCarousel();
3687
3687
  });
3688
3688
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxda/appkit",
3
- "version": "1.2.60",
3
+ "version": "1.2.61",
4
4
  "description": "小程序应用开发包",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.ts",
@@ -95,8 +95,10 @@ async function queryNoticeMsg() {
95
95
  tenantId: appkitOptions.tenant(),
96
96
  })
97
97
  .then((result) => {
98
- bannerMessages.value = (result || []).filter((item: any) => item.noticeType !== undefined)
99
- popMessages.value = (result || []).filter((item: any) => item.isPop)
98
+ if (!Array.isArray(result)) return
99
+
100
+ bannerMessages.value = result.filter((item: any) => item.noticeType !== undefined)
101
+ popMessages.value = result.filter((item: any) => item.isPop)
100
102
 
101
103
  startMessageCarousel()
102
104
  })
@@ -1,7 +1,14 @@
1
- import { HttpInstance, HttpClientConfig,
2
- HttpMethod, HttpRequestConfig,
3
- RequestData, ResponseData,
4
- ResponseRaw } from './types'
1
+ import {
2
+ HttpInstance,
3
+ HttpClientConfig,
4
+ HttpMethod,
5
+ HttpRequestConfig,
6
+ RequestData,
7
+ ResponseData,
8
+ ResponseRaw,
9
+ Paging,
10
+ HttpTranslate,
11
+ } from './types'
5
12
  /**
6
13
  * Useage:
7
14
  * const $http = createHttp({
@@ -23,56 +30,60 @@ const request: HttpInstance['request'] = <T>(config: HttpRequestConfig) => {
23
30
  ...config,
24
31
  }
25
32
  return new Promise<T>((resolve, reject) => {
26
- const data = config.data
27
- && clientConfig.translates
28
- && clientConfig.translates[c.url]
29
- ? clientConfig.translates[c.url]?.(c.data || {})
33
+ const data =
34
+ config.data && clientConfig.translates && clientConfig.translates[c.url]
35
+ ? (clientConfig.translates[c.url] as HttpTranslate)(c.data || {})
30
36
  : c.data
31
37
  console.log(`[][][][][]HTTP.${c.method}, ${c.baseUrl}${c.url}`, data)
32
- clientConfig.vendor?.request({
33
- url: `${c.baseUrl}${c.url}`,
34
- data,
35
- headers: c.headers,
36
- method: c.method,
37
- }).then((raw: ResponseRaw) => {
38
- // 按顺序执行拦截器
39
- for (const interc of c.interceptors || []) {
40
- const r = interc(raw)
41
- if (r) {
42
- // 某拦截器命中时
43
- // 按拦截结果 决定是否继续执行
44
- reject('===INTERCEPTED===' + raw.status)
45
- return false
46
- }
47
- }
48
- if (raw.data) {
49
- // 当用户配置含有 transforms 时, 使用用户提供的 transform
50
- // 先 endpoints transform
51
- // 再组装分页数据
52
- const response = clientConfig.transforms
53
- && clientConfig.transforms[c.url]
54
- ? clientConfig.transforms[c.url]?.(raw.data) as T
55
- : raw.data as T
56
- // 前端要求分页
57
- // endpoints transform 之前格式化分页数据
58
- // 并拼装回原 raw 数据
59
- const paging = config.data?.page
60
- ? clientConfig.paging?.transform(raw.data)
61
- : void 0
62
- resolve(
63
- paging
64
- ? {
65
- ...paging,
66
- data: response
67
- } as T
68
- : response
69
- )
70
- } else {
71
- resolve(raw as any)
72
- }
73
- }).catch((e: any) => {
74
- console.log('request.catch===', e)
75
- })
38
+
39
+ clientConfig.vendor &&
40
+ clientConfig.vendor
41
+ .request({
42
+ url: `${c.baseUrl}${c.url}`,
43
+ data,
44
+ headers: c.headers,
45
+ method: c.method,
46
+ })
47
+ .then((raw: ResponseRaw) => {
48
+ // 按顺序执行拦截器
49
+ for (const interc of c.interceptors || []) {
50
+ const r = interc(raw)
51
+ if (r) {
52
+ // 某拦截器命中时
53
+ // 按拦截结果 决定是否继续执行
54
+ reject('===INTERCEPTED===' + raw.status)
55
+ return false
56
+ }
57
+ }
58
+ if (raw.data) {
59
+ // 当用户配置含有 transforms 时, 使用用户提供的 transform
60
+ // endpoints transform
61
+ // 再组装分页数据
62
+ const response =
63
+ clientConfig.transforms && clientConfig.transforms[c.url]
64
+ ? ((clientConfig.transforms[c.url] as HttpTranslate)(raw.data) as T)
65
+ : (raw.data as T)
66
+ // 前端要求分页
67
+ // endpoints transform 之前格式化分页数据
68
+ // 并拼装回原 raw 数据
69
+ const paging = (config.data as RequestData).page
70
+ ? (clientConfig.paging as Paging).transform(raw.data)
71
+ : void 0
72
+ resolve(
73
+ paging
74
+ ? ({
75
+ ...paging,
76
+ data: response,
77
+ } as T)
78
+ : response
79
+ )
80
+ } else {
81
+ resolve(raw as any)
82
+ }
83
+ })
84
+ .catch((e: any) => {
85
+ console.log('request.catch===', e)
86
+ })
76
87
  })
77
88
  }
78
89
 
@@ -80,7 +91,7 @@ const get: HttpInstance['get'] = <T = ResponseData>(url: string, data?: RequestD
80
91
  return request<T>({
81
92
  url,
82
93
  data,
83
- method: HttpMethod.get
94
+ method: HttpMethod.get,
84
95
  })
85
96
  }
86
97
 
@@ -88,7 +99,7 @@ const post: HttpInstance['post'] = <T = ResponseData>(url: string, data: Request
88
99
  return request<T>({
89
100
  url,
90
101
  data,
91
- method: HttpMethod.post
102
+ method: HttpMethod.post,
92
103
  })
93
104
  }
94
105
 
@@ -98,13 +109,11 @@ const post: HttpInstance['post'] = <T = ResponseData>(url: string, data: Request
98
109
  */
99
110
  const defaultClientConfig: HttpClientConfig = {
100
111
  baseUrl: '/',
101
- interceptors: [
102
- (raw) => raw.status == 401
103
- ]
112
+ interceptors: [(raw) => raw.status == 401],
104
113
  }
105
114
 
106
115
  let clientConfig = {
107
- ...defaultClientConfig
116
+ ...defaultClientConfig,
108
117
  }
109
118
 
110
119
  /**
@@ -112,15 +121,15 @@ let clientConfig = {
112
121
  * @param config
113
122
  * @returns
114
123
  */
115
- export function createHttp (config: HttpClientConfig): HttpInstance {
124
+ export function createHttp(config: HttpClientConfig): HttpInstance {
116
125
  clientConfig = {
117
126
  ...defaultClientConfig,
118
- ...config
127
+ ...config,
119
128
  }
120
129
 
121
130
  return {
122
131
  request,
123
132
  get,
124
- post
133
+ post,
125
134
  }
126
135
  }