-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: 表单节点添加多选框,选项卡等组件 #1651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: 表单节点添加多选框,选项卡等组件 #1651
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
ui/src/components/dynamics-form/constructor/items/MultiSelectConstructor.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<template> | ||
<el-form-item> | ||
<template #label> | ||
<div class="flex-between"> | ||
选项值 | ||
<el-button link type="primary" @click.stop="addOption()"> | ||
<el-icon class="mr-4"> | ||
<Plus /> | ||
</el-icon> | ||
添加 | ||
</el-button> | ||
</div> | ||
</template> | ||
<el-row style="width: 100%" :gutter="10"> | ||
<el-col :span="10" | ||
><div class="grid-content ep-bg-purple" /> | ||
标签</el-col | ||
> | ||
<el-col :span="12" | ||
><div class="grid-content ep-bg-purple" /> | ||
选项值</el-col | ||
> | ||
</el-row> | ||
<el-row | ||
style="width: 100%" | ||
v-for="(option, $index) in formValue.option_list" | ||
:key="$index" | ||
:gutter="10" | ||
> | ||
<el-col :span="10" | ||
><div class="grid-content ep-bg-purple" /> | ||
<el-input v-model="formValue.option_list[$index].label" placeholder="请输入选项标签" | ||
/></el-col> | ||
<el-col :span="12" | ||
><div class="grid-content ep-bg-purple" /> | ||
<el-input v-model="formValue.option_list[$index].value" placeholder="请输入选项值" | ||
/></el-col> | ||
<el-col :span="1" | ||
><div class="grid-content ep-bg-purple" /> | ||
<el-button link class="ml-8" @click.stop="delOption($index)"> | ||
<el-icon> | ||
<Delete /> | ||
</el-icon> </el-button | ||
></el-col> | ||
</el-row> | ||
</el-form-item> | ||
<el-form-item | ||
label="默认值" | ||
:required="formValue.required" | ||
prop="default_value" | ||
:rules="formValue.required ? [{ required: true, message: '默认值 为必填属性' }] : []" | ||
> | ||
<el-select | ||
class="m-2" | ||
multiple | ||
collapse-tags | ||
filterable | ||
clearable | ||
v-model="formValue.default_value" | ||
:teleported="false" | ||
popper-class="default-select" | ||
> | ||
<el-option | ||
v-for="(option, index) in formValue.option_list" | ||
:key="index" | ||
:label="option.value" | ||
:value="option.value" | ||
/> | ||
</el-select> | ||
</el-form-item> | ||
</template> | ||
<script setup lang="ts"> | ||
import { computed, onMounted } from 'vue' | ||
|
||
const props = defineProps<{ | ||
modelValue: any | ||
}>() | ||
const emit = defineEmits(['update:modelValue']) | ||
const formValue = computed({ | ||
set: (item) => { | ||
emit('update:modelValue', item) | ||
}, | ||
get: () => { | ||
return props.modelValue | ||
} | ||
}) | ||
|
||
const addOption = () => { | ||
formValue.value.option_list.push({ value: '', label: '' }) | ||
} | ||
|
||
const delOption = (index: number) => { | ||
const option = formValue.value.option_list[index] | ||
if (option.value && formValue.value.default_value == option.value) { | ||
formValue.value.default_value = '' | ||
} | ||
formValue.value.option_list.splice(index, 1) | ||
} | ||
|
||
const getData = () => { | ||
return { | ||
input_type: 'MultiSelect', | ||
attrs: {}, | ||
default_value: formValue.value.default_value, | ||
textField: 'label', | ||
valueField: 'value', | ||
option_list: formValue.value.option_list | ||
} | ||
} | ||
const rander = (form_data: any) => { | ||
formValue.value.option_list = form_data.option_list || [] | ||
formValue.value.default_value = form_data.default_value | ||
} | ||
|
||
defineExpose({ getData, rander }) | ||
onMounted(() => { | ||
formValue.value.option_list = [] | ||
formValue.value.default_value = '' | ||
}) | ||
</script> | ||
<style lang="scss" scoped> | ||
:deep(.el-form-item__label) { | ||
display: block; | ||
} | ||
|
||
:deep(.el-select-dropdown) { | ||
max-width: 400px; | ||
} | ||
</style> | ||
122 changes: 122 additions & 0 deletions
122
ui/src/components/dynamics-form/constructor/items/RadioCardConstructor.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<template> | ||
<el-form-item> | ||
<template #label> | ||
<div class="flex-between"> | ||
选项值 | ||
<el-button link type="primary" @click.stop="addOption()"> | ||
<el-icon class="mr-4"> | ||
<Plus /> | ||
</el-icon> | ||
添加 | ||
</el-button> | ||
</div> | ||
</template> | ||
|
||
<el-row style="width: 100%" :gutter="10"> | ||
<el-col :span="10" | ||
><div class="grid-content ep-bg-purple" /> | ||
标签</el-col | ||
> | ||
<el-col :span="12" | ||
><div class="grid-content ep-bg-purple" /> | ||
选项值</el-col | ||
> | ||
</el-row> | ||
<el-row | ||
style="width: 100%" | ||
v-for="(option, $index) in formValue.option_list" | ||
:key="$index" | ||
:gutter="10" | ||
> | ||
<el-col :span="10" | ||
><div class="grid-content ep-bg-purple" /> | ||
<el-input v-model="formValue.option_list[$index].label" placeholder="请输入选项标签" | ||
/></el-col> | ||
<el-col :span="12" | ||
><div class="grid-content ep-bg-purple" /> | ||
<el-input v-model="formValue.option_list[$index].value" placeholder="请输入选项值" | ||
/></el-col> | ||
<el-col :span="1" | ||
><div class="grid-content ep-bg-purple" /> | ||
<el-button link class="ml-8" @click.stop="delOption($index)"> | ||
<el-icon> | ||
<Delete /> | ||
</el-icon> </el-button | ||
></el-col> | ||
</el-row> | ||
</el-form-item> | ||
<el-form-item | ||
label="默认值" | ||
:required="formValue.required" | ||
prop="default_value" | ||
:rules="formValue.required ? [{ required: true, message: '默认值 为必填属性' }] : []" | ||
> | ||
<RadioCard | ||
:form-field="formField" | ||
v-model="formValue.default_value" | ||
:other-params="{}" | ||
field="default_value" | ||
> | ||
</RadioCard> | ||
</el-form-item> | ||
</template> | ||
<script setup lang="ts"> | ||
import { computed, onMounted } from 'vue' | ||
import RadioCard from '@/components/dynamics-form/items/radio/RadioCard.vue' | ||
const props = defineProps<{ | ||
modelValue: any | ||
}>() | ||
const emit = defineEmits(['update:modelValue']) | ||
const formValue = computed({ | ||
set: (item) => { | ||
emit('update:modelValue', item) | ||
}, | ||
get: () => { | ||
return props.modelValue | ||
} | ||
}) | ||
|
||
const addOption = () => { | ||
formValue.value.option_list.push({ value: '', label: '' }) | ||
} | ||
|
||
const delOption = (index: number) => { | ||
const option = formValue.value.option_list[index] | ||
if (option.value && formValue.value.default_value == option.value) { | ||
formValue.value.default_value = '' | ||
} | ||
formValue.value.option_list.splice(index, 1) | ||
} | ||
const formField = computed(() => { | ||
return getData() | ||
}) | ||
const getData = () => { | ||
return { | ||
input_type: 'RadioCard', | ||
attrs: {}, | ||
default_value: formValue.value.default_value, | ||
text_field: 'label', | ||
value_field: 'value', | ||
option_list: formValue.value.option_list | ||
} | ||
} | ||
const rander = (form_data: any) => { | ||
formValue.value.option_list = form_data.option_list || [] | ||
formValue.value.default_value = form_data.default_value | ||
} | ||
|
||
defineExpose({ getData, rander }) | ||
onMounted(() => { | ||
formValue.value.option_list = [] | ||
formValue.value.default_value = '' | ||
}) | ||
</script> | ||
<style lang="scss" scoped> | ||
:deep(.el-form-item__label) { | ||
display: block; | ||
} | ||
|
||
:deep(.el-select-dropdown) { | ||
max-width: 400px; | ||
} | ||
</style> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个代码是一个 Vue 库的一部分,但缺少必要的注释和版本信息以保证其质量。它提供了一个动态表单组件,包含选项输入框(用于添加或删除标签)和一个默认值输入框。 主要问题:
为了改进:
由于缺乏上下文中描述的情况细节,以上只是一些基本改进建议。 在实际应用中,请参考其他社区论坛的经验分享或者官方文档来帮助完善这部分代码。 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段模板代码看起来基本符合规范,并且在一些细节上做了很好的设计和准备。没有发现明显的问题或需要改进的地方。
但是,如果你想要对样式做一些更改以使其更易于阅读,请告诉我你的具体要求,我可以帮助你调整样式规则。
总之,这是一个不错的开始点。如果有任何问题,尽管提出!