2021-11-17 16:45:22 +00:00
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export default {
|
|
|
|
name: "LayRate",
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed, defineProps, withDefaults } from "vue";
|
|
|
|
import "./index.less";
|
|
|
|
|
|
|
|
export interface LayRateProps {
|
|
|
|
theme?: string;
|
|
|
|
length?: number;
|
|
|
|
modelValue: number;
|
|
|
|
readonly?: boolean | string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<LayRateProps>(), {
|
|
|
|
length: 5,
|
|
|
|
modelValue: 0,
|
|
|
|
readonly: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits(["update:modelValue"]);
|
|
|
|
|
|
|
|
const currentValue = computed({
|
|
|
|
get: function () {
|
|
|
|
return props.modelValue;
|
|
|
|
},
|
|
|
|
set: function (val) {
|
|
|
|
emit("update:modelValue", val);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const mouseenter = function (index: number, event: any) {
|
|
|
|
if (props.readonly) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
currentValue.value = index;
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
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>
|