vue-2024-ui 0.0.3 → 0.0.5
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 +47 -50
- package/src/components/g-table.vue +35 -27
package/package.json
CHANGED
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
<slot :name="`${key}-label`" :data :item :model>{{ item.label }}</slot>
|
|
16
16
|
</template>
|
|
17
17
|
</el-form-item>
|
|
18
|
-
<el-form-item style="width: 100%;">
|
|
18
|
+
<el-form-item style="width: 100%;" v-if="!model.form.footer.hidden">
|
|
19
19
|
<slot name="footer">
|
|
20
|
-
<div
|
|
20
|
+
<div :style="model.form.footer.style">
|
|
21
21
|
<slot name="footer-left"></slot>
|
|
22
|
-
<el-button @click="
|
|
22
|
+
<el-button @click="model.form.submit.submit(model)" v-bind="model.form.submit"
|
|
23
23
|
v-if="!model.form.submit.hidden">
|
|
24
24
|
{{ model.form.submit.submitText }}
|
|
25
25
|
</el-button>
|
|
26
|
-
<el-button @click="
|
|
26
|
+
<el-button @click="model.form.reset.reset(model)" v-bind="model.form.reset"
|
|
27
27
|
v-if="!model.form.reset.hidden">{{
|
|
28
28
|
model.form.reset.resetText
|
|
29
29
|
}}</el-button>
|
|
@@ -70,8 +70,11 @@ model.value.form = {
|
|
|
70
70
|
},
|
|
71
71
|
// 表单底部属性
|
|
72
72
|
footer: {
|
|
73
|
-
|
|
74
|
-
...model.value.form?.footer
|
|
73
|
+
hidden: false,
|
|
74
|
+
...model.value.form?.footer,
|
|
75
|
+
style: {
|
|
76
|
+
display: "flex", width: "100%", "align-items": "center", justifyContent: "center", margin: "5px", ...model.value.form?.footer?.style
|
|
77
|
+
},
|
|
75
78
|
},
|
|
76
79
|
//表单提交按钮属性
|
|
77
80
|
submit: {
|
|
@@ -80,6 +83,17 @@ model.value.form = {
|
|
|
80
83
|
submitText: "提交",
|
|
81
84
|
plain: true,
|
|
82
85
|
hidden: false,
|
|
86
|
+
submit: async (model) => {
|
|
87
|
+
console.log(model);
|
|
88
|
+
if (!gform.value) return
|
|
89
|
+
await gform.value.validate((valid, fields) => {
|
|
90
|
+
if (valid) {
|
|
91
|
+
emits("submit", formInfo.value, model);
|
|
92
|
+
} else {
|
|
93
|
+
console.log('error submit!', fields);
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
},
|
|
83
97
|
...model.value.form?.submit
|
|
84
98
|
},
|
|
85
99
|
//表单重置按钮属性
|
|
@@ -88,48 +102,33 @@ model.value.form = {
|
|
|
88
102
|
resetText: "重置",
|
|
89
103
|
hidden: false,
|
|
90
104
|
plain: true,
|
|
105
|
+
reset: () => {
|
|
106
|
+
if (!gform.value) return
|
|
107
|
+
let isreset = true;
|
|
108
|
+
emits("reset", (flag) => {
|
|
109
|
+
isreset = flag;
|
|
110
|
+
});
|
|
111
|
+
if (isreset) {
|
|
112
|
+
gform.value.resetFields();
|
|
113
|
+
}
|
|
114
|
+
},
|
|
91
115
|
...model.value.form?.reset
|
|
92
116
|
},
|
|
117
|
+
dialog: {
|
|
118
|
+
width: 635,
|
|
119
|
+
...model.value.form?.dialog
|
|
120
|
+
}
|
|
93
121
|
};
|
|
94
122
|
//合并表单项默认属性
|
|
95
123
|
model.value.formItems = {
|
|
96
124
|
type: "hidden",
|
|
97
|
-
...model.value.formItems,
|
|
98
125
|
style: {
|
|
99
126
|
width: "100%",
|
|
100
127
|
...model.value.formItems?.style
|
|
101
|
-
}
|
|
128
|
+
},
|
|
129
|
+
...model.value.formItems,
|
|
102
130
|
};
|
|
103
131
|
|
|
104
|
-
// 提交表单
|
|
105
|
-
const submitForm = async (model) => {
|
|
106
|
-
if (!gform.value) return
|
|
107
|
-
await gform.value.validate((valid, fields) => {
|
|
108
|
-
if (valid) {
|
|
109
|
-
emits("submit", formInfo.value, model);
|
|
110
|
-
} else {
|
|
111
|
-
console.log('error submit!', fields);
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 重置表单
|
|
117
|
-
const resetForm = () => {
|
|
118
|
-
if (!gform.value) return
|
|
119
|
-
let isreset = true;
|
|
120
|
-
emits("reset", (flag) => {
|
|
121
|
-
isreset = flag;
|
|
122
|
-
});
|
|
123
|
-
if (isreset) {
|
|
124
|
-
gform.value.resetFields();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 定义对外暴露的函数
|
|
129
|
-
defineExpose({
|
|
130
|
-
submit: submitForm, reset: resetForm
|
|
131
|
-
})
|
|
132
|
-
|
|
133
132
|
//获取表单项验证规则
|
|
134
133
|
const getItemRulesByItem = (item) => {
|
|
135
134
|
// 组装验证规则
|
|
@@ -223,14 +222,14 @@ const load = () => {
|
|
|
223
222
|
if (!model.value.form.inline) {
|
|
224
223
|
model.value.form.columns = 1;
|
|
225
224
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
columnsWidth.value = 300;
|
|
229
|
-
model.value.form.style.width = columns.value * 300 + 'px';
|
|
230
|
-
} else {
|
|
231
|
-
columnsWidth.value = removePx(width) / model.value.form.columns;
|
|
232
|
-
model.value.form.style.width = columns.value * columnsWidth.value + 'px';
|
|
225
|
+
if (model.value.form.style.width) {
|
|
226
|
+
columnsWidth.value = removePx(model.value.form.style.width) / model.value.form.columns;
|
|
233
227
|
}
|
|
228
|
+
else {
|
|
229
|
+
model.value.form.style.width = "600px";
|
|
230
|
+
}
|
|
231
|
+
model.value.form.dialog.width = +model.value?.form?.style?.width.replace("px", "")+35+"px";
|
|
232
|
+
console.log(model.value.form.dialog.width);
|
|
234
233
|
for (const [key, value] of Object.entries(items.value)) {
|
|
235
234
|
model.value[key].formItem = { ...model.value[key].formItem, ...value.formItem }
|
|
236
235
|
model.value[key].formItem.style = { ...model.value[key].formItem.style, ...value.formItem.style };
|
|
@@ -251,15 +250,13 @@ watch(() => model.value.form.columns, () => load());
|
|
|
251
250
|
watch(() => model.value.form.inline, () => load());
|
|
252
251
|
|
|
253
252
|
const removePx = (el) => parseFloat(el.replace("px", ""));
|
|
254
|
-
|
|
255
253
|
//表单项
|
|
256
|
-
const items = computed(() => Object.fromEntries(Object.entries(model.value).filter(a => a[1].type != "hidden")
|
|
254
|
+
const items = computed(() => Object.fromEntries(Object.entries(model.value).filter(a => a[1].type != "hidden")
|
|
255
|
+
.filter(a => (a[1].edit !== false))
|
|
256
|
+
.filter(a => (a[1].type !== "control"))
|
|
257
|
+
.map(key => [key[0], key[1]])));
|
|
257
258
|
//表单提交对象
|
|
258
259
|
const formInfo = computed(() => Object.fromEntries(Object.entries(model.value).filter(a => a[1].type != "hidden").map(key => [key[0], key[1].value])));
|
|
259
260
|
//表单列数
|
|
260
261
|
const columns = computed(() => model.value.form.columns);
|
|
261
|
-
//表单列的宽度减去右边距
|
|
262
|
-
const formItemsWidth = computed(() => columnsWidth.value - marginRight.value);
|
|
263
|
-
//表单宽度
|
|
264
|
-
const formWidth = computed(() => columns.value * columnsWidth.value);
|
|
265
262
|
</script>
|
|
@@ -13,17 +13,19 @@
|
|
|
13
13
|
<div class="control" v-bind="value">
|
|
14
14
|
<slot name="control">
|
|
15
15
|
<slot name="control-left" :row :column :$index> </slot>
|
|
16
|
-
<slot name="control-
|
|
17
|
-
v-if="model.control.
|
|
18
|
-
<el-button v-bind="model.control.
|
|
19
|
-
@click="model.control.
|
|
16
|
+
<slot name="control-view" :row :column :$index
|
|
17
|
+
v-if="model.control.view.auth(row, column, $index)">
|
|
18
|
+
<el-button v-bind="model.control.view"
|
|
19
|
+
@click="model.control.view.view(row, column, $index, model)">{{
|
|
20
|
+
model.control.view.label
|
|
20
21
|
}}</el-button>
|
|
21
22
|
</slot>
|
|
22
23
|
<slot name="control-edit-left" :row :column :$index> </slot>
|
|
23
24
|
<slot name="control-edit" :row :column :$index
|
|
24
25
|
v-if="model.control.edit.auth(row, column, $index)">
|
|
25
26
|
<el-button v-bind="model.control.edit"
|
|
26
|
-
@click="model.control.edit.edit(row, column, $index)">{{
|
|
27
|
+
@click="model.control.edit.edit(row, column, $index, model)">{{
|
|
28
|
+
model.control.edit.label
|
|
27
29
|
}}</el-button>
|
|
28
30
|
</slot>
|
|
29
31
|
<slot name="control-edit-right" :row :column :$index> </slot>
|
|
@@ -60,20 +62,21 @@
|
|
|
60
62
|
</slot>
|
|
61
63
|
</template>
|
|
62
64
|
|
|
63
|
-
<script setup
|
|
65
|
+
<script setup>
|
|
64
66
|
import dayjs from 'dayjs';
|
|
65
67
|
import ElementPlus from 'element-plus'
|
|
66
68
|
import { ElMessageBox } from 'element-plus';
|
|
67
|
-
import { computed, onMounted, reactive, watchEffect, h, createApp, ref } from 'vue';
|
|
69
|
+
import { computed, onMounted, reactive, watchEffect, watch, h, createApp, ref } from 'vue';
|
|
68
70
|
import { ElDialog } from 'element-plus';
|
|
69
|
-
import gyc from "./index"
|
|
71
|
+
//import gyc from "./index"
|
|
72
|
+
import GForm from './g-form.vue';
|
|
70
73
|
|
|
71
74
|
defineOptions({
|
|
72
75
|
name: "g-table",
|
|
73
76
|
inheritAttrs: false
|
|
74
77
|
})
|
|
75
78
|
|
|
76
|
-
const emits = defineEmits(['load', '
|
|
79
|
+
const emits = defineEmits(['load', 'view', "edit", "delete"]);
|
|
77
80
|
const model = defineModel({ required: true });
|
|
78
81
|
|
|
79
82
|
//table default attrs
|
|
@@ -110,38 +113,42 @@ model.value.table = {
|
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
model.value.control = {
|
|
113
|
-
type: model.value?.control ? "control" : 'hidden', label: '操作', width: 250, fixed: 'right', ...model.value?.control,
|
|
116
|
+
type: model.value?.control ? "control" : 'hidden', label: '操作', edit: false, width: 250, fixed: 'right', ...model.value?.control,
|
|
114
117
|
style: { ...model.value?.control?.style },
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
view: {
|
|
119
|
+
label: '查看', text: true, type: 'success',
|
|
117
120
|
auth: (row, column, $index) => {
|
|
118
121
|
return false;
|
|
119
122
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
view: (row, column, $index, m) => {
|
|
124
|
+
model.value.form.disabled = true;
|
|
125
|
+
emits("view", row, column, $index, m);
|
|
123
126
|
openModal({
|
|
124
127
|
title: '查看',
|
|
128
|
+
...model.value.form.dialog,
|
|
125
129
|
slots: {
|
|
126
130
|
// 自定义插槽内容
|
|
127
|
-
default: () =>
|
|
131
|
+
default: () => h(GForm, { modelValue: model.value }),
|
|
132
|
+
...model.value?.form?.dialog?.slots
|
|
128
133
|
},
|
|
129
134
|
});
|
|
130
|
-
}, ...model.value?.control?.
|
|
135
|
+
}, ...model.value?.control?.view
|
|
131
136
|
},
|
|
132
137
|
edit: {
|
|
133
|
-
|
|
138
|
+
label: '编辑', text: true, type: 'primary',
|
|
134
139
|
auth: (row, column, $index) => {
|
|
135
140
|
return true;
|
|
136
141
|
},
|
|
137
|
-
edit: (row, column, $index) => {
|
|
138
|
-
model.value.form.disabled=undefined;
|
|
139
|
-
emits("edit", row, column, $index);
|
|
142
|
+
edit: (row, column, $index, m) => {
|
|
143
|
+
model.value.form.disabled = undefined;
|
|
144
|
+
emits("edit", row, column, $index, m);
|
|
140
145
|
openModal({
|
|
141
146
|
title: '编辑',
|
|
147
|
+
...model.value.form.dialog,
|
|
142
148
|
slots: {
|
|
143
149
|
// 自定义插槽内容
|
|
144
|
-
default: () =>
|
|
150
|
+
default: () => h(GForm, { modelValue: model.value }),
|
|
151
|
+
...model.value?.form?.dialog?.slots
|
|
145
152
|
},
|
|
146
153
|
});
|
|
147
154
|
|
|
@@ -179,26 +186,28 @@ const itemValue = reactive({
|
|
|
179
186
|
|
|
180
187
|
// 用 createApp 方法封装打开模态窗的方法
|
|
181
188
|
const openModal = (props = {}) => {
|
|
189
|
+
const el = document.createElement('div');
|
|
182
190
|
const app = createApp({
|
|
183
191
|
setup() {
|
|
184
192
|
const visible = ref(true);
|
|
185
193
|
const closeModal = () => {
|
|
186
194
|
visible.value = false;
|
|
187
195
|
app.unmount(); // 关闭对话框时卸载组件
|
|
196
|
+
delete el.remove(); // 关闭对话框时删除元素
|
|
188
197
|
};
|
|
189
198
|
return () => h(ElDialog, {
|
|
190
199
|
modelValue: visible.value,
|
|
191
200
|
'onUpdate:modelValue': closeModal,
|
|
192
|
-
width: 635,
|
|
193
201
|
draggable: true,
|
|
194
|
-
"append-to-body":true,
|
|
202
|
+
"append-to-body": true,
|
|
203
|
+
"v-if": visible.value,
|
|
204
|
+
width:model.value.form.dialog.width,
|
|
195
205
|
...props
|
|
196
206
|
},
|
|
197
207
|
() => [
|
|
198
208
|
props.slots.header ? h('div', { slot: 'header' }, props.slots.header()) : null,
|
|
199
209
|
// 传递名为 'default' 的插槽
|
|
200
210
|
props.slots.default ? h(props.slots.default()) : null,
|
|
201
|
-
// 传递名为 'header' 的插槽
|
|
202
211
|
// 传递名为 'footer' 的插槽
|
|
203
212
|
props.slots.footer ? h('div', { slot: 'footer' }, props.slots.footer()) : null,
|
|
204
213
|
// 可以继续添加其他插槽...
|
|
@@ -206,8 +215,7 @@ const openModal = (props = {}) => {
|
|
|
206
215
|
);
|
|
207
216
|
}
|
|
208
217
|
});
|
|
209
|
-
|
|
210
|
-
app.use(ElementPlus).use(gyc).mount(el);
|
|
218
|
+
app.use(ElementPlus).mount(el);
|
|
211
219
|
document.body.appendChild(el);
|
|
212
220
|
};
|
|
213
221
|
|