morghulis 2.0.65 → 2.0.67

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,99 +1,485 @@
1
- # Morghulis 按钮组件
1
+ # Morghulis UI 组件库
2
2
 
3
- 一个简单的Vue 3 TypeScript按钮组件库,提供美观且易用的按钮组件。
3
+ 基于Vue 3和TypeScript的数据库便捷搭建UI组件库,集成了Element Plus和FontAwesome图标,提供丰富的数据库操作界面组件。
4
4
 
5
- ## 安装
5
+ ## 特性
6
6
 
7
- ```bash
8
- npm install morghulis
7
+ - 基于Vue 3和TypeScript开发
8
+ - 自动集成Element Plus,无需额外安装
9
+ - 集成FontAwesome图标
10
+ - 提供高度可定制的对话框组件,适用于数据库操作交互
11
+ - 简化数据库表单创建和管理流程
12
+ - 内置常用数据库操作UI模板
13
+
14
+ ## 快速开始
15
+
16
+ 在你的Vue 3项目中引入并使用组件库:
17
+
18
+ ```js
19
+ // main.ts 或 main.js
20
+ import { createApp } from 'vue'
21
+ import App from './App.vue'
22
+ import { createMorghulis } from 'morghulis'
23
+ import 'morghulis/dist/style.css'
24
+
25
+ const app = createApp(App)
26
+
27
+ // 使用Morghulis UI,自动集成Element Plus
28
+ app.use(createMorghulis())
29
+
30
+ app.mount('#app')
9
31
  ```
10
32
 
11
- ## 使用
33
+ ## 组件
34
+
35
+ ### MTable 表格组件
12
36
 
13
- ### 基本用法
37
+ 高度可定制的表格组件,适用于数据展示和操作。
38
+
39
+ #### 基本用法
14
40
 
15
41
  ```vue
16
42
  <template>
17
- <MButton>默认按钮</MButton>
18
- <MButton color="success" round>成功按钮</MButton>
19
- <MButton color="warning" size="large">警告按钮</MButton>
20
- <MButton color="danger" disabled>危险按钮</MButton>
43
+ <m-table
44
+ :view="tableView"
45
+ :loading="loading"
46
+ :buttons="tableButtons"
47
+ >
48
+ <!-- 自定义单元格 -->
49
+ <template #cell="{ field, row, prop }">
50
+ <m-cell
51
+ :field="field"
52
+ :bean="row"
53
+ :disabled="false"
54
+ ></m-cell>
55
+ </template>
56
+
57
+ <!-- 自定义头部 -->
58
+ <template #header>
59
+ <h3>表格标题</h3>
60
+ </template>
61
+
62
+ <!-- 自定义底部 -->
63
+ <template #footer>
64
+ <el-pagination :total="total" />
65
+ </template>
66
+ </m-table>
21
67
  </template>
22
68
 
23
- <script setup lang="ts">
24
- import { MButton } from 'morghulis'
69
+ <script setup>
70
+ import { ref } from 'vue'
71
+
72
+ // 表格视图定义
73
+ const tableView = ref({
74
+ fields: {
75
+ name: { label: '姓名', domain: 'string' },
76
+ age: { label: '年龄', domain: 'number' },
77
+ birthday: { label: '生日', domain: 'date' }
78
+ }
79
+ })
80
+
81
+ // 表格按钮定义
82
+ const tableButtons = [
83
+ {
84
+ title: '编辑',
85
+ type: 'primary',
86
+ handler: (row) => {
87
+ console.log('编辑行:', row)
88
+ }
89
+ },
90
+ {
91
+ title: '删除',
92
+ type: 'danger',
93
+ handler: (row) => {
94
+ console.log('删除行:', row)
95
+ }
96
+ }
97
+ ]
98
+
99
+ const loading = ref(false)
100
+ const total = ref(100)
25
101
  </script>
26
102
  ```
27
103
 
28
- ### 导入样式
104
+ #### 属性
105
+
106
+ | 属性名 | 类型 | 默认值 | 说明 |
107
+ | --- | --- | --- | --- |
108
+ | loading | boolean | false | 是否显示加载状态 |
109
+ | view | MetaView | - | 表格视图定义,包含字段配置 |
110
+ | buttons | MTableButton[] | [] | 表格行操作按钮配置 |
111
+ | columns | MTableColumn[] | [] | 自定义列配置 |
112
+ | sortableCallback | Function | - | 排序回调函数 |
113
+ | border | boolean | true | 是否显示边框 |
114
+ | fit | boolean | true | 列的宽度是否自撑开 |
115
+ | showHeader | boolean | true | 是否显示表头 |
116
+ | highlightCurrentRow | boolean | false | 是否高亮当前行 |
117
+
118
+ #### 插槽
119
+
120
+ | 插槽名 | 说明 |
121
+ | --- | --- |
122
+ | header | 表格顶部区域 |
123
+ | header-tool | 表格顶部工具区域 |
124
+ | footer | 表格底部区域 |
125
+ | footer-tool | 表格底部工具区域 |
126
+ | cell | 自定义单元格内容,参数包含 field, row, prop |
127
+ | pop-meta | 元数据弹出框内容 |
128
+ | pop-search | 搜索弹出框内容 |
129
+ | pop-field | 字段弹出框内容 |
130
+ | pop-cell | 单元格弹出框内容 |
131
+ | pop-index | 索引弹出框内容 |
132
+
133
+ #### 方法
134
+
135
+ | 方法名 | 参数 | 说明 |
136
+ | --- | --- | --- |
137
+ | getSelection | - | 获取当前选中的行 |
138
+ | setSelection | (rows) | 设置选中的行 |
139
+ | closePopover | - | 关闭当前打开的弹出框 |
140
+
141
+ ### MCell 单元格组件
142
+
143
+ 根据字段类型自动渲染不同类型的单元格组件。
144
+
145
+ #### 基本用法
146
+
147
+ ```vue
148
+ <template>
149
+ <m-cell
150
+ :field="field"
151
+ :bean="dataItem"
152
+ :disabled="false"
153
+ ></m-cell>
154
+ </template>
155
+
156
+ <script setup>
157
+ import { ref } from 'vue'
158
+
159
+ // 字段定义
160
+ const field = ref({
161
+ prop: 'name',
162
+ label: '姓名',
163
+ domain: 'string' // 可选值: string, number, boolean, date, time, select, color 等
164
+ })
29
165
 
30
- ```ts
31
- // 在main.ts中导入样式
32
- import 'morghulis/dist/morghulis.css'
166
+ // 数据项
167
+ const dataItem = ref({
168
+ name: '张三',
169
+ age: 30,
170
+ isActive: true
171
+ })
172
+ </script>
33
173
  ```
34
174
 
35
- ### 使用弹窗功能
175
+ #### 属性
176
+
177
+ | 属性名 | 类型 | 默认值 | 说明 |
178
+ | --- | --- | --- | --- |
179
+ | field | MetaField | - | 字段定义,包含prop、domain等属性 |
180
+ | bean | DataItem | - | 数据对象 |
181
+ | disabled | boolean | false | 是否禁用编辑 |
182
+
183
+ ### MDialog 对话框组件
184
+
185
+ 高度可定制的对话框组件,适用于数据库操作交互。
186
+
187
+ #### 基本用法
36
188
 
37
189
  ```vue
38
190
  <template>
39
- <MButton ref="buttonRef" popupMessage="自定义弹窗消息">点击弹窗</MButton>
40
- <button @click="showCustomPopup">手动调用弹窗</button>
191
+ <m-dialog
192
+ v-model="dialogVisible"
193
+ title="用户信息"
194
+ sub-title="编辑用户详情"
195
+ :confirm="handleConfirm"
196
+ >
197
+ <!-- 对话框内容 -->
198
+ </m-dialog>
199
+
200
+ <el-button @click="openDialog">打开对话框</el-button>
41
201
  </template>
42
202
 
43
- <script setup lang="ts">
203
+ <script setup>
44
204
  import { ref } from 'vue'
45
- import { MButton } from 'morghulis'
46
205
 
47
- const buttonRef = ref()
206
+ const dialogVisible = ref(false)
207
+ const dialogRef = ref(null)
48
208
 
49
- function showCustomPopup() {
50
- buttonRef.value.popup('这是一个自定义弹窗!')
209
+ function openDialog() {
210
+ // 可以通过ref调用open方法打开对话框并传递数据
211
+ dialogRef.value.open({id: 1, name: '张三'})
212
+ }
213
+
214
+ function handleConfirm(data, done) {
215
+ // 处理确认逻辑
216
+ console.log('提交的数据:', data)
217
+ // 完成后关闭对话框
218
+ done()
51
219
  }
52
220
  </script>
53
221
  ```
54
222
 
55
- ## API
223
+ #### 属性
224
+
225
+ | 属性名 | 类型 | 默认值 | 说明 |
226
+ | --- | --- | --- | --- |
227
+ | modelValue | boolean | false | 控制对话框显示/隐藏 |
228
+ | title | string | '对话框' | 对话框标题 |
229
+ | subTitle | string | '' | 对话框副标题 |
230
+ | width | string/number | 600 | 对话框宽度 |
231
+ | fullscreen | boolean | false | 是否全屏显示 |
232
+ | top | string | '30px' | 对话框距离顶部的距离 |
233
+ | modal | boolean | true | 是否显示遮罩层 |
234
+ | modalClass | string | 'mor-dialog-modal' | 遮罩层的自定义类名 |
235
+ | headerClass | string | 'mor-dialog-header' | 头部的自定义类名 |
236
+ | bodyClass | string | 'mor-dialog-body-wrapper' | 内容区的自定义类名 |
237
+ | footerClass | string | 'mor-dialog-footer' | 底部的自定义类名 |
238
+ | appendToBody | boolean | true | 是否将对话框插入至body元素 |
239
+ | lockScroll | boolean | true | 是否在对话框出现时将body滚动锁定 |
240
+ | closeOnClickModal | boolean | true | 是否可以通过点击遮罩层关闭对话框 |
241
+ | closeOnPressEscape | boolean | true | 是否可以通过按下ESC键关闭对话框 |
242
+ | showClose | boolean | true | 是否显示关闭按钮 |
243
+ | draggable | boolean | false | 是否可拖拽 |
244
+ | center | boolean | false | 是否对头部和底部采用居中布局 |
245
+ | destroyOnClose | boolean | false | 关闭时是否销毁对话框内的元素 |
246
+ | confirm | Function | - | 确认按钮点击时的回调函数,参数为(data, done) |
247
+ | cancel | Function | - | 取消按钮点击时的回调函数,参数为(data, done) |
248
+ | confirmButtonText | string | '确定' | 确认按钮文本 |
249
+ | cancelButtonText | string | '取消' | 取消按钮文本 |
250
+
251
+ #### 方法
252
+
253
+ | 方法名 | 参数 | 说明 |
254
+ | --- | --- | --- |
255
+ | open | (data, config) | 打开对话框并传入数据,config可选,包含title和subTitle |
256
+ | close | - | 关闭对话框 |
257
+
258
+ #### 插槽
259
+
260
+ | 插槽名 | 说明 |
261
+ | --- | --- |
262
+ | default | 对话框内容 |
263
+ | title | 自定义标题区域 |
264
+ | sub-title | 自定义副标题区域 |
265
+ | header | 自定义头部区域 |
266
+ | footer | 自定义底部区域 |
267
+
268
+ ## Hooks
269
+
270
+ ### useMorghulisCookies
271
+
272
+ 提供Cookie操作的工具函数。
273
+
274
+ ```js
275
+ import { useMorghulisCookies } from 'morghulis'
276
+
277
+ const { get, set, remove, load } = useMorghulisCookies()
278
+
279
+ // 设置Cookie
280
+ set('user.name', '张三')
281
+
282
+ // 获取Cookie
283
+ const userName = get('user.name')
284
+
285
+ // 加载Cookie,如果不存在则设置默认值
286
+ const config = load('config', { theme: 'dark' })
287
+
288
+ // 删除Cookie
289
+ remove('user.name')
290
+ ```
291
+
292
+ #### 方法
293
+
294
+ | 方法名 | 参数 | 返回值 | 说明 |
295
+ | --- | --- | --- | --- |
296
+ | get | (path: string) | any | 获取指定路径的Cookie值 |
297
+ | set | (path: string, value?: any) | void | 设置指定路径的Cookie值 |
298
+ | load | (key: string, value?: any) | any | 获取指定键的Cookie值,如果不存在则设置默认值 |
299
+ | remove | (path: string) | void | 删除指定路径的Cookie值 |
300
+
301
+ ### useMorghulisAuthorize
302
+
303
+ 提供用户授权相关的工具函数。
304
+
305
+ ```js
306
+ import { useMorghulisAuthorize } from 'morghulis'
307
+
308
+ const { $client, user, check, login, logout, bearer } = useMorghulisAuthorize()
309
+
310
+ // 获取当前用户ID
311
+ const currentUser = user()
312
+
313
+ // 检查是否为指定用户
314
+ const isAdmin = check('admin')
315
+
316
+ // 登录
317
+ login('user123')
318
+
319
+ // 登出
320
+ logout()
321
+
322
+ // 获取Bearer令牌
323
+ const token = bearer()
324
+ ```
325
+
326
+ #### 方法和属性
327
+
328
+ | 名称 | 类型 | 说明 |
329
+ | --- | --- | --- |
330
+ | $client | string | 客户端唯一标识 |
331
+ | user | Function | 获取当前用户ID |
332
+ | check | Function | 检查当前用户是否为指定用户 |
333
+ | login | Function | 设置用户登录状态 |
334
+ | logout | Function | 清除用户登录状态 |
335
+ | bearer | Function | 获取Bearer认证令牌 |
336
+
337
+ ### useMorghulisChannel
338
+
339
+ 提供通道相关的工具函数。
340
+
341
+ ```js
342
+ import { useMorghulisChannel } from 'morghulis'
343
+
344
+ const { http } = useMorghulisChannel('/api')
345
+
346
+ // 使用http发送请求
347
+ http.get('/users').then(response => {
348
+ console.log(response.data)
349
+ })
350
+ ```
351
+
352
+ #### 方法
353
+
354
+ | 方法名 | 返回值 | 说明 |
355
+ | --- | --- | --- |
356
+ | http | AxiosInstance | 返回配置好的Axios实例 |
357
+
358
+ ### useMorghulisRequest
359
+
360
+ 提供请求相关的工具函数。
361
+
362
+ ```js
363
+ import { useMorghulisRequest } from 'morghulis'
364
+
365
+ const { getRequest } = useMorghulisRequest('/api')
366
+
367
+ // 获取配置好的请求实例
368
+ const http = getRequest()
369
+
370
+ // 发送请求
371
+ http.get('/users').then(response => {
372
+ console.log(response.data)
373
+ })
374
+ ```
375
+
376
+ #### 方法
377
+
378
+ | 方法名 | 参数 | 返回值 | 说明 |
379
+ | --- | --- | --- | --- |
380
+ | getRequest | (auth?: boolean) | AxiosInstance | 获取配置好的Axios实例,auth参数指定是否需要认证 |
381
+
382
+ ## 工具函数
383
+
384
+ ### $message
385
+
386
+ 提供消息提示功能。
387
+
388
+ ```js
389
+ import { $message } from 'morghulis'
390
+
391
+ // 成功提示
392
+ $message.success('操作成功')
393
+
394
+ // 信息提示
395
+ $message.info('提示信息')
396
+
397
+ // 警告提示
398
+ $message.warning('警告信息')
399
+
400
+ // 错误提示
401
+ $message.error('错误信息')
402
+ ```
403
+
404
+ #### 方法
405
+
406
+ | 方法名 | 参数 | 说明 |
407
+ | --- | --- | --- |
408
+ | info | (message: string) | 显示信息提示 |
409
+ | success | (message: string) | 显示成功提示 |
410
+ | warning | (message: string) | 显示警告提示 |
411
+ | error | (message: string) | 显示错误提示 |
56
412
 
57
- ### 属性
413
+ ### $alert
58
414
 
59
- | 属性名 | 类型 | 默认值 | 可选值 | 说明 |
60
- |-------|------|-------|-------|------|
61
- | color | string | 'primary' | 'primary', 'success', 'warning', 'danger', 'info' | 按钮颜色 |
62
- | size | string | 'medium' | 'small', 'medium', 'large' | 按钮尺寸 |
63
- | round | boolean | false | - | 是否为圆角按钮 |
64
- | disabled | boolean | false | - | 是否禁用 |
65
- | popupMessage | string | '按钮被点击!' | - | 自定义弹窗消息 |
415
+ 提供警告对话框功能。
66
416
 
67
- ### 事件
417
+ ```js
418
+ import { $alert } from 'morghulis'
68
419
 
69
- | 事件名 | 参数 | 说明 |
70
- |-------|------|------|
71
- | click | MouseEvent | 按钮点击事件 |
72
- | popup | string | 弹窗显示事件,参数为弹窗消息 |
420
+ // 成功提示
421
+ $alert.success('操作成功', '提示').then(() => {
422
+ // 点击确定按钮后的回调
423
+ })
73
424
 
74
- ### 方法
425
+ // 信息提示
426
+ $alert.info('提示信息')
427
+
428
+ // 警告提示
429
+ $alert.warning('警告信息', '警告')
430
+
431
+ // 错误提示
432
+ $alert.error('错误信息', '错误')
433
+ ```
434
+
435
+ #### 方法
75
436
 
76
437
  | 方法名 | 参数 | 返回值 | 说明 |
77
- |-------|------|-------|------|
78
- | popup | message: string | string | 显示弹窗,参数为弹窗消息 |
438
+ | --- | --- | --- | --- |
439
+ | info | (message: string, title?: string) | Promise | 显示信息警告框 |
440
+ | success | (message: string, title?: string) | Promise | 显示成功警告框 |
441
+ | warning | (message: string, title?: string) | Promise | 显示警告警告框 |
442
+ | error | (message: string, title?: string) | Promise | 显示错误警告框 |
79
443
 
80
- ## Python使用方法
444
+ ### $confirm
81
445
 
82
- 当使用pip安装morghulis包后,您可以在Python项目中使用此组件,并享受自动代码补全功能。
446
+ 提供确认对话框功能。
83
447
 
84
- ```python
85
- # 在您的Python项目中使用
86
- from morghulis import MButton
448
+ ```js
449
+ import { $confirm } from 'morghulis'
87
450
 
88
- # 创建按钮实例
89
- button = MButton(
90
- color="primary",
91
- size="medium",
92
- round=True,
93
- disabled=False,
94
- popupMessage="这是一个弹窗消息"
95
- )
451
+ // 确认操作
452
+ $confirm.warning('确定要删除吗?', '警告').then(() => {
453
+ // 点击确定按钮后的回调
454
+ }).catch(() => {
455
+ // 点击取消按钮后的回调
456
+ })
457
+ ```
96
458
 
97
- # 调用按钮方法
98
- button.popup("显示自定义弹窗")
459
+ #### 方法
460
+
461
+ | 方法名 | 参数 | 返回值 | 说明 |
462
+ | --- | --- | --- | --- |
463
+ | info | (message: string, title?: string) | Promise | 显示信息确认框 |
464
+ | success | (message: string, title?: string) | Promise | 显示成功确认框 |
465
+ | warning | (message: string, title?: string) | Promise | 显示警告确认框 |
466
+ | error | (message: string, title?: string) | Promise | 显示错误确认框 |
467
+
468
+ ## 配置选项
469
+
470
+ 在使用`createMorghulis`函数时,可以传入以下配置选项:
471
+
472
+ ```js
473
+ app.use(createMorghulis({
474
+ baseURL: '/api/', // API基础路径
475
+ minioURL: '/dfs/', // 文件服务基础路径
476
+ // 其他配置...
477
+ }))
99
478
  ```
479
+
480
+ | 选项名 | 类型 | 默认值 | 说明 |
481
+ | --- | --- | --- | --- |
482
+ | baseURL | string | '/api/' | API基础路径 |
483
+ | minioURL | string | '/dfs/' | 文件服务基础路径 |
484
+ | timeout | number | - | 请求超时时间 |
485
+ | headers | object | - | 请求头配置 |