@tmagic/form 1.3.0-alpha.2 → 1.3.0-alpha.20
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 +21 -0
- package/dist/tmagic-form.js +1400 -1187
- package/dist/tmagic-form.js.map +1 -1
- package/dist/tmagic-form.umd.cjs +1425 -1210
- package/dist/tmagic-form.umd.cjs.map +1 -1
- package/package.json +10 -11
- package/src/Form.vue +14 -2
- package/src/FormDialog.vue +20 -6
- package/src/FormDrawer.vue +134 -0
- package/src/containers/Col.vue +5 -1
- package/src/containers/Container.vue +16 -11
- package/src/containers/Fieldset.vue +5 -1
- package/src/containers/GroupList.vue +7 -2
- package/src/containers/GroupListItem.vue +15 -9
- package/src/containers/Panel.vue +5 -1
- package/src/containers/Row.vue +5 -1
- package/src/containers/Step.vue +5 -1
- package/src/containers/Table.vue +153 -151
- package/src/containers/Tabs.vue +14 -8
- package/src/fields/Cascader.vue +7 -13
- package/src/fields/Checkbox.vue +7 -13
- package/src/fields/CheckboxGroup.vue +9 -15
- package/src/fields/ColorPicker.vue +10 -14
- package/src/fields/Date.vue +11 -15
- package/src/fields/DateTime.vue +12 -16
- package/src/fields/Daterange.vue +7 -13
- package/src/fields/Display.vue +7 -11
- package/src/fields/DynamicField.vue +8 -14
- package/src/fields/Hidden.vue +7 -11
- package/src/fields/Link.vue +7 -13
- package/src/fields/Number.vue +12 -15
- package/src/fields/NumberRange.vue +50 -0
- package/src/fields/RadioGroup.vue +7 -13
- package/src/fields/Select.vue +28 -30
- package/src/fields/SelectOptionGroups.vue +7 -3
- package/src/fields/SelectOptions.vue +5 -1
- package/src/fields/Switch.vue +11 -15
- package/src/fields/Text.vue +12 -15
- package/src/fields/Textarea.vue +12 -15
- package/src/fields/Time.vue +10 -14
- package/src/index.ts +43 -37
- package/src/schema.ts +27 -5
- package/src/theme/form-drawer.scss +11 -0
- package/src/theme/index.scss +2 -0
- package/src/theme/number-range.scss +8 -0
- package/src/theme/panel.scss +6 -0
- package/src/utils/config.ts +1 -1
- package/src/utils/form.ts +2 -1
- package/types/Form.vue.d.ts +11 -6
- package/types/FormDialog.vue.d.ts +89 -125
- package/types/FormDrawer.vue.d.ts +338 -0
- package/types/containers/Col.vue.d.ts +1 -1
- package/types/containers/Container.vue.d.ts +6 -3
- package/types/containers/Fieldset.vue.d.ts +6 -3
- package/types/containers/GroupList.vue.d.ts +1 -1
- package/types/containers/GroupListItem.vue.d.ts +1 -1
- package/types/containers/Panel.vue.d.ts +3 -3
- package/types/containers/Row.vue.d.ts +1 -1
- package/types/containers/Step.vue.d.ts +6 -3
- package/types/containers/Table.vue.d.ts +9 -6
- package/types/containers/Tabs.vue.d.ts +6 -3
- package/types/fields/Cascader.vue.d.ts +3 -23
- package/types/fields/Checkbox.vue.d.ts +3 -23
- package/types/fields/CheckboxGroup.vue.d.ts +3 -23
- package/types/fields/ColorPicker.vue.d.ts +2 -24
- package/types/fields/Date.vue.d.ts +2 -24
- package/types/fields/DateTime.vue.d.ts +2 -24
- package/types/fields/Daterange.vue.d.ts +3 -23
- package/types/fields/Display.vue.d.ts +2 -18
- package/types/fields/DynamicField.vue.d.ts +3 -32
- package/types/fields/Hidden.vue.d.ts +2 -18
- package/types/fields/Link.vue.d.ts +3 -23
- package/types/fields/Number.vue.d.ts +2 -25
- package/types/fields/NumberRange.vue.d.ts +12 -0
- package/types/fields/RadioGroup.vue.d.ts +3 -23
- package/types/fields/Select.vue.d.ts +3 -23
- package/types/fields/SelectOptionGroups.vue.d.ts +2 -2
- package/types/fields/SelectOptions.vue.d.ts +2 -2
- package/types/fields/Switch.vue.d.ts +2 -24
- package/types/fields/Text.vue.d.ts +2 -25
- package/types/fields/Textarea.vue.d.ts +2 -25
- package/types/fields/Time.vue.d.ts +2 -24
- package/types/index.d.ts +6 -1
- package/types/schema.d.ts +25 -5
- package/types/utils/config.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.0-alpha.
|
|
2
|
+
"version": "1.3.0-alpha.20",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -36,28 +36,27 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@element-plus/icons-vue": "^2.0.9",
|
|
39
|
-
"@tmagic/design": "1.3.0-alpha.
|
|
40
|
-
"@tmagic/utils": "1.3.0-alpha.
|
|
39
|
+
"@tmagic/design": "1.3.0-alpha.20",
|
|
40
|
+
"@tmagic/utils": "1.3.0-alpha.20",
|
|
41
41
|
"lodash-es": "^4.17.21",
|
|
42
42
|
"sortablejs": "^1.14.0",
|
|
43
|
-
"vue": "^3.
|
|
43
|
+
"vue": "^3.3.4"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"vue": "^3.
|
|
46
|
+
"vue": "^3.3.4"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@babel/core": "^7.18.0",
|
|
50
50
|
"@types/lodash-es": "^4.17.4",
|
|
51
51
|
"@types/node": "^15.12.4",
|
|
52
52
|
"@types/sortablejs": "^1.10.7",
|
|
53
|
-
"@vitejs/plugin-vue": "^4.
|
|
54
|
-
"@vue/compiler-sfc": "^3.
|
|
55
|
-
"@vue/test-utils": "^2.
|
|
53
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
54
|
+
"@vue/compiler-sfc": "^3.3.4",
|
|
55
|
+
"@vue/test-utils": "^2.3.2",
|
|
56
56
|
"rimraf": "^3.0.2",
|
|
57
57
|
"sass": "^1.35.1",
|
|
58
58
|
"typescript": "^5.0.4",
|
|
59
|
-
"vite": "^4.
|
|
60
|
-
"
|
|
61
|
-
"vue-tsc": "^1.2.0"
|
|
59
|
+
"vite": "^4.4.4",
|
|
60
|
+
"vue-tsc": "^1.6.5"
|
|
62
61
|
}
|
|
63
62
|
}
|
package/src/Form.vue
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</TMagicForm>
|
|
27
27
|
</template>
|
|
28
28
|
|
|
29
|
-
<script setup lang="ts"
|
|
29
|
+
<script setup lang="ts">
|
|
30
30
|
import { provide, reactive, ref, toRaw, watch, watchEffect } from 'vue';
|
|
31
31
|
import { isEqual } from 'lodash-es';
|
|
32
32
|
import cloneDeep from 'lodash-es/cloneDeep';
|
|
@@ -38,6 +38,10 @@ import { getConfig } from './utils/config';
|
|
|
38
38
|
import { initValue } from './utils/form';
|
|
39
39
|
import type { FormConfig, FormState, FormValue, ValidateError } from './schema';
|
|
40
40
|
|
|
41
|
+
defineOptions({
|
|
42
|
+
name: 'MForm',
|
|
43
|
+
});
|
|
44
|
+
|
|
41
45
|
const props = withDefaults(
|
|
42
46
|
defineProps<{
|
|
43
47
|
/** 表单配置 */
|
|
@@ -58,6 +62,7 @@ const props = withDefaults(
|
|
|
58
62
|
labelPosition?: string;
|
|
59
63
|
keyProp?: string;
|
|
60
64
|
popperClass?: string;
|
|
65
|
+
extendState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
|
61
66
|
}>(),
|
|
62
67
|
{
|
|
63
68
|
config: () => [],
|
|
@@ -110,7 +115,7 @@ const formState: FormState = reactive<FormState>({
|
|
|
110
115
|
},
|
|
111
116
|
});
|
|
112
117
|
|
|
113
|
-
watchEffect(() => {
|
|
118
|
+
watchEffect(async () => {
|
|
114
119
|
formState.initValues = props.initValues;
|
|
115
120
|
formState.lastValues = props.lastValues;
|
|
116
121
|
formState.isCompare = props.isCompare;
|
|
@@ -118,6 +123,13 @@ watchEffect(() => {
|
|
|
118
123
|
formState.keyProp = props.keyProp;
|
|
119
124
|
formState.popperClass = props.popperClass;
|
|
120
125
|
formState.parentValues = props.parentValues;
|
|
126
|
+
|
|
127
|
+
if (typeof props.extendState === 'function') {
|
|
128
|
+
const state = (await props.extendState(formState)) || {};
|
|
129
|
+
Object.entries(state).forEach(([key, value]) => {
|
|
130
|
+
formState[key] = value;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
121
133
|
});
|
|
122
134
|
|
|
123
135
|
provide('mForm', formState);
|
package/src/FormDialog.vue
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
<TMagicButton v-if="hasStep && stepCount > stepActive" type="info" size="small" @click="nextStep"
|
|
47
47
|
>下一步</TMagicButton
|
|
48
48
|
>
|
|
49
|
-
<TMagicButton v-else type="primary" size="small" :loading="saveFetch" @click="save">{{
|
|
49
|
+
<TMagicButton v-else type="primary" size="small" :disabled="disabled" :loading="saveFetch" @click="save">{{
|
|
50
50
|
confirmText
|
|
51
51
|
}}</TMagicButton>
|
|
52
52
|
</slot>
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
</TMagicDialog>
|
|
57
57
|
</template>
|
|
58
58
|
|
|
59
|
-
<script setup lang="ts"
|
|
59
|
+
<script setup lang="ts">
|
|
60
60
|
import { computed, ref } from 'vue';
|
|
61
61
|
|
|
62
62
|
import { TMagicButton, TMagicCol, TMagicDialog, TMagicRow } from '@tmagic/design';
|
|
@@ -64,6 +64,10 @@ import { TMagicButton, TMagicCol, TMagicDialog, TMagicRow } from '@tmagic/design
|
|
|
64
64
|
import Form from './Form.vue';
|
|
65
65
|
import { FormConfig, StepConfig } from './schema';
|
|
66
66
|
|
|
67
|
+
defineOptions({
|
|
68
|
+
name: 'MFormDialog',
|
|
69
|
+
});
|
|
70
|
+
|
|
67
71
|
const props = withDefaults(
|
|
68
72
|
defineProps<{
|
|
69
73
|
config?: FormConfig;
|
|
@@ -114,10 +118,6 @@ const hasStep = computed(() => {
|
|
|
114
118
|
return false;
|
|
115
119
|
});
|
|
116
120
|
|
|
117
|
-
const cancel = () => {
|
|
118
|
-
dialogVisible.value = false;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
121
|
const closeHandler = () => {
|
|
122
122
|
stepActive.value = 1;
|
|
123
123
|
emit('close');
|
|
@@ -144,6 +144,18 @@ const changeHandler = (value: any) => {
|
|
|
144
144
|
emit('change', value);
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
+
const show = () => {
|
|
148
|
+
dialogVisible.value = true;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const hide = () => {
|
|
152
|
+
dialogVisible.value = false;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const cancel = () => {
|
|
156
|
+
hide();
|
|
157
|
+
};
|
|
158
|
+
|
|
147
159
|
defineExpose({
|
|
148
160
|
form,
|
|
149
161
|
saveFetch,
|
|
@@ -151,5 +163,7 @@ defineExpose({
|
|
|
151
163
|
|
|
152
164
|
cancel,
|
|
153
165
|
save,
|
|
166
|
+
show,
|
|
167
|
+
hide,
|
|
154
168
|
});
|
|
155
169
|
</script>
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<TMagicDrawer
|
|
3
|
+
class="m-form-drawer"
|
|
4
|
+
v-model="visible"
|
|
5
|
+
:title="title"
|
|
6
|
+
:close-on-press-escape="closeOnPressEscape"
|
|
7
|
+
:append-to-body="true"
|
|
8
|
+
:show-close="true"
|
|
9
|
+
:close-on-click-modal="true"
|
|
10
|
+
:size="width"
|
|
11
|
+
:zIndex="zIndex"
|
|
12
|
+
@open="openHandler"
|
|
13
|
+
@opened="openedHandler"
|
|
14
|
+
>
|
|
15
|
+
<div v-if="visible" ref="drawerBody" class="m-drawer-body">
|
|
16
|
+
<Form
|
|
17
|
+
ref="form"
|
|
18
|
+
:size="size"
|
|
19
|
+
:disabled="disabled"
|
|
20
|
+
:config="config"
|
|
21
|
+
:init-values="values"
|
|
22
|
+
:parent-values="parentValues"
|
|
23
|
+
:label-width="labelWidth"
|
|
24
|
+
@change="changeHandler"
|
|
25
|
+
></Form>
|
|
26
|
+
<slot></slot>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<template #footer>
|
|
30
|
+
<TMagicRow class="dialog-footer">
|
|
31
|
+
<TMagicCol :span="12" style="text-align: left">
|
|
32
|
+
<div style="min-height: 1px">
|
|
33
|
+
<slot name="left"></slot>
|
|
34
|
+
</div>
|
|
35
|
+
</TMagicCol>
|
|
36
|
+
<TMagicCol :span="12">
|
|
37
|
+
<slot name="footer">
|
|
38
|
+
<TMagicButton @click="hide">关闭</TMagicButton>
|
|
39
|
+
<TMagicButton type="primary" :disabled="disabled" :loading="saveFetch" @click="submitHandler">{{
|
|
40
|
+
confirmText
|
|
41
|
+
}}</TMagicButton>
|
|
42
|
+
</slot>
|
|
43
|
+
</TMagicCol>
|
|
44
|
+
</TMagicRow>
|
|
45
|
+
</template>
|
|
46
|
+
</TMagicDrawer>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script setup lang="ts">
|
|
50
|
+
import { ref, watchEffect } from 'vue';
|
|
51
|
+
|
|
52
|
+
import { TMagicButton, TMagicCol, TMagicDrawer, TMagicRow } from '@tmagic/design';
|
|
53
|
+
|
|
54
|
+
import Form from './Form.vue';
|
|
55
|
+
import type { FormConfig } from './schema';
|
|
56
|
+
|
|
57
|
+
defineOptions({
|
|
58
|
+
name: 'MFormDialog',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
withDefaults(
|
|
62
|
+
defineProps<{
|
|
63
|
+
config?: FormConfig;
|
|
64
|
+
values?: Object;
|
|
65
|
+
parentValues?: Object;
|
|
66
|
+
width?: string | number;
|
|
67
|
+
labelWidth?: string;
|
|
68
|
+
disabled?: boolean;
|
|
69
|
+
closeOnPressEscape?: boolean;
|
|
70
|
+
title?: string;
|
|
71
|
+
zIndex?: number;
|
|
72
|
+
size?: 'small' | 'default' | 'large';
|
|
73
|
+
confirmText?: string;
|
|
74
|
+
}>(),
|
|
75
|
+
{
|
|
76
|
+
closeOnPressEscape: true,
|
|
77
|
+
config: () => [],
|
|
78
|
+
values: () => ({}),
|
|
79
|
+
confirmText: '确定',
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const emit = defineEmits(['close', 'submit', 'error', 'change', 'open', 'opened']);
|
|
84
|
+
|
|
85
|
+
const form = ref<InstanceType<typeof Form>>();
|
|
86
|
+
const drawerBody = ref<HTMLDivElement>();
|
|
87
|
+
const visible = ref(false);
|
|
88
|
+
const saveFetch = ref(false);
|
|
89
|
+
const bodyHeight = ref(0);
|
|
90
|
+
|
|
91
|
+
watchEffect(() => {
|
|
92
|
+
if (drawerBody.value) {
|
|
93
|
+
bodyHeight.value = drawerBody.value.clientHeight;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const submitHandler = async () => {
|
|
98
|
+
try {
|
|
99
|
+
const values = await form.value?.submitForm();
|
|
100
|
+
emit('submit', values);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
emit('error', e);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const changeHandler = (value: any) => {
|
|
107
|
+
emit('change', value);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const openHandler = (value: any) => {
|
|
111
|
+
emit('open', value);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const openedHandler = (value: any) => {
|
|
115
|
+
emit('opened', value);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const show = () => {
|
|
119
|
+
visible.value = true;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const hide = () => {
|
|
123
|
+
visible.value = false;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
defineExpose({
|
|
127
|
+
form,
|
|
128
|
+
saveFetch,
|
|
129
|
+
bodyHeight,
|
|
130
|
+
|
|
131
|
+
show,
|
|
132
|
+
hide,
|
|
133
|
+
});
|
|
134
|
+
</script>
|
package/src/containers/Col.vue
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
</TMagicCol>
|
|
17
17
|
</template>
|
|
18
18
|
|
|
19
|
-
<script setup lang="ts"
|
|
19
|
+
<script setup lang="ts">
|
|
20
20
|
import { computed, inject } from 'vue';
|
|
21
21
|
|
|
22
22
|
import { TMagicCol } from '@tmagic/design';
|
|
@@ -26,6 +26,10 @@ import { display as displayFunction } from '../utils/form';
|
|
|
26
26
|
|
|
27
27
|
import Container from './Container.vue';
|
|
28
28
|
|
|
29
|
+
defineOptions({
|
|
30
|
+
name: 'MFormCol',
|
|
31
|
+
});
|
|
32
|
+
|
|
29
33
|
const props = defineProps<{
|
|
30
34
|
model: any;
|
|
31
35
|
lastValues?: any;
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
<div
|
|
3
3
|
v-if="config"
|
|
4
4
|
:style="config.tip ? 'display: flex;align-items: baseline;' : ''"
|
|
5
|
-
:class="config.className"
|
|
6
|
-
class="m-form-container"
|
|
5
|
+
:class="`m-form-container m-container-${type || ''} ${config.className || ''}`"
|
|
7
6
|
>
|
|
8
7
|
<m-fields-hidden
|
|
9
8
|
v-if="type === 'hidden'"
|
|
@@ -15,7 +14,7 @@
|
|
|
15
14
|
></m-fields-hidden>
|
|
16
15
|
|
|
17
16
|
<component
|
|
18
|
-
v-else-if="items && !
|
|
17
|
+
v-else-if="items && !text && type && display"
|
|
19
18
|
:key="key(config)"
|
|
20
19
|
:size="size"
|
|
21
20
|
:is="tagName"
|
|
@@ -36,12 +35,12 @@
|
|
|
36
35
|
<template v-else-if="type && display && !showDiff">
|
|
37
36
|
<TMagicFormItem
|
|
38
37
|
:style="config.tip ? 'flex: 1' : ''"
|
|
39
|
-
:class="{ hidden: `${itemLabelWidth}` === '0' || !
|
|
38
|
+
:class="{ hidden: `${itemLabelWidth}` === '0' || !text }"
|
|
40
39
|
:prop="itemProp"
|
|
41
40
|
:label-width="itemLabelWidth"
|
|
42
41
|
:rules="rule"
|
|
43
42
|
>
|
|
44
|
-
<template #label><span v-html="type === 'checkbox' ? '' :
|
|
43
|
+
<template #label><span v-html="type === 'checkbox' ? '' : text"></span></template>
|
|
45
44
|
<TMagicTooltip v-if="tooltip">
|
|
46
45
|
<component
|
|
47
46
|
:key="key(config)"
|
|
@@ -92,13 +91,13 @@
|
|
|
92
91
|
<!-- 上次内容 -->
|
|
93
92
|
<TMagicFormItem
|
|
94
93
|
:style="config.tip ? 'flex: 1' : ''"
|
|
95
|
-
:class="{ hidden: `${itemLabelWidth}` === '0' || !
|
|
94
|
+
:class="{ hidden: `${itemLabelWidth}` === '0' || !text }"
|
|
96
95
|
:prop="itemProp"
|
|
97
96
|
:label-width="itemLabelWidth"
|
|
98
97
|
:rules="rule"
|
|
99
98
|
style="background: #f7dadd"
|
|
100
99
|
>
|
|
101
|
-
<template #label><span v-html="type === 'checkbox' ? '' :
|
|
100
|
+
<template #label><span v-html="type === 'checkbox' ? '' : text"></span></template>
|
|
102
101
|
<TMagicTooltip v-if="tooltip">
|
|
103
102
|
<component
|
|
104
103
|
:key="key(config)"
|
|
@@ -141,13 +140,13 @@
|
|
|
141
140
|
<!-- 当前内容 -->
|
|
142
141
|
<TMagicFormItem
|
|
143
142
|
:style="config.tip ? 'flex: 1' : ''"
|
|
144
|
-
:class="{ hidden: `${itemLabelWidth}` === '0' || !
|
|
143
|
+
:class="{ hidden: `${itemLabelWidth}` === '0' || !text }"
|
|
145
144
|
:prop="itemProp"
|
|
146
145
|
:label-width="itemLabelWidth"
|
|
147
146
|
:rules="rule"
|
|
148
147
|
style="background: #def7da"
|
|
149
148
|
>
|
|
150
|
-
<template #label><span v-html="type === 'checkbox' ? '' :
|
|
149
|
+
<template #label><span v-html="type === 'checkbox' ? '' : text"></span></template>
|
|
151
150
|
<TMagicTooltip v-if="tooltip">
|
|
152
151
|
<component
|
|
153
152
|
:key="key(config)"
|
|
@@ -218,7 +217,7 @@
|
|
|
218
217
|
</div>
|
|
219
218
|
</template>
|
|
220
219
|
|
|
221
|
-
<script setup lang="ts"
|
|
220
|
+
<script setup lang="ts">
|
|
222
221
|
import { computed, inject, ref, resolveComponent, watch, watchEffect } from 'vue';
|
|
223
222
|
import { WarningFilled } from '@element-plus/icons-vue';
|
|
224
223
|
import { isEqual } from 'lodash-es';
|
|
@@ -228,6 +227,10 @@ import { TMagicButton, TMagicFormItem, TMagicIcon, TMagicTooltip } from '@tmagic
|
|
|
228
227
|
import { ChildConfig, ContainerCommonConfig, FormState, FormValue } from '../schema';
|
|
229
228
|
import { display as displayFunction, filterFunction, getRules } from '../utils/form';
|
|
230
229
|
|
|
230
|
+
defineOptions({
|
|
231
|
+
name: 'MFormContainer',
|
|
232
|
+
});
|
|
233
|
+
|
|
231
234
|
const props = withDefaults(
|
|
232
235
|
defineProps<{
|
|
233
236
|
/** 表单值 */
|
|
@@ -291,6 +294,8 @@ const tagName = computed(() => {
|
|
|
291
294
|
|
|
292
295
|
const disabled = computed(() => props.disabled || filterFunction(mForm, props.config.disabled, props));
|
|
293
296
|
|
|
297
|
+
const text = computed(() => filterFunction(mForm, props.config.text, props));
|
|
298
|
+
|
|
294
299
|
const tooltip = computed(() => filterFunction(mForm, props.config.tooltip, props));
|
|
295
300
|
|
|
296
301
|
const extra = computed(() => filterFunction(mForm, props.config.extra, props));
|
|
@@ -328,7 +333,7 @@ watch(
|
|
|
328
333
|
showDiff,
|
|
329
334
|
(showDiff) => {
|
|
330
335
|
if (type.value === 'hidden') return;
|
|
331
|
-
if (items.value && !
|
|
336
|
+
if (items.value && !text.value && type.value && display.value) return;
|
|
332
337
|
if (display.value && showDiff && type.value) {
|
|
333
338
|
emit('addDiffCount');
|
|
334
339
|
}
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
</fieldset>
|
|
62
62
|
</template>
|
|
63
63
|
|
|
64
|
-
<script lang="ts" setup
|
|
64
|
+
<script lang="ts" setup>
|
|
65
65
|
import { computed, inject } from 'vue';
|
|
66
66
|
|
|
67
67
|
import { TMagicCheckbox } from '@tmagic/design';
|
|
@@ -70,6 +70,10 @@ import { FieldsetConfig, FormState } from '../schema';
|
|
|
70
70
|
|
|
71
71
|
import Container from './Container.vue';
|
|
72
72
|
|
|
73
|
+
defineOptions({
|
|
74
|
+
name: 'MFormFieldset',
|
|
75
|
+
});
|
|
76
|
+
|
|
73
77
|
const props = withDefaults(
|
|
74
78
|
defineProps<{
|
|
75
79
|
labelWidth?: string;
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
@addDiffCount="onAddDiffCount()"
|
|
26
26
|
></MFieldsGroupListItem>
|
|
27
27
|
|
|
28
|
-
<TMagicButton @click="addHandler" size="small" :disabled="disabled" v-if="addable"
|
|
28
|
+
<TMagicButton @click="addHandler" size="small" :disabled="disabled" v-if="addable">新增</TMagicButton>
|
|
29
29
|
|
|
30
30
|
<TMagicButton :icon="Grid" size="small" @click="toggleMode" v-if="config.enableToggleMode">切换为表格</TMagicButton>
|
|
31
31
|
</div>
|
|
32
32
|
</template>
|
|
33
33
|
|
|
34
|
-
<script setup lang="ts"
|
|
34
|
+
<script setup lang="ts">
|
|
35
35
|
import { computed, inject } from 'vue';
|
|
36
36
|
import { Grid } from '@element-plus/icons-vue';
|
|
37
37
|
|
|
@@ -42,6 +42,10 @@ import { initValue } from '../utils/form';
|
|
|
42
42
|
|
|
43
43
|
import MFieldsGroupListItem from './GroupListItem.vue';
|
|
44
44
|
|
|
45
|
+
defineOptions({
|
|
46
|
+
name: 'MFormGroupList',
|
|
47
|
+
});
|
|
48
|
+
|
|
45
49
|
const props = defineProps<{
|
|
46
50
|
model: any;
|
|
47
51
|
lastValues?: any;
|
|
@@ -128,6 +132,7 @@ const toggleMode = () => {
|
|
|
128
132
|
text: null,
|
|
129
133
|
}))) as any;
|
|
130
134
|
};
|
|
135
|
+
|
|
131
136
|
const onAddDiffCount = () => emit('addDiffCount');
|
|
132
137
|
|
|
133
138
|
const getLastValues = (item: any, index: number) => item?.[index] || {};
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
</div>
|
|
43
43
|
</template>
|
|
44
44
|
|
|
45
|
-
<script setup lang="ts"
|
|
46
|
-
import { computed, inject, ref
|
|
45
|
+
<script setup lang="ts">
|
|
46
|
+
import { computed, inject, ref } from 'vue';
|
|
47
47
|
import { CaretBottom, CaretRight, CaretTop, Delete } from '@element-plus/icons-vue';
|
|
48
48
|
|
|
49
49
|
import { TMagicButton, TMagicIcon } from '@tmagic/design';
|
|
@@ -53,6 +53,10 @@ import { filterFunction } from '../utils/form';
|
|
|
53
53
|
|
|
54
54
|
import Container from './Container.vue';
|
|
55
55
|
|
|
56
|
+
defineOptions({
|
|
57
|
+
name: 'MFormGroupListItem',
|
|
58
|
+
});
|
|
59
|
+
|
|
56
60
|
const props = defineProps<{
|
|
57
61
|
model: any;
|
|
58
62
|
lastValues: any;
|
|
@@ -69,11 +73,7 @@ const props = defineProps<{
|
|
|
69
73
|
const emit = defineEmits(['swap-item', 'remove-item', 'change', 'addDiffCount']);
|
|
70
74
|
|
|
71
75
|
const mForm = inject<FormState | undefined>('mForm');
|
|
72
|
-
const expand = ref(
|
|
73
|
-
|
|
74
|
-
watchEffect(() => {
|
|
75
|
-
expand.value = !props.index;
|
|
76
|
-
});
|
|
76
|
+
const expand = ref(props.config.expandAll || !props.index);
|
|
77
77
|
|
|
78
78
|
const rowConfig = computed(() => ({
|
|
79
79
|
type: 'row',
|
|
@@ -88,7 +88,13 @@ const title = computed(() => {
|
|
|
88
88
|
return props.model[props.config.titleKey];
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
if (props.config.title) {
|
|
92
|
+
return filterFunction(mForm, props.config.title, props);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const titlePrefix = props.config.titlePrefix || '组';
|
|
96
|
+
|
|
97
|
+
return `${titlePrefix} ${String(props.index + 1)}`;
|
|
92
98
|
});
|
|
93
99
|
|
|
94
100
|
const length = computed(() => props.groupModel?.length || 0);
|
|
@@ -113,7 +119,7 @@ const showDelete = (index: number) => {
|
|
|
113
119
|
};
|
|
114
120
|
|
|
115
121
|
// 调换顺序
|
|
116
|
-
const changeOrder = (offset = 0) => emit('swap-item', props.index,
|
|
122
|
+
const changeOrder = (offset = 0) => emit('swap-item', props.index, props.index + offset);
|
|
117
123
|
|
|
118
124
|
const movable = () => {
|
|
119
125
|
const { movable } = props.config;
|
package/src/containers/Panel.vue
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
</TMagicCard>
|
|
58
58
|
</template>
|
|
59
59
|
|
|
60
|
-
<script setup lang="ts"
|
|
60
|
+
<script setup lang="ts">
|
|
61
61
|
import { computed, inject, ref } from 'vue';
|
|
62
62
|
import { CaretBottom, CaretRight } from '@element-plus/icons-vue';
|
|
63
63
|
|
|
@@ -68,6 +68,10 @@ import { filterFunction } from '../utils/form';
|
|
|
68
68
|
|
|
69
69
|
import Container from './Container.vue';
|
|
70
70
|
|
|
71
|
+
defineOptions({
|
|
72
|
+
name: 'MFormPanel',
|
|
73
|
+
});
|
|
74
|
+
|
|
71
75
|
const props = defineProps<{
|
|
72
76
|
model: any;
|
|
73
77
|
lastValues?: any;
|
package/src/containers/Row.vue
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
</TMagicRow>
|
|
20
20
|
</template>
|
|
21
21
|
|
|
22
|
-
<script setup lang="ts"
|
|
22
|
+
<script setup lang="ts">
|
|
23
23
|
import { inject } from 'vue';
|
|
24
24
|
|
|
25
25
|
import { TMagicRow } from '@tmagic/design';
|
|
@@ -28,6 +28,10 @@ import { FormState, RowConfig } from '../schema';
|
|
|
28
28
|
|
|
29
29
|
import Col from './Col.vue';
|
|
30
30
|
|
|
31
|
+
defineOptions({
|
|
32
|
+
name: 'MFormRow',
|
|
33
|
+
});
|
|
34
|
+
|
|
31
35
|
const props = defineProps<{
|
|
32
36
|
model: any;
|
|
33
37
|
lastValues?: any;
|
package/src/containers/Step.vue
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
</div>
|
|
33
33
|
</template>
|
|
34
34
|
|
|
35
|
-
<script setup lang="ts"
|
|
35
|
+
<script setup lang="ts">
|
|
36
36
|
import { inject, ref, watchEffect } from 'vue';
|
|
37
37
|
|
|
38
38
|
import { TMagicStep, TMagicSteps } from '@tmagic/design';
|
|
@@ -41,6 +41,10 @@ import { FormState, StepConfig } from '../schema';
|
|
|
41
41
|
|
|
42
42
|
import Container from './Container.vue';
|
|
43
43
|
|
|
44
|
+
defineOptions({
|
|
45
|
+
name: 'MFormStep',
|
|
46
|
+
});
|
|
47
|
+
|
|
44
48
|
const props = withDefaults(
|
|
45
49
|
defineProps<{
|
|
46
50
|
model: any;
|