Showing
3 changed files
with
51 additions
and
7 deletions
src/components/RadioField/index.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2022-08-30 11:34:19 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-08-30 11:42:03 | ||
| 5 | + * @FilePath: /data-table/src/components/RadioField/index.vue | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div class="radio-field-page"> | ||
| 10 | + <div class="label">{{ item.label }}<span v-if="item.required"> *</span></div> | ||
| 11 | + <van-field :name="item.key"> | ||
| 12 | + <template #input> | ||
| 13 | + <van-radio-group v-model="item.value"> | ||
| 14 | + <van-radio v-for="x in item.sub" :key="index" :name="x.key" icon-size="1rem" style="margin-bottom: 0.25rem;">{{ x.value }}</van-radio> | ||
| 15 | + </van-radio-group> | ||
| 16 | + </template> | ||
| 17 | + </van-field> | ||
| 18 | + </div> | ||
| 19 | +</template> | ||
| 20 | + | ||
| 21 | +<script setup> | ||
| 22 | +const props = defineProps({ | ||
| 23 | + item: Object | ||
| 24 | +}) | ||
| 25 | +</script> | ||
| 26 | + | ||
| 27 | +<style lang="less" scoped> | ||
| 28 | +.radio-field-page { | ||
| 29 | + .label { | ||
| 30 | + padding: 1rem 1rem 0 1rem; | ||
| 31 | + font-size: 0.9rem; | ||
| 32 | + font-weight: bold; | ||
| 33 | + span { | ||
| 34 | + color: red; | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | +} | ||
| 38 | +</style> |
| ... | @@ -2,12 +2,14 @@ import _ from 'lodash' | ... | @@ -2,12 +2,14 @@ import _ from 'lodash' |
| 2 | import TableField from '@/components/TableField/index.vue' | 2 | import TableField from '@/components/TableField/index.vue' |
| 3 | import TextField from '@/components/TextField/index.vue' | 3 | import TextField from '@/components/TextField/index.vue' |
| 4 | import TextareaField from '@/components/TextareaField/index.vue' | 4 | import TextareaField from '@/components/TextareaField/index.vue' |
| 5 | +import RadioField from '@/components/RadioField/index.vue' | ||
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| 7 | * 生成自定义组件类型 | 8 | * 生成自定义组件类型 |
| 8 | * @param {*} data | 9 | * @param {*} data |
| 9 | * @type text 单行文本 TextField | 10 | * @type text 单行文本 TextField |
| 10 | * @type textarea 多行文本 TextareaField | 11 | * @type textarea 多行文本 TextareaField |
| 12 | + * @type radio 单选框 RadioField | ||
| 11 | */ | 13 | */ |
| 12 | export function createComponentType(data) { | 14 | export function createComponentType(data) { |
| 13 | // 判断类型和使用组件 | 15 | // 判断类型和使用组件 |
| ... | @@ -28,10 +30,14 @@ export function createComponentType(data) { | ... | @@ -28,10 +30,14 @@ export function createComponentType(data) { |
| 28 | item.autosize = true; | 30 | item.autosize = true; |
| 29 | item.component = TextareaField; | 31 | item.component = TextareaField; |
| 30 | } | 32 | } |
| 31 | - // // 单选框 | 33 | + if (item.component_type === 'number') { |
| 32 | - // if (item.component_type === 'radio') { | 34 | + item.type = 'number'; |
| 33 | - // item.name = 'radio'; | 35 | + item.name = item.key; |
| 34 | - // item.component = TableField; | 36 | + item.component = TextField; |
| 35 | - // } | 37 | + } |
| 38 | + if (item.component_type === 'radio') { | ||
| 39 | + item.name = 'radio'; | ||
| 40 | + item.component = RadioField; | ||
| 41 | + } | ||
| 36 | }) | 42 | }) |
| 37 | } | 43 | } | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-07-18 10:22:22 | 2 | * @Date: 2022-07-18 10:22:22 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2022-08-30 10:35:45 | 4 | + * @LastEditTime: 2022-08-30 11:11:50 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -42,7 +42,7 @@ onMounted(() => { | ... | @@ -42,7 +42,7 @@ onMounted(() => { |
| 42 | label: '年龄', | 42 | label: '年龄', |
| 43 | placeholder: '请输入年龄', | 43 | placeholder: '请输入年龄', |
| 44 | component: '', | 44 | component: '', |
| 45 | - component_type: 'text', | 45 | + component_type: 'number', |
| 46 | required: false, | 46 | required: false, |
| 47 | }, { | 47 | }, { |
| 48 | key: 'gender', | 48 | key: 'gender', | ... | ... |
-
Please register or login to post a comment