mantur-components 0.1.0 → 0.1.1
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 +46 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,57 +1,67 @@
|
|
|
1
1
|
# mantur-components
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Mantur React 组件库,基于 React 和 Arco Design。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 安装
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install mantur-components
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
需要宿主项目提供以下 peer dependencies:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
npm install react react-dom @arco-design/web-react next-themes react-i18next
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
组件库使用 Tailwind 工具类,不再导出独立的 CSS 文件,不需要引入 `mantur-components/style.css`。
|
|
18
18
|
|
|
19
19
|
## ManturHeader
|
|
20
20
|
|
|
21
|
-
`ManturHeader`
|
|
21
|
+
`ManturHeader` 是 Mantur 用户端共用 Header。组件内部已经封装以下能力:
|
|
22
22
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
23
|
+
- 获取团队列表
|
|
24
|
+
- 获取当前团队
|
|
25
|
+
- 切换团队
|
|
26
|
+
- 获取用户积分
|
|
27
|
+
- 个人资料更新
|
|
28
|
+
- 退出登录
|
|
29
|
+
- 语言切换
|
|
30
|
+
- 主题切换
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
### 基础使用
|
|
33
33
|
|
|
34
34
|
```tsx
|
|
35
35
|
import { ManturHeader } from "mantur-components";
|
|
36
36
|
|
|
37
|
-
export function Header({
|
|
37
|
+
export function Header({
|
|
38
|
+
userInfo,
|
|
39
|
+
}: {
|
|
40
|
+
userInfo: { username?: string; nickname?: string; avatar?: string } | null;
|
|
41
|
+
}) {
|
|
38
42
|
return <ManturHeader user={userInfo} />;
|
|
39
43
|
}
|
|
40
44
|
```
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
### 禁用团队切换和自定义插槽
|
|
43
47
|
|
|
44
48
|
```tsx
|
|
45
49
|
import { ManturHeader } from "mantur-components";
|
|
46
50
|
|
|
47
|
-
export function Header({
|
|
51
|
+
export function Header({
|
|
52
|
+
userInfo,
|
|
53
|
+
disabled,
|
|
54
|
+
}: {
|
|
55
|
+
userInfo: UserInfo | null;
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
}) {
|
|
48
58
|
return (
|
|
49
59
|
<ManturHeader
|
|
50
60
|
user={userInfo}
|
|
51
61
|
disabled={disabled}
|
|
52
|
-
brandSlot={<span className="text-lg font-bold"
|
|
62
|
+
brandSlot={<span className="text-lg font-bold">自定义品牌</span>}
|
|
53
63
|
>
|
|
54
|
-
<div className="px-4"
|
|
64
|
+
<div className="px-4">自定义中间内容</div>
|
|
55
65
|
</ManturHeader>
|
|
56
66
|
);
|
|
57
67
|
}
|
|
@@ -68,15 +78,15 @@ interface ManturHeaderProps {
|
|
|
68
78
|
}
|
|
69
79
|
```
|
|
70
80
|
|
|
71
|
-
`user
|
|
81
|
+
`user`:右侧用户菜单展示的当前用户信息。
|
|
72
82
|
|
|
73
|
-
`disabled
|
|
83
|
+
`disabled`:是否禁用团队切换。为 `true` 时,团队选择器展示为禁用态,无法展开和切换。
|
|
74
84
|
|
|
75
|
-
`brandSlot
|
|
85
|
+
`brandSlot`:Logo 右侧品牌标题插槽。传入后显示传入内容;不传则显示默认国际化标题。
|
|
76
86
|
|
|
77
|
-
`children
|
|
87
|
+
`children`:Header 中间弹性区域插槽。传入后显示传入内容;不传则保持为空。
|
|
78
88
|
|
|
79
|
-
###
|
|
89
|
+
### 用户类型
|
|
80
90
|
|
|
81
91
|
```ts
|
|
82
92
|
interface ManturHeaderUser {
|
|
@@ -88,25 +98,27 @@ interface ManturHeaderUser {
|
|
|
88
98
|
}
|
|
89
99
|
```
|
|
90
100
|
|
|
91
|
-
|
|
101
|
+
## API 配置
|
|
92
102
|
|
|
93
|
-
|
|
103
|
+
默认情况下,组件库接口请求使用 `import.meta.env.VITE_API`,如果没有配置则回退到 `/api`。
|
|
94
104
|
|
|
95
|
-
|
|
105
|
+
可以在渲染组件前通过全局变量覆盖:
|
|
96
106
|
|
|
97
107
|
```ts
|
|
98
108
|
window.__MANTUR_COMPONENTS_API_BASE__ = "/api";
|
|
99
109
|
```
|
|
100
110
|
|
|
101
|
-
|
|
111
|
+
积分接口默认是 `/users/me/points`,也可以覆盖:
|
|
102
112
|
|
|
103
113
|
```ts
|
|
104
114
|
window.__MANTUR_COMPONENTS_POINTS_ENDPOINT__ = "/users/me/points";
|
|
105
115
|
```
|
|
106
116
|
|
|
107
|
-
|
|
117
|
+
## 团队上下文同步
|
|
118
|
+
|
|
119
|
+
团队列表、当前团队、切换团队都由 `ManturHeader` 内部处理。
|
|
108
120
|
|
|
109
|
-
|
|
121
|
+
如果宿主项目需要同步自己的 store,例如 `activeTenantId`、权限、角色、已开通应用,可以监听 `MANTUR_TENANT_CONTEXT_CHANGE_EVENT`。
|
|
110
122
|
|
|
111
123
|
```tsx
|
|
112
124
|
import {
|
|
@@ -118,7 +130,7 @@ import {
|
|
|
118
130
|
function applyTenantContext(detail: ManturTenantContextDetail) {
|
|
119
131
|
const tenantId = detail.auth?.tenantId || detail.currentTenant?.tenantId;
|
|
120
132
|
|
|
121
|
-
//
|
|
133
|
+
// 在这里同步宿主项目的状态。
|
|
122
134
|
// setActiveTenantId(tenantId)
|
|
123
135
|
// setPermissions(detail.auth?.permissions || [])
|
|
124
136
|
// setRoles(detail.auth?.roles || [])
|
|
@@ -137,7 +149,7 @@ if (snapshot) {
|
|
|
137
149
|
}
|
|
138
150
|
```
|
|
139
151
|
|
|
140
|
-
|
|
152
|
+
团队上下文数据结构:
|
|
141
153
|
|
|
142
154
|
```ts
|
|
143
155
|
interface ManturTenantContextDetail {
|
|
@@ -154,7 +166,7 @@ interface ManturTenantContextDetail {
|
|
|
154
166
|
}
|
|
155
167
|
```
|
|
156
168
|
|
|
157
|
-
|
|
169
|
+
## 导出的工具方法
|
|
158
170
|
|
|
159
171
|
```ts
|
|
160
172
|
import {
|
|
@@ -171,7 +183,7 @@ import {
|
|
|
171
183
|
} from "mantur-components";
|
|
172
184
|
```
|
|
173
185
|
|
|
174
|
-
##
|
|
186
|
+
## 构建
|
|
175
187
|
|
|
176
188
|
```bash
|
|
177
189
|
npm run build
|