Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3bf5ceae
authored
Mar 23, 2026
by
yancanhua
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 自定义表单
1 parent
108119a9
Pipeline
#73
for
3bf5ceae
failed
in 0 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
250 additions
and
1 deletions
apps/web/venus-usedcar-quality/src/components/CustomizeForm/Index.vue
apps/web/venus-usedcar-quality/src/components/CustomizeForm/selectDatePicker.vue
apps/web/venus-usedcar-quality/src/components/CustomizeForm/selectDropdown.vue
apps/web/venus-usedcar-quality/src/components/CustomizeForm/Index.vue
View file @
3bf5cea
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
ref
}
from
"vue"
;
import
selectDatePicker
from
"@/components/CustomizeForm/selectDatePicker.vue"
;
import
selectDropdown
from
"@/components/CustomizeForm/selectDropdown.vue"
;
// 获取父组件传递的model
const
props
=
defineProps
({
model
:
{
type
:
Array
,
default
:
()
=>
[],
},
});
const
form
=
ref
({});
const
rules
=
ref
({});
async
function
validate
()
{
return
{
data
:
formList
.
value
,
message
:
"操作成功"
,
success
:
true
,
};
}
const
formList
=
ref
([
{
interactionType
:
"text_input"
,
required
:
1
,
nodeName
:
"输入框"
,
placeholder
:
"请输入"
,
value
:
""
,
maxCount
:
10
,
},
{
interactionType
:
"textarea_input"
,
required
:
1
,
nodeName
:
"备注"
,
placeholder
:
"请输入"
,
value
:
"123131"
,
maxCount
:
50
,
},
{
interactionType
:
"number_input"
,
required
:
1
,
nodeName
:
"数字输入框"
,
placeholder
:
"请输入"
,
value
:
"12313"
,
maxCount
:
50
,
},
{
interactionType
:
"date_picker"
,
required
:
1
,
nodeName
:
"日期选择器"
,
placeholder
:
"请选择日期"
,
value
:
""
,
maxCount
:
50
,
},
{
interactionType
:
"dropdown"
,
required
:
1
,
nodeName
:
"下拉选择器"
,
placeholder
:
"请选择"
,
value
:
""
,
maxCount
:
50
,
},
]);
defineExpose
({
validate
,
});
</
script
>
</
script
>
<
template
>
<
template
>
<div>
<div>
自定义组件
<van-form
ref=
"customizeFormRef"
:model=
"form"
:rules=
"rules"
>
<div
v-for=
"(item, index) in formList"
:key=
"index"
:class=
"
{ 'border-bottom': index
< formList
.
length
-
1
}"
>
<!-- 文本输入框 -->
<div
v-if=
"item.interactionType == 'text_input'"
>
<van-field
v-model=
"item.value"
clearable
:label=
"item.nodeName"
:maxlength=
"item.maxCount"
:placeholder=
"item.placeholder"
:required=
"item.required === 1"
/>
</div>
<!-- 长文本输入框 -->
<div
v-if=
"item.interactionType == 'textarea_input'"
>
<van-field
v-model=
"item.value"
autosize
:label=
"item.nodeName"
:maxlength=
"item.maxCount"
clearable
:placeholder=
"item.placeholder"
:required=
"item.required === 1"
rows=
"2"
show-word-limit
type=
"textarea"
/>
</div>
<!-- 数字输入框 -->
<div
v-if=
"item.interactionType == 'number_input'"
>
<van-field
v-model=
"item.value"
:label=
"item.nodeName"
clearable
:maxlength=
"item.maxCount"
:placeholder=
"item.placeholder"
:required=
"item.required === 1"
type=
"number"
/>
</div>
<!-- 日期选择器 -->
<div
v-if=
"item.interactionType == 'date_picker'"
>
<selectDatePicker
:item=
"item"
:value=
"item.value"
@
update=
"item.value = $event"
/>
</div>
<!-- 下拉选择器 -->
<div
v-if=
"item.interactionType == 'dropdown'"
>
<selectDropdown
:item=
"item"
:value=
"item.value"
@
update=
"item.value = $event"
/>
</div>
</div>
</van-form>
</div>
</div>
</
template
>
</
template
>
...
...
apps/web/venus-usedcar-quality/src/components/CustomizeForm/selectDatePicker.vue
0 → 100644
View file @
3bf5cea
<
script
setup
lang=
"ts"
>
import
{
ref
}
from
"vue"
;
const
props
=
defineProps
({
item
:
{
type
:
Object
,
default
:
()
=>
{},
},
});
const
emit
=
defineEmits
([
"update"
]);
const
showPicker
=
ref
(
false
);
const
pickerValue
=
ref
([]);
function
handleShowPicker
()
{
showPicker
.
value
=
true
;
if
(
!
props
.
item
.
value
)
{
const
date
=
new
Date
();
pickerValue
.
value
=
[
date
.
getFullYear
(),
date
.
getMonth
()
+
1
,
date
.
getDate
()];
}
}
function
onConfirm
()
{
let
picker
=
""
;
if
(
pickerValue
.
value
.
length
>
0
)
{
picker
=
pickerValue
.
value
.
join
(
"-"
);
}
showPicker
.
value
=
false
;
props
.
item
.
value
=
picker
;
emit
(
"update"
,
picker
);
}
</
script
>
<
template
>
<div>
<van-field
v-model=
"item.value"
clearable
is-link
:label=
"item.nodeName"
name=
"datePicker"
:placeholder=
"item.placeholder"
readonly
:required=
"item.required === 1"
@
click=
"handleShowPicker"
/>
<van-popup
v-model:show=
"showPicker"
destroy-on-close
position=
"bottom"
>
<van-date-picker
v-model=
"pickerValue"
:title=
"item.nodeName"
@
cancel=
"showPicker = false"
@
confirm=
"onConfirm"
/>
</van-popup>
</div>
</
template
>
<
style
lang=
"scss"
scoped
></
style
>
apps/web/venus-usedcar-quality/src/components/CustomizeForm/selectDropdown.vue
0 → 100644
View file @
3bf5cea
<
script
setup
lang=
"ts"
>
import
{
computed
,
ref
}
from
"vue"
;
const
props
=
defineProps
({
item
:
{
type
:
Object
,
default
:
()
=>
{},
},
});
const
emit
=
defineEmits
([
"update"
]);
const
showPicker
=
ref
(
false
);
const
pickerValue
=
ref
([]);
const
columns
=
[
{
text
:
"杭州"
,
value
:
"杭州"
},
{
text
:
"宁波"
,
value
:
"宁波"
},
{
text
:
"温州"
,
value
:
"温州"
},
{
text
:
"绍兴"
,
value
:
"绍兴"
},
{
text
:
"湖州"
,
value
:
"湖州"
},
];
// 计算属性
const
columnsList
=
computed
(()
=>
{
return
columns
;
});
function
onConfirm
()
{
const
picker
=
pickerValue
.
value
&&
pickerValue
.
value
.
length
>
0
?
pickerValue
.
value
[
0
]
:
""
;
showPicker
.
value
=
false
;
props
.
item
.
value
=
picker
;
emit
(
"update"
,
picker
);
}
</
script
>
<
template
>
<div>
<van-field
v-model=
"item.value"
clearable
is-link
:label=
"item.nodeName"
name=
"datePicker"
:placeholder=
"item.placeholder"
readonly
:required=
"item.required === 1"
@
click=
"showPicker = true"
/>
<van-popup
v-model:show=
"showPicker"
destroy-on-close
position=
"bottom"
>
<van-picker
v-model=
"pickerValue"
:columns=
"columnsList"
:title=
"item.nodeName"
@
cancel=
"showPicker = false"
@
confirm=
"onConfirm"
/>
</van-popup>
</div>
</
template
>
<
style
lang=
"scss"
scoped
></
style
>
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment