@tmagic/form 1.2.0-beta.2 → 1.2.0-beta.21
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/dist/style.css +1 -1
- package/dist/tmagic-form.js +3673 -0
- package/dist/tmagic-form.js.map +1 -0
- package/dist/tmagic-form.umd.cjs +3713 -0
- package/dist/tmagic-form.umd.cjs.map +1 -0
- package/package.json +10 -9
- package/src/Form.vue +124 -159
- package/src/FormDialog.vue +108 -126
- package/src/containers/Col.vue +24 -38
- package/src/containers/Container.vue +143 -171
- package/src/containers/Fieldset.vue +15 -8
- package/src/containers/GroupList.vue +86 -116
- package/src/containers/GroupListItem.vue +91 -125
- package/src/containers/Panel.vue +29 -49
- package/src/containers/Row.vue +20 -40
- package/src/containers/Step.vue +38 -48
- package/src/containers/Table.vue +466 -481
- package/src/containers/Tabs.vue +94 -118
- package/src/fields/Cascader.vue +88 -136
- package/src/fields/Checkbox.vue +46 -50
- package/src/fields/CheckboxGroup.vue +39 -35
- package/src/fields/ColorPicker.vue +5 -3
- package/src/fields/Date.vue +21 -27
- package/src/fields/DateTime.vue +31 -39
- package/src/fields/Daterange.vue +4 -3
- package/src/fields/Display.vue +1 -1
- package/src/fields/DynamicField.vue +63 -77
- package/src/fields/Hidden.vue +1 -1
- package/src/fields/Link.vue +65 -86
- package/src/fields/Number.vue +32 -34
- package/src/fields/RadioGroup.vue +23 -23
- package/src/fields/Select.vue +294 -310
- package/src/fields/SelectOptionGroups.vue +11 -6
- package/src/fields/SelectOptions.vue +5 -3
- package/src/fields/Switch.vue +46 -49
- package/src/fields/Text.vue +99 -107
- package/src/fields/Textarea.vue +32 -44
- package/src/fields/Time.vue +21 -30
- package/src/index.ts +22 -23
- package/src/schema.ts +50 -12
- package/src/theme/form.scss +1 -1
- package/src/utils/form.ts +9 -5
- package/types/Form.vue.d.ts +211 -111
- package/types/FormDialog.vue.d.ts +813 -154
- package/types/containers/Col.vue.d.ts +96 -40
- package/types/containers/Container.vue.d.ts +126 -65
- package/types/containers/Fieldset.vue.d.ts +5 -3
- package/types/containers/GroupList.vue.d.ts +90 -53
- package/types/containers/GroupListItem.vue.d.ts +101 -67
- package/types/containers/Panel.vue.d.ts +96 -39
- package/types/containers/Row.vue.d.ts +96 -39
- package/types/containers/Step.vue.d.ts +106 -42
- package/types/containers/Table.vue.d.ts +161 -130
- package/types/containers/Tabs.vue.d.ts +97 -50
- package/types/fields/Cascader.vue.d.ts +95 -71
- package/types/fields/Checkbox.vue.d.ts +95 -56
- package/types/fields/CheckboxGroup.vue.d.ts +95 -53
- package/types/fields/ColorPicker.vue.d.ts +1 -3
- package/types/fields/Date.vue.d.ts +95 -54
- package/types/fields/DateTime.vue.d.ts +95 -54
- package/types/fields/Daterange.vue.d.ts +1 -3
- package/types/fields/Display.vue.d.ts +1 -3
- package/types/fields/DynamicField.vue.d.ts +95 -64
- package/types/fields/Hidden.vue.d.ts +1 -3
- package/types/fields/Link.vue.d.ts +60 -657
- package/types/fields/Number.vue.d.ts +99 -56
- package/types/fields/RadioGroup.vue.d.ts +96 -52
- package/types/fields/Select.vue.d.ts +97 -65
- package/types/fields/SelectOptionGroups.vue.d.ts +1 -3
- package/types/fields/SelectOptions.vue.d.ts +1 -3
- package/types/fields/Switch.vue.d.ts +95 -56
- package/types/fields/Text.vue.d.ts +98 -57
- package/types/fields/Textarea.vue.d.ts +100 -60
- package/types/fields/Time.vue.d.ts +95 -55
- package/types/index.d.ts +0 -1
- package/types/schema.d.ts +42 -9
- package/types/utils/form.d.ts +2 -1
- package/dist/tmagic-form.mjs +0 -3925
- package/dist/tmagic-form.mjs.map +0 -1
- package/dist/tmagic-form.umd.js +0 -3965
- package/dist/tmagic-form.umd.js.map +0 -1
- package/src/utils/fieldProps.ts +0 -39
- package/types/utils/fieldProps.d.ts +0 -21
package/src/Form.vue
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<TMagicForm
|
|
3
3
|
class="m-form"
|
|
4
|
-
ref="
|
|
4
|
+
ref="tMagicForm"
|
|
5
5
|
:model="values"
|
|
6
6
|
:label-width="labelWidth"
|
|
7
|
-
:disabled="disabled"
|
|
8
7
|
:style="`height: ${height}`"
|
|
9
8
|
:inline="inline"
|
|
10
9
|
:label-position="labelPosition"
|
|
11
10
|
>
|
|
12
11
|
<template v-if="initialized && Array.isArray(config)">
|
|
13
|
-
<
|
|
12
|
+
<Container
|
|
14
13
|
v-for="(item, index) in config"
|
|
14
|
+
:disabled="disabled"
|
|
15
15
|
:key="item[keyProp] ?? index"
|
|
16
16
|
:config="item"
|
|
17
17
|
:model="values"
|
|
@@ -19,175 +19,140 @@
|
|
|
19
19
|
:step-active="stepActive"
|
|
20
20
|
:size="size"
|
|
21
21
|
@change="changeHandler"
|
|
22
|
-
></
|
|
22
|
+
></Container>
|
|
23
23
|
</template>
|
|
24
|
-
</
|
|
24
|
+
</TMagicForm>
|
|
25
25
|
</template>
|
|
26
26
|
|
|
27
|
-
<script lang="ts">
|
|
28
|
-
import {
|
|
29
|
-
import
|
|
27
|
+
<script setup lang="ts" name="MForm">
|
|
28
|
+
import { provide, reactive, ref, toRaw, watch, watchEffect } from 'vue';
|
|
29
|
+
import cloneDeep from 'lodash-es/cloneDeep';
|
|
30
|
+
import isEqual from 'lodash-es/isEqual';
|
|
30
31
|
|
|
32
|
+
import { TMagicForm } from '@tmagic/design';
|
|
33
|
+
|
|
34
|
+
import Container from './containers/Container.vue';
|
|
31
35
|
import { getConfig } from './utils/config';
|
|
32
36
|
import { initValue } from './utils/form';
|
|
33
|
-
import { FormConfig, FormState, FormValue } from './schema';
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
labelPosition: {
|
|
93
|
-
type: String,
|
|
94
|
-
default: 'right',
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
keyProp: {
|
|
98
|
-
type: String,
|
|
99
|
-
default: '__key',
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
popperClass: {
|
|
103
|
-
type: String,
|
|
104
|
-
},
|
|
37
|
+
import type { FormConfig, FormState, FormValue, ValidateError } from './schema';
|
|
38
|
+
|
|
39
|
+
const props = withDefaults(
|
|
40
|
+
defineProps<{
|
|
41
|
+
config: FormConfig;
|
|
42
|
+
initValues: Object;
|
|
43
|
+
parentValues?: Object;
|
|
44
|
+
labelWidth?: string;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
height?: string;
|
|
47
|
+
stepActive?: string | number;
|
|
48
|
+
size?: 'small' | 'default' | 'large';
|
|
49
|
+
inline?: boolean;
|
|
50
|
+
labelPosition?: string;
|
|
51
|
+
keyProp?: string;
|
|
52
|
+
popperClass?: string;
|
|
53
|
+
}>(),
|
|
54
|
+
{
|
|
55
|
+
config: () => [],
|
|
56
|
+
initValues: () => ({}),
|
|
57
|
+
parentValues: () => ({}),
|
|
58
|
+
labelWidth: '200px',
|
|
59
|
+
disabled: false,
|
|
60
|
+
height: 'auto',
|
|
61
|
+
stepActive: 1,
|
|
62
|
+
inline: false,
|
|
63
|
+
labelPosition: 'right',
|
|
64
|
+
keyProp: '__key',
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const emit = defineEmits(['change', 'field-input', 'field-change']);
|
|
69
|
+
|
|
70
|
+
const tMagicForm = ref<InstanceType<typeof TMagicForm>>();
|
|
71
|
+
const initialized = ref(false);
|
|
72
|
+
const values = ref<FormValue>({});
|
|
73
|
+
const fields = new Map<string, any>();
|
|
74
|
+
|
|
75
|
+
const requestFuc = getConfig('request') as Function;
|
|
76
|
+
|
|
77
|
+
const formState: FormState = reactive<FormState>({
|
|
78
|
+
keyProp: props.keyProp,
|
|
79
|
+
popperClass: props.popperClass,
|
|
80
|
+
config: props.config,
|
|
81
|
+
initValues: props.initValues,
|
|
82
|
+
parentValues: props.parentValues,
|
|
83
|
+
values,
|
|
84
|
+
$emit: emit as (event: string, ...args: any[]) => void,
|
|
85
|
+
fields,
|
|
86
|
+
setField: (prop: string, field: any) => fields.set(prop, field),
|
|
87
|
+
getField: (prop: string) => fields.get(prop),
|
|
88
|
+
deleteField: (prop: string) => fields.delete(prop),
|
|
89
|
+
post: (options: any) => {
|
|
90
|
+
if (requestFuc) {
|
|
91
|
+
return requestFuc({
|
|
92
|
+
...options,
|
|
93
|
+
method: 'POST',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
105
96
|
},
|
|
97
|
+
});
|
|
106
98
|
|
|
107
|
-
|
|
99
|
+
watchEffect(() => {
|
|
100
|
+
formState.initValues = props.initValues;
|
|
101
|
+
formState.config = props.config;
|
|
102
|
+
formState.keyProp = props.keyProp;
|
|
103
|
+
formState.popperClass = props.popperClass;
|
|
104
|
+
formState.parentValues = props.parentValues;
|
|
105
|
+
});
|
|
108
106
|
|
|
109
|
-
|
|
110
|
-
// InstanceType<typeof ElForm>,构建types的时候会出错
|
|
111
|
-
const elForm = ref<any>();
|
|
112
|
-
const initialized = ref(false);
|
|
113
|
-
const values = ref<FormValue>({});
|
|
114
|
-
const fields = new Map<string, any>();
|
|
107
|
+
provide('mForm', formState);
|
|
115
108
|
|
|
116
|
-
|
|
109
|
+
watch(
|
|
110
|
+
[() => props.config, () => props.initValues],
|
|
111
|
+
([config], [preConfig]) => {
|
|
112
|
+
if (!isEqual(toRaw(config), toRaw(preConfig))) {
|
|
113
|
+
initialized.value = false;
|
|
114
|
+
}
|
|
117
115
|
|
|
118
|
-
|
|
119
|
-
keyProp: props.keyProp,
|
|
120
|
-
popperClass: props.popperClass,
|
|
121
|
-
config: props.config,
|
|
116
|
+
initValue(formState, {
|
|
122
117
|
initValues: props.initValues,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
setField: (prop: string, field: any) => fields.set(prop, field),
|
|
128
|
-
getField: (prop: string) => fields.get(prop),
|
|
129
|
-
deleteField: (prop: string) => fields.delete(prop),
|
|
130
|
-
post: (options: any) => {
|
|
131
|
-
if (requestFuc) {
|
|
132
|
-
return requestFuc({
|
|
133
|
-
...options,
|
|
134
|
-
method: 'POST',
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
},
|
|
118
|
+
config: props.config,
|
|
119
|
+
}).then((value) => {
|
|
120
|
+
values.value = value;
|
|
121
|
+
initialized.value = true;
|
|
138
122
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
123
|
+
},
|
|
124
|
+
{ immediate: true },
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const changeHandler = () => {
|
|
128
|
+
emit('change', values.value);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
defineExpose({
|
|
132
|
+
values,
|
|
133
|
+
formState,
|
|
134
|
+
initialized,
|
|
135
|
+
|
|
136
|
+
changeHandler,
|
|
137
|
+
|
|
138
|
+
resetForm: () => tMagicForm.value?.resetFields(),
|
|
139
|
+
|
|
140
|
+
submitForm: async (native?: boolean): Promise<any> => {
|
|
141
|
+
try {
|
|
142
|
+
await tMagicForm.value?.validate();
|
|
143
|
+
return native ? values.value : cloneDeep(toRaw(values.value));
|
|
144
|
+
} catch (invalidFields: any) {
|
|
145
|
+
const error: string[] = [];
|
|
146
|
+
|
|
147
|
+
Object.entries(invalidFields).forEach(([, ValidateError]) => {
|
|
148
|
+
(ValidateError as ValidateError[]).forEach(({ field, message }) => {
|
|
149
|
+
if (field && message) error.push(`${field} -> ${message}`);
|
|
150
|
+
if (field && !message) error.push(`${field} -> 出现错误`);
|
|
151
|
+
if (!field && message) error.push(`${message}`);
|
|
155
152
|
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
initialized,
|
|
162
|
-
values,
|
|
163
|
-
elForm,
|
|
164
|
-
|
|
165
|
-
formState,
|
|
166
|
-
|
|
167
|
-
changeHandler: () => {
|
|
168
|
-
emit('change', values.value);
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
resetForm: () => elForm.value?.resetFields(),
|
|
172
|
-
|
|
173
|
-
submitForm: async (native?: boolean): Promise<any> => {
|
|
174
|
-
try {
|
|
175
|
-
await elForm.value?.validate();
|
|
176
|
-
return native ? values.value : cloneDeep(toRaw(values.value));
|
|
177
|
-
} catch (invalidFields: any) {
|
|
178
|
-
const error: string[] = [];
|
|
179
|
-
|
|
180
|
-
Object.entries(invalidFields).forEach(([, ValidateError]) => {
|
|
181
|
-
(ValidateError as ValidateError[]).forEach(({ field, message }) => {
|
|
182
|
-
if (field && message) error.push(`${field} -> ${message}`);
|
|
183
|
-
if (field && !message) error.push(`${field} -> 出现错误`);
|
|
184
|
-
if (!field && message) error.push(`${message}`);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
throw new Error(error.join('<br>'));
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
};
|
|
153
|
+
});
|
|
154
|
+
throw new Error(error.join('<br>'));
|
|
155
|
+
}
|
|
191
156
|
},
|
|
192
157
|
});
|
|
193
158
|
</script>
|
package/src/FormDialog.vue
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<TMagicDialog
|
|
3
3
|
v-model="dialogVisible"
|
|
4
4
|
class="m-form-dialog"
|
|
5
5
|
top="20px"
|
|
6
6
|
append-to-body
|
|
7
7
|
:title="title"
|
|
8
8
|
:width="width"
|
|
9
|
+
:zIndex="zIndex"
|
|
9
10
|
:fullscreen="fullscreen"
|
|
10
11
|
:close-on-click-modal="false"
|
|
11
12
|
@close="closeHandler"
|
|
@@ -15,159 +16,140 @@
|
|
|
15
16
|
class="m-dialog-body"
|
|
16
17
|
:style="`max-height: ${bodyHeight}; overflow-y: auto; overflow-x: hidden;`"
|
|
17
18
|
>
|
|
18
|
-
<
|
|
19
|
+
<Form
|
|
19
20
|
v-model="stepActive"
|
|
20
21
|
ref="form"
|
|
21
22
|
:size="size"
|
|
23
|
+
:disabled="disabled"
|
|
22
24
|
:config="config"
|
|
23
25
|
:init-values="values"
|
|
24
26
|
:parent-values="parentValues"
|
|
25
27
|
:label-width="labelWidth"
|
|
26
28
|
@change="changeHandler"
|
|
27
|
-
></
|
|
29
|
+
></Form>
|
|
28
30
|
<slot></slot>
|
|
29
31
|
</div>
|
|
30
32
|
|
|
31
33
|
<template #footer>
|
|
32
|
-
<
|
|
33
|
-
<
|
|
34
|
+
<TMagicRow class="dialog-footer">
|
|
35
|
+
<TMagicCol :span="12" style="text-align: left">
|
|
34
36
|
<div style="min-height: 1px">
|
|
35
37
|
<slot name="left"></slot>
|
|
36
38
|
</div>
|
|
37
|
-
</
|
|
38
|
-
<
|
|
39
|
+
</TMagicCol>
|
|
40
|
+
<TMagicCol :span="12">
|
|
39
41
|
<slot name="footer">
|
|
40
|
-
<
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
>下一步</el-button
|
|
42
|
+
<TMagicButton @click="cancel" size="small">取 消</TMagicButton>
|
|
43
|
+
<TMagicButton v-if="hasStep && stepActive > 1" type="info" size="small" @click="preStep"
|
|
44
|
+
>上一步</TMagicButton
|
|
44
45
|
>
|
|
45
|
-
<
|
|
46
|
+
<TMagicButton v-if="hasStep && stepCount > stepActive" type="info" size="small" @click="nextStep"
|
|
47
|
+
>下一步</TMagicButton
|
|
48
|
+
>
|
|
49
|
+
<TMagicButton v-else type="primary" size="small" :loading="saveFetch" @click="save">{{
|
|
46
50
|
confirmText
|
|
47
|
-
}}</
|
|
51
|
+
}}</TMagicButton>
|
|
48
52
|
</slot>
|
|
49
|
-
</
|
|
50
|
-
</
|
|
53
|
+
</TMagicCol>
|
|
54
|
+
</TMagicRow>
|
|
51
55
|
</template>
|
|
52
|
-
</
|
|
56
|
+
</TMagicDialog>
|
|
53
57
|
</template>
|
|
54
58
|
|
|
55
|
-
<script lang="ts">
|
|
56
|
-
import { computed,
|
|
59
|
+
<script setup lang="ts" name="MFormDialog">
|
|
60
|
+
import { computed, ref } from 'vue';
|
|
61
|
+
|
|
62
|
+
import { TMagicButton, TMagicCol, TMagicDialog, TMagicRow } from '@tmagic/design';
|
|
57
63
|
|
|
58
64
|
import Form from './Form.vue';
|
|
59
65
|
import { FormConfig, StepConfig } from './schema';
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
67
|
+
const props = withDefaults(
|
|
68
|
+
defineProps<{
|
|
69
|
+
config?: FormConfig;
|
|
70
|
+
values?: Object;
|
|
71
|
+
parentValues?: Object;
|
|
72
|
+
width?: string | number;
|
|
73
|
+
labelWidth?: string;
|
|
74
|
+
fullscreen?: boolean;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
title?: string;
|
|
77
|
+
zIndex?: number;
|
|
78
|
+
size?: 'small' | 'default' | 'large';
|
|
79
|
+
confirmText?: string;
|
|
80
|
+
}>(),
|
|
81
|
+
{
|
|
82
|
+
config: () => [],
|
|
83
|
+
values: () => ({}),
|
|
84
|
+
confirmText: '确定',
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const emit = defineEmits(['close', 'submit', 'error', 'change']);
|
|
89
|
+
|
|
90
|
+
const form = ref<InstanceType<typeof Form>>();
|
|
91
|
+
const dialogVisible = ref(false);
|
|
92
|
+
const saveFetch = ref(false);
|
|
93
|
+
const stepActive = ref(1);
|
|
94
|
+
const bodyHeight = ref(`${document.body.clientHeight - 194}px`);
|
|
95
|
+
|
|
96
|
+
const stepCount = computed(() => {
|
|
97
|
+
const { length } = props.config;
|
|
98
|
+
for (let index = 0; index < length; index++) {
|
|
99
|
+
if (props.config[index].type === 'step') {
|
|
100
|
+
return (props.config[index] as StepConfig).items.length;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return 0;
|
|
104
|
+
});
|
|
87
105
|
|
|
88
|
-
|
|
106
|
+
const hasStep = computed(() => {
|
|
107
|
+
const { length } = props.config;
|
|
108
|
+
for (let index = 0; index < length; index++) {
|
|
109
|
+
if (props.config[index].type === 'step') {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
89
113
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
default: '确定',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
114
|
+
return false;
|
|
115
|
+
});
|
|
95
116
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const save = async () => {
|
|
136
|
-
try {
|
|
137
|
-
const values = await form.value?.submitForm();
|
|
138
|
-
emit('submit', values);
|
|
139
|
-
} catch (e) {
|
|
140
|
-
emit('error', e);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const preStep = () => {
|
|
145
|
-
stepActive.value -= 1;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const nextStep = () => {
|
|
149
|
-
stepActive.value += 1;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const changeHandler = (value: any) => {
|
|
153
|
-
emit('change', value);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
form,
|
|
158
|
-
saveFetch,
|
|
159
|
-
stepActive,
|
|
160
|
-
dialogVisible,
|
|
161
|
-
bodyHeight,
|
|
162
|
-
stepCount,
|
|
163
|
-
hasStep,
|
|
164
|
-
cancel,
|
|
165
|
-
closeHandler,
|
|
166
|
-
save,
|
|
167
|
-
preStep,
|
|
168
|
-
nextStep,
|
|
169
|
-
changeHandler,
|
|
170
|
-
};
|
|
171
|
-
},
|
|
117
|
+
const cancel = () => {
|
|
118
|
+
dialogVisible.value = false;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const closeHandler = () => {
|
|
122
|
+
stepActive.value = 1;
|
|
123
|
+
emit('close');
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const save = async () => {
|
|
127
|
+
try {
|
|
128
|
+
const values = await form.value?.submitForm();
|
|
129
|
+
emit('submit', values);
|
|
130
|
+
} catch (e) {
|
|
131
|
+
emit('error', e);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const preStep = () => {
|
|
136
|
+
stepActive.value -= 1;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const nextStep = () => {
|
|
140
|
+
stepActive.value += 1;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const changeHandler = (value: any) => {
|
|
144
|
+
emit('change', value);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
defineExpose({
|
|
148
|
+
form,
|
|
149
|
+
saveFetch,
|
|
150
|
+
dialogVisible,
|
|
151
|
+
|
|
152
|
+
cancel,
|
|
153
|
+
save,
|
|
172
154
|
});
|
|
173
155
|
</script>
|
package/src/containers/Col.vue
CHANGED
|
@@ -1,56 +1,42 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
2
|
+
<TMagicCol v-show="display && config.type !== 'hidden'" :span="span">
|
|
3
|
+
<Container
|
|
4
4
|
:model="model"
|
|
5
5
|
:config="config"
|
|
6
6
|
:prop="prop"
|
|
7
7
|
:label-width="config.labelWidth || labelWidth"
|
|
8
8
|
:expand-more="expandMore"
|
|
9
9
|
:size="size"
|
|
10
|
+
:disabled="disabled"
|
|
10
11
|
@change="changeHandler"
|
|
11
|
-
></
|
|
12
|
-
</
|
|
12
|
+
></Container>
|
|
13
|
+
</TMagicCol>
|
|
13
14
|
</template>
|
|
14
15
|
|
|
15
|
-
<script lang="ts">
|
|
16
|
-
import { computed,
|
|
16
|
+
<script setup lang="ts" name="MFormCol">
|
|
17
|
+
import { computed, inject } from 'vue';
|
|
18
|
+
|
|
19
|
+
import { TMagicCol } from '@tmagic/design';
|
|
17
20
|
|
|
18
21
|
import { ChildConfig, FormState } from '../schema';
|
|
19
22
|
import { display as displayFunction } from '../utils/form';
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
props: {
|
|
23
|
-
labelWidth: String,
|
|
24
|
-
expandMore: Boolean,
|
|
25
|
-
span: Number,
|
|
26
|
-
|
|
27
|
-
model: {
|
|
28
|
-
type: Object,
|
|
29
|
-
default: () => ({}),
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
config: {
|
|
33
|
-
type: Object as PropType<ChildConfig>,
|
|
34
|
-
default: () => ({}),
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
prop: String,
|
|
38
|
-
|
|
39
|
-
size: String,
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
emits: ['change'],
|
|
24
|
+
import Container from './Container.vue';
|
|
43
25
|
|
|
44
|
-
|
|
45
|
-
|
|
26
|
+
const props = defineProps<{
|
|
27
|
+
model: any;
|
|
28
|
+
config: ChildConfig;
|
|
29
|
+
labelWidth?: string;
|
|
30
|
+
expandMore?: boolean;
|
|
31
|
+
span?: number;
|
|
32
|
+
size?: string;
|
|
33
|
+
prop?: string;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
}>();
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
const emit = defineEmits(['change']);
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
changeHandler,
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
});
|
|
39
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
40
|
+
const display = computed(() => displayFunction(mForm, props.config.display, props));
|
|
41
|
+
const changeHandler = () => emit('change', props.model);
|
|
56
42
|
</script>
|