@npm.365xs.cn/vue-admin-framework 0.1.0 → 0.2.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/README.md +91 -63
- package/dist/access.d.ts +43 -0
- package/dist/components/AdminFrameworkLayout.vue.d.ts +2 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +702 -466
- package/dist/navigation.d.ts +6 -0
- package/dist/oauth.d.ts +4 -1
- package/dist/session.d.ts +32 -0
- package/package.json +37 -37
package/README.md
CHANGED
|
@@ -1,63 +1,91 @@
|
|
|
1
|
-
# @
|
|
2
|
-
|
|
3
|
-
Vue 3
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Vue 3、Vue Router、Element Plus 和 `@element-plus/icons-vue`。
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
# @npm.365xs.cn/vue-admin-framework
|
|
2
|
+
|
|
3
|
+
向上集团 Vue 3 公共管理后台框架。包统一提供 OAuth 2.0 Authorization Code + PKCE、
|
|
4
|
+
标准当前用户与全应用菜单读取、会话状态、动态侧栏、顶部用户区和访问页签。
|
|
5
|
+
|
|
6
|
+
消费应用只负责业务 Router、`admin-resources.json`、Mock 数据、品牌配置和业务页面。项目
|
|
7
|
+
需要安装 Vue 3、Vue Router、Element Plus 和 `@element-plus/icons-vue`。
|
|
8
|
+
|
|
9
|
+
## 标准 Access API
|
|
10
|
+
|
|
11
|
+
真实模式下由 `createAdminFrameworkSession` 内部统一调用:
|
|
12
|
+
|
|
13
|
+
```http
|
|
14
|
+
GET /api/current/me
|
|
15
|
+
GET /api/me/menus
|
|
16
|
+
Authorization: Bearer <application-access-token>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`/api/me/menus` 不带 `applicationCode`,必须返回 `applicationCode: null` 的全应用菜单。
|
|
20
|
+
公共包统一处理 Bearer Header、有效 Token 获取、401 单次刷新、响应校验、菜单规范化、
|
|
21
|
+
顶部用户信息和菜单加载状态。消费应用不得重复实现这两个标准客户端。
|
|
22
|
+
|
|
23
|
+
## 安装
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @npm.365xs.cn/vue-admin-framework
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
应用入口同时引入样式:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import '@npm.365xs.cn/vue-admin-framework/style.css'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Session 接入
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { defineStore } from 'pinia'
|
|
39
|
+
import { createAdminFrameworkSession } from '@npm.365xs.cn/vue-admin-framework'
|
|
40
|
+
import { oauthClient } from '@/services/auth'
|
|
41
|
+
import { mockMenus, mockUser } from '@/config/resources'
|
|
42
|
+
|
|
43
|
+
export const useSessionStore = defineStore('session', () =>
|
|
44
|
+
createAdminFrameworkSession({
|
|
45
|
+
oauthClient,
|
|
46
|
+
accessApiBaseUrl: import.meta.env.VITE_ACCESS_API_BASE_URL || '',
|
|
47
|
+
mockUser,
|
|
48
|
+
mockMenus,
|
|
49
|
+
defaultReturnUrl: '/admin/overview',
|
|
50
|
+
storageKeysToClear: ['admin_visited_tabs'],
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
路由守卫使用 `session.ensureAuthenticated()`、`session.login()` 和
|
|
56
|
+
`session.ensureLoaded()`;布局直接绑定 `session.menus`、`session.username`、
|
|
57
|
+
`session.loginAccount`、`session.initials`、`session.navigationLoaded` 和
|
|
58
|
+
`session.navigationError`。
|
|
59
|
+
|
|
60
|
+
## 跨应用单点登录
|
|
61
|
+
|
|
62
|
+
每个应用必须使用独立 OAuth Client、PKCE、本地 Access Token 和 Audience。禁止复制或共享
|
|
63
|
+
Access Token,也禁止把 Token 放入 URL、父域 Cookie 或跨应用共享存储。
|
|
64
|
+
|
|
65
|
+
跨应用免重复输入密码依赖 OAuth Authority 的 HttpOnly SSO Cookie:目标应用没有本地 Token
|
|
66
|
+
时仍进入标准 `/oauth2/authorize`,Authority 识别已有登录会话后直接签发目标应用授权码,
|
|
67
|
+
目标应用再换取自己的 Token。显式切换账号或退出当前应用后重新登录时,框架使用
|
|
68
|
+
`prompt=login` 强制展示登录页。
|
|
69
|
+
|
|
70
|
+
## 菜单与跨应用导航
|
|
71
|
+
|
|
72
|
+
菜单节点类型 `FrameworkMenuNode` 可携带 `menuDomain?: string | null`,表示所属应用 Origin。
|
|
73
|
+
公共包保留并规范化该字段,但不会把外部菜单注册到本地 Router。消费应用应使用
|
|
74
|
+
`createExternalMenuHrefResolver` 安全解析其他应用的 `menuDomain + route`,并通过整页跳转
|
|
75
|
+
进入目标应用。
|
|
76
|
+
|
|
77
|
+
## 发布产物
|
|
78
|
+
|
|
79
|
+
包只发布 ESM,并包含:
|
|
80
|
+
|
|
81
|
+
- `dist/index.js`
|
|
82
|
+
- `dist/index.d.ts`
|
|
83
|
+
- `dist/style.css`
|
|
84
|
+
- 组件和公共类型声明
|
|
85
|
+
|
|
86
|
+
发布前运行:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm run build
|
|
90
|
+
npm pack --dry-run
|
|
91
|
+
```
|
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { FrameworkMenuNode } from './menu';
|
|
2
|
+
import type { OAuthPkceClient } from './oauth';
|
|
3
|
+
export interface FrameworkRelationSummary {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface FrameworkCurrentUser {
|
|
9
|
+
userId: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
username: string;
|
|
12
|
+
loginAccount: string;
|
|
13
|
+
employeeNo: string;
|
|
14
|
+
mobile: string;
|
|
15
|
+
email: string;
|
|
16
|
+
status: string;
|
|
17
|
+
organizations: FrameworkRelationSummary[];
|
|
18
|
+
roles: FrameworkRelationSummary[];
|
|
19
|
+
lastLoginAt: string;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
}
|
|
22
|
+
export interface VisibleMenusResponse {
|
|
23
|
+
applicationCode: null;
|
|
24
|
+
menus: FrameworkMenuNode[];
|
|
25
|
+
tokenExpiresAt: string;
|
|
26
|
+
}
|
|
27
|
+
export interface AdminAccessClientOptions {
|
|
28
|
+
oauthClient: OAuthPkceClient;
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
fetcher?: typeof fetch;
|
|
31
|
+
}
|
|
32
|
+
export interface AdminAccessClient {
|
|
33
|
+
getCurrentUser(): Promise<FrameworkCurrentUser>;
|
|
34
|
+
getCurrentMenus(): Promise<FrameworkMenuNode[]>;
|
|
35
|
+
}
|
|
36
|
+
export declare class AdminAccessError extends Error {
|
|
37
|
+
readonly status: number;
|
|
38
|
+
readonly code: string;
|
|
39
|
+
readonly requestId: string;
|
|
40
|
+
constructor(message: string, status: number, code?: string, requestId?: string);
|
|
41
|
+
}
|
|
42
|
+
export declare function createAdminAccessClient(options: AdminAccessClientOptions): AdminAccessClient;
|
|
43
|
+
export declare function normalizeCurrentUser(value: unknown): FrameworkCurrentUser;
|
|
@@ -24,12 +24,12 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
24
24
|
onSettings?: (() => any) | undefined;
|
|
25
25
|
onNotifications?: (() => any) | undefined;
|
|
26
26
|
}>, {
|
|
27
|
+
username: string;
|
|
28
|
+
loginAccount: string;
|
|
27
29
|
resolveExternalMenuHref: (item: FrameworkMenuNode) => string | null;
|
|
28
30
|
brandSubtitle: string;
|
|
29
31
|
consoleName: string;
|
|
30
32
|
navigationError: string;
|
|
31
|
-
username: string;
|
|
32
|
-
loginAccount: string;
|
|
33
33
|
initials: string;
|
|
34
34
|
tabStorageKey: string;
|
|
35
35
|
maxTabs: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export { default as AdminFrameworkLayout } from './components/AdminFrameworkLayout.vue';
|
|
2
2
|
export { default as FrameworkMenuItem } from './components/FrameworkMenuItem.vue';
|
|
3
3
|
export { default as OAuthCallbackView } from './views/OAuthCallbackView.vue';
|
|
4
|
+
export { AdminAccessError, createAdminAccessClient, normalizeCurrentUser, } from './access';
|
|
5
|
+
export type { AdminAccessClient, AdminAccessClientOptions, FrameworkCurrentUser, FrameworkRelationSummary, VisibleMenusResponse, } from './access';
|
|
4
6
|
export type { FrameworkMenuNode } from './menu';
|
|
5
|
-
export { findMenuByRoute, findMenuTrail, flattenRoutableMenus, } from './navigation';
|
|
7
|
+
export { createExternalMenuHrefResolver, findMenuByRoute, findMenuTrail, flattenRoutableMenus, hasPageAccess, normalizeFrameworkMenus, } from './navigation';
|
|
6
8
|
export { createOAuthPkceClient, sanitizeReturnUrl, } from './oauth';
|
|
7
|
-
export type { OAuthLocation, OAuthPkceClient, OAuthPkceClientOptions, OAuthSession, } from './oauth';
|
|
9
|
+
export type { OAuthLocation, OAuthLoginOptions, OAuthPkceClient, OAuthPkceClientOptions, OAuthSession, } from './oauth';
|
|
10
|
+
export { createAdminFrameworkSession, } from './session';
|
|
11
|
+
export type { AdminFrameworkSession, AdminFrameworkSessionOptions, } from './session';
|
|
8
12
|
export { sha256 } from './sha256';
|
|
9
13
|
export { closeVisitedTab, normalizeVisitedTabs, retainActiveTab, upsertVisitedTab, } from './tabs';
|
|
10
14
|
export type { ClosedTabResult, FrameworkTab, } from './tabs';
|