Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2022-08-30 11:45:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
abe0a51ed56de7bdc9c7d95b4cfa1ed56c93c70e
abe0a51e
1 parent
ce75ea39
✨ feat: 新增单选框组件
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
7 deletions
src/components/RadioField/index.vue
src/hooks/useComponentType.js
src/views/index.vue
src/components/RadioField/index.vue
0 → 100644
View file @
abe0a51
<!--
* @Date: 2022-08-30 11:34:19
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-08-30 11:42:03
* @FilePath: /data-table/src/components/RadioField/index.vue
* @Description: 文件描述
-->
<template>
<div class="radio-field-page">
<div class="label">{{ item.label }}<span v-if="item.required"> *</span></div>
<van-field :name="item.key">
<template #input>
<van-radio-group v-model="item.value">
<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>
</van-radio-group>
</template>
</van-field>
</div>
</template>
<script setup>
const props = defineProps({
item: Object
})
</script>
<style lang="less" scoped>
.radio-field-page {
.label {
padding: 1rem 1rem 0 1rem;
font-size: 0.9rem;
font-weight: bold;
span {
color: red;
}
}
}
</style>
src/hooks/useComponentType.js
View file @
abe0a51
...
...
@@ -2,12 +2,14 @@ import _ from 'lodash'
import
TableField
from
'@/components/TableField/index.vue'
import
TextField
from
'@/components/TextField/index.vue'
import
TextareaField
from
'@/components/TextareaField/index.vue'
import
RadioField
from
'@/components/RadioField/index.vue'
/**
* 生成自定义组件类型
* @param {*} data
* @type text 单行文本 TextField
* @type textarea 多行文本 TextareaField
* @type radio 单选框 RadioField
*/
export
function
createComponentType
(
data
)
{
// 判断类型和使用组件
...
...
@@ -28,10 +30,14 @@ export function createComponentType(data) {
item
.
autosize
=
true
;
item
.
component
=
TextareaField
;
}
// // 单选框
// if (item.component_type === 'radio') {
// item.name = 'radio';
// item.component = TableField;
// }
if
(
item
.
component_type
===
'number'
)
{
item
.
type
=
'number'
;
item
.
name
=
item
.
key
;
item
.
component
=
TextField
;
}
if
(
item
.
component_type
===
'radio'
)
{
item
.
name
=
'radio'
;
item
.
component
=
RadioField
;
}
})
}
...
...
src/views/index.vue
View file @
abe0a51
<!--
* @Date: 2022-07-18 10:22:22
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-08-30 1
0:35:45
* @LastEditTime: 2022-08-30 1
1:11:50
* @FilePath: /data-table/src/views/index.vue
* @Description: 首页
-->
...
...
@@ -42,7 +42,7 @@ onMounted(() => {
label: '年龄',
placeholder: '请输入年龄',
component: '',
component_type: '
text
',
component_type: '
number
',
required: false,
}, {
key: 'gender',
...
...
Please
register
or
login
to post a comment