vue-2024-ui 0.0.9 → 0.0.10
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/package.json +1 -1
- package/src/components/g-form.vue +3 -4
- package/src/components/g-table.vue +46 -28
- package/src/components/index.d.ts +76 -23
- package/src/components/index.js +49 -11
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<slot name="footer" v-if="!model.form.footer.hidden">
|
|
21
21
|
<div :style="model.form.footer.style">
|
|
22
22
|
<slot name="footer-left"></slot>
|
|
23
|
-
<el-button @click="model.form.submit.click(formInfo, model)"
|
|
23
|
+
<el-button @click.stop="model.form.submit.click(formInfo, model)"
|
|
24
24
|
v-bind="filterObject(model.form.submit, k => !['click'].includes(k))"
|
|
25
25
|
v-if="!model?.form?.submit?.hidden">
|
|
26
26
|
{{ model?.form?.submit?.label }}
|
|
@@ -46,7 +46,7 @@ defineOptions({
|
|
|
46
46
|
inheritAttrs: false
|
|
47
47
|
})
|
|
48
48
|
const model = defineModel({ required: true });
|
|
49
|
-
const emits = defineEmits(["
|
|
49
|
+
const emits = defineEmits(["handSubmit", "reset"]);
|
|
50
50
|
const gform = ref(null);
|
|
51
51
|
let marginRight = ref(32);
|
|
52
52
|
const options = inject('options');
|
|
@@ -78,10 +78,10 @@ const defaultFormAttrs = {
|
|
|
78
78
|
plain: true,
|
|
79
79
|
hidden: false,
|
|
80
80
|
click: async (formInfo, model) => {
|
|
81
|
-
emits("usubmit", formInfo, model);
|
|
82
81
|
if (!gform.value) return
|
|
83
82
|
await gform.value.validate((valid, fields) => {
|
|
84
83
|
if (valid) {
|
|
84
|
+
emits("handSubmit", formInfo, model);
|
|
85
85
|
console.log("提交");
|
|
86
86
|
} else {
|
|
87
87
|
console.log('表单验证不通过!', fields);
|
|
@@ -144,7 +144,6 @@ const getItemRulesByItem = (item) => {
|
|
|
144
144
|
}
|
|
145
145
|
// 获取item属性并合并规则
|
|
146
146
|
const itemInfo = { ...itemDefaultRule, ...item };
|
|
147
|
-
|
|
148
147
|
//必填验证
|
|
149
148
|
if (itemInfo.required) {
|
|
150
149
|
itemRules.push({ required: true, message: `${itemInfo.label}不能为空!`, trigger: 'blur' });
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<slot name="control-add">
|
|
13
13
|
<el-button v-bind="model.control.add" @click="model.control.add.click(model)">{{
|
|
14
14
|
model.control.add.label
|
|
15
|
-
|
|
15
|
+
}}</el-button>
|
|
16
16
|
</slot>
|
|
17
17
|
<slot name="control-add-right"></slot>
|
|
18
18
|
</div>
|
|
@@ -89,11 +89,10 @@
|
|
|
89
89
|
<script setup>
|
|
90
90
|
import dayjs from 'dayjs';
|
|
91
91
|
import { ElMessageBox } from 'element-plus';
|
|
92
|
-
import { computed,
|
|
92
|
+
import { computed, watchEffect, inject, ref, h } from 'vue';
|
|
93
93
|
import GForm from './g-form.vue';
|
|
94
94
|
import gQuery from './g-query.vue';
|
|
95
|
-
import { openModal, mergeObjects, convertToPx } from './index';
|
|
96
|
-
import { filterObject } from '.';
|
|
95
|
+
import { openModal, mergeObjects, convertToPx, filterObject } from './index';
|
|
97
96
|
|
|
98
97
|
defineOptions({
|
|
99
98
|
name: "g-table",
|
|
@@ -140,9 +139,6 @@ model.value.table = mergeObjects(
|
|
|
140
139
|
options?.table,
|
|
141
140
|
model.value.table
|
|
142
141
|
);
|
|
143
|
-
|
|
144
|
-
let closeModel = ref(() => { });
|
|
145
|
-
const editModel = defineAsyncComponent(() => import('./g-form.vue'));
|
|
146
142
|
const defaultControl = {
|
|
147
143
|
type: 'control', label: '操作', edit: false, width: 250, fixed: 'right',
|
|
148
144
|
style: { ...model.value?.control?.style },
|
|
@@ -154,9 +150,6 @@ const defaultControl = {
|
|
|
154
150
|
dialog: {
|
|
155
151
|
title: '新增',
|
|
156
152
|
mode: "drawer",
|
|
157
|
-
slots: {
|
|
158
|
-
default: () => h(GForm, { modelValue: model.value }, { ...model.value.form.slots }),
|
|
159
|
-
},
|
|
160
153
|
},
|
|
161
154
|
auth: () => true,
|
|
162
155
|
click: (m) => {
|
|
@@ -164,6 +157,7 @@ const defaultControl = {
|
|
|
164
157
|
...model.value.form,
|
|
165
158
|
type: 'hidden',
|
|
166
159
|
disabled: undefined,
|
|
160
|
+
footer: { hidden: false }
|
|
167
161
|
};
|
|
168
162
|
let w = model.value?.form?.style?.width || 600;
|
|
169
163
|
if (model.value.control.add.dialog.mode == "drawer") {
|
|
@@ -177,7 +171,20 @@ const defaultControl = {
|
|
|
177
171
|
model.value[key].value = initFormData[key];
|
|
178
172
|
}
|
|
179
173
|
});
|
|
180
|
-
|
|
174
|
+
let colse = openModal(
|
|
175
|
+
{
|
|
176
|
+
...model.value?.control?.add?.dialog,
|
|
177
|
+
slots: {
|
|
178
|
+
default: () => h(GForm, {
|
|
179
|
+
modelValue: model.value,
|
|
180
|
+
...model.value.form,
|
|
181
|
+
key: new Date(),
|
|
182
|
+
onHandSubmit: () => {
|
|
183
|
+
colse();
|
|
184
|
+
},
|
|
185
|
+
}, { ...model.value.form.slots })
|
|
186
|
+
}
|
|
187
|
+
}, model.value?.control?.add?.dialog?.mode);
|
|
181
188
|
},
|
|
182
189
|
},
|
|
183
190
|
view: {
|
|
@@ -185,9 +192,6 @@ const defaultControl = {
|
|
|
185
192
|
dialog: {
|
|
186
193
|
title: '查看',
|
|
187
194
|
mode: "dialog",
|
|
188
|
-
slots: {
|
|
189
|
-
default: () => h(GForm, { modelValue: model.value }, { ...model.value.form.slots }),
|
|
190
|
-
},
|
|
191
195
|
},
|
|
192
196
|
auth: (row, column, $index) => {
|
|
193
197
|
return false;
|
|
@@ -197,6 +201,7 @@ const defaultControl = {
|
|
|
197
201
|
...model.value.form,
|
|
198
202
|
type: 'hidden',
|
|
199
203
|
disabled: true,
|
|
204
|
+
footer: { hidden: true }
|
|
200
205
|
};
|
|
201
206
|
let w = model.value?.form?.style?.width || 600;
|
|
202
207
|
if (model.value.control.view.dialog.mode == "drawer") {
|
|
@@ -210,7 +215,19 @@ const defaultControl = {
|
|
|
210
215
|
model.value[key].value = row[key];
|
|
211
216
|
}
|
|
212
217
|
});
|
|
213
|
-
|
|
218
|
+
let colse = openModal(
|
|
219
|
+
{
|
|
220
|
+
...model.value?.control?.view?.dialog,
|
|
221
|
+
slots: {
|
|
222
|
+
default: () => h(GForm, {
|
|
223
|
+
modelValue: model.value,
|
|
224
|
+
...model.value.form,
|
|
225
|
+
onHandSubmit: () => {
|
|
226
|
+
colse();
|
|
227
|
+
},
|
|
228
|
+
}, { ...model.value.form.slots })
|
|
229
|
+
}
|
|
230
|
+
}, model.value?.control?.view?.dialog?.mode);
|
|
214
231
|
},
|
|
215
232
|
},
|
|
216
233
|
edit: {
|
|
@@ -218,15 +235,6 @@ const defaultControl = {
|
|
|
218
235
|
dialog: {
|
|
219
236
|
title: '编辑',
|
|
220
237
|
mode: "dialog",
|
|
221
|
-
slots: {
|
|
222
|
-
default: () => {
|
|
223
|
-
model.value.form.onUsubmit = () => {
|
|
224
|
-
if (closeModel.value)
|
|
225
|
-
closeModel.value();
|
|
226
|
-
}
|
|
227
|
-
return h(editModel, { modelValue: model.value, ...model.value.form }, { ...model.value.form.slots })
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
238
|
},
|
|
231
239
|
auth: (row, column, $index) => {
|
|
232
240
|
return true;
|
|
@@ -236,6 +244,7 @@ const defaultControl = {
|
|
|
236
244
|
...model.value.form,
|
|
237
245
|
type: 'hidden',
|
|
238
246
|
disabled: undefined,
|
|
247
|
+
footer: { hidden: false }
|
|
239
248
|
};
|
|
240
249
|
let w = model.value?.form?.style?.width || 600;
|
|
241
250
|
if (model.value.control.edit.dialog.mode == "drawer") {
|
|
@@ -249,7 +258,19 @@ const defaultControl = {
|
|
|
249
258
|
model.value[key].value = row[key];
|
|
250
259
|
}
|
|
251
260
|
});
|
|
252
|
-
|
|
261
|
+
let colse = openModal(
|
|
262
|
+
{
|
|
263
|
+
...model.value?.control?.edit?.dialog,
|
|
264
|
+
slots: {
|
|
265
|
+
default: () => h(GForm, {
|
|
266
|
+
modelValue: model.value,
|
|
267
|
+
...model.value.form,
|
|
268
|
+
onHandSubmit: () => {
|
|
269
|
+
colse();
|
|
270
|
+
},
|
|
271
|
+
}, { ...model.value.form.slots })
|
|
272
|
+
}
|
|
273
|
+
}, model.value?.control?.edit?.dialog?.mode);
|
|
253
274
|
},
|
|
254
275
|
},
|
|
255
276
|
delete: {
|
|
@@ -350,9 +371,6 @@ const query = (q) => {
|
|
|
350
371
|
//model.value.table.load();
|
|
351
372
|
}
|
|
352
373
|
|
|
353
|
-
onMounted(() => {
|
|
354
|
-
|
|
355
|
-
});
|
|
356
374
|
|
|
357
375
|
watchEffect(() => {
|
|
358
376
|
model.value.table.load();
|
|
@@ -1,37 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const ElDrawer: Component;
|
|
1
|
+
// 导入Vue的Component模块
|
|
2
|
+
import { Component } from 'vue';
|
|
3
|
+
// 从element-plus库中导入ElDialog和ElDrawer组件
|
|
4
|
+
import { ElDialog, ElDrawer } from 'element-plus';
|
|
6
5
|
|
|
6
|
+
/**
|
|
7
|
+
* 全局选项的接口定义
|
|
8
|
+
*/
|
|
7
9
|
export interface GlobalOptions {
|
|
8
|
-
//
|
|
10
|
+
// 在这里定义全局选项的类型
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 打开模态框的属性接口定义
|
|
15
|
+
*/
|
|
11
16
|
export interface OpenModalProps {
|
|
17
|
+
// 在这里定义传递给模态组件的属性类型
|
|
12
18
|
slots?: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
// 默认插槽的函数类型定义
|
|
20
|
+
default?: (a: any) => any;
|
|
21
|
+
// 头部插槽的函数类型定义
|
|
22
|
+
header?: (p: any) => any;
|
|
23
|
+
// 底部插槽的函数类型定义
|
|
24
|
+
footer?: (p: any) => any;
|
|
16
25
|
};
|
|
17
|
-
// 其他props的类型定义
|
|
18
26
|
}
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
/**
|
|
29
|
+
* 转换为像素的选项接口定义
|
|
30
|
+
*/
|
|
31
|
+
export interface ConvertToPxOptions {
|
|
32
|
+
// 参考尺寸的可选属性,类型为number
|
|
33
|
+
referenceSize?: number;
|
|
34
|
+
}
|
|
21
35
|
|
|
22
|
-
|
|
36
|
+
/**
|
|
37
|
+
* 合并对象的选项接口定义
|
|
38
|
+
*/
|
|
39
|
+
export interface MergeObjectsOptions {
|
|
40
|
+
// 在这里定义合并对象的选项类型
|
|
41
|
+
}
|
|
23
42
|
|
|
24
|
-
|
|
43
|
+
/**
|
|
44
|
+
* 过滤对象的选项接口定义
|
|
45
|
+
*/
|
|
46
|
+
export interface FilterObjectOptions {
|
|
47
|
+
// 过滤函数的可选属性,类型为(key: string, value: any) => boolean
|
|
48
|
+
filter?: (key: string, value: any) => boolean;
|
|
49
|
+
}
|
|
25
50
|
|
|
26
|
-
|
|
51
|
+
/**
|
|
52
|
+
* 打开模态框的函数定义
|
|
53
|
+
* @param {OpenModalProps} [props] - 传递给模态组件的属性
|
|
54
|
+
* @param {'dialog' | 'drawer'} [mode] - 模态框的模式,可选值为'dialog'或'drawer'
|
|
55
|
+
* @returns {() => void} - 返回一个函数,用于关闭模态框
|
|
56
|
+
*/
|
|
57
|
+
export function openModal(props?: OpenModalProps, mode?: 'dialog' | 'drawer'): () => void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 将值转换为像素的函数定义
|
|
61
|
+
* @param {string | number} value - 需要转换的值
|
|
62
|
+
* @param {ConvertToPxOptions} [options] - 转换选项
|
|
63
|
+
* @returns {number} - 转换后的像素值
|
|
64
|
+
*/
|
|
65
|
+
export function convertToPx(value: string | number, options?: ConvertToPxOptions): number;
|
|
27
66
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
67
|
+
/**
|
|
68
|
+
* 合并多个对象的函数定义
|
|
69
|
+
* @param {...Record<string, any>} objects - 需要合并的对象
|
|
70
|
+
* @returns {Record<string, any>} - 合并后的对象
|
|
71
|
+
*/
|
|
72
|
+
export function mergeObjects(...objects: Array<Record<string, any>>): Record<string, any>;
|
|
33
73
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
74
|
+
/**
|
|
75
|
+
* 过滤对象的函数定义
|
|
76
|
+
* @param {Record<string, any>} obj - 需要过滤的对象
|
|
77
|
+
* @param {FilterObjectOptions} [options] - 过滤选项
|
|
78
|
+
* @returns {Record<string, any>} - 过滤后的对象
|
|
79
|
+
*/
|
|
80
|
+
export function filterObject(obj: Record<string, any>, options?: FilterObjectOptions): Record<string, any>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 扩展Vue的ComponentCustomProperties接口,添加openModel属性
|
|
84
|
+
*/
|
|
85
|
+
declare module 'vue' {
|
|
86
|
+
interface ComponentCustomProperties {
|
|
87
|
+
// openModel属性的类型定义,指向openModal函数
|
|
88
|
+
openModel: typeof openModal;
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/components/index.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import ElementPlus from 'element-plus'
|
|
4
4
|
import { ElDialog, ElDrawer } from "element-plus";
|
|
5
|
+
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
|
5
6
|
import gTable from "./g-table.vue";
|
|
6
7
|
import gForm from "./g-form.vue";
|
|
7
8
|
import { createApp, h, provide, readonly, ref } from "vue";
|
|
8
9
|
const globalOptions = {};
|
|
9
|
-
|
|
10
10
|
const components = [
|
|
11
11
|
gTable,
|
|
12
12
|
gForm
|
|
@@ -19,45 +19,73 @@ export default {
|
|
|
19
19
|
app.component(component.name, component);
|
|
20
20
|
}
|
|
21
21
|
app.provide("options", readonly(options));
|
|
22
|
-
app.config.globalProperties.
|
|
22
|
+
app.config.globalProperties.openModal = openModal;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 打开模态对话框的函数。
|
|
28
|
+
* @param {Object} modalProps - 模态对话框的属性。
|
|
29
|
+
* @param {string} [mode="dialog"] - 模态对话框的模式,支持"dialog"和"drawer"。
|
|
30
|
+
* @returns {Function} - 关闭模态对话框的函数。
|
|
31
|
+
*/
|
|
32
|
+
const openModal = (modalProps = {}, mode = "dialog") => {
|
|
33
|
+
// 创建一个新的 div 元素
|
|
26
34
|
const el = document.createElement('div');
|
|
35
|
+
// 定义关闭模态对话框的函数
|
|
27
36
|
let closeModal = () => { };
|
|
37
|
+
// 使用 ref 创建一个响应式的 visible 变量
|
|
28
38
|
const visible = ref(true);
|
|
39
|
+
// 创建一个新的 Vue 应用实例
|
|
29
40
|
let modalApp = createApp({
|
|
30
41
|
setup() {
|
|
42
|
+
// 定义关闭模态对话框的函数
|
|
31
43
|
closeModal = () => {
|
|
32
44
|
visible.value = false;
|
|
33
45
|
modalApp.unmount(); // 关闭对话框时卸载组件
|
|
34
|
-
|
|
46
|
+
el.remove(); // 关闭对话框时删除元素
|
|
35
47
|
modalApp = null;
|
|
36
48
|
};
|
|
37
|
-
|
|
49
|
+
// 返回渲染函数
|
|
38
50
|
return () => h(mode == "dialog" ? ElDialog : mode == "drawer" ? ElDrawer : null, {
|
|
39
51
|
modelValue: visible.value,
|
|
40
52
|
'onUpdate:modelValue': closeModal,
|
|
41
53
|
draggable: true,
|
|
42
54
|
"append-to-body": true,
|
|
43
|
-
|
|
55
|
+
'destroy-on-close': true,
|
|
56
|
+
...modalProps
|
|
44
57
|
},
|
|
45
58
|
{
|
|
46
|
-
default:
|
|
47
|
-
header:
|
|
48
|
-
footer:
|
|
59
|
+
default: modalProps.slots?.default ? () => modalProps.slots.default() : null,
|
|
60
|
+
header: modalProps.slots?.header ? () => h('div', {}, modalProps.slots.header()) : null,
|
|
61
|
+
footer: modalProps.slots?.footer ? () => h('div', {}, modalProps.slots.footer()) : null
|
|
49
62
|
}
|
|
50
63
|
);
|
|
51
64
|
}
|
|
52
65
|
});
|
|
66
|
+
// 注册全局组件
|
|
53
67
|
for (const component of components) {
|
|
54
68
|
modalApp.component(component.name, component);
|
|
55
69
|
}
|
|
56
|
-
|
|
70
|
+
// 提供全局选项
|
|
71
|
+
modalApp.provide("options", globalOptions);
|
|
72
|
+
// 使用 ElementPlus 插件
|
|
73
|
+
modalApp.use(ElementPlus, { locale: zhCn }).mount(el);
|
|
74
|
+
// 将元素添加到 body 中
|
|
57
75
|
document.body.appendChild(el);
|
|
76
|
+
// 返回关闭模态对话框的函数
|
|
58
77
|
return closeModal;
|
|
59
78
|
};
|
|
60
79
|
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 将值转换为像素的函数,支持px、vh、vw、%和calc表达式。
|
|
83
|
+
* @param {string|number} value - 需要转换的值。
|
|
84
|
+
* @param {number} [referenceSize=window.innerWidth] - 用于转换%值的参考大小。
|
|
85
|
+
* @returns {number} - 转换后的像素值。
|
|
86
|
+
* @throws {Error} - 如果无法识别单位或提供的参考大小无效。
|
|
87
|
+
*/
|
|
88
|
+
|
|
61
89
|
function convertToPx(value, referenceSize = window.innerWidth) {
|
|
62
90
|
// 如果已经是px,直接返回
|
|
63
91
|
if (typeof value === 'number') {
|
|
@@ -108,6 +136,11 @@ function convertToPx(value, referenceSize = window.innerWidth) {
|
|
|
108
136
|
throw new Error('Unsupported unit in value: ' + value);
|
|
109
137
|
}
|
|
110
138
|
|
|
139
|
+
/**
|
|
140
|
+
* 合并多个对象的函数,递归地合并嵌套对象。
|
|
141
|
+
* @param {...Object} objects - 需要合并的对象。
|
|
142
|
+
* @returns {Object} - 合并后的对象。
|
|
143
|
+
*/
|
|
111
144
|
|
|
112
145
|
function mergeObjects(...objects) {
|
|
113
146
|
const result = ref({});
|
|
@@ -127,7 +160,12 @@ function mergeObjects(...objects) {
|
|
|
127
160
|
return result.value;
|
|
128
161
|
}
|
|
129
162
|
|
|
130
|
-
|
|
163
|
+
/**
|
|
164
|
+
* 过滤对象的函数,根据给定的过滤条件返回一个新的对象。
|
|
165
|
+
* @param {Object} obj - 需要过滤的对象。
|
|
166
|
+
* @param {Function} filter - 过滤条件函数,接收键和值作为参数,返回布尔值。
|
|
167
|
+
* @returns {Object} - 过滤后的新对象。
|
|
168
|
+
*/
|
|
131
169
|
function filterObject(obj, filter = (key, value) => filter(key, value)) {
|
|
132
170
|
const result = {};
|
|
133
171
|
for (const key in obj) {
|