1.0.2 • Published 1 month ago

@tanzhenxing/zx-rate v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

zx-rate 评分组件

参考 Element Plus Rate 组件设计的 uni-app 评分组件,支持多种功能特性。

特性

  • ✅ 基础评分功能
  • ✅ 多种尺寸支持 (large/default/small)
  • ✅ 半星选择
  • ✅ 辅助文字显示
  • ✅ 分数显示
  • ✅ 可清空功能
  • ✅ 颜色分级
  • ✅ 自定义图标
  • ✅ 滑动手势支持
  • ✅ 只读模式
  • ✅ 编程式控制

基础用法

<template>
  <zx-rate v-model="value" />
</template>

<script setup>
import { ref } from 'vue';
const value = ref(0);
</script>

API

Props

属性名说明类型默认值
modelValue绑定值number0
max最大分值number5
size尺寸'large' \| 'default' \| 'small''default'
disabled是否为只读booleanfalse
allowHalf是否允许半选booleanfalse
lowThreshold低分和中等分数的界限值number2
highThreshold高分和中等分数的界限值number4
colorsicon的颜色Array | Object'#f7ba2a', '#f7ba2a', '#f7ba2a'
voidColor未选中icon的颜色string'#c6d1de'
disabledVoidColor只读时未选中icon的颜色string'#eff2f7'
icons图标组件Array | Object'star-fill', 'star-fill', 'star-fill'
voidIcon未被选中的图标名string'star'
disabledVoidIcon禁用状态的未选择图标string'star'
showText是否显示辅助文字booleanfalse
showScore是否显示当前分数booleanfalse
textColor辅助文字的颜色string''
texts辅助文字数组Array'极差', '失望', '一般', '满意', '惊喜'
scoreTemplate分数显示模板string'{value}'
clearable是否可以重置值为0booleanfalse
gutter图标之间的距离string | number'8rpx'
touchable是否可以通过滑动手势选择评分booleantrue
customStyle组件的样式,对象形式Object{}

Events

事件名说明回调参数
change分值改变时触发(value: number)

Methods

方法名说明参数
setCurrentValue设置当前值(value: number)
resetCurrentValue重置当前值-

使用示例

基础用法

<zx-rate v-model="value" />

颜色分级

<zx-rate 
  v-model="value" 
  :colors="['#99A9BF', '#F7BA2A', '#FF9900']" 
/>

允许半选

<zx-rate v-model="value" :allow-half="true" />

辅助文字

<zx-rate 
  v-model="value" 
  :show-text="true" 
  :texts="['极差', '失望', '一般', '满意', '惊喜']" 
/>

显示分数

<zx-rate 
  v-model="value" 
  :disabled="true"
  :show-score="true"
  :score-template="'{value} 分'"
/>

可清空

<zx-rate v-model="value" :clearable="true" />

自定义图标

<zx-rate 
  v-model="value" 
  :icons="['chat-dot-round', 'chat-line-round', 'chat-round']"
  void-icon="chat-line-round"
/>

编程式控制

<template>
  <zx-rate ref="rateRef" v-model="value" />
  <button @click="setRating(3)">设置为3分</button>
  <button @click="resetRating">重置</button>
</template>

<script setup>
import { ref } from 'vue';

const value = ref(0);
const rateRef = ref();

const setRating = (val) => {
  rateRef.value.setCurrentValue(val);
};

const resetRating = () => {
  rateRef.value.resetCurrentValue();
};
</script>

注意事项

  1. 组件依赖 zx-icon 图标组件
  2. 颜色和图标配置支持数组和对象两种格式
  3. 使用 v-model 进行双向数据绑定
  4. 建议在项目中统一图标库,确保图标名称的一致性
  5. 滑动手势在不同平台可能有细微差异,建议在真机上测试
1.0.2

1 month ago

1.0.1

2 months ago

1.0.0

1 year ago