morghulis 1.0.27 → 1.0.28
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 +166 -15
- package/dist/index.d.ts +251 -4
- package/package.json +5 -2
package/README.md
CHANGED
@@ -15,6 +15,7 @@ npm install morghulis
|
|
15
15
|
```typescript
|
16
16
|
import { createApp } from 'vue'
|
17
17
|
import { createMorghulis } from 'morghulis'
|
18
|
+
import 'morghulis/dist/index.css'
|
18
19
|
import App from './App.vue'
|
19
20
|
|
20
21
|
const app = createApp(App)
|
@@ -31,18 +32,37 @@ app.use(createMorghulis({
|
|
31
32
|
app.mount('#app')
|
32
33
|
```
|
33
34
|
|
35
|
+
### 样式导入
|
36
|
+
|
37
|
+
你可以通过以下任意方式导入样式:
|
38
|
+
|
39
|
+
```typescript
|
40
|
+
// 推荐方式
|
41
|
+
import 'morghulis/dist/index.css'
|
42
|
+
|
43
|
+
// 或使用以下方式之一
|
44
|
+
import 'morghulis/style'
|
45
|
+
import 'morghulis/dist/style'
|
46
|
+
import 'morghulis/dist/style.css'
|
47
|
+
```
|
48
|
+
|
34
49
|
### 单独使用组件
|
35
50
|
|
36
51
|
```typescript
|
37
|
-
import {
|
52
|
+
import { MDialog, MTable, MForm, DTable, DCell, DForm, DController, MCell } from 'morghulis'
|
53
|
+
import 'morghulis/dist/index.css'
|
38
54
|
|
39
55
|
// 在组件中使用
|
40
56
|
export default {
|
41
57
|
components: {
|
42
|
-
MTable,
|
43
58
|
MDialog,
|
59
|
+
MTable,
|
44
60
|
MForm,
|
45
|
-
DTable
|
61
|
+
DTable,
|
62
|
+
DCell,
|
63
|
+
DForm,
|
64
|
+
DController,
|
65
|
+
MCell
|
46
66
|
}
|
47
67
|
}
|
48
68
|
```
|
@@ -50,12 +70,13 @@ export default {
|
|
50
70
|
### 使用工具函数
|
51
71
|
|
52
72
|
```typescript
|
53
|
-
import { useMorghulisRequest, useMorghulisCookies } from 'morghulis'
|
73
|
+
import { useMorghulisAuthorize, useMorghulisRequest, useMorghulisCookies } from 'morghulis'
|
54
74
|
|
55
75
|
// 在组件中使用
|
56
76
|
setup() {
|
57
77
|
const { get, post } = useMorghulisRequest()
|
58
78
|
const { get: getCookie, set: setCookie } = useMorghulisCookies()
|
79
|
+
const { login, logout, check, bearer } = useMorghulisAuthorize()
|
59
80
|
|
60
81
|
// 使用这些函数...
|
61
82
|
}
|
@@ -63,23 +84,153 @@ setup() {
|
|
63
84
|
|
64
85
|
## 组件
|
65
86
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
87
|
+
### 对话框
|
88
|
+
|
89
|
+
```typescript
|
90
|
+
import { MDialog } from 'morghulis'
|
91
|
+
import type { MorDialogProps, MorDialogConfig } from 'morghulis'
|
92
|
+
|
93
|
+
// 在模板中使用
|
94
|
+
<MDialog
|
95
|
+
v-model="dialogVisible"
|
96
|
+
title="标题"
|
97
|
+
subTitle="副标题"
|
98
|
+
:width="600"
|
99
|
+
:fullscreen="false"
|
100
|
+
:modal="true"
|
101
|
+
@close="handleClose"
|
102
|
+
/>
|
103
|
+
|
104
|
+
// 使用组件的方法
|
105
|
+
const dialog = ref()
|
106
|
+
// 打开对话框
|
107
|
+
dialog.value.open(data, { title: '自定义标题', subTitle: '自定义副标题' })
|
108
|
+
// 关闭对话框
|
109
|
+
dialog.value.close()
|
110
|
+
```
|
111
|
+
|
112
|
+
### 表格组件
|
113
|
+
|
114
|
+
```typescript
|
115
|
+
import { MTable, DTable, DCell, DForm, DController } from 'morghulis'
|
116
|
+
|
117
|
+
// 数据表格
|
118
|
+
<DTable
|
119
|
+
:data="tableData"
|
120
|
+
:columns="columns"
|
121
|
+
/>
|
122
|
+
|
123
|
+
// 普通表格
|
124
|
+
<MTable
|
125
|
+
:data="tableData"
|
126
|
+
:columns="columns"
|
127
|
+
/>
|
128
|
+
```
|
70
129
|
|
71
130
|
## 工具函数
|
72
131
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
132
|
+
### 授权功能
|
133
|
+
|
134
|
+
```typescript
|
135
|
+
import { useMorghulisAuthorize } from 'morghulis'
|
136
|
+
import type { MorghulisAuthorize } from 'morghulis'
|
137
|
+
|
138
|
+
const auth = useMorghulisAuthorize()
|
139
|
+
|
140
|
+
// 登录
|
141
|
+
auth.login(userId)
|
142
|
+
|
143
|
+
// 检查用户是否登录
|
144
|
+
if (auth.check()) {
|
145
|
+
// 已登录
|
146
|
+
}
|
147
|
+
|
148
|
+
// 获取认证令牌
|
149
|
+
const token = auth.bearer()
|
150
|
+
|
151
|
+
// 登出
|
152
|
+
auth.logout()
|
153
|
+
```
|
154
|
+
|
155
|
+
### 请求功能
|
156
|
+
|
157
|
+
```typescript
|
158
|
+
import { useMorghulisRequest } from 'morghulis'
|
159
|
+
|
160
|
+
const { get, post, put, delete: del } = useMorghulisRequest()
|
161
|
+
|
162
|
+
// 发送请求
|
163
|
+
const response = await get('/api/users')
|
164
|
+
```
|
78
165
|
|
79
166
|
## 类型
|
80
167
|
|
81
168
|
所有类型都已导出,可以直接导入使用:
|
82
169
|
|
83
170
|
```typescript
|
84
|
-
|
85
|
-
|
171
|
+
// 导入组件属性类型
|
172
|
+
import type {
|
173
|
+
MorDialogProps,
|
174
|
+
MorDialogConfig,
|
175
|
+
MorOption,
|
176
|
+
MorghulisAuthorize
|
177
|
+
} from 'morghulis'
|
178
|
+
|
179
|
+
// 使用类型
|
180
|
+
const dialogProps: MorDialogProps = {
|
181
|
+
title: '标题',
|
182
|
+
width: 600,
|
183
|
+
modal: true,
|
184
|
+
confirmButtonText: '确认',
|
185
|
+
cancelButtonText: '取消',
|
186
|
+
confirm: (data, done) => {
|
187
|
+
// 处理确认逻辑
|
188
|
+
done()
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
// 使用配置类型
|
193
|
+
const options: MorOption = {
|
194
|
+
baseURL: '/api/',
|
195
|
+
minioURL: '/dfs/',
|
196
|
+
// 其他自定义配置...
|
197
|
+
}
|
198
|
+
```
|
199
|
+
|
200
|
+
## 全局类型支持
|
201
|
+
|
202
|
+
组件库提供全局类型支持,导入后可以在模板中直接使用组件名称,TypeScript 会自动提供类型检查和属性提示:
|
203
|
+
|
204
|
+
```vue
|
205
|
+
<template>
|
206
|
+
<MDialog
|
207
|
+
v-model="dialogVisible"
|
208
|
+
title="标题"
|
209
|
+
@close="handleClose"
|
210
|
+
/>
|
211
|
+
|
212
|
+
<!-- Element Plus 组件也有类型提示 -->
|
213
|
+
<ElButton type="primary">按钮</ElButton>
|
214
|
+
</template>
|
215
|
+
|
216
|
+
<script setup lang="ts">
|
217
|
+
import { ref } from 'vue'
|
218
|
+
// 无需导入组件,但需要导入库
|
219
|
+
import 'morghulis'
|
220
|
+
|
221
|
+
const dialogVisible = ref(false)
|
222
|
+
const handleClose = () => {
|
223
|
+
dialogVisible.value = false
|
224
|
+
}
|
225
|
+
</script>
|
226
|
+
```
|
227
|
+
|
228
|
+
## 版本说明
|
229
|
+
|
230
|
+
当前版本: 1.0.28
|
231
|
+
|
232
|
+
- 解决了类型声明冲突问题
|
233
|
+
- 提供了完整的组件类型定义
|
234
|
+
- 添加了全局类型支持
|
235
|
+
- 修复了CSS样式文件导入问题
|
236
|
+
- 增强了组件属性和方法的TypeScript智能提示
|
package/dist/index.d.ts
CHANGED
@@ -2,7 +2,12 @@ import type { App } from 'vue';
|
|
2
2
|
import type { ElDialog, ElButton, ElText, ElDivider, ElSpace } from 'element-plus';
|
3
3
|
|
4
4
|
// 导入Vue组件实例类型
|
5
|
-
import type { DefineComponent, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, EmitsOptions } from 'vue';
|
5
|
+
import type { DefineComponent, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, EmitsOptions, Component } from 'vue';
|
6
|
+
|
7
|
+
// 基础类型定义
|
8
|
+
export type UIFeedbackTypes = "success" | "info" | "warning" | "error";
|
9
|
+
export type UITextTypes = "success" | "info" | "warning" | "danger" | 'primary';
|
10
|
+
export type UISizeTypes = 'default' | 'small' | 'large' | "";
|
6
11
|
|
7
12
|
// 直接在类型定义文件中定义MorDialogProps,避免相对路径引用
|
8
13
|
export interface MorDialogProps {
|
@@ -54,6 +59,140 @@ export interface MorOption {
|
|
54
59
|
[key: string]: any
|
55
60
|
}
|
56
61
|
|
62
|
+
// 定义表格相关类型
|
63
|
+
export interface DataItem {
|
64
|
+
[key: string]: any;
|
65
|
+
}
|
66
|
+
|
67
|
+
export type Orders = Array<{
|
68
|
+
column: string;
|
69
|
+
asc?: boolean;
|
70
|
+
}>;
|
71
|
+
|
72
|
+
export interface DaoTypes {
|
73
|
+
add: (entity: string, bean: DataItem) => Promise<any>;
|
74
|
+
update: (entity: string, bean: DataItem) => Promise<any>;
|
75
|
+
delete: (entity: string, id: string | number) => Promise<any>;
|
76
|
+
get: (entity: string, id: string | number, options?: any) => Promise<any>;
|
77
|
+
list: (entity: string, options?: any) => Promise<any>;
|
78
|
+
page: (entity: string, page: number, size: number, options?: any) => Promise<any>;
|
79
|
+
}
|
80
|
+
|
81
|
+
export interface MetaField {
|
82
|
+
code: string;
|
83
|
+
name: string;
|
84
|
+
type: string;
|
85
|
+
options?: any[];
|
86
|
+
required?: boolean;
|
87
|
+
readonly?: boolean;
|
88
|
+
hidden?: boolean;
|
89
|
+
[key: string]: any;
|
90
|
+
}
|
91
|
+
|
92
|
+
export interface MetaView {
|
93
|
+
code: string;
|
94
|
+
name: string;
|
95
|
+
fields: MetaField[];
|
96
|
+
[key: string]: any;
|
97
|
+
}
|
98
|
+
|
99
|
+
export type SortableCallbackFn = (newIndex: number, oldIndex: number) => void;
|
100
|
+
|
101
|
+
export type MTableButton = {
|
102
|
+
size?: UISizeTypes;
|
103
|
+
handler?: (row: any, event?: Event) => void;
|
104
|
+
title?: string | Function;
|
105
|
+
type?: UITextTypes | Function;
|
106
|
+
link?: boolean | Function;
|
107
|
+
plain?: boolean | Function;
|
108
|
+
text?: boolean | Function;
|
109
|
+
round?: boolean | Function;
|
110
|
+
circle?: boolean | Function;
|
111
|
+
disabled?: boolean | Function;
|
112
|
+
dark?: boolean | Function;
|
113
|
+
color?: string | Function;
|
114
|
+
tag?: string | Function;
|
115
|
+
};
|
116
|
+
|
117
|
+
export type MTableColumn = {
|
118
|
+
label: string;
|
119
|
+
component: Component;
|
120
|
+
width?: string | number;
|
121
|
+
};
|
122
|
+
|
123
|
+
export interface TableProps {
|
124
|
+
data?: any[];
|
125
|
+
height?: string | number;
|
126
|
+
maxHeight?: string | number;
|
127
|
+
stripe?: boolean;
|
128
|
+
border?: boolean;
|
129
|
+
size?: string;
|
130
|
+
fit?: boolean;
|
131
|
+
showHeader?: boolean;
|
132
|
+
highlightCurrentRow?: boolean;
|
133
|
+
currentRowKey?: string | number;
|
134
|
+
rowClassName?: string | ((param: { row: any, rowIndex: number }) => string);
|
135
|
+
rowStyle?: object | ((param: { row: any, rowIndex: number }) => object);
|
136
|
+
cellClassName?: string | ((param: { row: any, column: any, rowIndex: number, columnIndex: number }) => string);
|
137
|
+
cellStyle?: object | ((param: { row: any, column: any, rowIndex: number, columnIndex: number }) => object);
|
138
|
+
headerRowClassName?: string | ((param: { row: any, rowIndex: number }) => string);
|
139
|
+
headerRowStyle?: object | ((param: { row: any, rowIndex: number }) => object);
|
140
|
+
headerCellClassName?: string | ((param: { row: any, column: any, rowIndex: number, columnIndex: number }) => string);
|
141
|
+
headerCellStyle?: object | ((param: { row: any, column: any, rowIndex: number, columnIndex: number }) => object);
|
142
|
+
rowKey?: string | ((row: any) => string);
|
143
|
+
emptyText?: string;
|
144
|
+
defaultExpandAll?: boolean;
|
145
|
+
expandRowKeys?: any[];
|
146
|
+
defaultSort?: { prop: string, order: string };
|
147
|
+
tooltipEffect?: string;
|
148
|
+
showSummary?: boolean;
|
149
|
+
sumText?: string;
|
150
|
+
summaryMethod?: (param: { columns: any[], data: any[] }) => any[];
|
151
|
+
spanMethod?: (param: { row: any, column: any, rowIndex: number, columnIndex: number }) => number[] | { rowspan: number, colspan: number };
|
152
|
+
selectOnIndeterminate?: boolean;
|
153
|
+
indent?: number;
|
154
|
+
lazy?: boolean;
|
155
|
+
load?: (row: any, treeNode: any, resolve: (data: any[]) => void) => void;
|
156
|
+
treeProps?: { children: string, hasChildren: string };
|
157
|
+
}
|
158
|
+
|
159
|
+
export interface MorghulisTableProps extends TableProps {
|
160
|
+
loading?: boolean;
|
161
|
+
view: MetaView;
|
162
|
+
buttons?: MTableButton[];
|
163
|
+
columns?: MTableColumn[];
|
164
|
+
sortableCallback?: SortableCallbackFn;
|
165
|
+
}
|
166
|
+
|
167
|
+
export interface DTableProps {
|
168
|
+
auth?: boolean;
|
169
|
+
db: DaoTypes;
|
170
|
+
entity: string;
|
171
|
+
code?: string;
|
172
|
+
size?: number;
|
173
|
+
page?: number;
|
174
|
+
includes?: DataItem;
|
175
|
+
excludes?: DataItem;
|
176
|
+
orders?: Orders;
|
177
|
+
buttons?: MTableButton[];
|
178
|
+
columns?: MTableColumn[];
|
179
|
+
}
|
180
|
+
|
181
|
+
export interface DCellProps {
|
182
|
+
view: MetaView;
|
183
|
+
prop: string;
|
184
|
+
bean: DataItem;
|
185
|
+
db: DaoTypes;
|
186
|
+
disabled?: boolean;
|
187
|
+
}
|
188
|
+
|
189
|
+
export interface DFormProps {
|
190
|
+
selection: any[];
|
191
|
+
view: MetaView;
|
192
|
+
db: DaoTypes;
|
193
|
+
bean: DataItem;
|
194
|
+
}
|
195
|
+
|
57
196
|
// 定义useMorghulisAuthorize函数的返回类型
|
58
197
|
export interface MorghulisAuthorize {
|
59
198
|
$client: string;
|
@@ -127,21 +266,129 @@ export declare const MDialog: DefineComponent<
|
|
127
266
|
// 导出MCell组件
|
128
267
|
export declare const MCell: DefineComponent<{}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<{}>, {}>;
|
129
268
|
|
269
|
+
// 导出MTable组件
|
270
|
+
export declare const MTable: DefineComponent<
|
271
|
+
MorghulisTableProps,
|
272
|
+
{},
|
273
|
+
{},
|
274
|
+
{},
|
275
|
+
{},
|
276
|
+
ComponentOptionsMixin,
|
277
|
+
ComponentOptionsMixin,
|
278
|
+
{
|
279
|
+
'selection-change': (selection: any[]) => true;
|
280
|
+
'sort': (column: any, prop: string, order: string) => true;
|
281
|
+
},
|
282
|
+
string,
|
283
|
+
VNodeProps & AllowedComponentProps & ComponentCustomProps,
|
284
|
+
Readonly<MorghulisTableProps> & {
|
285
|
+
'onSelection-change'?: (selection: any[]) => any;
|
286
|
+
'onSort'?: (column: any, prop: string, order: string) => any;
|
287
|
+
},
|
288
|
+
{}
|
289
|
+
>;
|
290
|
+
|
291
|
+
// 导出MForm组件
|
292
|
+
export declare const MForm: DefineComponent<{}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<{}>, {}>;
|
293
|
+
|
130
294
|
// 导出数据表格相关组件
|
131
|
-
export declare const DTable: DefineComponent<
|
132
|
-
|
133
|
-
|
295
|
+
export declare const DTable: DefineComponent<
|
296
|
+
DTableProps,
|
297
|
+
{},
|
298
|
+
{},
|
299
|
+
{},
|
300
|
+
{},
|
301
|
+
ComponentOptionsMixin,
|
302
|
+
ComponentOptionsMixin,
|
303
|
+
{},
|
304
|
+
string,
|
305
|
+
VNodeProps & AllowedComponentProps & ComponentCustomProps,
|
306
|
+
Readonly<DTableProps>,
|
307
|
+
{
|
308
|
+
size: number;
|
309
|
+
page: number;
|
310
|
+
}
|
311
|
+
> & {
|
312
|
+
refresh: () => void;
|
313
|
+
add: () => void;
|
314
|
+
edit: (row: any) => void;
|
315
|
+
remove: (row: any) => void;
|
316
|
+
handlePageSizeChange: (size: number) => void;
|
317
|
+
handleCurrentPageChange: (page: number) => void;
|
318
|
+
};
|
319
|
+
|
320
|
+
export declare const DCell: DefineComponent<
|
321
|
+
DCellProps,
|
322
|
+
{},
|
323
|
+
{},
|
324
|
+
{},
|
325
|
+
{},
|
326
|
+
ComponentOptionsMixin,
|
327
|
+
ComponentOptionsMixin,
|
328
|
+
{
|
329
|
+
cancel: (...args: any[]) => void;
|
330
|
+
save: (...args: any[]) => void;
|
331
|
+
},
|
332
|
+
string,
|
333
|
+
VNodeProps & AllowedComponentProps & ComponentCustomProps,
|
334
|
+
Readonly<DCellProps> & {
|
335
|
+
onCancel?: (...args: any[]) => any;
|
336
|
+
onSave?: (...args: any[]) => any;
|
337
|
+
},
|
338
|
+
{}
|
339
|
+
>;
|
340
|
+
|
341
|
+
export declare const DForm: DefineComponent<
|
342
|
+
DFormProps,
|
343
|
+
{},
|
344
|
+
{},
|
345
|
+
{},
|
346
|
+
{},
|
347
|
+
ComponentOptionsMixin,
|
348
|
+
ComponentOptionsMixin,
|
349
|
+
{},
|
350
|
+
string,
|
351
|
+
VNodeProps & AllowedComponentProps & ComponentCustomProps,
|
352
|
+
Readonly<DFormProps>,
|
353
|
+
{}
|
354
|
+
> & {
|
355
|
+
getData: () => any[];
|
356
|
+
};
|
357
|
+
|
134
358
|
export declare const DController: DefineComponent<{}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<{}>, {}>;
|
135
359
|
|
136
360
|
// 声明useMorghulisAuthorize函数
|
137
361
|
export declare function useMorghulisAuthorize(): MorghulisAuthorize;
|
138
362
|
|
363
|
+
// 其他hooks
|
364
|
+
export declare function useMorghulisChannel(): any;
|
365
|
+
export declare function useMorghulisSockets(baseURL?: string): any;
|
366
|
+
export declare function loadMorghulisSockets(baseURL?: string): any;
|
367
|
+
export declare function useMorghulisRequest(): {
|
368
|
+
get: <T = any>(url: string, params?: any, config?: any) => Promise<T>;
|
369
|
+
post: <T = any>(url: string, data?: any, config?: any) => Promise<T>;
|
370
|
+
put: <T = any>(url: string, data?: any, config?: any) => Promise<T>;
|
371
|
+
delete: <T = any>(url: string, data?: any, config?: any) => Promise<T>;
|
372
|
+
};
|
373
|
+
export declare function useMorghulisCookies(): {
|
374
|
+
get: (key: string, defaultValue?: any) => any;
|
375
|
+
set: (key: string, value: any, options?: any) => void;
|
376
|
+
remove: (key: string, options?: any) => void;
|
377
|
+
load: (key: string, defaultValue?: any) => any;
|
378
|
+
};
|
379
|
+
|
139
380
|
// 声明全局组件类型
|
140
381
|
declare module '@vue/runtime-core' {
|
141
382
|
export interface GlobalComponents {
|
142
383
|
// Morghulis组件
|
143
384
|
MDialog: typeof MDialog;
|
385
|
+
MTable: typeof MTable;
|
386
|
+
MForm: typeof MForm;
|
144
387
|
MCell: typeof MCell;
|
388
|
+
DTable: typeof DTable;
|
389
|
+
DCell: typeof DCell;
|
390
|
+
DForm: typeof DForm;
|
391
|
+
DController: typeof DController;
|
145
392
|
|
146
393
|
// Element Plus组件
|
147
394
|
ElButton: typeof ElButton;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "morghulis",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.28",
|
4
4
|
"private": false,
|
5
5
|
"description": "Vue 3组件库",
|
6
6
|
"type": "module",
|
@@ -16,7 +16,10 @@
|
|
16
16
|
"require": "./dist/index.umd.cjs",
|
17
17
|
"types": "./dist/index.d.ts"
|
18
18
|
},
|
19
|
-
"./dist/
|
19
|
+
"./dist/index.css": "./dist/index.css",
|
20
|
+
"./dist/style.css": "./dist/index.css",
|
21
|
+
"./style": "./dist/index.css",
|
22
|
+
"./dist/style": "./dist/index.css"
|
20
23
|
},
|
21
24
|
"typesVersions": {
|
22
25
|
"*": {
|