2021-10-04 00:06:19 +00:00
|
|
|
<template>
|
|
|
|
<ul class="layui-rate">
|
2021-10-08 07:42:14 +00:00
|
|
|
<li
|
2021-11-07 07:55:08 +00:00
|
|
|
v-for="index of length"
|
|
|
|
:key="index"
|
2021-10-12 03:30:07 +00:00
|
|
|
class="layui-inline"
|
2021-11-07 07:55:08 +00:00
|
|
|
@mouseenter="mouseenter(index, $event)"
|
2021-10-08 07:42:14 +00:00
|
|
|
>
|
2021-10-26 18:04:47 +00:00
|
|
|
<i
|
2021-11-07 07:55:08 +00:00
|
|
|
v-if="index <= currentValue"
|
2021-10-26 18:04:47 +00:00
|
|
|
class="layui-icon layui-icon-rate-solid"
|
|
|
|
:style="{ color: theme }"
|
|
|
|
/>
|
|
|
|
<i v-else class="layui-icon layui-icon-rate" :style="{ color: theme }" />
|
2021-10-04 00:06:19 +00:00
|
|
|
</li>
|
2021-11-07 07:55:08 +00:00
|
|
|
{{
|
|
|
|
currentValue
|
|
|
|
}}
|
2021-10-04 00:06:19 +00:00
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
2021-11-07 16:54:38 +00:00
|
|
|
import { computed, defineProps, withDefaults } from 'vue'
|
2021-10-04 00:06:19 +00:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
length?: number
|
2021-11-07 07:55:08 +00:00
|
|
|
modelValue: number
|
2021-11-07 16:54:38 +00:00
|
|
|
readonly?: boolean | string
|
2021-10-26 18:04:47 +00:00
|
|
|
theme?: string
|
2021-10-04 00:06:19 +00:00
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
length: 5,
|
2021-10-08 07:42:14 +00:00
|
|
|
modelValue: 0,
|
2021-10-26 18:04:47 +00:00
|
|
|
readonly: false,
|
2021-11-07 16:54:38 +00:00
|
|
|
theme: 'green',
|
2021-10-04 00:06:19 +00:00
|
|
|
}
|
|
|
|
)
|
2021-10-08 07:42:14 +00:00
|
|
|
|
|
|
|
const emit = defineEmits(['update:modelValue'])
|
|
|
|
|
2021-11-07 07:55:08 +00:00
|
|
|
const currentValue = computed({
|
|
|
|
get: function () {
|
|
|
|
return props.modelValue
|
|
|
|
},
|
|
|
|
set: function (val) {
|
|
|
|
emit('update:modelValue', val)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const mouseenter = function (index: number, event: any) {
|
2021-10-26 18:04:47 +00:00
|
|
|
if (props.readonly) {
|
|
|
|
return false
|
|
|
|
}
|
2021-11-07 07:55:08 +00:00
|
|
|
currentValue.value = index
|
2021-10-08 07:42:14 +00:00
|
|
|
}
|
2021-10-04 00:06:19 +00:00
|
|
|
</script>
|