@tmagic/form 1.7.7 → 1.7.8-beta.2
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/LICENSE +235 -164
- package/dist/es/Form.js +5 -0
- package/dist/es/Form.vue_vue_type_script_setup_true_lang.js +234 -0
- package/dist/es/FormBox.js +5 -0
- package/dist/es/FormBox.vue_vue_type_script_setup_true_lang.js +117 -0
- package/dist/es/FormDialog.js +5 -0
- package/dist/es/FormDialog.vue_vue_type_script_setup_true_lang.js +222 -0
- package/dist/es/FormDrawer.js +5 -0
- package/dist/es/FormDrawer.vue_vue_type_script_setup_true_lang.js +176 -0
- package/dist/es/_virtual/_rolldown/runtime.js +27 -0
- package/dist/es/containers/Col.js +5 -0
- package/dist/es/containers/Col.vue_vue_type_script_setup_true_lang.js +60 -0
- package/dist/es/containers/Container.js +5 -0
- package/dist/es/containers/Container.vue_vue_type_script_setup_true_lang.js +438 -0
- package/dist/es/containers/Fieldset.js +5 -0
- package/dist/es/containers/Fieldset.vue_vue_type_script_setup_true_lang.js +153 -0
- package/dist/es/containers/FlexLayout.js +5 -0
- package/dist/es/containers/FlexLayout.vue_vue_type_script_setup_true_lang.js +64 -0
- package/dist/es/containers/FormLabel.js +5 -0
- package/dist/es/containers/FormLabel.vue_vue_type_script_setup_true_lang.js +51 -0
- package/dist/es/containers/GroupList.js +5 -0
- package/dist/es/containers/GroupList.vue_vue_type_script_setup_true_lang.js +164 -0
- package/dist/es/containers/GroupListItem.js +5 -0
- package/dist/es/containers/GroupListItem.vue_vue_type_script_setup_true_lang.js +221 -0
- package/dist/es/containers/Panel.js +5 -0
- package/dist/es/containers/Panel.vue_vue_type_script_setup_true_lang.js +130 -0
- package/dist/es/containers/Row.js +5 -0
- package/dist/es/containers/Row.vue_vue_type_script_setup_true_lang.js +65 -0
- package/dist/es/containers/Step.js +5 -0
- package/dist/es/containers/Step.vue_vue_type_script_setup_true_lang.js +85 -0
- package/dist/es/containers/Tabs.js +5 -0
- package/dist/es/containers/Tabs.vue_vue_type_script_setup_true_lang.js +194 -0
- package/dist/es/fields/Cascader.js +5 -0
- package/dist/es/fields/Cascader.vue_vue_type_script_setup_true_lang.js +123 -0
- package/dist/es/fields/Checkbox.js +5 -0
- package/dist/es/fields/Checkbox.vue_vue_type_script_setup_true_lang.js +61 -0
- package/dist/es/fields/CheckboxGroup.js +5 -0
- package/dist/es/fields/CheckboxGroup.vue_vue_type_script_setup_true_lang.js +63 -0
- package/dist/es/fields/ColorPicker.js +5 -0
- package/dist/es/fields/ColorPicker.vue_vue_type_script_setup_true_lang.js +42 -0
- package/dist/es/fields/Date.js +5 -0
- package/dist/es/fields/Date.vue_vue_type_script_setup_true_lang.js +52 -0
- package/dist/es/fields/DateTime.js +5 -0
- package/dist/es/fields/DateTime.vue_vue_type_script_setup_true_lang.js +57 -0
- package/dist/es/fields/Daterange.js +5 -0
- package/dist/es/fields/Daterange.vue_vue_type_script_setup_true_lang.js +99 -0
- package/dist/es/fields/Display.js +5 -0
- package/dist/es/fields/Display.vue_vue_type_script_setup_true_lang.js +36 -0
- package/dist/es/fields/DynamicField.js +5 -0
- package/dist/es/fields/DynamicField.vue_vue_type_script_setup_true_lang.js +91 -0
- package/dist/es/fields/Hidden.js +5 -0
- package/dist/es/fields/Hidden.vue_vue_type_script_setup_true_lang.js +24 -0
- package/dist/es/fields/Link.js +5 -0
- package/dist/es/fields/Link.vue_vue_type_script_setup_true_lang.js +104 -0
- package/dist/es/fields/Number.js +5 -0
- package/dist/es/fields/Number.vue_vue_type_script_setup_true_lang.js +65 -0
- package/dist/es/fields/NumberRange.js +5 -0
- package/dist/es/fields/NumberRange.vue_vue_type_script_setup_true_lang.js +76 -0
- package/dist/es/fields/RadioGroup.js +5 -0
- package/dist/es/fields/RadioGroup.vue_vue_type_script_setup_true_lang.js +75 -0
- package/dist/es/fields/Select.js +5 -0
- package/dist/es/fields/Select.vue_vue_type_script_setup_true_lang.js +337 -0
- package/dist/es/fields/Switch.js +5 -0
- package/dist/es/fields/Switch.vue_vue_type_script_setup_true_lang.js +59 -0
- package/dist/es/fields/Text.js +5 -0
- package/dist/es/fields/Text.vue_vue_type_script_setup_true_lang.js +215 -0
- package/dist/es/fields/Textarea.js +5 -0
- package/dist/es/fields/Textarea.vue_vue_type_script_setup_true_lang.js +60 -0
- package/dist/es/fields/Time.js +5 -0
- package/dist/es/fields/Time.vue_vue_type_script_setup_true_lang.js +49 -0
- package/dist/es/fields/Timerange.js +5 -0
- package/dist/es/fields/Timerange.vue_vue_type_script_setup_true_lang.js +100 -0
- package/dist/es/index.js +41 -0
- package/dist/es/plugin.js +74 -0
- package/dist/es/schema.js +2 -0
- package/dist/es/style.css +325 -0
- package/dist/es/table/ActionsColumn.js +5 -0
- package/dist/es/table/ActionsColumn.vue_vue_type_script_setup_true_lang.js +107 -0
- package/dist/es/table/SortColumn.js +5 -0
- package/dist/es/table/SortColumn.vue_vue_type_script_setup_true_lang.js +88 -0
- package/dist/es/table/Table.js +5 -0
- package/dist/es/table/Table.vue_vue_type_script_setup_true_lang.js +232 -0
- package/dist/es/table/useAdd.js +71 -0
- package/dist/es/table/useFullscreen.js +15 -0
- package/dist/es/table/useImport.js +46 -0
- package/dist/es/table/usePagination.js +26 -0
- package/dist/es/table/useSelection.js +26 -0
- package/dist/es/table/useSortable.js +39 -0
- package/dist/es/table/useTableColumns.js +160 -0
- package/dist/es/utils/config.js +15 -0
- package/dist/es/utils/form.js +174 -0
- package/dist/es/utils/useAddField.js +13 -0
- package/dist/style.css +1 -1
- package/dist/tmagic-form.umd.cjs +7696 -8924
- package/package.json +7 -6
- package/src/Form.vue +2 -2
- package/src/containers/Container.vue +25 -20
- package/src/containers/GroupListItem.vue +3 -1
- package/src/fields/Hidden.vue +6 -2
- package/src/fields/RadioGroup.vue +1 -1
- package/src/fields/Timerange.vue +2 -2
- package/src/index.ts +8 -82
- package/src/plugin.ts +102 -0
- package/src/table/useSortable.ts +8 -4
- package/src/utils/config.ts +16 -1
- package/src/utils/form.ts +10 -7
- package/types/index.d.ts +1265 -1227
- package/dist/tmagic-form.js +0 -5940
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { initValue } from "./utils/form.js";
|
|
2
|
+
import { getConfig } from "./utils/config.js";
|
|
3
|
+
import Container_default from "./containers/Container.js";
|
|
4
|
+
import { Fragment, createBlock, createCommentVNode, createElementBlock, defineComponent, normalizeStyle, openBlock, provide, reactive, ref, renderList, shallowRef, toRaw, unref, useTemplateRef, watch, watchEffect, withCtx } from "vue";
|
|
5
|
+
import { cloneDeep, isEqual } from "lodash-es";
|
|
6
|
+
import { setValueByKeyPath } from "@tmagic/utils";
|
|
7
|
+
import { TMagicForm, tMagicMessage, tMagicMessageBox } from "@tmagic/design";
|
|
8
|
+
//#region packages/form/src/Form.vue?vue&type=script&setup=true&lang.ts
|
|
9
|
+
var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
10
|
+
name: "MForm",
|
|
11
|
+
__name: "Form",
|
|
12
|
+
props: {
|
|
13
|
+
config: { default: () => [] },
|
|
14
|
+
initValues: { default: () => ({}) },
|
|
15
|
+
lastValues: { default: () => ({}) },
|
|
16
|
+
isCompare: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
20
|
+
parentValues: { default: () => ({}) },
|
|
21
|
+
labelWidth: { default: "200px" },
|
|
22
|
+
disabled: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
default: false
|
|
25
|
+
},
|
|
26
|
+
height: { default: "auto" },
|
|
27
|
+
stepActive: { default: 1 },
|
|
28
|
+
size: {},
|
|
29
|
+
inline: {
|
|
30
|
+
type: Boolean,
|
|
31
|
+
default: false
|
|
32
|
+
},
|
|
33
|
+
labelPosition: { default: "right" },
|
|
34
|
+
keyProp: { default: "__key" },
|
|
35
|
+
popperClass: {},
|
|
36
|
+
preventSubmitDefault: { type: Boolean },
|
|
37
|
+
extendState: {}
|
|
38
|
+
},
|
|
39
|
+
emits: [
|
|
40
|
+
"change",
|
|
41
|
+
"error",
|
|
42
|
+
"field-input",
|
|
43
|
+
"field-change",
|
|
44
|
+
"update:stepActive"
|
|
45
|
+
],
|
|
46
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
47
|
+
const props = __props;
|
|
48
|
+
const emit = __emit;
|
|
49
|
+
const tMagicFormRef = useTemplateRef("tMagicForm");
|
|
50
|
+
const initialized = ref(false);
|
|
51
|
+
const values = ref({});
|
|
52
|
+
const lastValuesProcessed = ref({});
|
|
53
|
+
const fields = /* @__PURE__ */ new Map();
|
|
54
|
+
const requestFuc = getConfig("request");
|
|
55
|
+
const formState = reactive({
|
|
56
|
+
keyProp: props.keyProp,
|
|
57
|
+
popperClass: props.popperClass,
|
|
58
|
+
config: props.config,
|
|
59
|
+
initValues: props.initValues,
|
|
60
|
+
isCompare: props.isCompare,
|
|
61
|
+
lastValues: props.lastValues,
|
|
62
|
+
parentValues: props.parentValues,
|
|
63
|
+
values,
|
|
64
|
+
lastValuesProcessed,
|
|
65
|
+
$emit: emit,
|
|
66
|
+
fields,
|
|
67
|
+
setField: (prop, field) => fields.set(prop, field),
|
|
68
|
+
getField: (prop) => fields.get(prop),
|
|
69
|
+
deleteField: (prop) => fields.delete(prop),
|
|
70
|
+
$messageBox: tMagicMessageBox,
|
|
71
|
+
$message: tMagicMessage,
|
|
72
|
+
post: (options) => {
|
|
73
|
+
if (requestFuc) return requestFuc({
|
|
74
|
+
method: "POST",
|
|
75
|
+
...options
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
watchEffect(async () => {
|
|
80
|
+
formState.initValues = props.initValues;
|
|
81
|
+
formState.lastValues = props.lastValues;
|
|
82
|
+
formState.isCompare = props.isCompare;
|
|
83
|
+
formState.config = props.config;
|
|
84
|
+
formState.keyProp = props.keyProp;
|
|
85
|
+
formState.popperClass = props.popperClass;
|
|
86
|
+
formState.parentValues = props.parentValues;
|
|
87
|
+
if (typeof props.extendState === "function") {
|
|
88
|
+
const state = await props.extendState(formState) || {};
|
|
89
|
+
Object.entries(state).forEach(([key, value]) => {
|
|
90
|
+
formState[key] = value;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
provide("mForm", formState);
|
|
95
|
+
const changeRecords = shallowRef([]);
|
|
96
|
+
watch([() => props.config, () => props.initValues], ([config], [preConfig]) => {
|
|
97
|
+
changeRecords.value = [];
|
|
98
|
+
if (!isEqual(toRaw(config), toRaw(preConfig))) initialized.value = false;
|
|
99
|
+
initValue(formState, {
|
|
100
|
+
initValues: props.initValues,
|
|
101
|
+
config: props.config
|
|
102
|
+
}).then((value) => {
|
|
103
|
+
values.value = value;
|
|
104
|
+
initialized.value = !props.isCompare;
|
|
105
|
+
});
|
|
106
|
+
if (props.isCompare) initValue(formState, {
|
|
107
|
+
initValues: props.lastValues,
|
|
108
|
+
config: props.config
|
|
109
|
+
}).then((value) => {
|
|
110
|
+
lastValuesProcessed.value = value;
|
|
111
|
+
initialized.value = true;
|
|
112
|
+
});
|
|
113
|
+
}, { immediate: true });
|
|
114
|
+
const changeHandler = (v, eventData) => {
|
|
115
|
+
if (eventData.changeRecords?.length) {
|
|
116
|
+
for (const record of eventData.changeRecords) if (record.propPath) {
|
|
117
|
+
const index = changeRecords.value.findIndex((item) => item.propPath === record.propPath);
|
|
118
|
+
if (index > -1) changeRecords.value[index] = record;
|
|
119
|
+
else changeRecords.value.push(record);
|
|
120
|
+
setValueByKeyPath(record.propPath, record.value, values.value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
emit("change", values.value, eventData);
|
|
124
|
+
};
|
|
125
|
+
const submitHandler = (e) => {
|
|
126
|
+
if (props.preventSubmitDefault) e.preventDefault();
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* 通过 name 从 config 中查找对应的 text
|
|
130
|
+
* @param name - 字段名,支持点分隔的路径格式,如 'a.b.c'
|
|
131
|
+
* @param config - 表单配置数组
|
|
132
|
+
* @returns 找到的 text 值,如果未找到则返回 undefined
|
|
133
|
+
*/
|
|
134
|
+
const getTextByName = (name, config = props.config) => {
|
|
135
|
+
if (!name || !Array.isArray(config)) return void 0;
|
|
136
|
+
const nameParts = name.split(".");
|
|
137
|
+
const findInConfig = (configs, parts) => {
|
|
138
|
+
if (parts.length === 0) return void 0;
|
|
139
|
+
const [currentPart, ...remainingParts] = parts;
|
|
140
|
+
for (const item of configs) {
|
|
141
|
+
if (item.name === currentPart) {
|
|
142
|
+
if (remainingParts.length === 0) return typeof item.text === "string" ? item.text : void 0;
|
|
143
|
+
if ("items" in item && Array.isArray(item.items)) {
|
|
144
|
+
const result = findInConfig(item.items, remainingParts);
|
|
145
|
+
if (result !== void 0) return result;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if ("items" in item && Array.isArray(item.items)) {
|
|
149
|
+
const result = findInConfig(item.items, parts);
|
|
150
|
+
if (result !== void 0) return result;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
return findInConfig(config, nameParts);
|
|
155
|
+
};
|
|
156
|
+
__expose({
|
|
157
|
+
values,
|
|
158
|
+
lastValuesProcessed,
|
|
159
|
+
formState,
|
|
160
|
+
initialized,
|
|
161
|
+
changeRecords,
|
|
162
|
+
changeHandler,
|
|
163
|
+
resetForm: () => {
|
|
164
|
+
tMagicFormRef.value?.resetFields();
|
|
165
|
+
changeRecords.value = [];
|
|
166
|
+
},
|
|
167
|
+
submitForm: async (native) => {
|
|
168
|
+
try {
|
|
169
|
+
const result = await tMagicFormRef.value?.validate();
|
|
170
|
+
if (result !== true) throw result;
|
|
171
|
+
changeRecords.value = [];
|
|
172
|
+
return native ? values.value : cloneDeep(toRaw(values.value));
|
|
173
|
+
} catch (invalidFields) {
|
|
174
|
+
emit("error", invalidFields);
|
|
175
|
+
const error = [];
|
|
176
|
+
Object.entries(invalidFields).forEach(([prop, ValidateError]) => {
|
|
177
|
+
ValidateError.forEach(({ field, message }) => {
|
|
178
|
+
const name = field || prop;
|
|
179
|
+
const text = getTextByName(name, props.config) || name;
|
|
180
|
+
error.push(`${text} -> ${message}`);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
throw new Error(error.join("<br>"));
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
getTextByName
|
|
187
|
+
});
|
|
188
|
+
return (_ctx, _cache) => {
|
|
189
|
+
return openBlock(), createBlock(unref(TMagicForm), {
|
|
190
|
+
class: "m-form",
|
|
191
|
+
ref: "tMagicForm",
|
|
192
|
+
model: values.value,
|
|
193
|
+
"label-width": __props.labelWidth,
|
|
194
|
+
style: normalizeStyle(`height: ${__props.height}`),
|
|
195
|
+
inline: __props.inline,
|
|
196
|
+
"label-position": __props.labelPosition,
|
|
197
|
+
onSubmit: submitHandler
|
|
198
|
+
}, {
|
|
199
|
+
default: withCtx(() => [initialized.value && Array.isArray(__props.config) ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(__props.config, (item, index) => {
|
|
200
|
+
return openBlock(), createBlock(Container_default, {
|
|
201
|
+
disabled: __props.disabled,
|
|
202
|
+
key: item[__props.keyProp] ?? index,
|
|
203
|
+
config: item,
|
|
204
|
+
model: values.value,
|
|
205
|
+
"last-values": lastValuesProcessed.value,
|
|
206
|
+
"is-compare": __props.isCompare,
|
|
207
|
+
"label-width": item.labelWidth || __props.labelWidth,
|
|
208
|
+
"step-active": __props.stepActive,
|
|
209
|
+
size: __props.size,
|
|
210
|
+
onChange: changeHandler
|
|
211
|
+
}, null, 8, [
|
|
212
|
+
"disabled",
|
|
213
|
+
"config",
|
|
214
|
+
"model",
|
|
215
|
+
"last-values",
|
|
216
|
+
"is-compare",
|
|
217
|
+
"label-width",
|
|
218
|
+
"step-active",
|
|
219
|
+
"size"
|
|
220
|
+
]);
|
|
221
|
+
}), 128)) : createCommentVNode("v-if", true)]),
|
|
222
|
+
_: 1
|
|
223
|
+
}, 8, [
|
|
224
|
+
"model",
|
|
225
|
+
"label-width",
|
|
226
|
+
"style",
|
|
227
|
+
"inline",
|
|
228
|
+
"label-position"
|
|
229
|
+
]);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
//#endregion
|
|
234
|
+
export { Form_vue_vue_type_script_setup_true_lang_default as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import FormBox_vue_vue_type_script_setup_true_lang_default from "./FormBox.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
//#region packages/form/src/FormBox.vue
|
|
3
|
+
var FormBox_default = FormBox_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { FormBox_default as default };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import Form_default from "./Form.js";
|
|
2
|
+
import { computed, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeStyle, openBlock, ref, renderSlot, toDisplayString, unref, watchEffect, withCtx } from "vue";
|
|
3
|
+
import { TMagicButton, TMagicScrollbar } from "@tmagic/design";
|
|
4
|
+
//#region packages/form/src/FormBox.vue?vue&type=script&setup=true&lang.ts
|
|
5
|
+
var footerHeight = 60;
|
|
6
|
+
var FormBox_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
7
|
+
name: "MFormBox",
|
|
8
|
+
__name: "FormBox",
|
|
9
|
+
props: {
|
|
10
|
+
config: { default: () => [] },
|
|
11
|
+
values: { default: () => ({}) },
|
|
12
|
+
parentValues: {},
|
|
13
|
+
width: {},
|
|
14
|
+
height: {},
|
|
15
|
+
labelWidth: {},
|
|
16
|
+
disabled: { type: Boolean },
|
|
17
|
+
size: {},
|
|
18
|
+
confirmText: { default: "确定" },
|
|
19
|
+
inline: { type: Boolean },
|
|
20
|
+
labelPosition: {},
|
|
21
|
+
preventSubmitDefault: { type: Boolean }
|
|
22
|
+
},
|
|
23
|
+
emits: [
|
|
24
|
+
"change",
|
|
25
|
+
"submit",
|
|
26
|
+
"error"
|
|
27
|
+
],
|
|
28
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
29
|
+
const props = __props;
|
|
30
|
+
const emit = __emit;
|
|
31
|
+
const style = computed(() => {
|
|
32
|
+
const style = {};
|
|
33
|
+
if (typeof props.width === "number") style.width = `${props.width}px`;
|
|
34
|
+
if (typeof props.height === "number") style.height = `${props.height}px`;
|
|
35
|
+
return style;
|
|
36
|
+
});
|
|
37
|
+
const form = ref();
|
|
38
|
+
const saveFetch = ref(false);
|
|
39
|
+
const bodyHeight = ref(0);
|
|
40
|
+
watchEffect(() => {
|
|
41
|
+
if (!props.height) return;
|
|
42
|
+
bodyHeight.value = props.height - footerHeight;
|
|
43
|
+
});
|
|
44
|
+
const submitHandler = async () => {
|
|
45
|
+
try {
|
|
46
|
+
const changeRecords = form.value?.changeRecords;
|
|
47
|
+
emit("submit", await form.value?.submitForm(), { changeRecords });
|
|
48
|
+
} catch (e) {
|
|
49
|
+
emit("error", e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const changeHandler = (value, eventData) => {
|
|
53
|
+
emit("change", value, eventData);
|
|
54
|
+
};
|
|
55
|
+
const show = () => {};
|
|
56
|
+
const hide = () => {};
|
|
57
|
+
__expose({
|
|
58
|
+
form,
|
|
59
|
+
saveFetch,
|
|
60
|
+
show,
|
|
61
|
+
hide
|
|
62
|
+
});
|
|
63
|
+
return (_ctx, _cache) => {
|
|
64
|
+
return openBlock(), createElementBlock("div", {
|
|
65
|
+
class: "m-form-box",
|
|
66
|
+
style: normalizeStyle(style.value)
|
|
67
|
+
}, [createElementVNode("div", {
|
|
68
|
+
class: "m-box-body",
|
|
69
|
+
style: normalizeStyle(bodyHeight.value ? { height: `${bodyHeight.value}px` } : {})
|
|
70
|
+
}, [createVNode(unref(TMagicScrollbar), null, {
|
|
71
|
+
default: withCtx(() => [createVNode(Form_default, {
|
|
72
|
+
ref_key: "form",
|
|
73
|
+
ref: form,
|
|
74
|
+
size: __props.size,
|
|
75
|
+
disabled: __props.disabled,
|
|
76
|
+
config: __props.config,
|
|
77
|
+
"init-values": __props.values,
|
|
78
|
+
"parent-values": __props.parentValues,
|
|
79
|
+
"label-width": __props.labelWidth,
|
|
80
|
+
"label-position": __props.labelPosition,
|
|
81
|
+
inline: __props.inline,
|
|
82
|
+
"prevent-submit-default": __props.preventSubmitDefault,
|
|
83
|
+
onChange: changeHandler
|
|
84
|
+
}, null, 8, [
|
|
85
|
+
"size",
|
|
86
|
+
"disabled",
|
|
87
|
+
"config",
|
|
88
|
+
"init-values",
|
|
89
|
+
"parent-values",
|
|
90
|
+
"label-width",
|
|
91
|
+
"label-position",
|
|
92
|
+
"inline",
|
|
93
|
+
"prevent-submit-default"
|
|
94
|
+
]), renderSlot(_ctx.$slots, "default")]),
|
|
95
|
+
_: 3
|
|
96
|
+
})], 4), createElementVNode("div", {
|
|
97
|
+
class: "dialog-footer",
|
|
98
|
+
style: normalizeStyle(`height: ${footerHeight}px`)
|
|
99
|
+
}, [createElementVNode("div", null, [renderSlot(_ctx.$slots, "left")]), createElementVNode("div", null, [renderSlot(_ctx.$slots, "footer", {}, () => [createVNode(unref(TMagicButton), {
|
|
100
|
+
type: "primary",
|
|
101
|
+
size: __props.size,
|
|
102
|
+
disabled: __props.disabled,
|
|
103
|
+
loading: saveFetch.value,
|
|
104
|
+
onClick: submitHandler
|
|
105
|
+
}, {
|
|
106
|
+
default: withCtx(() => [createTextVNode(toDisplayString(__props.confirmText), 1)]),
|
|
107
|
+
_: 1
|
|
108
|
+
}, 8, [
|
|
109
|
+
"size",
|
|
110
|
+
"disabled",
|
|
111
|
+
"loading"
|
|
112
|
+
])])])], 4)], 4);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
//#endregion
|
|
117
|
+
export { FormBox_vue_vue_type_script_setup_true_lang_default as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import FormDialog_vue_vue_type_script_setup_true_lang_default from "./FormDialog.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
//#region packages/form/src/FormDialog.vue
|
|
3
|
+
var FormDialog_default = FormDialog_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { FormDialog_default as default };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import Form_default from "./Form.js";
|
|
2
|
+
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeStyle, openBlock, ref, renderSlot, toDisplayString, unref, withCtx } from "vue";
|
|
3
|
+
import { TMagicButton, TMagicCol, TMagicDialog, TMagicRow } from "@tmagic/design";
|
|
4
|
+
//#region packages/form/src/FormDialog.vue?vue&type=script&setup=true&lang.ts
|
|
5
|
+
var _hoisted_1 = { style: { "min-height": "1px" } };
|
|
6
|
+
var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
7
|
+
name: "MFormDialog",
|
|
8
|
+
__name: "FormDialog",
|
|
9
|
+
props: {
|
|
10
|
+
config: { default: () => [] },
|
|
11
|
+
values: { default: () => ({}) },
|
|
12
|
+
parentValues: {},
|
|
13
|
+
width: {},
|
|
14
|
+
labelWidth: {},
|
|
15
|
+
fullscreen: { type: Boolean },
|
|
16
|
+
disabled: { type: Boolean },
|
|
17
|
+
title: {},
|
|
18
|
+
inline: { type: Boolean },
|
|
19
|
+
labelPosition: {},
|
|
20
|
+
zIndex: {},
|
|
21
|
+
size: {},
|
|
22
|
+
confirmText: { default: "确定" },
|
|
23
|
+
preventSubmitDefault: { type: Boolean },
|
|
24
|
+
closeOnClickModal: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: false
|
|
27
|
+
},
|
|
28
|
+
closeOnPressEscape: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: false
|
|
31
|
+
},
|
|
32
|
+
destroyOnClose: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: false
|
|
35
|
+
},
|
|
36
|
+
showClose: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: true
|
|
39
|
+
},
|
|
40
|
+
showCancel: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
emits: [
|
|
46
|
+
"close",
|
|
47
|
+
"submit",
|
|
48
|
+
"error",
|
|
49
|
+
"change"
|
|
50
|
+
],
|
|
51
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
52
|
+
const props = __props;
|
|
53
|
+
const emit = __emit;
|
|
54
|
+
const form = ref();
|
|
55
|
+
const dialogVisible = ref(false);
|
|
56
|
+
const saveFetch = ref(false);
|
|
57
|
+
const stepActive = ref(1);
|
|
58
|
+
const bodyHeight = ref(`${document.body.clientHeight - 194}px`);
|
|
59
|
+
const stepCount = computed(() => {
|
|
60
|
+
const { length } = props.config;
|
|
61
|
+
for (let index = 0; index < length; index++) if (props.config[index].type === "step") return props.config[index].items.length;
|
|
62
|
+
return 0;
|
|
63
|
+
});
|
|
64
|
+
const hasStep = computed(() => {
|
|
65
|
+
const { length } = props.config;
|
|
66
|
+
for (let index = 0; index < length; index++) if (props.config[index].type === "step") return true;
|
|
67
|
+
return false;
|
|
68
|
+
});
|
|
69
|
+
const closeHandler = () => {
|
|
70
|
+
stepActive.value = 1;
|
|
71
|
+
emit("close");
|
|
72
|
+
};
|
|
73
|
+
const save = async () => {
|
|
74
|
+
try {
|
|
75
|
+
const changeRecords = form.value?.changeRecords;
|
|
76
|
+
emit("submit", await form.value?.submitForm(), { changeRecords });
|
|
77
|
+
} catch (e) {
|
|
78
|
+
emit("error", e);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const preStep = () => {
|
|
82
|
+
stepActive.value -= 1;
|
|
83
|
+
};
|
|
84
|
+
const nextStep = () => {
|
|
85
|
+
stepActive.value += 1;
|
|
86
|
+
};
|
|
87
|
+
const changeHandler = (value, eventData) => {
|
|
88
|
+
emit("change", value, eventData);
|
|
89
|
+
};
|
|
90
|
+
const show = () => {
|
|
91
|
+
dialogVisible.value = true;
|
|
92
|
+
};
|
|
93
|
+
const hide = () => {
|
|
94
|
+
dialogVisible.value = false;
|
|
95
|
+
};
|
|
96
|
+
const cancel = () => {
|
|
97
|
+
hide();
|
|
98
|
+
};
|
|
99
|
+
__expose({
|
|
100
|
+
form,
|
|
101
|
+
saveFetch,
|
|
102
|
+
dialogVisible,
|
|
103
|
+
cancel,
|
|
104
|
+
save,
|
|
105
|
+
show,
|
|
106
|
+
hide
|
|
107
|
+
});
|
|
108
|
+
return (_ctx, _cache) => {
|
|
109
|
+
return openBlock(), createBlock(unref(TMagicDialog), {
|
|
110
|
+
modelValue: dialogVisible.value,
|
|
111
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => dialogVisible.value = $event),
|
|
112
|
+
class: "m-form-dialog",
|
|
113
|
+
top: "20px",
|
|
114
|
+
"append-to-body": "",
|
|
115
|
+
title: __props.title,
|
|
116
|
+
width: __props.width,
|
|
117
|
+
zIndex: __props.zIndex,
|
|
118
|
+
fullscreen: __props.fullscreen,
|
|
119
|
+
"close-on-click-modal": __props.closeOnClickModal,
|
|
120
|
+
"close-on-press-escape": __props.closeOnPressEscape,
|
|
121
|
+
"destroy-on-close": __props.destroyOnClose,
|
|
122
|
+
"show-close": __props.showClose,
|
|
123
|
+
onClose: closeHandler
|
|
124
|
+
}, {
|
|
125
|
+
footer: withCtx(() => [createVNode(unref(TMagicRow), { class: "dialog-footer" }, {
|
|
126
|
+
default: withCtx(() => [createVNode(unref(TMagicCol), {
|
|
127
|
+
span: 12,
|
|
128
|
+
style: { "text-align": "left" }
|
|
129
|
+
}, {
|
|
130
|
+
default: withCtx(() => [createElementVNode("div", _hoisted_1, [renderSlot(_ctx.$slots, "left")])]),
|
|
131
|
+
_: 3
|
|
132
|
+
}), createVNode(unref(TMagicCol), { span: 12 }, {
|
|
133
|
+
default: withCtx(() => [renderSlot(_ctx.$slots, "footer", {}, () => [
|
|
134
|
+
__props.showCancel ? (openBlock(), createBlock(unref(TMagicButton), {
|
|
135
|
+
key: 0,
|
|
136
|
+
onClick: cancel,
|
|
137
|
+
size: "small"
|
|
138
|
+
}, {
|
|
139
|
+
default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("取 消", -1)])]),
|
|
140
|
+
_: 1
|
|
141
|
+
})) : createCommentVNode("v-if", true),
|
|
142
|
+
hasStep.value && stepActive.value > 1 ? (openBlock(), createBlock(unref(TMagicButton), {
|
|
143
|
+
key: 1,
|
|
144
|
+
type: "info",
|
|
145
|
+
size: "small",
|
|
146
|
+
onClick: preStep
|
|
147
|
+
}, {
|
|
148
|
+
default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode("上一步", -1)])]),
|
|
149
|
+
_: 1
|
|
150
|
+
})) : createCommentVNode("v-if", true),
|
|
151
|
+
hasStep.value && stepCount.value > stepActive.value ? (openBlock(), createBlock(unref(TMagicButton), {
|
|
152
|
+
key: 2,
|
|
153
|
+
type: "info",
|
|
154
|
+
size: "small",
|
|
155
|
+
onClick: nextStep
|
|
156
|
+
}, {
|
|
157
|
+
default: withCtx(() => [..._cache[4] || (_cache[4] = [createTextVNode("下一步", -1)])]),
|
|
158
|
+
_: 1
|
|
159
|
+
})) : (openBlock(), createBlock(unref(TMagicButton), {
|
|
160
|
+
key: 3,
|
|
161
|
+
type: "primary",
|
|
162
|
+
size: "small",
|
|
163
|
+
disabled: __props.disabled,
|
|
164
|
+
loading: saveFetch.value,
|
|
165
|
+
onClick: save
|
|
166
|
+
}, {
|
|
167
|
+
default: withCtx(() => [createTextVNode(toDisplayString(__props.confirmText), 1)]),
|
|
168
|
+
_: 1
|
|
169
|
+
}, 8, ["disabled", "loading"]))
|
|
170
|
+
])]),
|
|
171
|
+
_: 3
|
|
172
|
+
})]),
|
|
173
|
+
_: 3
|
|
174
|
+
})]),
|
|
175
|
+
default: withCtx(() => [dialogVisible.value ? (openBlock(), createElementBlock("div", {
|
|
176
|
+
key: 0,
|
|
177
|
+
class: "m-dialog-body",
|
|
178
|
+
style: normalizeStyle(`max-height: ${bodyHeight.value}; overflow-y: auto; overflow-x: hidden;`)
|
|
179
|
+
}, [createVNode(Form_default, {
|
|
180
|
+
modelValue: stepActive.value,
|
|
181
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => stepActive.value = $event),
|
|
182
|
+
ref_key: "form",
|
|
183
|
+
ref: form,
|
|
184
|
+
size: __props.size,
|
|
185
|
+
disabled: __props.disabled,
|
|
186
|
+
config: __props.config,
|
|
187
|
+
"init-values": __props.values,
|
|
188
|
+
"parent-values": __props.parentValues,
|
|
189
|
+
"label-width": __props.labelWidth,
|
|
190
|
+
"label-position": __props.labelPosition,
|
|
191
|
+
inline: __props.inline,
|
|
192
|
+
"prevent-submit-default": __props.preventSubmitDefault,
|
|
193
|
+
onChange: changeHandler
|
|
194
|
+
}, null, 8, [
|
|
195
|
+
"modelValue",
|
|
196
|
+
"size",
|
|
197
|
+
"disabled",
|
|
198
|
+
"config",
|
|
199
|
+
"init-values",
|
|
200
|
+
"parent-values",
|
|
201
|
+
"label-width",
|
|
202
|
+
"label-position",
|
|
203
|
+
"inline",
|
|
204
|
+
"prevent-submit-default"
|
|
205
|
+
]), renderSlot(_ctx.$slots, "default")], 4)) : createCommentVNode("v-if", true)]),
|
|
206
|
+
_: 3
|
|
207
|
+
}, 8, [
|
|
208
|
+
"modelValue",
|
|
209
|
+
"title",
|
|
210
|
+
"width",
|
|
211
|
+
"zIndex",
|
|
212
|
+
"fullscreen",
|
|
213
|
+
"close-on-click-modal",
|
|
214
|
+
"close-on-press-escape",
|
|
215
|
+
"destroy-on-close",
|
|
216
|
+
"show-close"
|
|
217
|
+
]);
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
//#endregion
|
|
222
|
+
export { FormDialog_vue_vue_type_script_setup_true_lang_default as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import FormDrawer_vue_vue_type_script_setup_true_lang_default from "./FormDrawer.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
//#region packages/form/src/FormDrawer.vue
|
|
3
|
+
var FormDrawer_default = FormDrawer_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { FormDrawer_default as default };
|