@tmagic/form 1.1.6 → 1.2.0-beta.10
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/tmagic-form.mjs +2318 -2632
- package/dist/tmagic-form.mjs.map +1 -1
- package/dist/tmagic-form.umd.js +2341 -2656
- package/dist/tmagic-form.umd.js.map +1 -1
- package/package.json +5 -5
- package/src/Form.vue +123 -158
- package/src/FormDialog.vue +140 -158
- package/src/containers/Col.vue +22 -38
- package/src/containers/Container.vue +138 -171
- package/src/containers/Fieldset.vue +12 -8
- package/src/containers/GroupList.vue +80 -112
- package/src/containers/GroupListItem.vue +87 -124
- package/src/containers/Panel.vue +26 -49
- package/src/containers/Row.vue +18 -40
- package/src/containers/Step.vue +36 -48
- package/src/containers/Table.vue +449 -479
- package/src/containers/Tabs.vue +92 -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 +20 -26
- 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 -321
- 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 +19 -30
- package/src/index.ts +22 -23
- package/src/schema.ts +46 -12
- package/src/utils/form.ts +4 -0
- package/types/Form.vue.d.ts +211 -111
- package/types/FormDialog.vue.d.ts +809 -154
- package/types/containers/Col.vue.d.ts +92 -40
- package/types/containers/Container.vue.d.ts +122 -65
- package/types/containers/Fieldset.vue.d.ts +1 -3
- package/types/containers/GroupList.vue.d.ts +86 -53
- package/types/containers/GroupListItem.vue.d.ts +97 -67
- package/types/containers/Panel.vue.d.ts +92 -39
- package/types/containers/Row.vue.d.ts +92 -39
- package/types/containers/Step.vue.d.ts +102 -42
- package/types/containers/Table.vue.d.ts +157 -130
- package/types/containers/Tabs.vue.d.ts +93 -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 +38 -9
- package/src/utils/fieldProps.ts +0 -39
- package/types/utils/fieldProps.d.ts +0 -21
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<span class="el-table__empty-text">暂无数据</span>
|
|
6
6
|
</div>
|
|
7
7
|
|
|
8
|
-
<
|
|
8
|
+
<MFieldsGroupListItem
|
|
9
9
|
v-else
|
|
10
10
|
v-for="(item, index) in model[name]"
|
|
11
11
|
:key="index"
|
|
@@ -19,138 +19,106 @@
|
|
|
19
19
|
@remove-item="removeHandler"
|
|
20
20
|
@swap-item="swapHandler"
|
|
21
21
|
@change="changeHandler"
|
|
22
|
-
></
|
|
22
|
+
></MFieldsGroupListItem>
|
|
23
23
|
|
|
24
|
-
<
|
|
24
|
+
<TMagicButton @click="addHandler" size="small" v-if="addable">添加组</TMagicButton>
|
|
25
25
|
|
|
26
|
-
<
|
|
26
|
+
<TMagicButton :icon="Grid" size="small" @click="toggleMode" v-if="config.enableToggleMode">切换为表格</TMagicButton>
|
|
27
27
|
</div>
|
|
28
28
|
</template>
|
|
29
29
|
|
|
30
|
-
<script lang="ts">
|
|
31
|
-
import { computed,
|
|
30
|
+
<script setup lang="ts" name="MFormGroupList">
|
|
31
|
+
import { computed, inject } from 'vue';
|
|
32
32
|
import { Grid } from '@element-plus/icons-vue';
|
|
33
33
|
|
|
34
|
+
import { TMagicButton } from '@tmagic/design';
|
|
35
|
+
|
|
34
36
|
import { FormState, GroupListConfig } from '../schema';
|
|
35
37
|
import { initValue } from '../utils/form';
|
|
36
38
|
|
|
37
39
|
import MFieldsGroupListItem from './GroupListItem.vue';
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const props = defineProps<{
|
|
42
|
+
model: any;
|
|
43
|
+
config: GroupListConfig;
|
|
44
|
+
name: string;
|
|
45
|
+
labelWidth?: string;
|
|
46
|
+
prop?: string;
|
|
47
|
+
size?: string;
|
|
48
|
+
}>();
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
labelWidth: String,
|
|
50
|
+
const emit = defineEmits(['change']);
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
type: Object,
|
|
49
|
-
default: () => ({}),
|
|
50
|
-
},
|
|
52
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
default: () => ({}),
|
|
55
|
-
},
|
|
54
|
+
const addable = computed(() => {
|
|
55
|
+
if (!props.name) return false;
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
if (typeof props.config.addable === 'function') {
|
|
58
|
+
return props.config.addable(mForm, {
|
|
59
|
+
model: props.model[props.name],
|
|
60
|
+
formValue: mForm?.values,
|
|
61
|
+
prop: props.prop,
|
|
62
|
+
config: props.config,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
default: '',
|
|
67
|
-
},
|
|
68
|
-
},
|
|
66
|
+
return typeof props.config.addable === 'undefined' ? true : props.config.addable;
|
|
67
|
+
});
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
const changeHandler = () => {
|
|
70
|
+
if (!props.name) return false;
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
emit('change', props.model[props.name]);
|
|
73
|
+
};
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const addHandler = async () => {
|
|
76
|
+
if (!props.name) return false;
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
return props.config.addable(mForm, {
|
|
80
|
-
model: props.model[props.name],
|
|
81
|
-
formValue: mForm?.values,
|
|
82
|
-
prop: props.prop,
|
|
83
|
-
config: props.config,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
78
|
+
let initValues = {};
|
|
86
79
|
|
|
87
|
-
|
|
80
|
+
if (typeof props.config.defaultAdd === 'function') {
|
|
81
|
+
initValues = await props.config.defaultAdd(mForm, {
|
|
82
|
+
model: props.model[props.name],
|
|
83
|
+
formValue: mForm?.values,
|
|
84
|
+
prop: props.prop,
|
|
85
|
+
config: props.config,
|
|
88
86
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
const swapHandler = (idx1: number, idx2: number) => {
|
|
128
|
-
if (!props.name) return false;
|
|
129
|
-
|
|
130
|
-
const [currRow] = props.model[props.name].splice(idx1, 1);
|
|
131
|
-
props.model[props.name].splice(idx2, 0, currRow);
|
|
132
|
-
changeHandler();
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const toggleMode = () => {
|
|
136
|
-
props.config.type = 'table';
|
|
137
|
-
props.config.groupItems = props.config.items;
|
|
138
|
-
props.config.items = (props.config.tableItems ||
|
|
139
|
-
props.config.items.map((item: any) => ({
|
|
140
|
-
...item,
|
|
141
|
-
label: item.label || item.text,
|
|
142
|
-
text: null,
|
|
143
|
-
}))) as any;
|
|
144
|
-
};
|
|
145
|
-
return {
|
|
146
|
-
Grid,
|
|
147
|
-
addable,
|
|
148
|
-
toggleMode,
|
|
149
|
-
removeHandler,
|
|
150
|
-
swapHandler,
|
|
151
|
-
changeHandler,
|
|
152
|
-
addHandler,
|
|
153
|
-
};
|
|
154
|
-
},
|
|
155
|
-
});
|
|
87
|
+
} else if (props.config.defaultAdd) {
|
|
88
|
+
initValues = props.config.defaultAdd;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const groupValue = await initValue(mForm, {
|
|
92
|
+
config: props.config.items,
|
|
93
|
+
initValues,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
props.model[props.name].push(groupValue);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const removeHandler = (index: number) => {
|
|
100
|
+
if (!props.name) return false;
|
|
101
|
+
|
|
102
|
+
props.model[props.name].splice(index, 1);
|
|
103
|
+
changeHandler();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const swapHandler = (idx1: number, idx2: number) => {
|
|
107
|
+
if (!props.name) return false;
|
|
108
|
+
|
|
109
|
+
const [currRow] = props.model[props.name].splice(idx1, 1);
|
|
110
|
+
props.model[props.name].splice(idx2, 0, currRow);
|
|
111
|
+
changeHandler();
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const toggleMode = () => {
|
|
115
|
+
props.config.type = 'table';
|
|
116
|
+
props.config.groupItems = props.config.items;
|
|
117
|
+
props.config.items = (props.config.tableItems ||
|
|
118
|
+
props.config.items.map((item: any) => ({
|
|
119
|
+
...item,
|
|
120
|
+
label: item.label || item.text,
|
|
121
|
+
text: null,
|
|
122
|
+
}))) as any;
|
|
123
|
+
};
|
|
156
124
|
</script>
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-fields-group-list-item">
|
|
3
3
|
<div>
|
|
4
|
-
<
|
|
4
|
+
<TMagicIcon style="margin-right: 7px" @click="expandHandler"
|
|
5
5
|
><CaretBottom v-if="expand" /><CaretRight v-else
|
|
6
|
-
/></
|
|
6
|
+
/></TMagicIcon>
|
|
7
7
|
|
|
8
|
-
<
|
|
8
|
+
<TMagicButton text @click="expandHandler">{{ title }}</TMagicButton>
|
|
9
9
|
|
|
10
|
-
<
|
|
10
|
+
<TMagicButton
|
|
11
11
|
v-show="showDelete(parseInt(String(index)))"
|
|
12
12
|
text
|
|
13
13
|
:icon="Delete"
|
|
14
14
|
style="color: #f56c6c"
|
|
15
15
|
@click="removeHandler"
|
|
16
|
-
></
|
|
16
|
+
></TMagicButton>
|
|
17
17
|
|
|
18
18
|
<template v-if="movable()">
|
|
19
|
-
<
|
|
20
|
-
>上移<
|
|
21
|
-
></
|
|
22
|
-
<
|
|
23
|
-
>下移<
|
|
24
|
-
></
|
|
19
|
+
<TMagicButton v-show="index !== 0" text size="small" @click="changeOrder(-1)"
|
|
20
|
+
>上移<TMagicIcon><CaretTop /></TMagicIcon
|
|
21
|
+
></TMagicButton>
|
|
22
|
+
<TMagicButton v-show="index !== length - 1" text size="small" @click="changeOrder(1)"
|
|
23
|
+
>下移<TMagicIcon><CaretBottom /></TMagicIcon
|
|
24
|
+
></TMagicButton>
|
|
25
25
|
</template>
|
|
26
26
|
|
|
27
27
|
<span v-if="itemExtra" v-html="itemExtra" class="m-form-tip"></span>
|
|
28
28
|
</div>
|
|
29
29
|
|
|
30
|
-
<
|
|
30
|
+
<Container
|
|
31
31
|
v-if="expand"
|
|
32
32
|
:config="rowConfig"
|
|
33
33
|
:model="model"
|
|
@@ -35,125 +35,88 @@
|
|
|
35
35
|
:prop="`${prop}${prop ? '.' : ''}${String(index)}`"
|
|
36
36
|
:size="size"
|
|
37
37
|
@change="changeHandler"
|
|
38
|
-
></
|
|
38
|
+
></Container>
|
|
39
39
|
</div>
|
|
40
40
|
</template>
|
|
41
41
|
|
|
42
|
-
<script lang="ts">
|
|
43
|
-
import { computed,
|
|
42
|
+
<script setup lang="ts" name="MFormGroupListItem">
|
|
43
|
+
import { computed, inject, ref, watchEffect } from 'vue';
|
|
44
44
|
import { CaretBottom, CaretRight, CaretTop, Delete } from '@element-plus/icons-vue';
|
|
45
45
|
|
|
46
|
+
import { TMagicButton, TMagicIcon } from '@tmagic/design';
|
|
47
|
+
|
|
46
48
|
import { FormState, GroupListConfig } from '../schema';
|
|
47
49
|
import { filterFunction } from '../utils/form';
|
|
48
50
|
|
|
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
|
-
setup(props, { emit }) {
|
|
85
|
-
const mForm = inject<FormState | undefined>('mForm');
|
|
86
|
-
const expand = ref(false);
|
|
87
|
-
|
|
88
|
-
watchEffect(() => {
|
|
89
|
-
expand.value = !props.index;
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const rowConfig = computed(() => ({
|
|
93
|
-
type: 'row',
|
|
94
|
-
span: props.config.span || 24,
|
|
95
|
-
items: props.config.items,
|
|
96
|
-
labelWidth: props.config.labelWidth,
|
|
97
|
-
[mForm?.keyProp || '__key']: `${props.config[mForm?.keyProp || '__key']}${String(props.index)}`,
|
|
98
|
-
}));
|
|
99
|
-
|
|
100
|
-
const title = computed(() => {
|
|
101
|
-
if (props.config.titleKey && props.model[props.config.titleKey]) {
|
|
102
|
-
return props.model[props.config.titleKey];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return `组 ${String(props.index)}`;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const length = computed(() => props.groupModel?.length || 0);
|
|
109
|
-
|
|
110
|
-
const itemExtra = computed(() => filterFunction(mForm, props.config.itemExtra, props));
|
|
111
|
-
|
|
112
|
-
const removeHandler = () => emit('remove-item', props.index);
|
|
113
|
-
|
|
114
|
-
const changeHandler = () => emit('change');
|
|
115
|
-
|
|
116
|
-
const expandHandler = () => {
|
|
117
|
-
expand.value = !expand.value;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// 希望支持单行可控制是否显示删除按钮,不会影响现有逻辑
|
|
121
|
-
const showDelete = (index: number) => {
|
|
122
|
-
const deleteFunc = props.config.delete;
|
|
123
|
-
if (deleteFunc && typeof deleteFunc === 'function') {
|
|
124
|
-
return deleteFunc(props.model, index, mForm?.values);
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// 调换顺序
|
|
130
|
-
const changeOrder = (offset = 0) => emit('swap-item', props.index, `${String(props.index)}${offset}`);
|
|
131
|
-
|
|
132
|
-
const movable = () => {
|
|
133
|
-
const { movable } = props.config;
|
|
134
|
-
|
|
135
|
-
// 没有设置时,默认可移动
|
|
136
|
-
if (movable === undefined) return true;
|
|
137
|
-
if (typeof movable === 'function') {
|
|
138
|
-
return movable(mForm, props.index || 0, props.model, props.groupModel);
|
|
139
|
-
}
|
|
140
|
-
return movable;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
expand,
|
|
145
|
-
expandHandler,
|
|
146
|
-
title,
|
|
147
|
-
showDelete,
|
|
148
|
-
removeHandler,
|
|
149
|
-
movable,
|
|
150
|
-
changeOrder,
|
|
151
|
-
itemExtra,
|
|
152
|
-
rowConfig,
|
|
153
|
-
changeHandler,
|
|
154
|
-
length,
|
|
155
|
-
Delete,
|
|
156
|
-
};
|
|
157
|
-
},
|
|
51
|
+
import Container from './Container.vue';
|
|
52
|
+
|
|
53
|
+
const props = defineProps<{
|
|
54
|
+
model: any;
|
|
55
|
+
groupModel: any[];
|
|
56
|
+
config: GroupListConfig;
|
|
57
|
+
labelWidth?: string;
|
|
58
|
+
prop?: string;
|
|
59
|
+
size?: string;
|
|
60
|
+
index: number;
|
|
61
|
+
}>();
|
|
62
|
+
|
|
63
|
+
const emit = defineEmits(['swap-item', 'remove-item', 'change']);
|
|
64
|
+
|
|
65
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
66
|
+
const expand = ref(false);
|
|
67
|
+
|
|
68
|
+
watchEffect(() => {
|
|
69
|
+
expand.value = !props.index;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const rowConfig = computed(() => ({
|
|
73
|
+
type: 'row',
|
|
74
|
+
span: props.config.span || 24,
|
|
75
|
+
items: props.config.items,
|
|
76
|
+
labelWidth: props.config.labelWidth,
|
|
77
|
+
[mForm?.keyProp || '__key']: `${props.config[mForm?.keyProp || '__key']}${String(props.index)}`,
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
const title = computed(() => {
|
|
81
|
+
if (props.config.titleKey && props.model[props.config.titleKey]) {
|
|
82
|
+
return props.model[props.config.titleKey];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return `组 ${String(props.index)}`;
|
|
158
86
|
});
|
|
87
|
+
|
|
88
|
+
const length = computed(() => props.groupModel?.length || 0);
|
|
89
|
+
|
|
90
|
+
const itemExtra = computed(() => filterFunction(mForm, props.config.itemExtra, props));
|
|
91
|
+
|
|
92
|
+
const removeHandler = () => emit('remove-item', props.index);
|
|
93
|
+
|
|
94
|
+
const changeHandler = () => emit('change');
|
|
95
|
+
|
|
96
|
+
const expandHandler = () => {
|
|
97
|
+
expand.value = !expand.value;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// 希望支持单行可控制是否显示删除按钮,不会影响现有逻辑
|
|
101
|
+
const showDelete = (index: number) => {
|
|
102
|
+
const deleteFunc = props.config.delete;
|
|
103
|
+
if (deleteFunc && typeof deleteFunc === 'function') {
|
|
104
|
+
return deleteFunc(props.model, index, mForm?.values);
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// 调换顺序
|
|
110
|
+
const changeOrder = (offset = 0) => emit('swap-item', props.index, `${String(props.index)}${offset}`);
|
|
111
|
+
|
|
112
|
+
const movable = () => {
|
|
113
|
+
const { movable } = props.config;
|
|
114
|
+
|
|
115
|
+
// 没有设置时,默认可移动
|
|
116
|
+
if (movable === undefined) return true;
|
|
117
|
+
if (typeof movable === 'function') {
|
|
118
|
+
return movable(mForm, props.index || 0, props.model, props.groupModel);
|
|
119
|
+
}
|
|
120
|
+
return movable;
|
|
121
|
+
};
|
|
159
122
|
</script>
|
package/src/containers/Panel.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<TMagicCard
|
|
3
3
|
v-if="items && items.length"
|
|
4
4
|
class="box-card m-form-panel"
|
|
5
5
|
:body-style="{ display: expand ? 'block' : 'none' }"
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<template #header>
|
|
8
8
|
<div class="clearfix">
|
|
9
9
|
<a href="javascript:" style="width: 100%; display: block" @click="expand = !expand">
|
|
10
|
-
<
|
|
10
|
+
<TMagicIcon><CaretBottom v-if="expand" /><CaretRight v-else /></TMagicIcon> {{ filter(config.title) }}
|
|
11
11
|
<span v-if="config && config.extra" v-html="config.extra" class="m-form-tip"></span>
|
|
12
12
|
</a>
|
|
13
13
|
</div>
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
<div v-if="config.schematic" style="display: flex">
|
|
20
20
|
<div style="flex: 1">
|
|
21
|
-
<
|
|
21
|
+
<Container
|
|
22
22
|
v-for="(item, index) in items"
|
|
23
23
|
:key="item[mForm?.keyProp || '__key'] ?? index"
|
|
24
24
|
:config="item"
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
:size="size"
|
|
28
28
|
:label-width="config.labelWidth || labelWidth"
|
|
29
29
|
@change="changeHandler"
|
|
30
|
-
></
|
|
30
|
+
></Container>
|
|
31
31
|
</div>
|
|
32
32
|
|
|
33
33
|
<img class="m-form-schematic" :src="config.schematic" />
|
|
34
34
|
</div>
|
|
35
35
|
|
|
36
36
|
<template v-else>
|
|
37
|
-
<
|
|
37
|
+
<Container
|
|
38
38
|
v-for="(item, index) in items"
|
|
39
39
|
:key="item[mForm?.keyProp || '__key'] ?? index"
|
|
40
40
|
:config="item"
|
|
@@ -43,64 +43,41 @@
|
|
|
43
43
|
:size="size"
|
|
44
44
|
:label-width="config.labelWidth || labelWidth"
|
|
45
45
|
@change="changeHandler"
|
|
46
|
-
></
|
|
46
|
+
></Container>
|
|
47
47
|
</template>
|
|
48
48
|
</div>
|
|
49
|
-
</
|
|
49
|
+
</TMagicCard>
|
|
50
50
|
</template>
|
|
51
51
|
|
|
52
|
-
<script lang="ts">
|
|
53
|
-
import { computed,
|
|
52
|
+
<script setup lang="ts" name="MFormPanel">
|
|
53
|
+
import { computed, inject, ref } from 'vue';
|
|
54
54
|
import { CaretBottom, CaretRight } from '@element-plus/icons-vue';
|
|
55
55
|
|
|
56
|
+
import { TMagicCard, TMagicIcon } from '@tmagic/design';
|
|
57
|
+
|
|
56
58
|
import { FormState, PanelConfig } from '../schema';
|
|
57
59
|
import { filterFunction } from '../utils/form';
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
name: 'm-form-panel',
|
|
61
|
-
|
|
62
|
-
components: { CaretBottom, CaretRight },
|
|
63
|
-
|
|
64
|
-
props: {
|
|
65
|
-
labelWidth: String,
|
|
66
|
-
|
|
67
|
-
model: {
|
|
68
|
-
type: Object,
|
|
69
|
-
default: () => ({}),
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
config: {
|
|
73
|
-
type: Object as PropType<PanelConfig>,
|
|
74
|
-
default: () => ({}),
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
prop: String,
|
|
78
|
-
|
|
79
|
-
size: String,
|
|
80
|
-
|
|
81
|
-
name: String,
|
|
82
|
-
},
|
|
61
|
+
import Container from './Container.vue';
|
|
83
62
|
|
|
84
|
-
|
|
63
|
+
const props = defineProps<{
|
|
64
|
+
model: any;
|
|
65
|
+
config: PanelConfig;
|
|
66
|
+
name: string;
|
|
67
|
+
labelWidth?: string;
|
|
68
|
+
prop?: string;
|
|
69
|
+
size?: string;
|
|
70
|
+
}>();
|
|
85
71
|
|
|
86
|
-
|
|
87
|
-
const mForm = inject<FormState | undefined>('mForm');
|
|
72
|
+
const emit = defineEmits(['change']);
|
|
88
73
|
|
|
89
|
-
|
|
74
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
90
75
|
|
|
91
|
-
|
|
76
|
+
const expand = ref(props.config.expand !== false);
|
|
92
77
|
|
|
93
|
-
|
|
78
|
+
const items = computed(() => props.config.items);
|
|
94
79
|
|
|
95
|
-
|
|
80
|
+
const filter = (config: any) => filterFunction(mForm, config, props);
|
|
96
81
|
|
|
97
|
-
|
|
98
|
-
mForm,
|
|
99
|
-
expand,
|
|
100
|
-
items,
|
|
101
|
-
filter,
|
|
102
|
-
changeHandler,
|
|
103
|
-
};
|
|
104
|
-
},
|
|
105
|
-
});
|
|
82
|
+
const changeHandler = () => emit('change', props.model);
|
|
106
83
|
</script>
|
package/src/containers/Row.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<TMagicRow :gutter="10">
|
|
3
3
|
<Col
|
|
4
4
|
v-for="(col, index) in config.items"
|
|
5
5
|
:key="col[mForm?.keyProp || '__key'] ?? index"
|
|
@@ -12,53 +12,31 @@
|
|
|
12
12
|
:size="size"
|
|
13
13
|
@change="changeHandler"
|
|
14
14
|
/>
|
|
15
|
-
</
|
|
15
|
+
</TMagicRow>
|
|
16
16
|
</template>
|
|
17
17
|
|
|
18
|
-
<script lang="ts">
|
|
19
|
-
import {
|
|
18
|
+
<script setup lang="ts" name="MFormRow">
|
|
19
|
+
import { inject } from 'vue';
|
|
20
|
+
|
|
21
|
+
import { TMagicRow } from '@tmagic/design';
|
|
20
22
|
|
|
21
23
|
import { FormState, RowConfig } from '../schema';
|
|
22
24
|
|
|
23
25
|
import Col from './Col.vue';
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
model: {
|
|
35
|
-
type: Object,
|
|
36
|
-
default: () => ({}),
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
config: {
|
|
40
|
-
type: Object as PropType<RowConfig>,
|
|
41
|
-
default: () => ({}),
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
prop: String,
|
|
45
|
-
|
|
46
|
-
name: String,
|
|
47
|
-
|
|
48
|
-
size: String,
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
emits: ['change'],
|
|
27
|
+
const props = defineProps<{
|
|
28
|
+
model: any;
|
|
29
|
+
config: RowConfig;
|
|
30
|
+
name: string;
|
|
31
|
+
labelWidth?: string;
|
|
32
|
+
prop?: string;
|
|
33
|
+
size?: string;
|
|
34
|
+
expandMore?: boolean;
|
|
35
|
+
}>();
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
const mForm = inject<FormState | undefined>('mForm');
|
|
37
|
+
const emit = defineEmits(['change']);
|
|
55
38
|
|
|
56
|
-
|
|
39
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
57
40
|
|
|
58
|
-
|
|
59
|
-
mForm,
|
|
60
|
-
changeHandler,
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
});
|
|
41
|
+
const changeHandler = () => emit('change', props.name ? props.model[props.name] : props.model);
|
|
64
42
|
</script>
|