@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
|
@@ -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"
|
|
@@ -15,142 +15,112 @@
|
|
|
15
15
|
:index="index"
|
|
16
16
|
:label-width="labelWidth"
|
|
17
17
|
:size="size"
|
|
18
|
+
:disabled="disabled"
|
|
18
19
|
:group-model="model[name]"
|
|
19
20
|
@remove-item="removeHandler"
|
|
20
21
|
@swap-item="swapHandler"
|
|
21
22
|
@change="changeHandler"
|
|
22
|
-
></
|
|
23
|
+
></MFieldsGroupListItem>
|
|
23
24
|
|
|
24
|
-
<
|
|
25
|
+
<TMagicButton @click="addHandler" size="small" :disabled="disabled" v-if="addable">添加组</TMagicButton>
|
|
25
26
|
|
|
26
|
-
<
|
|
27
|
+
<TMagicButton :icon="Grid" size="small" @click="toggleMode" v-if="config.enableToggleMode">切换为表格</TMagicButton>
|
|
27
28
|
</div>
|
|
28
29
|
</template>
|
|
29
30
|
|
|
30
|
-
<script lang="ts">
|
|
31
|
-
import { computed,
|
|
31
|
+
<script setup lang="ts" name="MFormGroupList">
|
|
32
|
+
import { computed, inject } from 'vue';
|
|
32
33
|
import { Grid } from '@element-plus/icons-vue';
|
|
33
34
|
|
|
35
|
+
import { TMagicButton } from '@tmagic/design';
|
|
36
|
+
|
|
34
37
|
import { FormState, GroupListConfig } from '../schema';
|
|
35
38
|
import { initValue } from '../utils/form';
|
|
36
39
|
|
|
37
40
|
import MFieldsGroupListItem from './GroupListItem.vue';
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
const props = defineProps<{
|
|
43
|
+
model: any;
|
|
44
|
+
config: GroupListConfig;
|
|
45
|
+
name: string;
|
|
46
|
+
labelWidth?: string;
|
|
47
|
+
prop?: string;
|
|
48
|
+
size?: string;
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
}>();
|
|
51
|
+
|
|
52
|
+
const emit = defineEmits(['change']);
|
|
53
|
+
|
|
54
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
55
|
+
|
|
56
|
+
const addable = computed(() => {
|
|
57
|
+
if (!props.name) return false;
|
|
58
|
+
|
|
59
|
+
if (typeof props.config.addable === 'function') {
|
|
60
|
+
return props.config.addable(mForm, {
|
|
61
|
+
model: props.model[props.name],
|
|
62
|
+
formValue: mForm?.values,
|
|
63
|
+
prop: props.prop,
|
|
64
|
+
config: props.config,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
default: '',
|
|
67
|
-
},
|
|
68
|
-
},
|
|
68
|
+
return typeof props.config.addable === 'undefined' ? true : props.config.addable;
|
|
69
|
+
});
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
const changeHandler = () => {
|
|
72
|
+
if (!props.name) return false;
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
emit('change', props.model[props.name]);
|
|
75
|
+
};
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
const addHandler = async () => {
|
|
78
|
+
if (!props.name) return false;
|
|
77
79
|
|
|
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
|
-
}
|
|
80
|
+
let initValues = {};
|
|
86
81
|
|
|
87
|
-
|
|
82
|
+
if (typeof props.config.defaultAdd === 'function') {
|
|
83
|
+
initValues = await props.config.defaultAdd(mForm, {
|
|
84
|
+
model: props.model[props.name],
|
|
85
|
+
formValue: mForm?.values,
|
|
86
|
+
prop: props.prop,
|
|
87
|
+
config: props.config,
|
|
88
88
|
});
|
|
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
|
-
});
|
|
89
|
+
} else if (props.config.defaultAdd) {
|
|
90
|
+
initValues = props.config.defaultAdd;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const groupValue = await initValue(mForm, {
|
|
94
|
+
config: props.config.items,
|
|
95
|
+
initValues,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
props.model[props.name].push(groupValue);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const removeHandler = (index: number) => {
|
|
102
|
+
if (!props.name) return false;
|
|
103
|
+
|
|
104
|
+
props.model[props.name].splice(index, 1);
|
|
105
|
+
changeHandler();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const swapHandler = (idx1: number, idx2: number) => {
|
|
109
|
+
if (!props.name) return false;
|
|
110
|
+
|
|
111
|
+
const [currRow] = props.model[props.name].splice(idx1, 1);
|
|
112
|
+
props.model[props.name].splice(idx2, 0, currRow);
|
|
113
|
+
changeHandler();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const toggleMode = () => {
|
|
117
|
+
props.config.type = 'table';
|
|
118
|
+
props.config.groupItems = props.config.items;
|
|
119
|
+
props.config.items = (props.config.tableItems ||
|
|
120
|
+
props.config.items.map((item: any) => ({
|
|
121
|
+
...item,
|
|
122
|
+
label: item.label || item.text,
|
|
123
|
+
text: null,
|
|
124
|
+
}))) as any;
|
|
125
|
+
};
|
|
156
126
|
</script>
|
|
@@ -1,159 +1,125 @@
|
|
|
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 :disabled="disabled" @click="expandHandler">{{ title }}</TMagicButton>
|
|
9
9
|
|
|
10
|
-
<
|
|
10
|
+
<TMagicButton
|
|
11
11
|
v-show="showDelete(parseInt(String(index)))"
|
|
12
|
+
style="color: #f56c6c"
|
|
12
13
|
text
|
|
13
14
|
:icon="Delete"
|
|
14
|
-
|
|
15
|
+
:disabled="disabled"
|
|
15
16
|
@click="removeHandler"
|
|
16
|
-
></
|
|
17
|
+
></TMagicButton>
|
|
17
18
|
|
|
18
19
|
<template v-if="movable()">
|
|
19
|
-
<
|
|
20
|
-
>上移<
|
|
21
|
-
></
|
|
22
|
-
<
|
|
23
|
-
>下移<
|
|
24
|
-
></
|
|
20
|
+
<TMagicButton v-show="index !== 0" text :disabled="disabled" size="small" @click="changeOrder(-1)"
|
|
21
|
+
>上移<TMagicIcon><CaretTop /></TMagicIcon
|
|
22
|
+
></TMagicButton>
|
|
23
|
+
<TMagicButton v-show="index !== length - 1" :disabled="disabled" text size="small" @click="changeOrder(1)"
|
|
24
|
+
>下移<TMagicIcon><CaretBottom /></TMagicIcon
|
|
25
|
+
></TMagicButton>
|
|
25
26
|
</template>
|
|
26
27
|
|
|
27
28
|
<span v-if="itemExtra" v-html="itemExtra" class="m-form-tip"></span>
|
|
28
29
|
</div>
|
|
29
30
|
|
|
30
|
-
<
|
|
31
|
+
<Container
|
|
31
32
|
v-if="expand"
|
|
32
33
|
:config="rowConfig"
|
|
33
34
|
:model="model"
|
|
34
35
|
:labelWidth="labelWidth"
|
|
35
36
|
:prop="`${prop}${prop ? '.' : ''}${String(index)}`"
|
|
36
37
|
:size="size"
|
|
38
|
+
:disabled="disabled"
|
|
37
39
|
@change="changeHandler"
|
|
38
|
-
></
|
|
40
|
+
></Container>
|
|
39
41
|
</div>
|
|
40
42
|
</template>
|
|
41
43
|
|
|
42
|
-
<script lang="ts">
|
|
43
|
-
import { computed,
|
|
44
|
+
<script setup lang="ts" name="MFormGroupListItem">
|
|
45
|
+
import { computed, inject, ref, watchEffect } from 'vue';
|
|
44
46
|
import { CaretBottom, CaretRight, CaretTop, Delete } from '@element-plus/icons-vue';
|
|
45
47
|
|
|
48
|
+
import { TMagicButton, TMagicIcon } from '@tmagic/design';
|
|
49
|
+
|
|
46
50
|
import { FormState, GroupListConfig } from '../schema';
|
|
47
51
|
import { filterFunction } from '../utils/form';
|
|
48
52
|
|
|
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
|
-
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
|
-
},
|
|
53
|
+
import Container from './Container.vue';
|
|
54
|
+
|
|
55
|
+
const props = defineProps<{
|
|
56
|
+
model: any;
|
|
57
|
+
groupModel: any[];
|
|
58
|
+
config: GroupListConfig;
|
|
59
|
+
labelWidth?: string;
|
|
60
|
+
prop?: string;
|
|
61
|
+
size?: string;
|
|
62
|
+
index: number;
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
}>();
|
|
65
|
+
|
|
66
|
+
const emit = defineEmits(['swap-item', 'remove-item', 'change']);
|
|
67
|
+
|
|
68
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
69
|
+
const expand = ref(false);
|
|
70
|
+
|
|
71
|
+
watchEffect(() => {
|
|
72
|
+
expand.value = !props.index;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const rowConfig = computed(() => ({
|
|
76
|
+
type: 'row',
|
|
77
|
+
span: props.config.span || 24,
|
|
78
|
+
items: props.config.items,
|
|
79
|
+
labelWidth: props.config.labelWidth,
|
|
80
|
+
[mForm?.keyProp || '__key']: `${props.config[mForm?.keyProp || '__key']}${String(props.index)}`,
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
const title = computed(() => {
|
|
84
|
+
if (props.config.titleKey && props.model[props.config.titleKey]) {
|
|
85
|
+
return props.model[props.config.titleKey];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return `组 ${String(props.index)}`;
|
|
158
89
|
});
|
|
90
|
+
|
|
91
|
+
const length = computed(() => props.groupModel?.length || 0);
|
|
92
|
+
|
|
93
|
+
const itemExtra = computed(() => filterFunction(mForm, props.config.itemExtra, props));
|
|
94
|
+
|
|
95
|
+
const removeHandler = () => emit('remove-item', props.index);
|
|
96
|
+
|
|
97
|
+
const changeHandler = () => emit('change');
|
|
98
|
+
|
|
99
|
+
const expandHandler = () => {
|
|
100
|
+
expand.value = !expand.value;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// 希望支持单行可控制是否显示删除按钮,不会影响现有逻辑
|
|
104
|
+
const showDelete = (index: number) => {
|
|
105
|
+
const deleteFunc = props.config.delete;
|
|
106
|
+
if (deleteFunc && typeof deleteFunc === 'function') {
|
|
107
|
+
return deleteFunc(props.model, index, mForm?.values);
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// 调换顺序
|
|
113
|
+
const changeOrder = (offset = 0) => emit('swap-item', props.index, `${String(props.index)}${offset}`);
|
|
114
|
+
|
|
115
|
+
const movable = () => {
|
|
116
|
+
const { movable } = props.config;
|
|
117
|
+
|
|
118
|
+
// 没有设置时,默认可移动
|
|
119
|
+
if (movable === undefined) return true;
|
|
120
|
+
if (typeof movable === 'function') {
|
|
121
|
+
return movable(mForm, props.index || 0, props.model, props.groupModel);
|
|
122
|
+
}
|
|
123
|
+
return movable;
|
|
124
|
+
};
|
|
159
125
|
</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,89 +18,69 @@
|
|
|
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"
|
|
25
25
|
:model="name ? model[name] : model"
|
|
26
26
|
:prop="prop"
|
|
27
27
|
:size="size"
|
|
28
|
+
:disabled="disabled"
|
|
28
29
|
:label-width="config.labelWidth || labelWidth"
|
|
29
30
|
@change="changeHandler"
|
|
30
|
-
></
|
|
31
|
+
></Container>
|
|
31
32
|
</div>
|
|
32
33
|
|
|
33
34
|
<img class="m-form-schematic" :src="config.schematic" />
|
|
34
35
|
</div>
|
|
35
36
|
|
|
36
37
|
<template v-else>
|
|
37
|
-
<
|
|
38
|
+
<Container
|
|
38
39
|
v-for="(item, index) in items"
|
|
39
40
|
:key="item[mForm?.keyProp || '__key'] ?? index"
|
|
40
41
|
:config="item"
|
|
41
42
|
:model="name ? model[name] : model"
|
|
42
43
|
:prop="prop"
|
|
43
44
|
:size="size"
|
|
45
|
+
:disabled="disabled"
|
|
44
46
|
:label-width="config.labelWidth || labelWidth"
|
|
45
47
|
@change="changeHandler"
|
|
46
|
-
></
|
|
48
|
+
></Container>
|
|
47
49
|
</template>
|
|
48
50
|
</div>
|
|
49
|
-
</
|
|
51
|
+
</TMagicCard>
|
|
50
52
|
</template>
|
|
51
53
|
|
|
52
|
-
<script lang="ts">
|
|
53
|
-
import { computed,
|
|
54
|
+
<script setup lang="ts" name="MFormPanel">
|
|
55
|
+
import { computed, inject, ref } from 'vue';
|
|
54
56
|
import { CaretBottom, CaretRight } from '@element-plus/icons-vue';
|
|
55
57
|
|
|
58
|
+
import { TMagicCard, TMagicIcon } from '@tmagic/design';
|
|
59
|
+
|
|
56
60
|
import { FormState, PanelConfig } from '../schema';
|
|
57
61
|
import { filterFunction } from '../utils/form';
|
|
58
62
|
|
|
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
|
-
},
|
|
63
|
+
import Container from './Container.vue';
|
|
83
64
|
|
|
84
|
-
|
|
65
|
+
const props = defineProps<{
|
|
66
|
+
model: any;
|
|
67
|
+
config: PanelConfig;
|
|
68
|
+
name: string;
|
|
69
|
+
labelWidth?: string;
|
|
70
|
+
prop?: string;
|
|
71
|
+
size?: string;
|
|
72
|
+
disabled?: boolean;
|
|
73
|
+
}>();
|
|
85
74
|
|
|
86
|
-
|
|
87
|
-
const mForm = inject<FormState | undefined>('mForm');
|
|
75
|
+
const emit = defineEmits(['change']);
|
|
88
76
|
|
|
89
|
-
|
|
77
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
90
78
|
|
|
91
|
-
|
|
79
|
+
const expand = ref(props.config.expand !== false);
|
|
92
80
|
|
|
93
|
-
|
|
81
|
+
const items = computed(() => props.config.items);
|
|
94
82
|
|
|
95
|
-
|
|
83
|
+
const filter = (config: any) => filterFunction(mForm, config, props);
|
|
96
84
|
|
|
97
|
-
|
|
98
|
-
mForm,
|
|
99
|
-
expand,
|
|
100
|
-
items,
|
|
101
|
-
filter,
|
|
102
|
-
changeHandler,
|
|
103
|
-
};
|
|
104
|
-
},
|
|
105
|
-
});
|
|
85
|
+
const changeHandler = () => emit('change', props.model);
|
|
106
86
|
</script>
|