@blocklet/ui-react 3.1.48 → 3.1.49
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/.aigne/doc-smith/config.yaml +76 -0
- package/.aigne/doc-smith/history.yaml +9 -0
- package/.aigne/doc-smith/output/structure-plan.json +249 -0
- package/.aigne/doc-smith/upload-cache.yaml +528 -0
- package/docs/_sidebar.md +19 -0
- package/docs/components-component-management-blocklet-studio.ja.md +194 -0
- package/docs/components-component-management-blocklet-studio.md +194 -0
- package/docs/components-component-management-blocklet-studio.zh-TW.md +194 -0
- package/docs/components-component-management-blocklet-studio.zh.md +194 -0
- package/docs/components-component-management-component-installer.ja.md +256 -0
- package/docs/components-component-management-component-installer.md +256 -0
- package/docs/components-component-management-component-installer.zh-TW.md +256 -0
- package/docs/components-component-management-component-installer.zh.md +256 -0
- package/docs/components-component-management.ja.md +59 -0
- package/docs/components-component-management.md +59 -0
- package/docs/components-component-management.zh-TW.md +59 -0
- package/docs/components-component-management.zh.md +59 -0
- package/docs/components-layout-dashboard.ja.md +231 -0
- package/docs/components-layout-dashboard.md +231 -0
- package/docs/components-layout-dashboard.zh-TW.md +231 -0
- package/docs/components-layout-dashboard.zh.md +231 -0
- package/docs/components-layout-footer.ja.md +165 -0
- package/docs/components-layout-footer.md +165 -0
- package/docs/components-layout-footer.zh-TW.md +165 -0
- package/docs/components-layout-footer.zh.md +165 -0
- package/docs/components-layout-header.ja.md +233 -0
- package/docs/components-layout-header.md +233 -0
- package/docs/components-layout-header.zh-TW.md +233 -0
- package/docs/components-layout-header.zh.md +233 -0
- package/docs/components-layout.ja.md +50 -0
- package/docs/components-layout.md +50 -0
- package/docs/components-layout.zh-TW.md +50 -0
- package/docs/components-layout.zh.md +50 -0
- package/docs/components-notifications.ja.md +173 -0
- package/docs/components-notifications.md +173 -0
- package/docs/components-notifications.zh-TW.md +174 -0
- package/docs/components-notifications.zh.md +173 -0
- package/docs/components-user-management-user-center.ja.md +183 -0
- package/docs/components-user-management-user-center.md +183 -0
- package/docs/components-user-management-user-center.zh-TW.md +183 -0
- package/docs/components-user-management-user-center.zh.md +183 -0
- package/docs/components-user-management-user-sessions.ja.md +164 -0
- package/docs/components-user-management-user-sessions.md +164 -0
- package/docs/components-user-management-user-sessions.zh-TW.md +164 -0
- package/docs/components-user-management-user-sessions.zh.md +164 -0
- package/docs/components-user-management.ja.md +76 -0
- package/docs/components-user-management.md +76 -0
- package/docs/components-user-management.zh-TW.md +76 -0
- package/docs/components-user-management.zh.md +76 -0
- package/docs/components-utilities-icon.ja.md +106 -0
- package/docs/components-utilities-icon.md +106 -0
- package/docs/components-utilities-icon.zh-TW.md +106 -0
- package/docs/components-utilities-icon.zh.md +106 -0
- package/docs/components-utilities.ja.md +136 -0
- package/docs/components-utilities.md +136 -0
- package/docs/components-utilities.zh-TW.md +136 -0
- package/docs/components-utilities.zh.md +136 -0
- package/docs/components.ja.md +27 -0
- package/docs/components.md +27 -0
- package/docs/components.zh-TW.md +27 -0
- package/docs/components.zh.md +27 -0
- package/docs/core-concepts.ja.md +164 -0
- package/docs/core-concepts.md +164 -0
- package/docs/core-concepts.zh-TW.md +164 -0
- package/docs/core-concepts.zh.md +164 -0
- package/docs/getting-started.ja.md +132 -0
- package/docs/getting-started.md +132 -0
- package/docs/getting-started.zh-TW.md +132 -0
- package/docs/getting-started.zh.md +132 -0
- package/docs/hooks-api.ja.md +214 -0
- package/docs/hooks-api.md +214 -0
- package/docs/hooks-api.zh-TW.md +214 -0
- package/docs/hooks-api.zh.md +214 -0
- package/docs/how-to-guides.ja.md +413 -0
- package/docs/how-to-guides.md +413 -0
- package/docs/how-to-guides.zh-TW.md +413 -0
- package/docs/how-to-guides.zh.md +413 -0
- package/docs/overview.ja.md +91 -0
- package/docs/overview.md +91 -0
- package/docs/overview.zh-TW.md +91 -0
- package/docs/overview.zh.md +91 -0
- package/glossary.md +12 -0
- package/lib/Dashboard/index.js +46 -42
- package/lib/Footer/index.js +51 -36
- package/lib/Header/index.js +48 -44
- package/lib/UserCenter/components/settings.js +1 -0
- package/lib/UserCenter/components/user-center.js +133 -133
- package/lib/blocklets.d.ts +13 -2
- package/lib/blocklets.js +40 -40
- package/lib/common/header-addons.js +37 -33
- package/package.json +7 -7
- package/src/Dashboard/index.jsx +8 -3
- package/src/Footer/index.jsx +22 -4
- package/src/Header/index.tsx +7 -2
- package/src/UserCenter/components/settings.tsx +1 -0
- package/src/UserCenter/components/user-center.tsx +6 -6
- package/src/blocklets.js +18 -9
- package/src/common/header-addons.jsx +7 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# UserSessions
|
|
2
|
+
|
|
3
|
+
The `UserSessions` component renders a comprehensive data table for displaying and managing a user's login sessions. It provides a clear overview of all active, expired, and offline sessions across various devices, giving users control over their account security.
|
|
4
|
+
|
|
5
|
+
The component is designed to be a plug-and-play solution for developers needing to implement session management features. It handles data fetching, pagination, UI rendering, and actions like logging out of specific sessions.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Session Filtering:** Users can easily filter sessions by their status: `online`, `expired`, or `offline`.
|
|
10
|
+
- **Detailed Information:** Each session entry displays parsed user-agent data, including the operating system, device type (browser), and wallet OS.
|
|
11
|
+
- **IP Geolocation:** Automatically resolves and displays the geographical region based on the last login IP address.
|
|
12
|
+
- **Session Termination:** Allows users to terminate any session except the current one.
|
|
13
|
+
- **Bulk Actions:** Includes a "Logout All" feature to terminate all sessions of a specific status.
|
|
14
|
+
- **Responsive Design:** Adapts to different screen sizes, ensuring a consistent user experience on both desktop and mobile devices.
|
|
15
|
+
|
|
16
|
+
## How It Works
|
|
17
|
+
|
|
18
|
+
The `UserSessions` component operates by requesting session data from a developer-provided function. This design decouples the component from any specific backend implementation, offering greater flexibility.
|
|
19
|
+
|
|
20
|
+
```d2
|
|
21
|
+
direction: down
|
|
22
|
+
|
|
23
|
+
User-Interaction: {
|
|
24
|
+
shape: c4-person
|
|
25
|
+
label: "User"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
UserSessions-Component: {
|
|
29
|
+
label: "UserSessions Component"
|
|
30
|
+
shape: rectangle
|
|
31
|
+
|
|
32
|
+
Datatable: {
|
|
33
|
+
label: "Datatable"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Actions: {
|
|
37
|
+
label: "Logout / Logout All"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Application-Backend: {
|
|
42
|
+
label: "Application Backend"
|
|
43
|
+
shape: rectangle
|
|
44
|
+
|
|
45
|
+
API-Endpoint: {
|
|
46
|
+
label: "API Endpoint\n(e.g., /api/sessions)"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Database: {
|
|
50
|
+
shape: cylinder
|
|
51
|
+
label: "Session Storage"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
User-Interaction -> UserSessions-Component.Datatable: "1. Views sessions"
|
|
56
|
+
UserSessions-Component -> Application-Backend.API-Endpoint: "2. Calls `getUserSessions` prop"
|
|
57
|
+
Application-Backend.API-Endpoint -> Database: "3. Fetches session data"
|
|
58
|
+
Database -> Application-Backend.API-Endpoint: "4. Returns data"
|
|
59
|
+
Application-Backend.API-Endpoint -> UserSessions-Component: "5. Resolves promise with list and paging"
|
|
60
|
+
UserSessions-Component.Datatable -> User-Interaction: "6. Renders sessions"
|
|
61
|
+
User-Interaction -> UserSessions-Component.Actions: "7. Clicks 'Logout'"
|
|
62
|
+
UserSessions-Component.Actions -> Application-Backend.API-Endpoint: "8. Sends logout request"
|
|
63
|
+
Application-Backend.API-Endpoint -> Database: "9. Deletes session"
|
|
64
|
+
UserSessions-Component -> Application-Backend.API-Endpoint: "10. Refreshes data"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
To use the `UserSessions` component, you must provide a `user` object and a `getUserSessions` function. The `getUserSessions` function is responsible for fetching the session data from your backend service.
|
|
70
|
+
|
|
71
|
+
```javascript Integration Example icon=lucide:code
|
|
72
|
+
import { UserSessions } from '@arcblock/blocklet-ui-react';
|
|
73
|
+
import { client } from './libs/client'; // Your API client instance
|
|
74
|
+
|
|
75
|
+
// The user object for whom sessions are being displayed.
|
|
76
|
+
const currentUser = {
|
|
77
|
+
did: 'z1...',
|
|
78
|
+
name: 'Alice',
|
|
79
|
+
// other user properties
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* This function fetches session data from your backend.
|
|
84
|
+
* The UserSessions component will call this function whenever it needs new data.
|
|
85
|
+
*
|
|
86
|
+
* @param {object} params - The query parameters.
|
|
87
|
+
* @param {number} params.page - The current page number.
|
|
88
|
+
* @param {number} params.pageSize - The number of items per page.
|
|
89
|
+
* @param {string} params.status - The session status to filter by ('online', 'expired', 'offline').
|
|
90
|
+
* @returns {Promise<{ list: UserSession[], paging: { total: number } }>} A promise that resolves to the session data.
|
|
91
|
+
*/
|
|
92
|
+
const fetchUserSessions = async ({ page, pageSize, status }) => {
|
|
93
|
+
const response = await client.user.getSessions({
|
|
94
|
+
page,
|
|
95
|
+
pageSize,
|
|
96
|
+
status,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Ensure the return format matches the component's requirements
|
|
100
|
+
return {
|
|
101
|
+
list: response?.list || [],
|
|
102
|
+
paging: {
|
|
103
|
+
total: response?.paging?.total || 0,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default function MyAccountSessionsPage() {
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
<h2>Manage Your Login Sessions</h2>
|
|
112
|
+
<UserSessions
|
|
113
|
+
user={currentUser}
|
|
114
|
+
getUserSessions={fetchUserSessions}
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Props
|
|
122
|
+
|
|
123
|
+
The `UserSessions` component accepts the following props to customize its behavior and appearance.
|
|
124
|
+
|
|
125
|
+
<x-field-group>
|
|
126
|
+
<x-field data-name="user" data-type="User" data-required="true">
|
|
127
|
+
<x-field-desc markdown>The user object for whom the sessions are being displayed. The component requires this to provide context for the session list.</x-field-desc>
|
|
128
|
+
</x-field>
|
|
129
|
+
<x-field data-name="getUserSessions" data-type="function" data-required="true">
|
|
130
|
+
<x-field-desc markdown>An asynchronous function responsible for fetching paginated session data from your backend. It receives an object with `page`, `pageSize`, and `status` and must return a `Promise` that resolves to an object with the shape `{ list: UserSession[], paging: { total: number } }`.</x-field-desc>
|
|
131
|
+
</x-field>
|
|
132
|
+
<x-field data-name="showAction" data-type="boolean" data-default="true" data-required="false">
|
|
133
|
+
<x-field-desc markdown>Controls the visibility of the "Actions" column, which contains the logout buttons. Set to `false` to create a read-only view.</x-field-desc>
|
|
134
|
+
</x-field>
|
|
135
|
+
<x-field data-name="showUser" data-type="boolean" data-default="true" data-required="false">
|
|
136
|
+
<x-field-desc markdown>Controls the visibility of the "User" column. This is useful in multi-user or administrative contexts where identifying the user for each session is necessary.</x-field-desc>
|
|
137
|
+
</x-field>
|
|
138
|
+
<x-field data-name="showOffline" data-type="boolean" data-default="false" data-required="false">
|
|
139
|
+
<x-field-desc markdown>Determines whether the "Offline" filter option is available in the UI. Offline sessions typically represent long-lived sessions that are not currently active.</x-field-desc>
|
|
140
|
+
</x-field>
|
|
141
|
+
<x-field data-name="showAppPid" data-type="boolean" data-default="false" data-required="false">
|
|
142
|
+
<x-field-desc markdown>Controls the visibility of the "App Pid" column, which can display a Blocklet's Program ID associated with the session.</x-field-desc>
|
|
143
|
+
</x-field>
|
|
144
|
+
</x-field-group>
|
|
145
|
+
|
|
146
|
+
## Displayed Information
|
|
147
|
+
|
|
148
|
+
The component renders the following information for each session in the data table:
|
|
149
|
+
|
|
150
|
+
| Column | Description |
|
|
151
|
+
| :--- | :--- |
|
|
152
|
+
| **Platform** | The operating system and version derived from the session's user-agent string (e.g., `Windows/10`). |
|
|
153
|
+
| **Device Type** | The browser or application used for the session (e.g., `Chrome/108.0.0`). |
|
|
154
|
+
| **Wallet OS** | The operating system of the connected DID wallet, if available. |
|
|
155
|
+
| **App Pid** | The Program ID of the Blocklet that created the session. (Visible if `showAppPid` is `true`). |
|
|
156
|
+
| **User** | The user associated with the session. (Visible if `showUser` is `true`). |
|
|
157
|
+
| **Created At** | The timestamp when the session was initially created. |
|
|
158
|
+
| **Last Active** | The timestamp of the last activity. For expired sessions, this column shows "Expired". |
|
|
159
|
+
| **Last Login IP** | The last known IP address for the session, along with its resolved geographical region. |
|
|
160
|
+
| **Actions** | Provides a button to log out of the session. (Visible if `showAction` is `true`). |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
For a complete user management interface, consider using the `UserSessions` component within the [UserCenter](./components-user-management-user-center.md) component.
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# UserSessions
|
|
2
|
+
|
|
3
|
+
`UserSessions` 元件會渲染一個全面的資料表,用於顯示和管理使用者的登入會話。它清晰地概覽了所有在各種裝置上的活躍、過期和離線會話,讓使用者能夠掌控其帳戶安全。
|
|
4
|
+
|
|
5
|
+
此元件被設計為一個隨插即用的解決方案,供需要實作會話管理功能的開發人員使用。它處理資料擷取、分頁、UI 渲染以及登出特定會話等操作。
|
|
6
|
+
|
|
7
|
+
## 功能
|
|
8
|
+
|
|
9
|
+
- **會話篩選:** 使用者可以輕鬆地按會話狀態篩選:`online`、`expired` 或 `offline`。
|
|
10
|
+
- **詳細資訊:** 每個會話條目都會顯示解析後的使用者代理資料,包括作業系統、裝置類型(瀏覽器)和錢包作業系統。
|
|
11
|
+
- **IP 地理位置:** 根據上次登入的 IP 位址自動解析並顯示地理區域。
|
|
12
|
+
- **終止會話:** 允許使用者終止除了當前會話以外的任何會話。
|
|
13
|
+
- **批次操作:** 包含「全部登出」功能,以終止特定狀態下的所有會話。
|
|
14
|
+
- **響應式設計:** 適應不同螢幕尺寸,確保在桌面和行動裝置上擁有一致的使用者體驗。
|
|
15
|
+
|
|
16
|
+
## 運作方式
|
|
17
|
+
|
|
18
|
+
`UserSessions` 元件透過向開發人員提供的函式請求會話資料來運作。這種設計將元件與任何特定的後端實作解耦,提供了更大的靈活性。
|
|
19
|
+
|
|
20
|
+
```d2
|
|
21
|
+
direction: down
|
|
22
|
+
|
|
23
|
+
User-Interaction: {
|
|
24
|
+
shape: c4-person
|
|
25
|
+
label: "使用者"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
UserSessions-Component: {
|
|
29
|
+
label: "UserSessions 元件"
|
|
30
|
+
shape: rectangle
|
|
31
|
+
|
|
32
|
+
Datatable: {
|
|
33
|
+
label: "資料表"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Actions: {
|
|
37
|
+
label: "登出 / 全部登出"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Application-Backend: {
|
|
42
|
+
label: "應用程式後端"
|
|
43
|
+
shape: rectangle
|
|
44
|
+
|
|
45
|
+
API-Endpoint: {
|
|
46
|
+
label: "API 端點\n(例如 /api/sessions)"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Database: {
|
|
50
|
+
shape: cylinder
|
|
51
|
+
label: "會話儲存"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
User-Interaction -> UserSessions-Component.Datatable: "1. 查看會話"
|
|
56
|
+
UserSessions-Component -> Application-Backend.API-Endpoint: "2. 呼叫 `getUserSessions` 屬性"
|
|
57
|
+
Application-Backend.API-Endpoint -> Database: "3. 擷取會話資料"
|
|
58
|
+
Database -> Application-Backend.API-Endpoint: "4. 回傳資料"
|
|
59
|
+
Application-Backend.API-Endpoint -> UserSessions-Component: "5. 以列表和分頁解析 promise"
|
|
60
|
+
UserSessions-Component.Datatable -> User-Interaction: "6. 渲染會話"
|
|
61
|
+
User-Interaction -> UserSessions-Component.Actions: "7. 點擊「登出」"
|
|
62
|
+
UserSessions-Component.Actions -> Application-Backend.API-Endpoint: "8. 發送登出請求"
|
|
63
|
+
Application-Backend.API-Endpoint -> Database: "9. 刪除會話"
|
|
64
|
+
UserSessions-Component -> Application-Backend.API-Endpoint: "10. 重新整理資料"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 使用方式
|
|
68
|
+
|
|
69
|
+
要使用 `UserSessions` 元件,您必須提供一個 `user` 物件和一個 `getUserSessions` 函式。`getUserSessions` 函式負責從您的後端服務中擷取會話資料。
|
|
70
|
+
|
|
71
|
+
```javascript 整合範例 icon=lucide:code
|
|
72
|
+
import { UserSessions } from '@arcblock/blocklet-ui-react';
|
|
73
|
+
import { client } from './libs/client'; // 您的 API 客戶端實例
|
|
74
|
+
|
|
75
|
+
// 正在顯示其會話的使用者物件。
|
|
76
|
+
const currentUser = {
|
|
77
|
+
did: 'z1...',
|
|
78
|
+
name: 'Alice',
|
|
79
|
+
// 其他使用者屬性
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 此函式從您的後端擷取會話資料。
|
|
84
|
+
* 每當需要新資料時,UserSessions 元件將會呼叫此函式。
|
|
85
|
+
*
|
|
86
|
+
* @param {object} params - 查詢參數。
|
|
87
|
+
* @param {number} params.page - 當前頁碼。
|
|
88
|
+
* @param {number} params.pageSize - 每頁的項目數。
|
|
89
|
+
* @param {string} params.status - 用於篩選的會話狀態('online'、'expired'、'offline')。
|
|
90
|
+
* @returns {Promise<{ list: UserSession[], paging: { total: number } }>} 一個解析為會話資料的 promise。
|
|
91
|
+
*/
|
|
92
|
+
const fetchUserSessions = async ({ page, pageSize, status }) => {
|
|
93
|
+
const response = await client.user.getSessions({
|
|
94
|
+
page,
|
|
95
|
+
pageSize,
|
|
96
|
+
status,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 確保回傳格式符合元件的要求
|
|
100
|
+
return {
|
|
101
|
+
list: response?.list || [],
|
|
102
|
+
paging: {
|
|
103
|
+
total: response?.paging?.total || 0,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default function MyAccountSessionsPage() {
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
<h2>管理您的登入會話</h2>
|
|
112
|
+
<UserSessions
|
|
113
|
+
user={currentUser}
|
|
114
|
+
getUserSessions={fetchUserSessions}
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 屬性
|
|
122
|
+
|
|
123
|
+
`UserSessions` 元件接受以下屬性以自訂其行為和外觀。
|
|
124
|
+
|
|
125
|
+
<x-field-group>
|
|
126
|
+
<x-field data-name="user" data-type="User" data-required="true">
|
|
127
|
+
<x-field-desc markdown>正在顯示其會話的使用者物件。元件需要此物件來為會話列表提供上下文。</x-field-desc>
|
|
128
|
+
</x-field>
|
|
129
|
+
<x-field data-name="getUserSessions" data-type="function" data-required="true">
|
|
130
|
+
<x-field-desc markdown>一個非同步函式,負責從您的後端擷取分頁的會話資料。它會接收一個包含 `page`、`pageSize` 和 `status` 的物件,並且必須回傳一個解析為 `{ list: UserSession[], paging: { total: number } }` 形狀物件的 `Promise`。</x-field-desc>
|
|
131
|
+
</x-field>
|
|
132
|
+
<x-field data-name="showAction" data-type="boolean" data-default="true" data-required="false">
|
|
133
|
+
<x-field-desc markdown>控制「操作」欄位的可見性,該欄位包含登出按鈕。設定為 `false` 可建立唯讀視圖。</x-field-desc>
|
|
134
|
+
</x-field>
|
|
135
|
+
<x-field data-name="showUser" data-type="boolean" data-default="true" data-required="false">
|
|
136
|
+
<x-field-desc markdown>控制「使用者」欄位的可見性。這在多使用者或管理情境中很有用,因為在這些情境下需要識別每個會話的使用者。</x-field-desc>
|
|
137
|
+
</x-field>
|
|
138
|
+
<x-field data-name="showOffline" data-type="boolean" data-default="false" data-required="false">
|
|
139
|
+
<x-field-desc markdown>決定「離線」篩選選項是否在 UI 中可用。離線會話通常代表目前不活躍的長期會話。</x-field-desc>
|
|
140
|
+
</x-field>
|
|
141
|
+
<x-field data-name="showAppPid" data-type="boolean" data-default="false" data-required="false">
|
|
142
|
+
<x-field-desc markdown>控制「App Pid」欄位的可見性,該欄位可以顯示與會話關聯的 Blocklet 的程式 ID。</x-field-desc>
|
|
143
|
+
</x-field>
|
|
144
|
+
</x-field-group>
|
|
145
|
+
|
|
146
|
+
## 顯示資訊
|
|
147
|
+
|
|
148
|
+
此元件在資料表中為每個會話渲染以下資訊:
|
|
149
|
+
|
|
150
|
+
| 欄位 | 說明 |
|
|
151
|
+
| :--- | :--- |
|
|
152
|
+
| **Platform** | 從會話的使用者代理字串中解析出的作業系統和版本(例如 `Windows/10`)。 |
|
|
153
|
+
| **Device Type** | 用於此會話的瀏覽器或應用程式(例如 `Chrome/108.0.0`)。 |
|
|
154
|
+
| **Wallet OS** | 已連接的 DID 錢包的作業系統(如果有的話)。 |
|
|
155
|
+
| **App Pid** | 建立此會話的 Blocklet 的程式 ID。(如果 `showAppPid` 為 `true` 則可見)。 |
|
|
156
|
+
| **User** | 與此會話關聯的使用者。(如果 `showUser` 為 `true` 則可見)。 |
|
|
157
|
+
| **Created At** | 會話最初建立的時間戳。 |
|
|
158
|
+
| **Last Active** | 上次活動的時間戳。對於已過期的會話,此欄位顯示「已過期」。 |
|
|
159
|
+
| **Last Login IP** | 此會話的最後已知 IP 位址,及其解析出的地理區域。 |
|
|
160
|
+
| **Actions** | 提供一個登出此會話的按鈕。(如果 `showAction` 為 `true` 則可見)。 |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
若要獲得一個完整的使用者管理介面,請考慮在 [UserCenter](./components-user-management-user-center.md) 元件中使用 `UserSessions` 元件。
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# UserSessions
|
|
2
|
+
|
|
3
|
+
`UserSessions` 组件渲染一个全面的数据表格,用于显示和管理用户的登录会话。它清晰地概览了用户在各种设备上的所有活跃、已过期和离线会话,让用户能够控制其账户安全。
|
|
4
|
+
|
|
5
|
+
该组件被设计成一个即插即用的解决方案,供需要实现会话管理功能的开发者使用。它负责处理数据获取、分页、UI 渲染以及登出特定会话等操作。
|
|
6
|
+
|
|
7
|
+
## 功能
|
|
8
|
+
|
|
9
|
+
- **会话筛选:** 用户可以轻松按状态(`online`、`expired` 或 `offline`)筛选会话。
|
|
10
|
+
- **详细信息:** 每个会话条目都会显示解析后的 user-agent 数据,包括操作系统、设备类型(浏览器)和钱包操作系统。
|
|
11
|
+
- **IP 地理位置:** 根据上次登录的 IP 地址自动解析并显示地理区域。
|
|
12
|
+
- **会话终止:** 允许用户终止除当前会话之外的任何会话。
|
|
13
|
+
- **批量操作:** 包含“全部登出”功能,可终止特定状态下的所有会話。
|
|
14
|
+
- **响应式设计:** 适应不同屏幕尺寸,确保在桌面和移动设备上提供一致的用户体验。
|
|
15
|
+
|
|
16
|
+
## 工作原理
|
|
17
|
+
|
|
18
|
+
`UserSessions` 组件通过调用开发者提供的函数来请求会话数据。这种设计将组件与任何特定的后端实现解耦,从而提供了更大的灵活性。
|
|
19
|
+
|
|
20
|
+
```d2
|
|
21
|
+
direction: down
|
|
22
|
+
|
|
23
|
+
User-Interaction: {
|
|
24
|
+
shape: c4-person
|
|
25
|
+
label: "用户"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
UserSessions-Component: {
|
|
29
|
+
label: "UserSessions 组件"
|
|
30
|
+
shape: rectangle
|
|
31
|
+
|
|
32
|
+
Datatable: {
|
|
33
|
+
label: "数据表格"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Actions: {
|
|
37
|
+
label: "登出 / 全部登出"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Application-Backend: {
|
|
42
|
+
label: "应用后端"
|
|
43
|
+
shape: rectangle
|
|
44
|
+
|
|
45
|
+
API-Endpoint: {
|
|
46
|
+
label: "API 端点\n(例如, /api/sessions)"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Database: {
|
|
50
|
+
shape: cylinder
|
|
51
|
+
label: "会话存储"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
User-Interaction -> UserSessions-Component.Datatable: "1. 查看会话"
|
|
56
|
+
UserSessions-Component -> Application-Backend.API-Endpoint: "2. 调用 `getUserSessions` 属性"
|
|
57
|
+
Application-Backend.API-Endpoint -> Database: "3. 获取会话数据"
|
|
58
|
+
Database -> Application-Backend.API-Endpoint: "4. 返回数据"
|
|
59
|
+
Application-Backend.API-Endpoint -> UserSessions-Component: "5. 以列表和分页信息解析 Promise"
|
|
60
|
+
UserSessions-Component.Datatable -> User-Interaction: "6. 渲染会话"
|
|
61
|
+
User-Interaction -> UserSessions-Component.Actions: "7. 点击'登出'"
|
|
62
|
+
UserSessions-Component.Actions -> Application-Backend.API-Endpoint: "8. 发送登出请求"
|
|
63
|
+
Application-Backend.API-Endpoint -> Database: "9. 删除会话"
|
|
64
|
+
UserSessions-Component -> Application-Backend.API-Endpoint: "10. 刷新数据"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 用法
|
|
68
|
+
|
|
69
|
+
要使用 `UserSessions` 组件,您必须提供一个 `user` 对象和一个 `getUserSessions` 函数。`getUserSessions` 函数负责从您的后端服务获取会话数据。
|
|
70
|
+
|
|
71
|
+
```javascript Integration Example icon=lucide:code
|
|
72
|
+
import { UserSessions } from '@arcblock/blocklet-ui-react';
|
|
73
|
+
import { client } from './libs/client'; // 您的 API 客户端实例
|
|
74
|
+
|
|
75
|
+
// 正在显示其会话的用户对象。
|
|
76
|
+
const currentUser = {
|
|
77
|
+
did: 'z1...',
|
|
78
|
+
name: 'Alice',
|
|
79
|
+
// other user properties
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 此函数从您的后端获取会话数据。
|
|
84
|
+
* UserSessions 组件在需要新数据时会调用此函数。
|
|
85
|
+
*
|
|
86
|
+
* @param {object} params - 查询参数。
|
|
87
|
+
* @param {number} params.page - 当前页码。
|
|
88
|
+
* @param {number} params.pageSize - 每页的项目数。
|
|
89
|
+
* @param {string} params.status - 用于筛选的会话状态('online'、'expired'、'offline')。
|
|
90
|
+
* @returns {Promise<{ list: UserSession[], paging: { total: number } }>} 一个解析为会话数据的 Promise。
|
|
91
|
+
*/
|
|
92
|
+
const fetchUserSessions = async ({ page, pageSize, status }) => {
|
|
93
|
+
const response = await client.user.getSessions({
|
|
94
|
+
page,
|
|
95
|
+
pageSize,
|
|
96
|
+
status,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 确保返回格式符合组件的要求
|
|
100
|
+
return {
|
|
101
|
+
list: response?.list || [],
|
|
102
|
+
paging: {
|
|
103
|
+
total: response?.paging?.total || 0,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default function MyAccountSessionsPage() {
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
<h2>管理您的登录会话</h2>
|
|
112
|
+
<UserSessions
|
|
113
|
+
user={currentUser}
|
|
114
|
+
getUserSessions={fetchUserSessions}
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 属性
|
|
122
|
+
|
|
123
|
+
`UserSessions` 组件接受以下属性以自定义其行为和外观。
|
|
124
|
+
|
|
125
|
+
<x-field-group>
|
|
126
|
+
<x-field data-name="user" data-type="User" data-required="true">
|
|
127
|
+
<x-field-desc markdown>正在显示其会话的用户对象。组件需要此对象为会话列表提供上下文。</x-field-desc>
|
|
128
|
+
</x-field>
|
|
129
|
+
<x-field data-name="getUserSessions" data-type="function" data-required="true">
|
|
130
|
+
<x-field-desc markdown>一个异步函数,负责从您的后端获取分页的会话数据。它接收一个包含 `page`、`pageSize` 和 `status` 的对象,并且必须返回一个解析为 `{ list: UserSession[], paging: { total: number } }` 形状对象的 `Promise`。</x-field-desc>
|
|
131
|
+
</x-field>
|
|
132
|
+
<x-field data-name="showAction" data-type="boolean" data-default="true" data-required="false">
|
|
133
|
+
<x-field-desc markdown>控制包含登出按钮的“操作”列的可见性。设置为 `false` 可创建只读视图。</x-field-desc>
|
|
134
|
+
</x-field>
|
|
135
|
+
<x-field data-name="showUser" data-type="boolean" data-default="true" data-required="false">
|
|
136
|
+
<x-field-desc markdown>控制“用户”列的可见性。这在需要为每个会话识别用户的多用户或管理上下文中很有用。</x-field-desc>
|
|
137
|
+
</x-field>
|
|
138
|
+
<x-field data-name="showOffline" data-type="boolean" data-default="false" data-required="false">
|
|
139
|
+
<x-field-desc markdown>决定“离线”筛选选项在 UI 中是否可用。离线会话通常代表当前不活跃的长期会话。</x-field-desc>
|
|
140
|
+
</x-field>
|
|
141
|
+
<x-field data-name="showAppPid" data-type="boolean" data-default="false" data-required="false">
|
|
142
|
+
<x-field-desc markdown>控制“应用 Pid”列的可见性,该列可以显示与会话关联的 Blocklet 的程序 ID。</x-field-desc>
|
|
143
|
+
</x-field>
|
|
144
|
+
</x-field-group>
|
|
145
|
+
|
|
146
|
+
## 显示信息
|
|
147
|
+
|
|
148
|
+
该组件在数据表格中为每个会话渲染以下信息:
|
|
149
|
+
|
|
150
|
+
| 列 | 描述 |
|
|
151
|
+
| :--- | :--- |
|
|
152
|
+
| **平台** | 从会话的 user-agent 字符串派生的操作系统和版本(例如 `Windows/10`)。 |
|
|
153
|
+
| **设备类型** | 用于会话的浏览器或应用程序(例如 `Chrome/108.0.0`)。 |
|
|
154
|
+
| **钱包操作系统** | 连接的 DID 钱包的操作系统(如果可用)。 |
|
|
155
|
+
| **应用 Pid** | 创建会话的 Blocklet 的程序 ID。(`showAppPid` 为 `true` 时可见)。 |
|
|
156
|
+
| **用户** | 与会话关联的用户。(`showUser` 为 `true` 时可见)。 |
|
|
157
|
+
| **创建于** | 会话最初创建时的时间戳。 |
|
|
158
|
+
| **上次活跃** | 上次活动的时间戳。对于已过期的会话,此列显示“已过期”。 |
|
|
159
|
+
| **上次登录 IP** | 会话的最后已知 IP 地址及其解析的地理区域。 |
|
|
160
|
+
| **操作** | 提供一个用于登出该会话的按钮。(`showAction` 为 `true` 时可见)。 |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
要获得完整的用户管理界面,请考虑在 [UserCenter](./components-user-management-user-center.md) 组件中使用 `UserSessions` 组件。
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# ユーザー管理
|
|
2
|
+
|
|
3
|
+
ユーザー管理スイートは、ユーザー関連の重要な機能を取り扱うために設計された、事前構築済みのReactコンポーネントのコレクションを提供します。これらのコンポーネントは、アプリケーション内でのユーザープロファイル、セッション管理、組織切り替えの実装を簡素化し、一貫性のある信頼性の高いユーザーエクスペリエンスを保証します。
|
|
4
|
+
|
|
5
|
+
このセクションでは、スイートで利用可能な主要コンポーネントの概要を説明します。詳細な実装ガイドとAPIリファレンスについては、以下にリンクされている特定のコンポーネントのドキュメントを参照してください。
|
|
6
|
+
|
|
7
|
+
```d2
|
|
8
|
+
direction: down
|
|
9
|
+
|
|
10
|
+
User: {
|
|
11
|
+
shape: c4-person
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Application: {
|
|
15
|
+
label: "Blocklet アプリケーション"
|
|
16
|
+
shape: rectangle
|
|
17
|
+
grid-columns: 1
|
|
18
|
+
grid-gap: 100
|
|
19
|
+
|
|
20
|
+
UserCenter: {
|
|
21
|
+
label: "UserCenter\n(プロファイルと設定)"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
UserSessions: {
|
|
25
|
+
label: "UserSessions\n(ログインアクティビティ)"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
OrgsSwitch: {
|
|
29
|
+
label: "OrgsSwitch\n(チームコンテキスト)"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
User -> Application.UserCenter: "プロファイルを管理"
|
|
34
|
+
User -> Application.UserSessions: "セッションを確認"
|
|
35
|
+
User -> Application.OrgsSwitch: "組織を切り替え"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## コアコンポーネント
|
|
39
|
+
|
|
40
|
+
このスイートは、それぞれがユーザー管理の特定の側面に対応する、いくつかの主要なコンポーネントで構成されています。
|
|
41
|
+
|
|
42
|
+
<x-cards>
|
|
43
|
+
<x-card data-title="UserCenter" data-icon="lucide:user-cog" data-href="/components/user-management/user-center">
|
|
44
|
+
ユーザープロファイルの表示と管理を行うための包括的なコンポーネントです。ユーザー設定、パスポート管理、他のユーザーをフォローするなどのソーシャルインタラクションを処理する機能が含まれています。
|
|
45
|
+
</x-card>
|
|
46
|
+
<x-card data-title="UserSessions" data-icon="lucide:smartphone-nfc" data-href="/components/user-management/user-sessions">
|
|
47
|
+
ユーザーがさまざまなデバイスでのアクティブおよび過去のログインセッションを表示・管理できるようにする、セキュリティに重点を置いたコンポーネントで、アカウントのセキュリティを強化します。
|
|
48
|
+
</x-card>
|
|
49
|
+
</x-cards>
|
|
50
|
+
|
|
51
|
+
### 組織の切り替え
|
|
52
|
+
|
|
53
|
+
`OrgsSwitch` コンポーネントは、複数の組織に所属するユーザー向けにドロップダウンメニューインターフェースを提供します。これにより、チームベースまたはマルチテナント機能を持つアプリケーションにとって重要な、シームレスなコンテキスト切り替えが可能になります。
|
|
54
|
+
|
|
55
|
+
**主な機能:**
|
|
56
|
+
|
|
57
|
+
* **現在の組織の表示:** ユーザーの現在の組織コンテキストを明確に表示します。
|
|
58
|
+
* **組織リスト:** ユーザーが切り替え可能なすべての組織を一覧表示し、パフォーマンス向上のための無限スクロール機能を備えています。
|
|
59
|
+
* **検索機能:** 特定の組織を素早くフィルタリングして見つけるための検索バーが含まれています。
|
|
60
|
+
* **作成とナビゲーション:** 新しい組織を作成するオプションと、すべての組織を管理するための専用ページへのリンクを提供します。
|
|
61
|
+
|
|
62
|
+
### ユーザーインタラクション用のフック
|
|
63
|
+
|
|
64
|
+
ソーシャル機能の開発を容易にするため、このライブラリには複雑なロジックを抽象化するカスタムフックとコンテキストも含まれています。
|
|
65
|
+
|
|
66
|
+
* **`useFollow` フック**: このフックは、他のユーザーをフォローおよびアンフォローするための完全なロジックを管理します。APIリクエストと状態変更を処理し、現在のフォロー状態 (`followed`) と、`followUser` および `unfollowUser` 関数を返します。
|
|
67
|
+
* **`UserFollowersProvider` コンテキスト**: フォロー状態が複数のコンポーネント間でアクセス可能である必要があるアプリケーションの場合、このプロバイダーはコンポーネントツリーの一部をラップし、`useUserFollowersContext` フックを介してフォローの状態とアクションを利用可能にします。
|
|
68
|
+
|
|
69
|
+
## まとめ
|
|
70
|
+
|
|
71
|
+
このコンポーネントスイートは、ライブラリで構築されたあらゆるアプリケーションにおける堅牢なユーザー管理のために必要なビルディングブロックを提供します。これらのコンポーネントを使用することで、開発を加速し、アプリケーションがユーザーアカウント管理とセキュリティのベストプラクティスに従うことを保証できます。
|
|
72
|
+
|
|
73
|
+
詳細な実装ガイドについては、特定のコンポーネントのドキュメントに進んでください。
|
|
74
|
+
|
|
75
|
+
* **次へ:** [UserCenter](./components-user-management-user-center.md)
|
|
76
|
+
* **関連項目:** [UserSessions](./components-user-management-user-sessions.md)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# User Management
|
|
2
|
+
|
|
3
|
+
The User Management suite provides a collection of pre-built React components designed to handle essential user-related functionalities. These components simplify the implementation of user profiles, session management, and organization switching within your application, ensuring a consistent and reliable user experience.
|
|
4
|
+
|
|
5
|
+
This section provides an overview of the main components available in the suite. For detailed implementation guides and API references, please refer to the specific component documentation linked below.
|
|
6
|
+
|
|
7
|
+
```d2
|
|
8
|
+
direction: down
|
|
9
|
+
|
|
10
|
+
User: {
|
|
11
|
+
shape: c4-person
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Application: {
|
|
15
|
+
label: "Blocklet Application"
|
|
16
|
+
shape: rectangle
|
|
17
|
+
grid-columns: 1
|
|
18
|
+
grid-gap: 100
|
|
19
|
+
|
|
20
|
+
UserCenter: {
|
|
21
|
+
label: "UserCenter\n(Profile & Settings)"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
UserSessions: {
|
|
25
|
+
label: "UserSessions\n(Login Activity)"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
OrgsSwitch: {
|
|
29
|
+
label: "OrgsSwitch\n(Team Context)"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
User -> Application.UserCenter: "Manages profile"
|
|
34
|
+
User -> Application.UserSessions: "Reviews sessions"
|
|
35
|
+
User -> Application.OrgsSwitch: "Switches organization"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Core Components
|
|
39
|
+
|
|
40
|
+
The suite is composed of several key components, each addressing a specific aspect of user management.
|
|
41
|
+
|
|
42
|
+
<x-cards>
|
|
43
|
+
<x-card data-title="UserCenter" data-icon="lucide:user-cog" data-href="/components/user-management/user-center">
|
|
44
|
+
A comprehensive component for displaying and managing user profiles. It includes features for handling user settings, passport management, and social interactions like following other users.
|
|
45
|
+
</x-card>
|
|
46
|
+
<x-card data-title="UserSessions" data-icon="lucide:smartphone-nfc" data-href="/components/user-management/user-sessions">
|
|
47
|
+
A security-focused component that allows users to view and manage their active and past login sessions across different devices, enhancing account security.
|
|
48
|
+
</x-card>
|
|
49
|
+
</x-cards>
|
|
50
|
+
|
|
51
|
+
### Organization Switching
|
|
52
|
+
|
|
53
|
+
The `OrgsSwitch` component provides a dropdown menu interface for users who belong to multiple organizations. It allows for seamless context switching, which is critical for applications with team-based or multi-tenant features.
|
|
54
|
+
|
|
55
|
+
**Key Features:**
|
|
56
|
+
|
|
57
|
+
* **Current Organization Display:** Clearly shows the user's current organizational context.
|
|
58
|
+
* **Organization List:** Lists all available organizations a user can switch to, complete with infinite scrolling for performance.
|
|
59
|
+
* **Search Functionality:** Includes a search bar to quickly filter and find a specific organization.
|
|
60
|
+
* **Creation and Navigation:** Provides options to create a new organization and a link to a dedicated page for managing all organizations.
|
|
61
|
+
|
|
62
|
+
### Hooks for User Interaction
|
|
63
|
+
|
|
64
|
+
To facilitate the development of social features, the library also includes custom hooks and contexts that abstract away complex logic.
|
|
65
|
+
|
|
66
|
+
* **`useFollow` hook**: This hook manages the complete logic for following and unfollowing other users. It handles the API requests and state changes, returning the current follow status (`followed`) and functions to `followUser` and `unfollowUser`.
|
|
67
|
+
* **`UserFollowersProvider` context**: For applications where follow status needs to be accessible across multiple components, this provider wraps a section of your component tree and makes the follow state and actions available via the `useUserFollowersContext` hook.
|
|
68
|
+
|
|
69
|
+
## Summary
|
|
70
|
+
|
|
71
|
+
This suite of components provides the necessary building blocks for robust user management in any application built with the library. By using these components, you can accelerate development and ensure your application follows best practices for user account management and security.
|
|
72
|
+
|
|
73
|
+
For detailed implementation guides, please proceed to the specific component documentation.
|
|
74
|
+
|
|
75
|
+
* **Next:** [UserCenter](./components-user-management-user-center.md)
|
|
76
|
+
* **See Also:** [UserSessions](./components-user-management-user-sessions.md)
|