Showing
4 changed files
with
62 additions
and
5 deletions
src/components/CheckboxField/index.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2022-08-30 11:34:19 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-08-30 13:29:43 | ||
| 5 | + * @FilePath: /data-table/src/components/CheckboxField/index.vue | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div class="checkbox-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-checkbox-group v-model="item.value"> | ||
| 14 | + <van-checkbox v-for="x in item.sub" :key="index" :name="x.key" icon-size="1rem" shape="square" | ||
| 15 | + style="margin-bottom: 0.25rem;">{{ x.value }}</van-checkbox> | ||
| 16 | + </van-checkbox-group> | ||
| 17 | + </template> | ||
| 18 | + </van-field> | ||
| 19 | + </div> | ||
| 20 | +</template> | ||
| 21 | + | ||
| 22 | +<script setup> | ||
| 23 | +const props = defineProps({ | ||
| 24 | + item: Object | ||
| 25 | +}) | ||
| 26 | +</script> | ||
| 27 | + | ||
| 28 | +<style lang="less" scoped> | ||
| 29 | +.checkbox-field-page { | ||
| 30 | + .label { | ||
| 31 | + padding: 1rem 1rem 0 1rem; | ||
| 32 | + font-size: 0.9rem; | ||
| 33 | + font-weight: bold; | ||
| 34 | + span { | ||
| 35 | + color: red; | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | +} | ||
| 39 | +</style> |
| ... | @@ -3,6 +3,7 @@ import TableField from '@/components/TableField/index.vue' | ... | @@ -3,6 +3,7 @@ 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 | import RadioField from '@/components/RadioField/index.vue' |
| 6 | +import CheckboxField from '@/components/CheckboxField/index.vue' | ||
| 6 | 7 | ||
| 7 | /** | 8 | /** |
| 8 | * 生成自定义组件类型 | 9 | * 生成自定义组件类型 |
| ... | @@ -10,6 +11,7 @@ import RadioField from '@/components/RadioField/index.vue' | ... | @@ -10,6 +11,7 @@ import RadioField from '@/components/RadioField/index.vue' |
| 10 | * @type text 单行文本 TextField | 11 | * @type text 单行文本 TextField |
| 11 | * @type textarea 多行文本 TextareaField | 12 | * @type textarea 多行文本 TextareaField |
| 12 | * @type radio 单选框 RadioField | 13 | * @type radio 单选框 RadioField |
| 14 | + * @type checkbox 多选框 CheckboxField | ||
| 13 | */ | 15 | */ |
| 14 | export function createComponentType(data) { | 16 | export function createComponentType(data) { |
| 15 | // 判断类型和使用组件 | 17 | // 判断类型和使用组件 |
| ... | @@ -36,8 +38,10 @@ export function createComponentType(data) { | ... | @@ -36,8 +38,10 @@ export function createComponentType(data) { |
| 36 | item.component = TextField; | 38 | item.component = TextField; |
| 37 | } | 39 | } |
| 38 | if (item.component_type === 'radio') { | 40 | if (item.component_type === 'radio') { |
| 39 | - item.name = 'radio'; | ||
| 40 | item.component = RadioField; | 41 | item.component = RadioField; |
| 41 | } | 42 | } |
| 43 | + if (item.component_type === 'checkbox') { | ||
| 44 | + item.component = CheckboxField; | ||
| 45 | + } | ||
| 42 | }) | 46 | }) |
| 43 | } | 47 | } | ... | ... |
| ... | @@ -2,12 +2,12 @@ | ... | @@ -2,12 +2,12 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-31 12:06:19 | 3 | * @Date: 2022-05-31 12:06:19 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2022-08-29 16:44:15 | 5 | + * @LastEditTime: 2022-08-30 13:21:07 |
| 6 | * @FilePath: /data-table/src/main.js | 6 | * @FilePath: /data-table/src/main.js |
| 7 | * @Description: | 7 | * @Description: |
| 8 | */ | 8 | */ |
| 9 | import { createApp } from 'vue'; | 9 | import { createApp } from 'vue'; |
| 10 | -import { Button, Image as VanImage, Col, Row, Icon, Form, Field, CellGroup, ConfigProvider, Toast, Uploader, Empty, Tab, Tabs, Overlay, NumberKeyboard, Lazyload, List, PullRefresh, Popup, Picker, Sticky, Stepper, Tag, Swipe, SwipeItem, Dialog, ActionSheet, Loading, Checkbox, Search, NavBar, Collapse, CollapseItem, RadioGroup, Radio } from 'vant'; | 10 | +import { Button, Image as VanImage, Col, Row, Icon, Form, Field, CellGroup, ConfigProvider, Toast, Uploader, Empty, Tab, Tabs, Overlay, NumberKeyboard, Lazyload, List, PullRefresh, Popup, Picker, Sticky, Stepper, Tag, Swipe, SwipeItem, Dialog, ActionSheet, Loading, Checkbox, Search, NavBar, Collapse, CollapseItem, RadioGroup, Radio, CheckboxGroup } from 'vant'; |
| 11 | import router from './router'; | 11 | import router from './router'; |
| 12 | import App from './App.vue'; | 12 | import App from './App.vue'; |
| 13 | // import axios from './utils/axios'; | 13 | // import axios from './utils/axios'; |
| ... | @@ -23,6 +23,6 @@ app.config.warnHandler = () => null; | ... | @@ -23,6 +23,6 @@ app.config.warnHandler = () => null; |
| 23 | 23 | ||
| 24 | app.config.globalProperties.$http = axios; // 关键语句 | 24 | app.config.globalProperties.$http = axios; // 关键语句 |
| 25 | 25 | ||
| 26 | -app.use(pinia).use(router).use(Button).use(VanImage).use(Col).use(Row).use(Icon).use(Form).use(Field).use(CellGroup).use(Toast).use(Uploader).use(Empty).use(Tab).use(Tabs).use(Overlay).use(NumberKeyboard).use(Lazyload).use(List).use(PullRefresh).use(Popup).use(Picker).use(Sticky).use(Stepper).use(Tag).use(Swipe).use(SwipeItem).use(Dialog).use(ActionSheet).use(Loading).use(Checkbox).use(Search).use(ConfigProvider).use(NavBar).use(Collapse).use(CollapseItem).use(Radio).use(RadioGroup); | 26 | +app.use(pinia).use(router).use(Button).use(VanImage).use(Col).use(Row).use(Icon).use(Form).use(Field).use(CellGroup).use(Toast).use(Uploader).use(Empty).use(Tab).use(Tabs).use(Overlay).use(NumberKeyboard).use(Lazyload).use(List).use(PullRefresh).use(Popup).use(Picker).use(Sticky).use(Stepper).use(Tag).use(Swipe).use(SwipeItem).use(Dialog).use(ActionSheet).use(Loading).use(Checkbox).use(Search).use(ConfigProvider).use(NavBar).use(Collapse).use(CollapseItem).use(Radio).use(RadioGroup).use(CheckboxGroup); |
| 27 | 27 | ||
| 28 | app.mount('#app'); | 28 | app.mount('#app'); | ... | ... |
| 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 11:11:50 | 4 | + * @LastEditTime: 2022-08-30 13:28:54 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -59,6 +59,20 @@ onMounted(() => { | ... | @@ -59,6 +59,20 @@ onMounted(() => { |
| 59 | value: '女' | 59 | value: '女' |
| 60 | }] | 60 | }] |
| 61 | }, { | 61 | }, { |
| 62 | + key: 'hobby', | ||
| 63 | + value: [], | ||
| 64 | + label: '兴趣爱好', | ||
| 65 | + placeholder: '', | ||
| 66 | + component: '', | ||
| 67 | + component_type: 'checkbox', | ||
| 68 | + sub: [{ | ||
| 69 | + key: 'football', | ||
| 70 | + value: '足球' | ||
| 71 | + }, { | ||
| 72 | + key: 'basketball', | ||
| 73 | + value: '篮球' | ||
| 74 | + }] | ||
| 75 | + }, { | ||
| 62 | key: 'message', | 76 | key: 'message', |
| 63 | value: 'zzz', | 77 | value: 'zzz', |
| 64 | label: '留言', | 78 | label: '留言', | ... | ... |
-
Please register or login to post a comment