@talknote/create-talknote-h5 0.0.9 → 0.1.0

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
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "registry": "https://registry.npmjs.org/"
6
6
  },
7
- "version": "0.0.9",
7
+ "version": "0.1.0",
8
8
  "description": "Create a Talknote Alita H5 project.",
9
9
  "license": "MIT",
10
10
  "private": false,
@@ -1,10 +1,10 @@
1
1
  <h1 align="center">Alita Pro</h1>
2
2
 
3
- 帮助你快速使用 alita
3
+ 帮助你快速使用 alita, 基于Umi 的移动端开发框架
4
4
 
5
5
  ```
6
- pnpm i
7
- pnpm start
6
+ yarn
7
+ yarn dev
8
8
  ```
9
9
 
10
10
  ### 首页
@@ -132,13 +132,13 @@ useEffect(() => {
132
132
  ### 格式化
133
133
 
134
134
  ```
135
- pnpm format
135
+ yarn format
136
136
  ```
137
137
 
138
138
  ### 构建
139
139
 
140
140
  ```
141
- pnpm build
141
+ yarn build
142
142
  ```
143
143
 
144
144
  ### 调试工具
@@ -21,7 +21,7 @@
21
21
  ]
22
22
  },
23
23
  "dependencies": {
24
- "@talknote/h5-bridge":"^0.0.3",
24
+ "@talknote/h5-bridge":"^0.0.4",
25
25
  "@alita/flow": "^3.1.1",
26
26
  "alita": "^3.2.27",
27
27
  "antd-mobile": "^5.15.1",
@@ -10,14 +10,41 @@ import type {
10
10
  TabBarProps,
11
11
  TitleListItem,
12
12
  } from 'alita';
13
- import TalkNoteH5Bridge from '@talknote/h5-bridge';
13
+ import TalkNoteH5Bridge, { type RequestBaseInfo } from '@talknote/h5-bridge';
14
+
15
+ // 缓存原生请求信息,避免每次请求都调用 bridge
16
+ let cachedRequestInfo: RequestBaseInfo | null = null;
17
+
18
+ async function getRequestInfo(): Promise<RequestBaseInfo | null> {
19
+ if (cachedRequestInfo) return cachedRequestInfo;
20
+ try {
21
+ cachedRequestInfo = await TalkNoteH5Bridge.getRequestBaseInfo();
22
+ return cachedRequestInfo;
23
+ } catch (error) {
24
+ console.error('获取原生请求信息失败:', error);
25
+ return null;
26
+ }
27
+ }
14
28
 
15
29
  export const request = {
16
- prefix: '/api',
30
+ prefix: '',
17
31
  method: 'get',
32
+ requestInterceptors: [
33
+ async (url: string, options: any) => {
34
+ const info = await getRequestInfo();
35
+ if (info) {
36
+ const headers: Record<string, string> = { ...(info.headers || {}) };
37
+ if (!headers.token && info.token) {
38
+ headers.Authorization = info.token;
39
+ }
40
+ // 业务请求自带的 header 优先级更高
41
+ options.headers = { ...headers, ...(options.headers || {}) };
42
+ }
43
+ return { url, options };
44
+ },
45
+ ],
18
46
  errorHandler: (error: ResponseError) => {
19
47
  // 集中处理错误
20
- console.log(11111111);
21
48
  console.log(error);
22
49
  },
23
50
  };