@cst-ui/nano-buttons 0.2.1 → 0.2.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 +136 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,21 @@ Nano 项目主题按钮组件库,基于 Vue 3 和 Element Plus 封装。
|
|
|
4
4
|
|
|
5
5
|
这个包用于统一提供 Nano 系列按钮组件,并通过子入口提供弹窗标签页化的公共能力。模板中统一使用横线法组件名,例如 `<nano-button>`,不再保留旧命名。
|
|
6
6
|
|
|
7
|
+
## 入口说明
|
|
8
|
+
|
|
9
|
+
包内能力按子入口拆分,按钮和弹窗标签页可以分开引入:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// 兼容旧按钮入口
|
|
13
|
+
import NanoButtons from '@cst-ui/nano-buttons'
|
|
14
|
+
|
|
15
|
+
// 明确的按钮入口
|
|
16
|
+
import NanoButtons from '@cst-ui/nano-buttons/buttons'
|
|
17
|
+
|
|
18
|
+
// 弹窗标签页入口
|
|
19
|
+
import { createNanoDialogTabs } from '@cst-ui/nano-buttons/dialog-tabs'
|
|
20
|
+
```
|
|
21
|
+
|
|
7
22
|
## 在线文档
|
|
8
23
|
|
|
9
24
|
组件效果、安装方式、使用示例和 API 说明见在线文档:
|
|
@@ -84,13 +99,131 @@ import NanoButtons from '@cst-ui/nano-buttons/buttons'
|
|
|
84
99
|
|
|
85
100
|
## 弹窗标签页
|
|
86
101
|
|
|
87
|
-
|
|
102
|
+
弹窗标签页能力用于把原本的弹窗按开关切换成系统 tab 页,同时保留原弹窗模式。公共包只负责打开模式、上下文缓存、保存结果通知、关闭回来源页和 `NanoDialogTabPage` 页面壳;业务项目负责注册页面、请求数据和保存业务。
|
|
103
|
+
|
|
104
|
+
### 入口安装
|
|
105
|
+
|
|
106
|
+
在应用入口安装插件:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { createNanoDialogTabs } from '@cst-ui/nano-buttons/dialog-tabs'
|
|
110
|
+
|
|
111
|
+
app.use(createNanoDialogTabs({
|
|
112
|
+
router,
|
|
113
|
+
parentRouteName: 'layout',
|
|
114
|
+
registry: dialogRegistry,
|
|
115
|
+
mode: () => DIALOG_OPEN_MODE,
|
|
116
|
+
translate: key => i18n.global.t(key),
|
|
117
|
+
tabAdapter: {
|
|
118
|
+
getTabs: () => tabStore.tabsOption,
|
|
119
|
+
getCurrentIndex: () => tabStore.currentIndex,
|
|
120
|
+
setCurrentIndex: index => tabStore.SET_TAB(index),
|
|
121
|
+
deleteTab: index => tabStore.DELETE_TAB(index),
|
|
122
|
+
},
|
|
123
|
+
}))
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 注册页面
|
|
127
|
+
|
|
128
|
+
在业务项目维护弹窗注册表:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
export const dialogRegistry = {
|
|
132
|
+
userEdit: {
|
|
133
|
+
suffix: '/edit',
|
|
134
|
+
title: 'dialog.user.edit',
|
|
135
|
+
component: async () => await import('@/views/user/components/edit-page.vue'),
|
|
136
|
+
props: {
|
|
137
|
+
mode: 'edit',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 打开弹窗或 tab
|
|
144
|
+
|
|
145
|
+
原页面统一使用 `openDialog`。开关为 `dialog` 时走 `openModal`,开关为 `tab` 时打开注册页面:
|
|
88
146
|
|
|
89
147
|
```ts
|
|
90
|
-
import {
|
|
148
|
+
import { useDialogOpen } from '@cst-ui/nano-buttons/dialog-tabs'
|
|
149
|
+
|
|
150
|
+
const { openDialog } = useDialogOpen()
|
|
151
|
+
|
|
152
|
+
openDialog({
|
|
153
|
+
key: 'userEdit',
|
|
154
|
+
routeSuffix: `/edit/${row.id}`,
|
|
155
|
+
routePatternSuffix: '/edit/:id',
|
|
156
|
+
context: {
|
|
157
|
+
id: row.id,
|
|
158
|
+
},
|
|
159
|
+
openModal: () => {
|
|
160
|
+
data.showEdit = true
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### tab 页面
|
|
166
|
+
|
|
167
|
+
tab 页面用 `NanoDialogTabPage` 统一标题、内容滚动、底部操作区和上下文失效兜底:
|
|
168
|
+
|
|
169
|
+
```vue
|
|
170
|
+
<template>
|
|
171
|
+
<NanoDialogTabPage
|
|
172
|
+
:title-key="pageTitleKey"
|
|
173
|
+
:loading="loading"
|
|
174
|
+
:expired="expired"
|
|
175
|
+
@close="closeCurrentDialogTab"
|
|
176
|
+
>
|
|
177
|
+
<UserEditForm
|
|
178
|
+
:item="item"
|
|
179
|
+
variant="page"
|
|
180
|
+
@cancel="closeCurrentDialogTab"
|
|
181
|
+
@save-ok="onSaveOk"
|
|
182
|
+
/>
|
|
183
|
+
</NanoDialogTabPage>
|
|
184
|
+
</template>
|
|
185
|
+
|
|
186
|
+
<script setup lang="ts">
|
|
187
|
+
import { NanoDialogTabPage, useDialogPage } from '@cst-ui/nano-buttons/dialog-tabs'
|
|
188
|
+
|
|
189
|
+
const {
|
|
190
|
+
route,
|
|
191
|
+
dialogContext,
|
|
192
|
+
closeCurrentDialogTab,
|
|
193
|
+
emitSavedAndClose,
|
|
194
|
+
} = useDialogPage<{ id?: string }>('dialog.user.edit')
|
|
195
|
+
|
|
196
|
+
const id = computed(() => dialogContext.value?.id ?? route.params.id)
|
|
197
|
+
|
|
198
|
+
const onSaveOk = () => {
|
|
199
|
+
emitSavedAndClose('userEdit', { id: id.value })
|
|
200
|
+
}
|
|
201
|
+
</script>
|
|
91
202
|
```
|
|
92
203
|
|
|
93
|
-
|
|
204
|
+
### 保存后刷新来源页
|
|
205
|
+
|
|
206
|
+
来源页可以监听保存结果并刷新列表:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { onDialogResult } from '@cst-ui/nano-buttons/dialog-tabs'
|
|
210
|
+
|
|
211
|
+
onMounted(() => {
|
|
212
|
+
const remove = onDialogResult((result) => {
|
|
213
|
+
if (result.key === 'userEdit' && result.type === 'saved')
|
|
214
|
+
loadList()
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
onUnmounted(remove)
|
|
218
|
+
})
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### 使用建议
|
|
222
|
+
|
|
223
|
+
1. 路由上的业务主键只放可被正常访问的 ID,不放敏感数据。
|
|
224
|
+
2. `context` 只作为临时上下文,页面刷新后可能失效,页面应提供兜底提示或根据路由主键重新查数据。
|
|
225
|
+
3. 标题传多语言 key,不在公共模块里写死业务文案。
|
|
226
|
+
4. 保存成功统一用 `emitSavedAndClose` 通知来源页刷新。
|
|
94
227
|
|
|
95
228
|
## 维护与发布
|
|
96
229
|
|