vsoft-ui 1.0.3 → 1.0.4

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 CHANGED
@@ -1,214 +1,240 @@
1
- # VSoft UI
2
-
3
- 基于 Element Plus 的 Vue3 组件库,支持全局权限控制
4
-
5
- [![npm version](https://img.shields.io/npm/v/vsoft-ui.svg)](https://www.npmjs.com/package/vsoft-ui)
6
- [![license](https://img.shields.io/npm/l/vsoft-ui.svg)](https://github.com/your-username/vsoft-ui/blob/main/LICENSE)
7
- [![vue](https://img.shields.io/badge/Vue-3.3+-brightgreen.svg)](https://vuejs.org/)
8
- [![element-plus](https://img.shields.io/badge/Element%20Plus-2.13+-blue.svg)](https://element-plus.org/)
9
-
10
- ## 简介
11
-
12
- VSoft UI 是一个基于 Vue 3 和 Element Plus 的二次封装组件库,专注于提供简单高效的权限控制解决方案。通过组件级、指令级和 Hook 级三种权限控制方式,帮助开发者快速构建具有权限管理功能的应用。
13
-
14
- ## 主要特性
15
-
16
- - 📦 基于 Element Plus,提供一致的设计语言
17
- - 🔒 内置权限控制功能,支持三种权限控制方式
18
- - 🚀 零学习成本,基于 Vue 3 Composition API
19
- - 📝 完整的 TypeScript 支持
20
- - 🛠️ 丰富的示例和详细文档
21
-
22
- ## 快速开始
23
-
24
- ### 安装
25
-
26
- ```bash
27
- # 使用 pnpm(推荐)
28
- pnpm add vsoft-ui
29
-
30
- # 或使用 npm
31
- npm install vsoft-ui
32
-
33
- # 或使用 yarn
34
- yarn add vsoft-ui
35
- ```
36
-
37
- ### 引入
38
-
39
- ```typescript
40
- import { createApp } from 'vue'
41
- import ElementPlus from 'element-plus'
42
- import 'element-plus/dist/index.css'
43
- import VSoftUI from 'vsoft-ui'
44
- import App from './App.vue'
45
-
46
- const app = createApp(App)
47
- app.use(ElementPlus)
48
- app.use(VSoftUI)
49
- app.mount('#app')
50
- ```
51
-
52
- ### 设置权限
53
-
54
- 在应用启动时设置用户权限:
55
-
56
- ```typescript
57
- // main.ts
58
- import { permission } from 'vsoft-ui'
59
-
60
- // 设置用户权限
61
- permission.setPermissions(['button:add', 'button:edit', 'input:query'])
62
- ```
63
-
64
- ## 组件使用
65
-
66
- ### 按钮组件
67
-
68
- ```vue
69
- <template>
70
- <!-- 基本用法 -->
71
- <v-button type="primary">主要按钮</v-button>
72
-
73
- <!-- 权限控制 -->
74
- <v-button type="success" permission="button:add">添加按钮</v-button>
75
- <v-button type="warning" permission="['button:edit', 'button:update']">编辑按钮</v-button>
76
- <v-button type="danger" permission="['button:delete', 'button:manage']" permission-mode="all">删除按钮</v-button>
77
- </template>
78
- ```
79
-
80
- ### 输入框组件
81
-
82
- ```vue
83
- <template>
84
- <!-- 基本用法 -->
85
- <v-input v-model="value" placeholder="请输入内容" />
86
-
87
- <!-- 权限控制 -->
88
- <v-input v-model="value" permission="input:query" placeholder="查询输入框" />
89
- </template>
90
-
91
- <script setup lang="ts">
92
- import { ref } from 'vue'
93
-
94
- const value = ref('')
95
- </script>
96
- ```
97
-
98
- ## 权限控制
99
-
100
- VSoft UI 提供三种权限控制方式:
101
-
102
- ### 1. 组件级权限控制
103
-
104
- 所有 VSoft UI 组件都支持 `permission` 和 `permission-mode` 属性:
105
-
106
- ```vue
107
- <template>
108
- <!-- 基本权限控制 -->
109
- <v-button permission="button:add">添加按钮</v-button>
110
-
111
- <!-- 多权限控制(任一权限) -->
112
- <v-button permission="['button:edit', 'button:update']">编辑按钮</v-button>
113
-
114
- <!-- 多权限控制(所有权限) -->
115
- <v-button permission="['button:delete', 'button:manage']" permission-mode="all">删除按钮</v-button>
116
- </template>
117
- ```
118
-
119
- ### 2. 指令级权限控制
120
-
121
- 使用 `v-permission` 指令对任何元素进行权限控制:
122
-
123
- ```vue
124
- <template>
125
- <!-- 基本权限控制 -->
126
- <el-button v-permission="'button:delete'" type="danger">删除按钮</el-button>
127
-
128
- <!-- 使用 any 修饰符 -->
129
- <el-button v-permission:any="['button:edit', 'button:update']" type="warning">编辑按钮</el-button>
130
-
131
- <!-- 使用 all 修饰符 -->
132
- <el-button v-permission:all="['button:manage', 'button:admin']" type="primary">管理按钮</el-button>
133
- </template>
134
- ```
135
-
136
- ### 3. Hook 级权限控制
137
-
138
- 使用 `usePermission` Hook 进行更灵活的权限判断:
139
-
140
- ```vue
141
- <template>
142
- <el-button v-if="canAdd" type="primary" @click="handleAdd">添加按钮</el-button>
143
- <el-button v-if="canEdit" type="success" @click="handleEdit">编辑按钮</el-button>
144
- </template>
145
-
146
- <script setup lang="ts">
147
- import { usePermission } from 'vsoft-ui'
148
-
149
- const { hasPermission } = usePermission()
150
-
151
- const canAdd = hasPermission('button:add')
152
- const canEdit = hasPermission('button:edit')
153
-
154
- const handleAdd = () => { /* ... */ }
155
- const handleEdit = () => { /* ... */ }
156
- </script>
157
- ```
158
-
159
- ## 开发
160
-
161
- ### 运行示例
162
-
163
- ```bash
164
- pnpm dev
165
- ```
166
-
167
- ### 构建
168
-
169
- ```bash
170
- pnpm build
171
- ```
172
-
173
- ### 文档
174
-
175
- ```bash
176
- # 启动文档开发服务器
177
- pnpm dev:docs
178
-
179
- # 构建文档
180
- pnpm build:docs
181
- ```
182
-
183
- ## 文档
184
-
185
- - [完整文档](https://your-username.github.io/vsoft-ui/)
186
- - [权限控制指南](/permission/usage)
187
- - [组件文档](/components)
188
-
189
- ## 贡献
190
-
191
- 欢迎提交 Issue 和 Pull Request!
192
-
193
- ## 许可证
194
-
195
- [MIT](LICENSE)
196
-
197
- ## 更新日志
198
-
199
- ### v1.0.2
200
-
201
- - 修复组件构建问题
202
- - 优化权限控制逻辑
203
- - 完善文档内容
204
-
205
- ### v1.0.1
206
-
207
- - 修复组件级权限控制问题
208
- - 优化组件传参机制
209
-
210
- ### v1.0.0
211
-
212
- - 初始版本发布
213
- - 实现 Button 和 Input 组件
214
- - 添加三种权限控制方式
1
+ # VSoft UI
2
+
3
+ 基于 Element Plus 的二次封装组件库,包含全局权限控制功能。
4
+
5
+ ## 特性
6
+
7
+ - 📦 基于 Element Plus 二次封装
8
+ - 🔒 内置全局权限控制功能
9
+ - 🚀 支持 Vue 3 + TypeScript
10
+ - 📖 完整的类型定义
11
+ - 💪 组件化开发,易于维护和扩展
12
+ - 📱 响应式设计,适配各种设备
13
+
14
+ ## 安装
15
+
16
+ 使用 pnpm 安装:
17
+
18
+ ```bash
19
+ pnpm add vsoft-ui
20
+ ```
21
+
22
+ ## 快速开始
23
+
24
+ ### 1. 引入组件库
25
+
26
+ 在 main.ts 中引入并安装组件库,组件库会自动安装 Element Plus 和注册所有图标:
27
+
28
+ ```typescript
29
+ import { createApp } from 'vue'
30
+ import App from './App.vue'
31
+ import VSoftUI from 'vsoft-ui'
32
+
33
+ const app = createApp(App)
34
+
35
+ // 安装 VSoft UI 组件库(自动安装 Element Plus 和注册所有图标)
36
+ app.use(VSoftUI)
37
+
38
+ app.mount('#app')
39
+ ```
40
+
41
+ ### 2. 初始化权限
42
+
43
+ 在应用初始化时设置权限列表:
44
+
45
+ ```typescript
46
+ import { usePermission } from 'vsoft-ui'
47
+
48
+ const { setPermissions } = usePermission()
49
+
50
+ // 设置权限列表
51
+ setPermissions(['user:view', 'user:edit', 'button:click'])
52
+ ```
53
+
54
+ ### 3. 使用图标
55
+
56
+ 组件库自动注册了所有 Element Plus 图标,您可以在封装组件中直接使用:
57
+
58
+ ```vue
59
+ <!-- 在封装组件中直接使用图标名称 -->
60
+ <v-button type="primary" icon="Plus">添加</v-button>
61
+
62
+ <!-- 在封装组件中使用图标组件 -->
63
+ <v-button type="success">
64
+ <el-icon><Edit /></el-icon>
65
+ 编辑
66
+ </v-button>
67
+ ```
68
+
69
+ ## 全局权限控制
70
+
71
+ ### 1. 权限控制指令 `v-permission`
72
+
73
+ **基本用法:**
74
+
75
+ ```vue
76
+ <!-- 单个权限 -->
77
+ <v-button v-permission="'user:view'" type="primary">查看用户</v-button>
78
+
79
+ <!-- any模式(默认)- 满足任一权限 -->
80
+ <v-button v-permission="['user:view', 'user:edit']" type="success">编辑用户</v-button>
81
+
82
+ <!-- all模式 - 需要所有权限 -->
83
+ <v-button v-permission:all="['user:view', 'user:edit']" type="warning">需要查看和编辑权限</v-button>
84
+
85
+ <!-- 黑名单模式(无此权限时显示) -->
86
+ <v-button v-permission:blacklist="'user:delete'" type="danger">删除用户</v-button>
87
+
88
+ <!-- 黑名单 + all模式 -->
89
+ <v-button v-permission:blacklist.all="['user:delete', 'user:update']" type="info">无删除和更新权限时显示</v-button>
90
+ ```
91
+
92
+ ### 2. 权限控制组合式函数 `usePermission`
93
+
94
+ **基本用法:**
95
+
96
+ ```vue
97
+ <script setup lang="ts">
98
+ import { usePermission } from 'vsoft-ui'
99
+
100
+ const { hasPermission, hasAllPermissions, setPermissions, getPermissions, clearPermissions } = usePermission()
101
+
102
+ // 检查单个权限
103
+ const canView = hasPermission('user:view')
104
+
105
+ // 检查多个权限(满足任一即可)
106
+ const canEditOrDelete = hasPermission(['user:edit', 'user:delete'])
107
+
108
+ // 检查所有权限(必须全部满足)
109
+ const hasAll = hasAllPermissions(['user:view', 'user:edit'])
110
+
111
+ // 设置权限
112
+ setPermissions(['user:view', 'user:edit'])
113
+
114
+ // 获取权限列表
115
+ const permissions = getPermissions()
116
+
117
+ // 清除权限
118
+ clearPermissions()
119
+ </script>
120
+ ```
121
+
122
+ ## 示例组件
123
+
124
+ ### VButton 组件
125
+
126
+ 基于 Element Plus Button 二次封装,内置权限控制功能。
127
+
128
+ **基本用法:**
129
+
130
+ ```vue
131
+ <!-- 有权限的按钮 -->
132
+ <v-button permission="button:click" type="primary">点击按钮</v-button>
133
+
134
+ <!-- 无权限的按钮(自动禁用) -->
135
+ <v-button permission="button:disabled" type="success">禁用按钮</v-button>
136
+
137
+ <!-- 多权限按钮 -->
138
+ <v-button permission="['user:view', 'button:click']" type="warning">多权限按钮</v-button>
139
+
140
+ <!-- 黑名单模式 -->
141
+ <v-button permission="user:delete" permission-mode="blacklist" type="danger">黑名单按钮</v-button>
142
+ ```
143
+
144
+ **Props:**
145
+
146
+ | 属性名 | 类型 | 默认值 | 说明 |
147
+ | --- | --- | --- | --- |
148
+ | permission | `string string[]` | `undefined` | 按钮所需权限 |
149
+ | permission-mode | `'whitelist' 'blacklist'` | `'whitelist'` | 权限模式 |
150
+ | 其他属性 | - | - | 继承 Element Plus Button 的所有属性 |
151
+
152
+ ## 构建和发布
153
+
154
+ ### 构建组件库
155
+
156
+ ```bash
157
+ # 构建组件库
158
+ pnpm run build
159
+
160
+ # 生成类型声明文件
161
+ pnpm run build:types
162
+ ```
163
+
164
+ ### 开发模式
165
+
166
+ ```bash
167
+ # 启动开发服务器
168
+ pnpm run dev
169
+ ```
170
+
171
+ ### 代码检查
172
+
173
+ ```bash
174
+ # 运行 ESLint 检查
175
+ pnpm run lint
176
+ ```
177
+
178
+ ## 目录结构
179
+
180
+ ```
181
+ ├── src/
182
+ │ ├── components/ # 组件目录
183
+ │ │ └── VButton/ # VButton 组件
184
+ │ ├── directives/ # 指令目录
185
+ │ │ └── permission.ts # 权限控制指令
186
+ │ ├── composables/ # 组合式函数目录
187
+ │ │ └── usePermission.ts # 权限控制组合式函数
188
+ │ ├── utils/ # 工具函数目录
189
+ │ │ └── permission.ts # 权限管理工具
190
+ │ ├── styles/ # 样式目录
191
+ │ └── index.ts # 入口文件
192
+ ├── examples/ # 示例应用
193
+ ├── types/ # 类型定义
194
+ ├── vite.config.ts # Vite 配置
195
+ ├── tsconfig.json # TypeScript 配置
196
+ └── package.json # 项目配置
197
+ ```
198
+
199
+ ## 开发指南
200
+
201
+ ### 1. 创建新组件
202
+
203
+ `src/components` 目录下创建新组件目录,包含 `index.vue` 和 `index.ts` 文件:
204
+
205
+ ```bash
206
+ mkdir -p src/components/NewComponent
207
+ ```
208
+
209
+ ### 2. 编写组件代码
210
+
211
+ 在 `index.vue` 中编写组件逻辑,在 `index.ts` 中导出组件:
212
+
213
+ ```typescript
214
+ // src/components/NewComponent/index.ts
215
+ import NewComponent from './index.vue'
216
+
217
+ export { NewComponent }
218
+ export default NewComponent
219
+ ```
220
+
221
+ ### 3. 导出组件
222
+
223
+ 在 `src/index.ts` 中导出新组件:
224
+
225
+ ```typescript
226
+ // src/index.ts
227
+ export * from './components/NewComponent'
228
+
229
+ // 在 install 函数中注册组件
230
+ export const install = (app: App) => {
231
+ // 已有的组件注册
232
+ app.component('VButton', VButton)
233
+ // 新组件注册
234
+ app.component('NewComponent', NewComponent)
235
+ }
236
+ ```
237
+
238
+ ## 许可证
239
+
240
+ MIT