@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/containers/Tabs.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<TMagicTabs
|
|
3
3
|
v-model="activeTabName"
|
|
4
4
|
:class="config.dynamic ? 'magic-form-dynamic-tab' : 'magic-form-tab'"
|
|
5
5
|
:type="config.tabType"
|
|
@@ -10,17 +10,19 @@
|
|
|
10
10
|
@tab-remove="onTabRemove"
|
|
11
11
|
>
|
|
12
12
|
<template v-for="(tab, tabIndex) in tabs">
|
|
13
|
-
<
|
|
13
|
+
<component
|
|
14
14
|
v-if="display(tab.display) && tabItems(tab).length"
|
|
15
|
+
:is="uiComponent.component"
|
|
15
16
|
:key="tab[mForm?.keyProp || '__key'] ?? tabIndex"
|
|
16
17
|
:name="filter(tab.status) || tabIndex.toString()"
|
|
17
18
|
:label="filter(tab.title)"
|
|
18
19
|
:lazy="tab.lazy || false"
|
|
19
20
|
>
|
|
20
|
-
<
|
|
21
|
+
<Container
|
|
21
22
|
v-for="item in tabItems(tab)"
|
|
22
23
|
:key="item[mForm?.keyProp || '__key']"
|
|
23
24
|
:config="item"
|
|
25
|
+
:disabled="disabled"
|
|
24
26
|
:model="
|
|
25
27
|
config.dynamic
|
|
26
28
|
? (name ? model[name] : model)[tabIndex]
|
|
@@ -35,18 +37,24 @@
|
|
|
35
37
|
:label-width="tab.labelWidth || labelWidth"
|
|
36
38
|
:expand-more="expandMore"
|
|
37
39
|
@change="changeHandler"
|
|
38
|
-
></
|
|
39
|
-
</
|
|
40
|
+
></Container>
|
|
41
|
+
</component>
|
|
40
42
|
</template>
|
|
41
|
-
</
|
|
43
|
+
</TMagicTabs>
|
|
42
44
|
</template>
|
|
43
45
|
|
|
44
|
-
<script lang="ts">
|
|
45
|
-
import { computed,
|
|
46
|
+
<script setup lang="ts" name="MFormTabs">
|
|
47
|
+
import { computed, inject, ref, watchEffect } from 'vue';
|
|
46
48
|
import { cloneDeep } from 'lodash-es';
|
|
47
49
|
|
|
48
|
-
import {
|
|
49
|
-
|
|
50
|
+
import { getConfig, TMagicTabs } from '@tmagic/design';
|
|
51
|
+
|
|
52
|
+
import { FormState, TabConfig, TabPaneConfig } from '../schema';
|
|
53
|
+
import { display as displayFunc, filterFunction } from '../utils/form';
|
|
54
|
+
|
|
55
|
+
import Container from './Container.vue';
|
|
56
|
+
|
|
57
|
+
const uiComponent = getConfig('components').tabPane;
|
|
50
58
|
|
|
51
59
|
const getActive = (mForm: FormState | undefined, props: any, activeTabName: string) => {
|
|
52
60
|
const { config, model, prop } = props;
|
|
@@ -59,7 +67,7 @@ const getActive = (mForm: FormState | undefined, props: any, activeTabName: stri
|
|
|
59
67
|
return '0';
|
|
60
68
|
};
|
|
61
69
|
|
|
62
|
-
const
|
|
70
|
+
const tabClick = (mForm: FormState | undefined, tab: any, props: any) => {
|
|
63
71
|
const { config, model, prop } = props;
|
|
64
72
|
|
|
65
73
|
// 兼容vue2的element-ui
|
|
@@ -75,123 +83,91 @@ const tabClickHandler = (mForm: FormState | undefined, tab: any, props: any) =>
|
|
|
75
83
|
}
|
|
76
84
|
};
|
|
77
85
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
const props = defineProps<{
|
|
87
|
+
model: any;
|
|
88
|
+
config: TabConfig;
|
|
89
|
+
name: string;
|
|
90
|
+
size?: string;
|
|
91
|
+
labelWidth?: string;
|
|
92
|
+
prop?: string;
|
|
93
|
+
expandMore?: boolean;
|
|
94
|
+
disabled?: boolean;
|
|
95
|
+
}>();
|
|
96
|
+
|
|
97
|
+
const emit = defineEmits(['change']);
|
|
98
|
+
|
|
99
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
100
|
+
const activeTabName = ref(getActive(mForm, props, ''));
|
|
101
|
+
|
|
102
|
+
const tabs = computed(() => {
|
|
103
|
+
if (props.config.dynamic) {
|
|
104
|
+
if (!props.config.name) throw new Error('dynamic tab 必须配置name');
|
|
105
|
+
return props.model[props.config.name] || [];
|
|
106
|
+
}
|
|
107
|
+
return props.config.items;
|
|
108
|
+
});
|
|
94
109
|
|
|
95
|
-
|
|
110
|
+
const filter = (config: any) => filterFunction(mForm, config, props);
|
|
96
111
|
|
|
97
|
-
|
|
112
|
+
watchEffect(() => {
|
|
113
|
+
if (typeof props.config.activeChange === 'function') {
|
|
114
|
+
props.config.activeChange(mForm, activeTabName.value, {
|
|
115
|
+
model: props.model,
|
|
116
|
+
prop: props.prop,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
98
120
|
|
|
99
|
-
|
|
100
|
-
},
|
|
121
|
+
const tabItems = (tab: TabPaneConfig) => (props.config.dynamic ? props.config.items : tab.items);
|
|
101
122
|
|
|
102
|
-
|
|
103
|
-
change(values: FormValue) {
|
|
104
|
-
return values;
|
|
105
|
-
},
|
|
106
|
-
},
|
|
123
|
+
const tabClickHandler = (tab: any) => tabClick(mForm, tab, props);
|
|
107
124
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const activeTabName = ref(getActive(mForm, props, ''));
|
|
125
|
+
const onTabAdd = () => {
|
|
126
|
+
if (!props.config.name) throw new Error('dynamic tab 必须配置name');
|
|
111
127
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return props.config.items;
|
|
128
|
+
if (typeof props.config.onTabAdd === 'function') {
|
|
129
|
+
props.config.onTabAdd(mForm, {
|
|
130
|
+
model: props.model,
|
|
131
|
+
prop: props.prop,
|
|
132
|
+
config: props.config,
|
|
118
133
|
});
|
|
134
|
+
} else if (tabs.value.length > 0) {
|
|
135
|
+
const newObj = cloneDeep(tabs.value[0]);
|
|
136
|
+
newObj.title = `标签${tabs.value.length + 1}`;
|
|
137
|
+
props.model[props.config.name].push(newObj);
|
|
138
|
+
}
|
|
139
|
+
emit('change', props.model);
|
|
140
|
+
mForm?.$emit('field-change', props.prop, props.model[props.config.name]);
|
|
141
|
+
};
|
|
119
142
|
|
|
120
|
-
|
|
143
|
+
const onTabRemove = (tabName: string) => {
|
|
144
|
+
if (!props.config.name) throw new Error('dynamic tab 必须配置name');
|
|
121
145
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
}
|
|
146
|
+
if (typeof props.config.onTabRemove === 'function') {
|
|
147
|
+
props.config.onTabRemove(mForm, tabName, {
|
|
148
|
+
model: props.model,
|
|
149
|
+
prop: props.prop,
|
|
150
|
+
config: props.config,
|
|
129
151
|
});
|
|
152
|
+
} else {
|
|
153
|
+
props.model[props.config.name].splice(+tabName, 1);
|
|
154
|
+
|
|
155
|
+
// 防止删除后没有选中的问题
|
|
156
|
+
if (tabName < activeTabName.value || activeTabName.value >= props.model[props.config.name].length) {
|
|
157
|
+
activeTabName.value = (+activeTabName.value - 1).toString();
|
|
158
|
+
tabClick(mForm, { name: activeTabName.value }, props);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
emit('change', props.model);
|
|
162
|
+
mForm?.$emit('field-change', props.prop, props.model[props.config.name]);
|
|
163
|
+
};
|
|
130
164
|
|
|
131
|
-
|
|
132
|
-
mForm,
|
|
133
|
-
|
|
134
|
-
activeTabName,
|
|
135
|
-
|
|
136
|
-
tabs,
|
|
137
|
-
|
|
138
|
-
filter,
|
|
139
|
-
|
|
140
|
-
tabItems: (tab: TabPaneConfig) => (props.config.dynamic ? props.config.items : tab.items),
|
|
141
|
-
|
|
142
|
-
tabClickHandler: (tab: any) => tabClickHandler(mForm, tab, props),
|
|
143
|
-
|
|
144
|
-
onTabAdd: () => {
|
|
145
|
-
if (!props.config.name) throw new Error('dynamic tab 必须配置name');
|
|
146
|
-
|
|
147
|
-
if (typeof props.config.onTabAdd === 'function') {
|
|
148
|
-
props.config.onTabAdd(mForm, {
|
|
149
|
-
model: props.model,
|
|
150
|
-
prop: props.prop,
|
|
151
|
-
config: props.config,
|
|
152
|
-
});
|
|
153
|
-
} else if (tabs.value.length > 0) {
|
|
154
|
-
const newObj = cloneDeep(tabs.value[0]);
|
|
155
|
-
newObj.title = `标签${tabs.value.length + 1}`;
|
|
156
|
-
props.model[props.config.name].push(newObj);
|
|
157
|
-
}
|
|
158
|
-
emit('change', props.model);
|
|
159
|
-
mForm?.$emit('field-change', props.prop, props.model[props.config.name]);
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
onTabRemove: (tabName: string) => {
|
|
163
|
-
if (!props.config.name) throw new Error('dynamic tab 必须配置name');
|
|
164
|
-
|
|
165
|
-
if (typeof props.config.onTabRemove === 'function') {
|
|
166
|
-
props.config.onTabRemove(mForm, tabName, {
|
|
167
|
-
model: props.model,
|
|
168
|
-
prop: props.prop,
|
|
169
|
-
config: props.config,
|
|
170
|
-
});
|
|
171
|
-
} else {
|
|
172
|
-
props.model[props.config.name].splice(+tabName, 1);
|
|
173
|
-
|
|
174
|
-
// 防止删除后没有选中的问题
|
|
175
|
-
if (tabName < activeTabName.value || activeTabName.value >= props.model[props.config.name].length) {
|
|
176
|
-
activeTabName.value = (+activeTabName.value - 1).toString();
|
|
177
|
-
tabClickHandler(mForm, { name: activeTabName.value }, props);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
emit('change', props.model);
|
|
181
|
-
mForm?.$emit('field-change', props.prop, props.model[props.config.name]);
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
display: (displayConfig: any) => display(mForm, displayConfig, props),
|
|
185
|
-
|
|
186
|
-
changeHandler: () => {
|
|
187
|
-
emit('change', props.model);
|
|
188
|
-
if (typeof props.config.onChange === 'function') {
|
|
189
|
-
props.config.onChange(mForm, { model: props.model, prop: props.prop, config: props.config });
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
},
|
|
194
|
-
});
|
|
165
|
+
const display = (displayConfig: any) => displayFunc(mForm, displayConfig, props);
|
|
195
166
|
|
|
196
|
-
|
|
167
|
+
const changeHandler = () => {
|
|
168
|
+
emit('change', props.model);
|
|
169
|
+
if (typeof props.config.onChange === 'function') {
|
|
170
|
+
props.config.onChange(mForm, { model: props.model, prop: props.prop, config: props.config });
|
|
171
|
+
}
|
|
172
|
+
};
|
|
197
173
|
</script>
|
package/src/fields/Cascader.vue
CHANGED
|
@@ -1,146 +1,98 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
></el-cascader>
|
|
16
|
-
</div>
|
|
2
|
+
<TMagicCascader
|
|
3
|
+
v-model="model[name]"
|
|
4
|
+
ref="tMagicCascader"
|
|
5
|
+
style="width: 100%"
|
|
6
|
+
clearable
|
|
7
|
+
filterable
|
|
8
|
+
:size="size"
|
|
9
|
+
:placeholder="config.placeholder"
|
|
10
|
+
:disabled="disabled"
|
|
11
|
+
:options="options"
|
|
12
|
+
:props="{ multiple: config.multiple }"
|
|
13
|
+
@change="changeHandler"
|
|
14
|
+
></TMagicCascader>
|
|
17
15
|
</template>
|
|
18
16
|
|
|
19
|
-
<script lang="ts">
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
defineComponent,
|
|
24
|
-
getCurrentInstance,
|
|
25
|
-
inject,
|
|
26
|
-
PropType,
|
|
27
|
-
ref,
|
|
28
|
-
watchEffect,
|
|
29
|
-
} from 'vue';
|
|
17
|
+
<script setup lang="ts" name="MFormCascader">
|
|
18
|
+
import { inject, ref, watchEffect } from 'vue';
|
|
19
|
+
|
|
20
|
+
import { TMagicCascader } from '@tmagic/design';
|
|
30
21
|
|
|
31
22
|
import { CascaderConfig, FormState } from '../schema';
|
|
32
23
|
import { getConfig } from '../utils/config';
|
|
33
|
-
import fieldProps from '../utils/fieldProps';
|
|
34
24
|
import { useAddField } from '../utils/useAddField';
|
|
35
25
|
|
|
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
|
-
formValues: mForm.values,
|
|
82
|
-
config: props.config,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
postOptions.data = body;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const res = await requestFunc(postOptions);
|
|
89
|
-
|
|
90
|
-
remoteData.value = res[option.root];
|
|
91
|
-
if (remoteData.value && typeof option?.item === 'function') {
|
|
92
|
-
options.value = option.item(res[option.root]);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// 初始化
|
|
97
|
-
if (typeof props.config.options === 'function' && props.model && mForm) {
|
|
98
|
-
watchEffect(
|
|
99
|
-
() =>
|
|
100
|
-
(options.value = (props.config.options as Function)(vm, { model: props.model, formValues: mForm.values })),
|
|
101
|
-
);
|
|
102
|
-
} else if (!props.config.options || !props.config.options.length || props.config.remote) {
|
|
103
|
-
Promise.resolve(setRemoteOptions());
|
|
26
|
+
const props = defineProps<{
|
|
27
|
+
config: CascaderConfig;
|
|
28
|
+
model: any;
|
|
29
|
+
initValues?: any;
|
|
30
|
+
values?: any;
|
|
31
|
+
name: string;
|
|
32
|
+
prop: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
size: 'mini' | 'small' | 'medium';
|
|
35
|
+
}>();
|
|
36
|
+
|
|
37
|
+
const emit = defineEmits(['change']);
|
|
38
|
+
|
|
39
|
+
const mForm = inject<FormState | null>('mForm');
|
|
40
|
+
|
|
41
|
+
useAddField(props.prop);
|
|
42
|
+
|
|
43
|
+
const requestFunc = getConfig('request') as Function;
|
|
44
|
+
|
|
45
|
+
const tMagicCascader = ref<InstanceType<typeof TMagicCascader>>();
|
|
46
|
+
|
|
47
|
+
const options = Array.isArray(props.config.options) ? ref(props.config.options) : ref([]);
|
|
48
|
+
const remoteData = ref<any>(null);
|
|
49
|
+
|
|
50
|
+
const setRemoteOptions = async function () {
|
|
51
|
+
const { config } = props;
|
|
52
|
+
const { option } = config;
|
|
53
|
+
if (!option) return;
|
|
54
|
+
let { body } = option;
|
|
55
|
+
|
|
56
|
+
const postOptions: Record<string, any> = {
|
|
57
|
+
url: option.url,
|
|
58
|
+
cache: option.cache,
|
|
59
|
+
timeout: option.timeout,
|
|
60
|
+
data: {},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (body && mForm) {
|
|
64
|
+
if (typeof body === 'function' && props.model && mForm) {
|
|
65
|
+
body = body(mForm, {
|
|
66
|
+
model: props.model,
|
|
67
|
+
formValue: mForm.values,
|
|
68
|
+
formValues: mForm.values,
|
|
69
|
+
config: props.config,
|
|
70
|
+
});
|
|
104
71
|
}
|
|
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
|
-
if (!cascader.value) return;
|
|
132
|
-
cascader.value.query = '';
|
|
133
|
-
cascader.value.previousQuery = null;
|
|
134
|
-
emit('change', value);
|
|
135
|
-
},
|
|
136
|
-
addHandler: () => {
|
|
137
|
-
if (!dialog.value) return;
|
|
138
|
-
dialog.value.dialogVisible = true;
|
|
139
|
-
},
|
|
140
|
-
editAfterAction: () => {
|
|
141
|
-
setRemoteOptions();
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
},
|
|
145
|
-
});
|
|
72
|
+
postOptions.data = body;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const res = await requestFunc(postOptions);
|
|
76
|
+
|
|
77
|
+
remoteData.value = res[option.root];
|
|
78
|
+
if (remoteData.value && typeof option?.item === 'function') {
|
|
79
|
+
options.value = option.item(res[option.root]);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// 初始化
|
|
84
|
+
if (typeof props.config.options === 'function' && props.model && mForm) {
|
|
85
|
+
watchEffect(
|
|
86
|
+
() => (options.value = (props.config.options as Function)(mForm, { model: props.model, formValues: mForm.values })),
|
|
87
|
+
);
|
|
88
|
+
} else if (!props.config.options || !props.config.options.length || props.config.remote) {
|
|
89
|
+
Promise.resolve(setRemoteOptions());
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const changeHandler = (value: any) => {
|
|
93
|
+
if (!tMagicCascader.value) return;
|
|
94
|
+
tMagicCascader.value.setQuery('');
|
|
95
|
+
tMagicCascader.value.setPreviousQuery(null);
|
|
96
|
+
emit('change', value);
|
|
97
|
+
};
|
|
146
98
|
</script>
|
package/src/fields/Checkbox.vue
CHANGED
|
@@ -1,67 +1,63 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<TMagicCheckbox
|
|
3
3
|
v-model="model[name]"
|
|
4
4
|
:size="size"
|
|
5
5
|
:trueLabel="activeValue"
|
|
6
6
|
:falseLabel="inactiveValue"
|
|
7
7
|
:disabled="disabled"
|
|
8
|
-
:label="config.text"
|
|
9
8
|
@change="changeHandler"
|
|
10
|
-
|
|
9
|
+
>{{ config.text }}</TMagicCheckbox
|
|
10
|
+
>
|
|
11
11
|
</template>
|
|
12
12
|
|
|
13
|
-
<script lang="ts">
|
|
14
|
-
import { computed
|
|
13
|
+
<script setup lang="ts" name="MFormCheckbox">
|
|
14
|
+
import { computed } from 'vue';
|
|
15
|
+
|
|
16
|
+
import { TMagicCheckbox } from '@tmagic/design';
|
|
15
17
|
|
|
16
18
|
import { CheckboxConfig } from '../schema';
|
|
17
|
-
import fieldProps from '../utils/fieldProps';
|
|
18
19
|
import { useAddField } from '../utils/useAddField';
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return undefined;
|
|
47
|
-
}),
|
|
48
|
-
|
|
49
|
-
inactiveValue: computed(() => {
|
|
50
|
-
if (typeof props.config.inactiveValue === 'undefined') {
|
|
51
|
-
if (props.config.filter === 'number') {
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
return props.config.inactiveValue;
|
|
56
|
-
}
|
|
21
|
+
const props = defineProps<{
|
|
22
|
+
config: CheckboxConfig;
|
|
23
|
+
model: any;
|
|
24
|
+
initValues?: any;
|
|
25
|
+
values?: any;
|
|
26
|
+
name: string;
|
|
27
|
+
prop: string;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
size: 'mini' | 'small' | 'medium';
|
|
30
|
+
}>();
|
|
31
|
+
|
|
32
|
+
const emit = defineEmits(['change']);
|
|
33
|
+
|
|
34
|
+
useAddField(props.prop);
|
|
35
|
+
|
|
36
|
+
const activeValue = computed(() => {
|
|
37
|
+
if (typeof props.config.activeValue === 'undefined') {
|
|
38
|
+
if (props.config.filter === 'number') {
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
return props.config.activeValue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return undefined;
|
|
46
|
+
});
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
const inactiveValue = computed(() => {
|
|
49
|
+
if (typeof props.config.inactiveValue === 'undefined') {
|
|
50
|
+
if (props.config.filter === 'number') {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
return props.config.inactiveValue;
|
|
55
|
+
}
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
emit('change', value);
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
},
|
|
57
|
+
return undefined;
|
|
66
58
|
});
|
|
59
|
+
|
|
60
|
+
const changeHandler = (value: number | boolean) => {
|
|
61
|
+
emit('change', value);
|
|
62
|
+
};
|
|
67
63
|
</script>
|