morghulis 1.0.23 → 1.0.25
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 +51 -451
- package/dist/favicon.ico +0 -0
- package/dist/index.css +1 -0
- package/dist/index.js +8880 -0
- package/dist/index.umd.cjs +38 -0
- package/dist/types.d.ts +731 -0
- package/package.json +50 -32
- package/dist/morghulis.es.js +0 -2737
- package/dist/morghulis.es.js.map +0 -1
- package/dist/morghulis.umd.js +0 -11
- package/dist/morghulis.umd.js.map +0 -1
- package/dist/style.css +0 -4
- package/types/index.d.ts +0 -152
package/README.md
CHANGED
@@ -1,485 +1,85 @@
|
|
1
|
-
# Morghulis
|
1
|
+
# Morghulis
|
2
2
|
|
3
|
-
|
3
|
+
一个基于Vue 3的组件库,提供了多种实用组件和工具函数。
|
4
4
|
|
5
|
-
##
|
5
|
+
## 安装
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
- 提供高度可定制的对话框组件,适用于数据库操作交互
|
11
|
-
- 简化数据库表单创建和管理流程
|
12
|
-
- 内置常用数据库操作UI模板
|
7
|
+
```bash
|
8
|
+
npm install morghulis
|
9
|
+
```
|
13
10
|
|
14
|
-
##
|
11
|
+
## 使用
|
15
12
|
|
16
|
-
|
13
|
+
### 全局注册
|
17
14
|
|
18
|
-
```
|
19
|
-
// main.ts 或 main.js
|
15
|
+
```typescript
|
20
16
|
import { createApp } from 'vue'
|
21
|
-
import App from './App.vue'
|
22
17
|
import { createMorghulis } from 'morghulis'
|
23
|
-
import '
|
18
|
+
import App from './App.vue'
|
24
19
|
|
25
20
|
const app = createApp(App)
|
26
21
|
|
27
|
-
//
|
22
|
+
// 使用默认配置
|
28
23
|
app.use(createMorghulis())
|
29
24
|
|
25
|
+
// 或者自定义配置
|
26
|
+
app.use(createMorghulis({
|
27
|
+
baseURL: '/api/',
|
28
|
+
minioURL: '/dfs/'
|
29
|
+
}))
|
30
|
+
|
30
31
|
app.mount('#app')
|
31
32
|
```
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
### MTable 表格组件
|
34
|
+
### 单独使用组件
|
36
35
|
|
37
|
-
|
36
|
+
```typescript
|
37
|
+
import { MTable, MDialog, MForm, DTable } from 'morghulis'
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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>
|
67
|
-
</template>
|
68
|
-
|
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' }
|
39
|
+
// 在组件中使用
|
40
|
+
export default {
|
41
|
+
components: {
|
42
|
+
MTable,
|
43
|
+
MDialog,
|
44
|
+
MForm,
|
45
|
+
DTable
|
78
46
|
}
|
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)
|
101
|
-
</script>
|
102
|
-
```
|
103
|
-
|
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
|
-
})
|
165
|
-
|
166
|
-
// 数据项
|
167
|
-
const dataItem = ref({
|
168
|
-
name: '张三',
|
169
|
-
age: 30,
|
170
|
-
isActive: true
|
171
|
-
})
|
172
|
-
</script>
|
47
|
+
}
|
173
48
|
```
|
174
49
|
|
175
|
-
|
50
|
+
### 使用工具函数
|
176
51
|
|
177
|
-
|
178
|
-
|
179
|
-
| field | MetaField | - | 字段定义,包含prop、domain等属性 |
|
180
|
-
| bean | DataItem | - | 数据对象 |
|
181
|
-
| disabled | boolean | false | 是否禁用编辑 |
|
52
|
+
```typescript
|
53
|
+
import { useMorghulisRequest, useMorghulisCookies } from 'morghulis'
|
182
54
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
#### 基本用法
|
188
|
-
|
189
|
-
```vue
|
190
|
-
<template>
|
191
|
-
<m-dialog
|
192
|
-
v-model="dialogVisible"
|
193
|
-
title="用户信息"
|
194
|
-
sub-title="编辑用户详情"
|
195
|
-
:confirm="handleConfirm"
|
196
|
-
>
|
197
|
-
<!-- 对话框内容 -->
|
198
|
-
</m-dialog>
|
55
|
+
// 在组件中使用
|
56
|
+
setup() {
|
57
|
+
const { get, post } = useMorghulisRequest()
|
58
|
+
const { get: getCookie, set: setCookie } = useMorghulisCookies()
|
199
59
|
|
200
|
-
|
201
|
-
</template>
|
202
|
-
|
203
|
-
<script setup>
|
204
|
-
import { ref } from 'vue'
|
205
|
-
|
206
|
-
const dialogVisible = ref(false)
|
207
|
-
const dialogRef = ref(null)
|
208
|
-
|
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()
|
60
|
+
// 使用这些函数...
|
219
61
|
}
|
220
|
-
</script>
|
221
|
-
```
|
222
|
-
|
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
62
|
```
|
291
63
|
|
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
|
-
#### 方法
|
64
|
+
## 组件
|
377
65
|
|
378
|
-
|
379
|
-
|
380
|
-
|
66
|
+
- `MTable`: 表格组件
|
67
|
+
- `MDialog`: 对话框组件
|
68
|
+
- `MForm`: 表单组件
|
69
|
+
- `DTable`: 数据表格组件
|
381
70
|
|
382
71
|
## 工具函数
|
383
72
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
import { $message } from 'morghulis'
|
73
|
+
- `useMorghulisAuthorize`: 授权相关函数
|
74
|
+
- `useMorghulisChannel`: 通道相关函数
|
75
|
+
- `useMorghulisSockets`: Socket相关函数
|
76
|
+
- `useMorghulisRequest`: 请求相关函数
|
77
|
+
- `useMorghulisCookies`: Cookie相关函数
|
390
78
|
|
391
|
-
|
392
|
-
$message.success('操作成功')
|
79
|
+
## 类型
|
393
80
|
|
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) | 显示错误提示 |
|
412
|
-
|
413
|
-
### $alert
|
414
|
-
|
415
|
-
提供警告对话框功能。
|
416
|
-
|
417
|
-
```js
|
418
|
-
import { $alert } from 'morghulis'
|
419
|
-
|
420
|
-
// 成功提示
|
421
|
-
$alert.success('操作成功', '提示').then(() => {
|
422
|
-
// 点击确定按钮后的回调
|
423
|
-
})
|
424
|
-
|
425
|
-
// 信息提示
|
426
|
-
$alert.info('提示信息')
|
427
|
-
|
428
|
-
// 警告提示
|
429
|
-
$alert.warning('警告信息', '警告')
|
430
|
-
|
431
|
-
// 错误提示
|
432
|
-
$alert.error('错误信息', '错误')
|
433
|
-
```
|
434
|
-
|
435
|
-
#### 方法
|
436
|
-
|
437
|
-
| 方法名 | 参数 | 返回值 | 说明 |
|
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 | 显示错误警告框 |
|
443
|
-
|
444
|
-
### $confirm
|
445
|
-
|
446
|
-
提供确认对话框功能。
|
447
|
-
|
448
|
-
```js
|
449
|
-
import { $confirm } from 'morghulis'
|
450
|
-
|
451
|
-
// 确认操作
|
452
|
-
$confirm.warning('确定要删除吗?', '警告').then(() => {
|
453
|
-
// 点击确定按钮后的回调
|
454
|
-
}).catch(() => {
|
455
|
-
// 点击取消按钮后的回调
|
456
|
-
})
|
457
|
-
```
|
458
|
-
|
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
|
-
}))
|
478
|
-
```
|
81
|
+
所有类型都已导出,可以直接导入使用:
|
479
82
|
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
| minioURL | string | '/dfs/' | 文件服务基础路径 |
|
484
|
-
| timeout | number | - | 请求超时时间 |
|
485
|
-
| headers | object | - | 请求头配置 |
|
83
|
+
```typescript
|
84
|
+
import { MorghulisOptions, UIFeedbackTypes } from 'morghulis'
|
85
|
+
```
|
package/dist/favicon.ico
ADDED
Binary file
|