@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 +1 -1
- package/template/README.md +5 -5
- package/template/package.json +1 -1
- package/template/src/app.tsx +30 -3
package/package.json
CHANGED
package/template/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<h1 align="center">Alita Pro</h1>
|
|
2
2
|
|
|
3
|
-
帮助你快速使用 alita
|
|
3
|
+
帮助你快速使用 alita, 基于Umi 的移动端开发框架
|
|
4
4
|
|
|
5
5
|
```
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
yarn
|
|
7
|
+
yarn dev
|
|
8
8
|
```
|
|
9
9
|
|
|
10
10
|
### 首页
|
|
@@ -132,13 +132,13 @@ useEffect(() => {
|
|
|
132
132
|
### 格式化
|
|
133
133
|
|
|
134
134
|
```
|
|
135
|
-
|
|
135
|
+
yarn format
|
|
136
136
|
```
|
|
137
137
|
|
|
138
138
|
### 构建
|
|
139
139
|
|
|
140
140
|
```
|
|
141
|
-
|
|
141
|
+
yarn build
|
|
142
142
|
```
|
|
143
143
|
|
|
144
144
|
### 调试工具
|
package/template/package.json
CHANGED
package/template/src/app.tsx
CHANGED
|
@@ -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: '
|
|
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
|
};
|