vue-2024-ui 0.0.4 → 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 +29 -22
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,13 +62,13 @@
|
|
|
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"
|
|
70
72
|
import GForm from './g-form.vue';
|
|
71
73
|
|
|
72
74
|
defineOptions({
|
|
@@ -74,7 +76,7 @@ defineOptions({
|
|
|
74
76
|
inheritAttrs: false
|
|
75
77
|
})
|
|
76
78
|
|
|
77
|
-
const emits = defineEmits(['load', '
|
|
79
|
+
const emits = defineEmits(['load', 'view', "edit", "delete"]);
|
|
78
80
|
const model = defineModel({ required: true });
|
|
79
81
|
|
|
80
82
|
//table default attrs
|
|
@@ -111,38 +113,42 @@ model.value.table = {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
model.value.control = {
|
|
114
|
-
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,
|
|
115
117
|
style: { ...model.value?.control?.style },
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
view: {
|
|
119
|
+
label: '查看', text: true, type: 'success',
|
|
118
120
|
auth: (row, column, $index) => {
|
|
119
121
|
return false;
|
|
120
122
|
},
|
|
121
|
-
|
|
122
|
-
emits("read", row, column, $index);
|
|
123
|
+
view: (row, column, $index, m) => {
|
|
123
124
|
model.value.form.disabled = true;
|
|
125
|
+
emits("view", row, column, $index, m);
|
|
124
126
|
openModal({
|
|
125
127
|
title: '查看',
|
|
128
|
+
...model.value.form.dialog,
|
|
126
129
|
slots: {
|
|
127
130
|
// 自定义插槽内容
|
|
128
131
|
default: () => h(GForm, { modelValue: model.value }),
|
|
132
|
+
...model.value?.form?.dialog?.slots
|
|
129
133
|
},
|
|
130
134
|
});
|
|
131
|
-
}, ...model.value?.control?.
|
|
135
|
+
}, ...model.value?.control?.view
|
|
132
136
|
},
|
|
133
137
|
edit: {
|
|
134
|
-
|
|
138
|
+
label: '编辑', text: true, type: 'primary',
|
|
135
139
|
auth: (row, column, $index) => {
|
|
136
140
|
return true;
|
|
137
141
|
},
|
|
138
|
-
edit: (row, column, $index) => {
|
|
142
|
+
edit: (row, column, $index, m) => {
|
|
139
143
|
model.value.form.disabled = undefined;
|
|
140
|
-
emits("edit", row, column, $index);
|
|
144
|
+
emits("edit", row, column, $index, m);
|
|
141
145
|
openModal({
|
|
142
146
|
title: '编辑',
|
|
147
|
+
...model.value.form.dialog,
|
|
143
148
|
slots: {
|
|
144
149
|
// 自定义插槽内容
|
|
145
150
|
default: () => h(GForm, { modelValue: model.value }),
|
|
151
|
+
...model.value?.form?.dialog?.slots
|
|
146
152
|
},
|
|
147
153
|
});
|
|
148
154
|
|
|
@@ -180,26 +186,28 @@ const itemValue = reactive({
|
|
|
180
186
|
|
|
181
187
|
// 用 createApp 方法封装打开模态窗的方法
|
|
182
188
|
const openModal = (props = {}) => {
|
|
189
|
+
const el = document.createElement('div');
|
|
183
190
|
const app = createApp({
|
|
184
191
|
setup() {
|
|
185
192
|
const visible = ref(true);
|
|
186
193
|
const closeModal = () => {
|
|
187
194
|
visible.value = false;
|
|
188
195
|
app.unmount(); // 关闭对话框时卸载组件
|
|
196
|
+
delete el.remove(); // 关闭对话框时删除元素
|
|
189
197
|
};
|
|
190
198
|
return () => h(ElDialog, {
|
|
191
199
|
modelValue: visible.value,
|
|
192
200
|
'onUpdate:modelValue': closeModal,
|
|
193
|
-
width: 635,
|
|
194
201
|
draggable: true,
|
|
195
202
|
"append-to-body": true,
|
|
203
|
+
"v-if": visible.value,
|
|
204
|
+
width:model.value.form.dialog.width,
|
|
196
205
|
...props
|
|
197
206
|
},
|
|
198
207
|
() => [
|
|
199
208
|
props.slots.header ? h('div', { slot: 'header' }, props.slots.header()) : null,
|
|
200
209
|
// 传递名为 'default' 的插槽
|
|
201
210
|
props.slots.default ? h(props.slots.default()) : null,
|
|
202
|
-
// 传递名为 'header' 的插槽
|
|
203
211
|
// 传递名为 'footer' 的插槽
|
|
204
212
|
props.slots.footer ? h('div', { slot: 'footer' }, props.slots.footer()) : null,
|
|
205
213
|
// 可以继续添加其他插槽...
|
|
@@ -207,8 +215,7 @@ const openModal = (props = {}) => {
|
|
|
207
215
|
);
|
|
208
216
|
}
|
|
209
217
|
});
|
|
210
|
-
|
|
211
|
-
app.use(ElementPlus).use(gyc).mount(el);
|
|
218
|
+
app.use(ElementPlus).mount(el);
|
|
212
219
|
document.body.appendChild(el);
|
|
213
220
|
};
|
|
214
221
|
|