(component): 评分组件增加清除功能

评分组件增加清除功能

ISSUES CLOSED: #I50JOX
This commit is contained in:
xumi 2022-05-17 01:09:05 +08:00
parent 092650b049
commit f8538c7d4d
3 changed files with 59 additions and 2 deletions

View File

@ -27,3 +27,16 @@
cursor: default; cursor: default;
transform: scale(1); 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;
}

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
export default { export default {
name: "LayRate", name: "LayRate"
}; };
</script> </script>
@ -16,6 +16,8 @@ export interface LayRateProps {
half?: boolean; half?: boolean;
text?: boolean; text?: boolean;
isBlock?: boolean; isBlock?: boolean;
hasClear?: boolean;
clearIcon?: string;
icons?: string[]; icons?: string[];
} }
@ -26,6 +28,8 @@ const props = withDefaults(defineProps<LayRateProps>(), {
half: false, half: false,
text: false, text: false,
isBlock: false, isBlock: false,
hasClear: false,
clearIcon: "layui-icon-close-fill",
icons: () => [ icons: () => [
"layui-icon-rate", "layui-icon-rate",
"layui-icon-rate-half", "layui-icon-rate-half",
@ -33,7 +37,7 @@ const props = withDefaults(defineProps<LayRateProps>(), {
], ],
}); });
const emit = defineEmits(["update:modelValue", "select"]); const emit = defineEmits(["update:modelValue", "select", "clear"]);
const currentValue = ref<number>(props.modelValue); const currentValue = ref<number>(props.modelValue);
// //
@ -77,6 +81,16 @@ const action = function (index: number, event: any) {
emit("update:modelValue", currentValue.value); emit("update:modelValue", currentValue.value);
emit("select", currentValue.value); emit("select", currentValue.value);
}; };
//
const showClearIcon = computed(
() => !props.readonly && props.hasClear
);
const clearRate = function(){
tempValue.value = 0;
currentValue.value = 0;
emit("clear", currentValue.value);
}
</script> </script>
<template> <template>
@ -116,5 +130,8 @@ const action = function (index: number, event: any) {
</slot> </slot>
</span> </span>
</template> </template>
<template v-if="showClearIcon">
<i :class="['layui-icon', 'layui-rate-clear-icon', clearIcon]" @click="clearRate" title="清除评分"></i>
</template>
</div> </div>
</template> </template>

View File

@ -89,6 +89,30 @@ export default {
::: :::
::: title 清除功能
:::
::: demo
<template>
<lay-rate v-model="clearHalf" :half="true" :is-block="true" has-clear></lay-rate>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
const clearHalf = ref(0.5)
return {
clearHalf
}
}
}
</script>
:::
::: title 自定义内容 ::: title 自定义内容
::: :::
@ -289,6 +313,8 @@ export default {
| half | 设定组件是否可以选择半星 | `boolean` | false | | half | 设定组件是否可以选择半星 | `boolean` | false |
| text | 是否显示评分对应的内容 | `boolean` | false | | text | 是否显示评分对应的内容 | `boolean` | false |
| is-block | 评分是否显示为快元素 | `boolean` | false | | is-block | 评分是否显示为快元素 | `boolean` | false |
| has-clear | 评分是否需要清除功能 | `boolean` | false |
| clear-icon | 评分清除功能使用的图标`class` | `string` | `layui-icon-close-fill` |
| icons | 评分使用图标`class``["空心", "实心"]`/`["空心", "半心", "实心"]` | `string[]` | 星型 | | icons | 评分使用图标`class``["空心", "实心"]`/`["空心", "半心", "实心"]` | `string[]` | 星型 |
::: :::
@ -312,6 +338,7 @@ export default {
| 属性 | 描述 | 回调参数 | | 属性 | 描述 | 回调参数 |
| -------- | -------- | ------ | | -------- | -------- | ------ |
| select | 选中之后触发事件 | (value: number) | | select | 选中之后触发事件 | (value: number) |
| clear | 清除之后触发事件 | (value: number) |
::: :::