1+ import { useGlobalProperties } from "@/hooks/useGlobalProperties" ;
2+ import { createEditorColorProp , createEditorInputNumberProp , createEditorInputProp , createEditorModelBindProp , createEditorSwitchProp } from "@/utils/visual-editor-props" ;
3+ import { Field , Rate } from "vant" ;
4+ import { createFieldProps } from "../createFieldProps" ;
5+
6+ export default {
7+ key : 'rate' ,
8+ moduleName : 'baseWidgets' ,
9+ label : '评分' ,
10+ preview : ( ) => (
11+ < Field
12+ name = "rate"
13+ v-slots = { { input : ( ) => < Rate modelValue = { 3 } /> } }
14+ > </ Field >
15+ ) ,
16+ render : ( { styles, block, props } ) => {
17+ const { registerRef } = useGlobalProperties ( )
18+ let rules = [ ]
19+ try {
20+ rules = JSON . parse ( props . rules )
21+ } catch ( e ) { }
22+
23+ return ( ) => (
24+ < div style = { styles } >
25+ < Field
26+ { ...props }
27+ modelValue = { '' }
28+ name = { Array . isArray ( props . name ) ? [ ...props . name ] . pop ( ) : props . name }
29+ v-slots = { {
30+ input : ( ) => (
31+ < Rate
32+ ref = { ( el ) => registerRef ( el , block . _vid ) }
33+ { ...props }
34+ v-model = { props . modelValue }
35+ > </ Rate >
36+ ) ,
37+ } }
38+ />
39+ </ div >
40+ )
41+ } ,
42+ props : {
43+ modelValue : createEditorInputNumberProp ( { label : '当前分值' , defaultValue : 3 } ) ,
44+ gutter : createEditorModelBindProp ( { label : '图标间距' , defaultValue : '4px' } ) ,
45+ size : createEditorInputProp ( { label : '图标大小' , defaultValue : '20px' } ) ,
46+ count : createEditorInputNumberProp ( { label : '图标总数' , defaultValue : 5 } ) ,
47+ label : createEditorInputProp ( { label : '输入框左侧文本' , defaultValue : '评分' } ) ,
48+ color : createEditorColorProp ( { label : '选中时的颜色' , defaultValue : '#ee0a24' } ) ,
49+ voidColor : createEditorColorProp ( { label : '未选中时的颜色' , defaultValue : '#c8c9cc' } ) ,
50+ disabledColor : createEditorColorProp ( { label : '选中时的颜色' , defaultValue : '#c8c9c' } ) ,
51+ icon :createEditorInputProp ( { label : '选中时的图标名称或图片链接' , defaultValue : 'star' } ) ,
52+ voidIcon : createEditorInputProp ( { label : '未选中时的图标名称或图片链接' , defaultValue : 'star-o' } ) ,
53+ iconPrefix : createEditorInputProp ( { label : '图标类名前缀' , defaultValue : 'van-icon' } ) ,
54+ allowHalf : createEditorSwitchProp ( { label : '是否允许半选' , defaultValue : false } ) ,
55+ clearable : createEditorSwitchProp ( { label : '是否允许再次点击后清除' , defaultValue : false } ) ,
56+ touchable : createEditorSwitchProp ( { label : '是否可以通过滑动手势选择评分' , defaultValue : true } ) ,
57+ ...createFieldProps ( )
58+ } ,
59+ events : [
60+ { label : '当前分值变化时触发的事件' , value : 'change' } ,
61+ ] ,
62+ resize : {
63+ width : true ,
64+ } ,
65+ model : {
66+ default : '绑定字段' ,
67+ } ,
68+ }
0 commit comments