@lark-apaas/client-toolkit 1.1.35 → 1.1.36
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/lib/utils/axiosConfig.js
CHANGED
|
@@ -131,15 +131,17 @@ function initAxiosConfig(axiosInstance) {
|
|
|
131
131
|
if (!axiosInstance) axiosInstance = axios;
|
|
132
132
|
axiosInstance.interceptors.request.use((config)=>{
|
|
133
133
|
const requestUUID = crypto.randomUUID();
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
135
|
+
const stacktrace = getStacktrace();
|
|
136
|
+
requestStacktraceMap.set(requestUUID, stacktrace);
|
|
137
|
+
}
|
|
136
138
|
config._requestUUID = requestUUID;
|
|
137
139
|
config._startTime = Date.now();
|
|
138
140
|
const csrfToken = window.csrfToken;
|
|
139
141
|
if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
|
|
140
142
|
return config;
|
|
141
143
|
}, (error)=>Promise.reject(error));
|
|
142
|
-
axiosInstance.interceptors.response.use((response)=>{
|
|
144
|
+
'production' !== process.env.NODE_ENV && axiosInstance.interceptors.response.use((response)=>{
|
|
143
145
|
logResponse('success', response);
|
|
144
146
|
return response;
|
|
145
147
|
}, (error)=>{
|
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { initAxiosConfig } from "./axiosConfig.js";
|
|
3
3
|
let axiosInstance;
|
|
4
|
+
function showToast(message, duration = 3000) {
|
|
5
|
+
return new Promise((resolve)=>{
|
|
6
|
+
const toast = document.createElement('div');
|
|
7
|
+
const iconSvg = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M8 1.333a6.667 6.667 0 1 1 0 13.334A6.667 6.667 0 0 1 8 1.333ZM8 10a.667.667 0 1 0 0 1.333A.667.667 0 0 0 8 10Zm0-5.333a.667.667 0 0 0-.667.666v3.334a.667.667 0 0 0 1.334 0V5.333A.667.667 0 0 0 8 4.667Z" fill="#ff811a"/>
|
|
9
|
+
</svg>`;
|
|
10
|
+
const iconWrapper = document.createElement('span');
|
|
11
|
+
iconWrapper.innerHTML = iconSvg;
|
|
12
|
+
Object.assign(iconWrapper.style, {
|
|
13
|
+
display: 'flex',
|
|
14
|
+
alignItems: 'center',
|
|
15
|
+
marginRight: '8px',
|
|
16
|
+
flexShrink: '0'
|
|
17
|
+
});
|
|
18
|
+
const textWrapper = document.createElement('span');
|
|
19
|
+
textWrapper.textContent = message;
|
|
20
|
+
toast.appendChild(iconWrapper);
|
|
21
|
+
toast.appendChild(textWrapper);
|
|
22
|
+
Object.assign(toast.style, {
|
|
23
|
+
position: 'fixed',
|
|
24
|
+
top: '20%',
|
|
25
|
+
left: '50%',
|
|
26
|
+
transform: 'translate(-50%, -50%)',
|
|
27
|
+
display: 'flex',
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
padding: '12px 16px',
|
|
30
|
+
backgroundColor: '#fff',
|
|
31
|
+
color: '#1f2329',
|
|
32
|
+
border: '1px solid #dee0e3',
|
|
33
|
+
borderRadius: '6px',
|
|
34
|
+
fontSize: '14px',
|
|
35
|
+
lineHeight: '1.5',
|
|
36
|
+
zIndex: '99999',
|
|
37
|
+
maxWidth: '80vw',
|
|
38
|
+
wordBreak: 'break-word',
|
|
39
|
+
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.03), 0 3px 6px rgba(0, 0, 0, 0.05), 0 6px 18px rgba(0, 0, 0, 0.03)',
|
|
40
|
+
opacity: '0',
|
|
41
|
+
transition: 'opacity 0.3s ease'
|
|
42
|
+
});
|
|
43
|
+
document.body.appendChild(toast);
|
|
44
|
+
requestAnimationFrame(()=>{
|
|
45
|
+
toast.style.opacity = '1';
|
|
46
|
+
});
|
|
47
|
+
setTimeout(()=>{
|
|
48
|
+
toast.style.opacity = '0';
|
|
49
|
+
setTimeout(()=>{
|
|
50
|
+
document.body.removeChild(toast);
|
|
51
|
+
resolve();
|
|
52
|
+
}, 300);
|
|
53
|
+
}, duration);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
4
56
|
function getAxiosForBackend() {
|
|
5
57
|
if (!axiosInstance) {
|
|
6
58
|
axiosInstance = axios.create({
|
|
@@ -9,7 +61,9 @@ function getAxiosForBackend() {
|
|
|
9
61
|
axiosInstance.interceptors.response.use(null, (err)=>{
|
|
10
62
|
if (err.config.meta?.autoJumpToLogin !== false) {
|
|
11
63
|
const loginUrl = err.response?.headers?.['x-login-url'];
|
|
12
|
-
if (loginUrl)
|
|
64
|
+
if (loginUrl) showToast('需要登录后才能执行操作,将自动跳转登录页', 3000).then(()=>{
|
|
65
|
+
window.location.href = loginUrl;
|
|
66
|
+
});
|
|
13
67
|
}
|
|
14
68
|
return Promise.reject(err);
|
|
15
69
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.36",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@ant-design/colors": "^7.2.1",
|
|
82
82
|
"@ant-design/cssinjs": "^1.24.0",
|
|
83
83
|
"@data-loom/js": "^0.4.3",
|
|
84
|
-
"@lark-apaas/miaoda-inspector": "^1.0.
|
|
84
|
+
"@lark-apaas/miaoda-inspector": "^1.0.9",
|
|
85
85
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
86
86
|
"@radix-ui/react-popover": "^1.1.15",
|
|
87
87
|
"@radix-ui/react-slot": "^1.2.3",
|