ztxkui 4.2.18-53 → 4.2.18-55
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/components/utils/fetch.d.ts +10 -0
- package/dist/components/utils/fetch.js +119 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/locales/en-US.json +809 -0
- package/dist/locales/zh-CN.json +809 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function customFetch(url: any, options: any): Promise<unknown>;
|
|
2
|
+
export declare function catchHandle(data: {
|
|
3
|
+
customKey: string;
|
|
4
|
+
customValue: string;
|
|
5
|
+
mark: string;
|
|
6
|
+
}, idKey?: string): Promise<unknown>;
|
|
7
|
+
export declare function parseJwt(token: any): {
|
|
8
|
+
header: any;
|
|
9
|
+
payload: any;
|
|
10
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { getToken } from 'ztxkutils/dist/authority';
|
|
13
|
+
export function customFetch(url, options) {
|
|
14
|
+
// 检查原生 fetch 是否存在
|
|
15
|
+
if (window.fetch) {
|
|
16
|
+
return fetch(url, options);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// 使用 XMLHttpRequest 来模拟 fetch
|
|
20
|
+
return new Promise(function (resolve, reject) {
|
|
21
|
+
var xhr = new XMLHttpRequest();
|
|
22
|
+
xhr.open(options && options.method ? options.method : 'GET', url);
|
|
23
|
+
// 设置请求头
|
|
24
|
+
if (options && options.headers) {
|
|
25
|
+
Object.keys(options.headers).forEach(function (key) {
|
|
26
|
+
xhr.setRequestHeader(key, options.headers[key]);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
xhr.onload = function () {
|
|
30
|
+
var response = {
|
|
31
|
+
ok: xhr.status >= 200 && xhr.status < 300,
|
|
32
|
+
status: xhr.status,
|
|
33
|
+
statusText: xhr.statusText,
|
|
34
|
+
url: xhr.responseURL,
|
|
35
|
+
text: function () { return Promise.resolve(xhr.responseText); },
|
|
36
|
+
json: function () { return Promise.resolve(JSON.parse(xhr.responseText)); },
|
|
37
|
+
blob: function () { return Promise.resolve(new Blob([xhr.response])); },
|
|
38
|
+
clone: function () { return response; },
|
|
39
|
+
headers: {
|
|
40
|
+
get: function (name) { return xhr.getResponseHeader(name); },
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
resolve(response);
|
|
44
|
+
};
|
|
45
|
+
xhr.onerror = function () {
|
|
46
|
+
reject(new TypeError('Network request failed'));
|
|
47
|
+
};
|
|
48
|
+
xhr.ontimeout = function () {
|
|
49
|
+
reject(new TypeError('Network request failed: timeout'));
|
|
50
|
+
};
|
|
51
|
+
// 设置请求体
|
|
52
|
+
if (options && options.body) {
|
|
53
|
+
xhr.send(options.body);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
xhr.send();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// 缓存数据变更、新增
|
|
62
|
+
export function catchHandle(data, idKey) {
|
|
63
|
+
// const id = window.localStorage.getItem(idKey);
|
|
64
|
+
var token = getToken();
|
|
65
|
+
var payload = (parseJwt(token) || {}).payload;
|
|
66
|
+
// if (id) {
|
|
67
|
+
// customFetch('/api/zmdms-user/user-custom/update', {
|
|
68
|
+
// method: 'POST',
|
|
69
|
+
// body: JSON.stringify({
|
|
70
|
+
// id,
|
|
71
|
+
// systemCategory: '1',
|
|
72
|
+
// userId: payload?.user_id,
|
|
73
|
+
// userName: payload?.real_name,
|
|
74
|
+
// ...data,
|
|
75
|
+
// }),
|
|
76
|
+
// headers: {
|
|
77
|
+
// 'Content-Type': 'application/json',
|
|
78
|
+
// 'Zmdms-Auth': token,
|
|
79
|
+
// },
|
|
80
|
+
// });
|
|
81
|
+
// } else {
|
|
82
|
+
// 不需要修改
|
|
83
|
+
return customFetch('/api/zmdms-user/user-custom/save', {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
body: JSON.stringify(__assign({ systemCategory: '1', userId: payload === null || payload === void 0 ? void 0 : payload.user_id, userName: payload === null || payload === void 0 ? void 0 : payload.real_name }, data)),
|
|
86
|
+
headers: {
|
|
87
|
+
'Content-Type': 'application/json',
|
|
88
|
+
'Zmdms-Auth': token,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
// }
|
|
92
|
+
}
|
|
93
|
+
export function parseJwt(token) {
|
|
94
|
+
try {
|
|
95
|
+
var base64UrlDecode = function (str) {
|
|
96
|
+
// 将 Base64Url 编码转换为 Base64 编码
|
|
97
|
+
var base64 = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
98
|
+
// 对 Base64 编码的字符串进行解码
|
|
99
|
+
var jsonPayload = decodeURIComponent(atob(base64)
|
|
100
|
+
.split('')
|
|
101
|
+
.map(function (c) {
|
|
102
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
103
|
+
})
|
|
104
|
+
.join(''));
|
|
105
|
+
return JSON.parse(jsonPayload);
|
|
106
|
+
};
|
|
107
|
+
var parts = token.split('.');
|
|
108
|
+
if (parts.length !== 3) {
|
|
109
|
+
throw new Error('The token is invalid');
|
|
110
|
+
}
|
|
111
|
+
var header = base64UrlDecode(parts[0]);
|
|
112
|
+
var payload = base64UrlDecode(parts[1]);
|
|
113
|
+
return { header: header, payload: payload };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error('Failed to parse JWT:', error);
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -54,3 +54,5 @@ export { default as Watermark } from './components/Watermark';
|
|
|
54
54
|
export { ConfigProvider, Drawer, Space, Grid, Divider, Dropdown, Badge, List, Result, Spin, Popconfirm, TreeSelect, Tree, Progress, Cascader, Tooltip, Descriptions, Image, Popover, Breadcrumb, Transfer, Row, Col, notification, Slider, Rate, Affix, } from 'antd';
|
|
55
55
|
export { default as zhCN } from 'antd/lib/locale/zh_CN';
|
|
56
56
|
export { default as Icon, createFromIconfontCN } from '@ant-design/icons';
|
|
57
|
+
export { default as ztxkuiZhCn } from './locales/zh-CN.json';
|
|
58
|
+
export { default as ztxkuiEnUs } from './locales/en-US.json';
|
package/dist/index.js
CHANGED
|
@@ -172,3 +172,5 @@ export { default as Watermark } from './components/Watermark';
|
|
|
172
172
|
export { ConfigProvider, Drawer, Space, Grid, Divider, Dropdown, Badge, List, Result, Spin, Popconfirm, TreeSelect, Tree, Progress, Cascader, Tooltip, Descriptions, Image, Popover, Breadcrumb, Transfer, Row, Col, notification, Slider, Rate, Affix, } from 'antd';
|
|
173
173
|
export { default as zhCN } from 'antd/lib/locale/zh_CN';
|
|
174
174
|
export { default as Icon, createFromIconfontCN } from '@ant-design/icons';
|
|
175
|
+
export { default as ztxkuiZhCn } from './locales/zh-CN.json';
|
|
176
|
+
export { default as ztxkuiEnUs } from './locales/en-US.json';
|