From d6749f95c526c0e71ec946bd3bb777bc42b2c34a Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期日, 20 十月 2024 17:59:31 +0800 Subject: [PATCH] 工艺绑定优化 --- src/components/Form/src/components/RadioButtonGroup.vue | 83 +++++++++++++++++++---------------------- 1 files changed, 38 insertions(+), 45 deletions(-) diff --git a/src/components/Form/src/components/RadioButtonGroup.vue b/src/components/Form/src/components/RadioButtonGroup.vue index 698635e..fe9a12c 100644 --- a/src/components/Form/src/components/RadioButtonGroup.vue +++ b/src/components/Form/src/components/RadioButtonGroup.vue @@ -2,62 +2,55 @@ * @Description:It is troublesome to implement radio button group in the form. So it is extracted independently as a separate component --> <template> - <RadioGroup v-bind="attrs" v-model:value="state" button-style="solid"> + <Radio.Group v-bind="attrs" v-model:value="state" button-style="solid"> <template v-for="item in getOptions" :key="`${item.value}`"> - <RadioButton :value="item.value" :disabled="item.disabled" @click="handleClick(item)"> + <Radio.Button :value="item.value" :disabled="item.disabled" @click="handleClick(item)"> {{ item.label }} - </RadioButton> + </Radio.Button> </template> - </RadioGroup> + </Radio.Group> </template> -<script lang="ts"> - import { defineComponent, PropType, computed, ref } from 'vue'; +<script lang="ts" setup> + import { PropType, computed, ref } from 'vue'; import { Radio } from 'ant-design-vue'; - import { isString } from '/@/utils/is'; - import { useRuleFormItem } from '/@/hooks/component/useFormItem'; + import { isString } from '@/utils/is'; + import { useRuleFormItem } from '@/hooks/component/useFormItem'; import { useAttrs } from '@vben/hooks'; type OptionsItem = { label: string; value: string | number | boolean; disabled?: boolean }; type RadioItem = string | OptionsItem; - export default defineComponent({ - name: 'RadioButtonGroup', - components: { - RadioGroup: Radio.Group, - RadioButton: Radio.Button, + defineOptions({ name: 'RadioButtonGroup' }); + + const props = defineProps({ + value: { + type: [String, Number, Boolean] as PropType<string | number | boolean>, }, - props: { - value: { - type: [String, Number, Boolean] as PropType<string | number | boolean>, - }, - options: { - type: Array as PropType<RadioItem[]>, - default: () => [], - }, - }, - emits: ['change'], - setup(props) { - const attrs = useAttrs(); - const emitData = ref<any[]>([]); - // Embedded in the form, just use the hook binding to perform form verification - const [state] = useRuleFormItem(props, 'value', 'change', emitData); - - // Processing options value - const getOptions = computed((): OptionsItem[] => { - const { options } = props; - if (!options || options?.length === 0) return []; - - const isStringArr = options.some((item) => isString(item)); - if (!isStringArr) return options as OptionsItem[]; - - return options.map((item) => ({ label: item, value: item })) as OptionsItem[]; - }); - - function handleClick(...args) { - emitData.value = args; - } - - return { state, getOptions, attrs, handleClick }; + options: { + type: Array as PropType<RadioItem[]>, + default: () => [], }, }); + + // const emit = defineEmits(['change']); + + const attrs = useAttrs(); + const emitData = ref<any[]>([]); + // Embedded in the form, just use the hook binding to perform form verification + const [state] = useRuleFormItem(props, 'value', 'change', emitData); + + // Processing options value + const getOptions = computed((): OptionsItem[] => { + const { options } = props; + if (!options || options?.length === 0) return []; + + const isStringArr = options.some((item) => isString(item)); + if (!isStringArr) return options as OptionsItem[]; + + return options.map((item) => ({ label: item, value: item })) as OptionsItem[]; + }); + + function handleClick(...args) { + emitData.value = args; + } </script> -- Gitblit v1.9.3