@yuku123/z-frontend-common 1.1.0 → 1.1.2
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/README.md +22 -10
- package/dist/ComponentDoc-C4XFElke.js +1657 -0
- package/dist/index.js +160 -154
- package/dist/ui-echarts.js +54 -0
- package/dist/ui.js +19 -19
- package/package.json +6 -2
- package/src/components/ui/ComponentDoc.jsx +890 -0
- package/src/components/ui/echarts.js +8 -0
- package/src/components/ui/index.js +3 -2
- package/src/index.js +19 -2
- package/src/services/request.js +19 -5
- package/dist/PagedTable-DyjNokXN.js +0 -1211
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图表子路径 `@yuku123/z-frontend-common/ui/echarts`。
|
|
3
|
+
*
|
|
4
|
+
* EChartsChart 是 ui 目录里唯一依赖 echarts 的组件, 故不进扁平桶:
|
|
5
|
+
* 绝大多数域组件 (z-gw/z-ctc/z-oss/z-msg …) 从不画图, 让它们 resolve echarts/core
|
|
6
|
+
* 会直接构建失败。需要图表的域显式引本子路径并自行声明 echarts 依赖。
|
|
7
|
+
*/
|
|
8
|
+
export {default as EChartsChart} from './EChartsChart.jsx'
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* - ErrorState 错误状态 (原因 + 重试)
|
|
14
14
|
* - LoadingState 骨架屏 (cards/table/list/detail)
|
|
15
15
|
* - SearchInput Debounced 搜索 (300ms, Enter 立即, Esc 清空)
|
|
16
|
-
* - EChartsChart 安全 echarts 包装 (自动 dispose/resize)
|
|
17
16
|
* - PageHeader 页面标题 (面包屑 + 返回 + 操作区)
|
|
18
17
|
*/
|
|
19
18
|
|
|
@@ -27,10 +26,12 @@ export {default as EmptyState} from './EmptyState'
|
|
|
27
26
|
export {default as ErrorState} from './ErrorState'
|
|
28
27
|
export {default as LoadingState} from './LoadingState'
|
|
29
28
|
export {default as SearchInput} from './SearchInput'
|
|
30
|
-
|
|
29
|
+
// EChartsChart 走 ./echarts 子路径: 它是本目录唯一引 echarts 的组件,
|
|
31
30
|
export {default as PageHeader} from './PageHeader'
|
|
32
31
|
export {default as TableToolbar, RefreshButton} from './TableToolbar'
|
|
33
32
|
export {default as StatusBadge} from './StatusBadge'
|
|
34
33
|
export {default as PagedTable} from './PagedTable'
|
|
34
|
+
// ComponentDoc - 组件文档页(§7):左侧 240px TOC + 右侧正文,各仓只提供 DOC.md
|
|
35
|
+
export {default as ComponentDoc} from './ComponentDoc'
|
|
35
36
|
|
|
36
37
|
export {brand, palette, neutral, radius, shadow, lift, space, fontSize, antdTheme} from './tokens'
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* z-frontend-common 桶导出 —— lead 008 前端开发规范唯一承载仓。
|
|
3
3
|
*
|
|
4
|
-
* 40
|
|
4
|
+
* 40 个 suit 的 AppLayout / LoginPage 唯一来源;31 个 <repo>-component 的
|
|
5
5
|
* services 层消费 createRequest / request / authRequest。
|
|
6
6
|
*
|
|
7
7
|
* API 契约与 0.1.1 完全兼容(ErrorBoundary / LoginPage / StatusTag /
|
|
@@ -26,7 +26,18 @@ import { createRequest, setupInterceptors, unwrapResponse, request, authRequest
|
|
|
26
26
|
export { createRequest, setupInterceptors, unwrapResponse, request, authRequest }
|
|
27
27
|
|
|
28
28
|
// 0.1.1 default 桶契约原样保留(Ge 对象),老调用方 `import zfc from '@yuku123/z-frontend-common'` 不断
|
|
29
|
-
|
|
29
|
+
//
|
|
30
|
+
// ⚠ 桶额外**转发 axios 的 HTTP 动词方法**(get/post/put/patch/delete/head/options)。
|
|
31
|
+
// 起因:仓里有 6 个包的 services/api.js 写的是「默认导入当 axios 实例用」——
|
|
32
|
+
// `import request from '@yuku123/z-frontend-common'` 然后 `request.get('/xxx')`,
|
|
33
|
+
// 而默认导出是桶对象 ⇒ request.get 不存在 ⇒ 一调就抛
|
|
34
|
+
// "TypeError: Xt.get is not a function"(线上 /msg/inbox 白屏就是它,2026-10-20 实测)。
|
|
35
|
+
// 那 6 个包的 dist 已发到 npm(z-oss / z-mq / z-gw / z-cache / z-graph / z-msg),
|
|
36
|
+
// 改它们要逐个重新发版;这里在桶上补一层转发,让「默认导入当 axios 用」的老写法继续能跑。
|
|
37
|
+
// 逐个转发(而不是 Object.assign(bucket, request)):axios 实例自己也有个 .request 方法,
|
|
38
|
+
// 整包 assign 会把桶里 request=「axios 实例」这个契约覆盖成 axios 的 request 方法。
|
|
39
|
+
const httpVerbs = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options']
|
|
40
|
+
const bucket = {
|
|
30
41
|
AppLayout,
|
|
31
42
|
StatusTag,
|
|
32
43
|
defaultStatusMap,
|
|
@@ -36,3 +47,9 @@ export default {
|
|
|
36
47
|
authRequest,
|
|
37
48
|
createRequest,
|
|
38
49
|
}
|
|
50
|
+
for (const verb of httpVerbs) {
|
|
51
|
+
if (typeof request[verb] === 'function' && !(verb in bucket)) {
|
|
52
|
+
bucket[verb] = (...args) => request[verb](...args)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export default bucket
|
package/src/services/request.js
CHANGED
|
@@ -17,7 +17,7 @@ export function unwrapResponse(body) {
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* axios 拦截器装配(request / authRequest 预建实例与 createRequest 工厂共用)。
|
|
20
|
-
* 与 0.1.1 的 API 契约逐字段一致,
|
|
20
|
+
* 与 0.1.1 的 API 契约逐字段一致,31 个 component 仓的 services 层在消费,不能改签名。
|
|
21
21
|
*/
|
|
22
22
|
export function setupInterceptors(instance, options = {}) {
|
|
23
23
|
const {
|
|
@@ -37,9 +37,23 @@ export function setupInterceptors(instance, options = {}) {
|
|
|
37
37
|
(error) => {
|
|
38
38
|
const status = error.response?.status
|
|
39
39
|
if (status === 401) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
// ⚠ 401 有两种含义,HTTP 码一样但语义相反,必须分开:
|
|
41
|
+
// 会话 401(平台 SSO 层): {"success":false,"code":401,"message":"未登录或Token无效","data":null}
|
|
42
|
+
// 业务 401(子域自己的凭据/口径): {"success":false,"errorCode":"MISSING_API_KEY","message":"..."}
|
|
43
|
+
// 业务 401 **不是**平台会话过期 —— 清 token 跳登录会把人直接踢出系统。
|
|
44
|
+
// 实测(2026-10-20):z-script 的 /api/script/** 被它自己的 ApiKeyAuthInterceptor
|
|
45
|
+
// 拦成 401 MISSING_API_KEY,一进 /script/manage 就被踢回 /login
|
|
46
|
+
// (运维面当年为此把该页从菜单里摘掉了)。
|
|
47
|
+
// 判据用「响应体带 errorCode」:平台会话 401 不带 errorCode,业务 401 带 —— 互斥,不会误伤真会话失效。
|
|
48
|
+
const body = error.response?.data
|
|
49
|
+
const isBusiness401 = !!(body && typeof body === 'object' && body.errorCode)
|
|
50
|
+
if (isBusiness401) {
|
|
51
|
+
console.warn(`[401] 业务鉴权失败(不是会话过期,不跳登录): ${error.config?.url} → ${body.errorCode}`)
|
|
52
|
+
} else {
|
|
53
|
+
localStorage.removeItem(tokenKey)
|
|
54
|
+
localStorage.removeItem(userInfoKey)
|
|
55
|
+
window.location.href = unauthorizedRedirect
|
|
56
|
+
}
|
|
43
57
|
} else if (status === 403) {
|
|
44
58
|
console.error('没有权限访问该资源')
|
|
45
59
|
} else if (status === 500) {
|
|
@@ -52,7 +66,7 @@ export function setupInterceptors(instance, options = {}) {
|
|
|
52
66
|
}
|
|
53
67
|
|
|
54
68
|
/**
|
|
55
|
-
* axios 实例工厂 ——
|
|
69
|
+
* axios 实例工厂 —— 31 个 <repo>-component 的 services/api.js 用它建各自的请求实例。
|
|
56
70
|
* @param {Object} options
|
|
57
71
|
* @param {string} [options.baseURL='/api']
|
|
58
72
|
* @param {number} [options.timeout=10000]
|