2022-11-14 03:59:26 +00:00
import { w as withInstall } from "../badge/index2.js" ;
import { defineComponent , ref , computed , watch , openBlock , createElementBlock , normalizeClass , createElementVNode , Fragment , renderList , unref , normalizeStyle , renderSlot , createTextVNode , toDisplayString , createCommentVNode } from "vue" ;
var index = /* @__PURE__ */ ( ( ) => ".layui-rate,.layui-rate *{display:inline-block;vertical-align:middle}.layui-rate{padding:10px 5px 10px 0;font-size:0}.layui-rate li i.layui-icon{font-size:20px;color:#ffb800;margin-right:5px;transition:all .3s;-webkit-transition:all .3s}.layui-rate li i:hover{cursor:pointer;transform:scale(1.12);-webkit-transform:scale(1.12)}.layui-rate[readonly] li i:hover{cursor:default;transform:scale(1)}.layui-rate-clear-icon{display:inline-block;color:#c6c6c6;padding-top:3px;font-size:18px;vertical-align:middle}.layui-rate-clear-icon:hover{cursor:pointer;color:#ff4949}\n" ) ( ) ;
const _hoisted _1 = [ "onMousemove" , "onClick" ] ;
const _hoisted _2 = {
key : 0 ,
class : "layui-inline"
} ;
const _ _default _ _ = {
name : "LayRate"
} ;
const _sfc _main = defineComponent ( {
... _ _default _ _ ,
props : {
theme : null ,
length : { default : 5 } ,
modelValue : { default : 0 } ,
readonly : { type : [ Boolean , String ] , default : false } ,
half : { type : Boolean , default : false } ,
text : { type : Boolean , default : false } ,
isBlock : { type : Boolean , default : false } ,
allowClear : { type : Boolean , default : false } ,
clearIcon : { default : "layui-icon-close-fill" } ,
icons : { default : ( ) => [
"layui-icon-rate" ,
"layui-icon-rate-half" ,
"layui-icon-rate-solid"
] }
} ,
emits : [ "update:modelValue" , "select" , "clear" ] ,
setup ( _ _props , { emit } ) {
const props = _ _props ;
const currentValue = ref ( props . modelValue ) ;
const tempValue = ref ( currentValue . value ) ;
2024-09-24 09:04:44 +00:00
const isHalf = computed (
( ) => props . half && Math . round ( currentValue . value ) !== currentValue . value
) ;
watch (
( ) => props . modelValue ,
( ) => {
currentValue . value = props . modelValue ;
tempValue . value = props . modelValue ;
}
) ;
2022-11-14 03:59:26 +00:00
const getValue = function ( index2 , event ) {
if ( ! props . half ) {
return index2 ;
}
return index2 - ( event . offsetX <= event . target . offsetWidth / 2 ? 0.5 : 0 ) ;
} ;
const mousemove = function ( index2 , event ) {
if ( props . readonly ) {
return false ;
}
currentValue . value = getValue ( index2 , event ) ;
} ;
const mouseleave = function ( ) {
if ( props . readonly ) {
return false ;
}
currentValue . value = tempValue . value ;
} ;
const action = function ( index2 , event ) {
if ( props . readonly ) {
return false ;
}
currentValue . value = getValue ( index2 , event ) ;
tempValue . value = currentValue . value ;
emit ( "update:modelValue" , currentValue . value ) ;
emit ( "select" , currentValue . value ) ;
} ;
const showClearIcon = computed ( ( ) => ! props . readonly && props . allowClear ) ;
const clearRate = function ( ) {
tempValue . value = 0 ;
currentValue . value = 0 ;
emit ( "clear" , currentValue . value ) ;
} ;
return ( _ctx , _cache ) => {
return openBlock ( ) , createElementBlock ( "div" , {
class : normalizeClass ( _ _props . isBlock ? "layui-block" : "layui-inline" )
} , [
createElementVNode ( "ul" , {
class : "layui-rate" ,
onMouseleave : mouseleave
} , [
( openBlock ( true ) , createElementBlock ( Fragment , null , renderList ( _ _props . length , ( index2 ) => {
return openBlock ( ) , createElementBlock ( "li" , {
key : index2 ,
class : "layui-inline" ,
onMousemove : ( $event ) => mousemove ( index2 , $event ) ,
onClick : ( $event ) => action ( index2 , $event )
} , [
index2 <= Math . ceil ( currentValue . value ) ? ( openBlock ( ) , createElementBlock ( "i" , {
key : 0 ,
class : normalizeClass ( [
"layui-icon" ,
` ${ _ _props . icons [ _ _props . icons . length - ( unref ( isHalf ) && index2 === Math . ceil ( currentValue . value ) ? 2 : 1 ) ] } `
] ) ,
style : normalizeStyle ( { color : _ _props . theme } )
} , null , 6 ) ) : ( openBlock ( ) , createElementBlock ( "i" , {
key : 1 ,
class : normalizeClass ( [ "layui-icon" ] . concat ( _ _props . icons [ 0 ] ) ) ,
style : normalizeStyle ( { color : _ _props . theme } )
} , null , 6 ) )
] , 40 , _hoisted _1 ) ;
} ) , 128 ) )
] , 32 ) ,
_ _props . text ? ( openBlock ( ) , createElementBlock ( "span" , _hoisted _2 , [
renderSlot ( _ctx . $slots , "default" , { value : currentValue . value } , ( ) => [
createTextVNode ( toDisplayString ( currentValue . value + "\u661F" ) , 1 )
] )
] ) ) : createCommentVNode ( "" , true ) ,
unref ( showClearIcon ) ? ( openBlock ( ) , createElementBlock ( "i" , {
key : 1 ,
class : normalizeClass ( [ "layui-icon" , "layui-rate-clear-icon" , _ _props . clearIcon ] ) ,
onClick : clearRate ,
title : "\u6E05\u9664\u8BC4\u5206"
} , null , 2 ) ) : createCommentVNode ( "" , true )
] , 2 ) ;
} ;
}
} ) ;
const component = withInstall ( _sfc _main ) ;
export { component as default } ;