当前位置: 首页 > news >正文

uniapp评价组件

在这里插入图片描述
在这里插入图片描述
组件目录 components/Evaluation.vue

<template><view class="evaluation-container"><!-- 综合评价 --><view class="evaluation-item" @tap="parentTap"><text class="label label-1">综合评价</text><view class="rating-icons"><imagev-for="(icon, index) in ratingIcons":key="index":class="['rating-icon', { active: icon.active }]":src="icon.active ? icon.selectedSrcDynamic : icon.unselectedSrc"@tap.stop="setRating(index)"/></view><text class="comment-text">{{ getCommentText(ratingIcons.filter(i => i.active).length) }}</text></view><!-- 描述相符 --><view class="evaluation-item" @tap="parentTap"><text class="label">描述相符</text><view class="heart-icons"><imagev-for="(heart, index) in descriptionHearts":key="index":class="['heart-icon', { active: heart.active }]":src="heart.active ? '/static/evaluate/heart-filled.png' : '/static/evaluate/heart-empty.png'"@tap.stop="setHeart(index, 'description')"/></view><text class="comment-text">{{ getCommentText(descriptionHearts.filter(i => i.active).length) }}</text></view><!-- 物流服务 --><view class="evaluation-item" @tap="parentTap"><text class="label">物流服务</text><view class="heart-icons"><imagev-for="(heart, index) in logisticsHearts":key="index":class="['heart-icon', { active: heart.active }]":src="heart.active ? '/static/evaluate/heart-filled.png' : '/static/evaluate/heart-empty.png'"@tap.stop="setHeart(index, 'logistics')"/></view><text class="comment-text">{{ getCommentText(logisticsHearts.filter(i => i.active).length) }}</text></view><!-- 服务态度 --><view class="evaluation-item" @tap="parentTap"><text class="label">服务态度</text><view class="heart-icons"><imagev-for="(heart, index) in serviceHearts":key="index":class="['heart-icon', { active: heart.active }]":src="heart.active ? '/static/evaluate/heart-filled.png' : '/static/evaluate/heart-empty.png'"@tap.stop="setHeart(index, 'service')"/></view><text class="comment-text">{{ getCommentText(serviceHearts.filter(i => i.active).length) }}</text></view></view>
</template><script>
export default {name: 'Evaluation',props: {defaultValues: {type: Object,default: () => ({})},readonly: {type: Boolean,default: false}},data() {return {ratingIcons: [{unselectedSrc: '/static/evaluate/face-very-bad-unselected.png',selectedSrc: '/static/evaluate/face-very-bad.png',selectedSrcDynamic: null,active: false},{unselectedSrc: '/static/evaluate/face-bad-unselected.png',selectedSrc: '/static/evaluate/face-bad.png',selectedSrcDynamic: null,active: false},{unselectedSrc: '/static/evaluate/face-neutral-unselected.png',selectedSrc: '/static/evaluate/face-neutral.png',selectedSrcDynamic: null,active: false},{unselectedSrc: '/static/evaluate/face-good-unselected.png',selectedSrc: '/static/evaluate/face-good.png',selectedSrcDynamic: null,active: false},{unselectedSrc: '/static/evaluate/face-very-good-unselected.png',selectedSrc: '/static/evaluate/face-very-good.png',selectedSrcDynamic: null,active: false}],descriptionHearts: Array(5).fill({ active: false }).map(h => ({ ...h })),logisticsHearts: Array(5).fill({ active: false }).map(h => ({ ...h })),serviceHearts: Array(5).fill({ active: false }).map(h => ({ ...h })),commentTexts: ['很差', '不满意', '一般', '满意', '超赞']};},mounted() {this.initEvaluation(this.defaultValues);},methods: {parentTap() {},setRating(index) {if (this.readonly) return;const selectedSrc = this.ratingIcons[index].selectedSrc;this.ratingIcons.forEach((icon, i) => {icon.active = i <= index;icon.selectedSrcDynamic = i <= index ? selectedSrc : null;});},setHeart(index, type) {if (this.readonly) return;const hearts = this[type + 'Hearts'];hearts.forEach((heart, i) => {heart.active = i <= index;});},getResult() {return {overall: this.ratingIcons.filter(i => i.active).length,description: this.descriptionHearts.filter(i => i.active).length,logistics: this.logisticsHearts.filter(i => i.active).length,service: this.serviceHearts.filter(i => i.active).length};},initEvaluation({ overall = 0, description = 0, logistics = 0, service = 0 }) {const selectedSrc = this.ratingIcons[overall - 1]?.selectedSrc || null;this.ratingIcons.forEach((icon, i) => {icon.active = i < overall;icon.selectedSrcDynamic = i < overall ? selectedSrc : null;});const setHearts = (arr, score) => {arr.forEach((item, i) => {item.active = i < score;});};setHearts(this.descriptionHearts, description);setHearts(this.logisticsHearts, logistics);setHearts(this.serviceHearts, service);},getCommentText(count) {if (count === 0) return '';return this.commentTexts[count - 1];}}
};
</script><style scoped>
.evaluation-container {/* padding: 20px; */
}
.evaluation-item {display: flex;align-items: center;margin-bottom: 28rpx;
}
.label{font-size: 28rpx;color: #2D2D2D;
}
.label-1{color: #0F1724;font-weight: 600;
}.rating-icons,
.heart-icons {display: flex;/* gap: 10px; */
}
.rating-icon,
.heart-icon {width: 60rpx;height: 60rpx;margin-left: 30rpx;
}/* 动画效果 */
@keyframes bounce {0% {transform: scale(1);}40% {transform: scale(1.3);}100% {transform: scale(1);}
}.rating-icon.active,
.heart-icon.active {animation: bounce 0.3s ease;
}/* 文案样式 */
.comment-text {margin-left: 24rpx;font-weight: 600;font-size: 28rpx;color: #0F1724;white-space: nowrap;
}
</style>

页面使用

<template><view><Evaluationref="evaluation":default-values="{ overall: 0, description: 0, logistics: 0, service: 0 }":readonly="false"/><button @tap="submit">提交</button></view>
</template><script>
import Evaluation from '@/components/Evaluation.vue';export default {components: { Evaluation },methods: {submit() {const result = this.$refs.evaluation.getResult();console.log('提交评分结果', result);}}
};
</script>

readonly是否允许点击一般详情页可以传true不让点击


文章转载自:
http://blanketyblank.hfytgp.cn
http://backformation.hfytgp.cn
http://alpestrine.hfytgp.cn
http://avram.hfytgp.cn
http://asyntactic.hfytgp.cn
http://benzoin.hfytgp.cn
http://choriamb.hfytgp.cn
http://bps.hfytgp.cn
http://banian.hfytgp.cn
http://antifertility.hfytgp.cn
http://calmness.hfytgp.cn
http://biquinary.hfytgp.cn
http://campus.hfytgp.cn
http://cavalcade.hfytgp.cn
http://camphire.hfytgp.cn
http://assai.hfytgp.cn
http://cabman.hfytgp.cn
http://baobab.hfytgp.cn
http://chariness.hfytgp.cn
http://agonal.hfytgp.cn
http://brake.hfytgp.cn
http://aasvogel.hfytgp.cn
http://centesimal.hfytgp.cn
http://atremble.hfytgp.cn
http://beamed.hfytgp.cn
http://brunizem.hfytgp.cn
http://catamenia.hfytgp.cn
http://apodeictic.hfytgp.cn
http://chronosphere.hfytgp.cn
http://beneficent.hfytgp.cn
http://www.dtcms.com/a/255238.html

相关文章:

  • 从生活场景学透 JavaScript 原型与原型链
  • 微信小程序扫码添加音频播放报错{errCode:10001, errMsg:“errCode:602,err:error,not found param“}
  • VR 看房:突破成长痛点,展望未来趋势
  • YOLOv5 自定义模型 Android 部署完整指南
  • C++11 右值引用(Rvalue Reference)
  • uni-app-配合iOS App项目开发apple watch app
  • bit sbit sfr的区别
  • 【Pandas】pandas DataFrame squeeze
  • RISC-V物联网关,支持鸿蒙,T-Thread实时系统
  • Android 中 解析 XML 字符串的几种方式
  • 如何使用 Dockerfile 创建自定义镜像
  • 轻量级web开发框架之Flask web开发框架学习:get请求数据的发送
  • 国产芯片能在服务器领域替代Intel(经验总结贴)
  • phpstudy无法启动mysql,一启动就关闭,完美解决
  • WIFI原因造成ESP8266不断重启的解决办法
  • 【Linux驱动开发 ---- 4.2_平台设备(Platform Devices)概述】
  • 电影感户外柔和光线人像街拍摄影后期Lr调色教程,手机滤镜PS+Lightroom预设下载!
  • 【内存】Linux 内核优化实战 - vm.max_map_count
  • Java枚举类如何避免反射攻击和序列化攻击
  • 零基础RT-thread第四节:电容按键
  • 自动化性能回退机制——蓝绿部署与灰度发布
  • Electron (02)集成 SpringBoot:服务与桌面程序协同启动方案
  • 回文链表C++
  • 设计模式精讲 Day 8:组合模式(Composite Pattern)
  • Transformer实战——Hugging Face环境配置与应用详解
  • 什么是seata
  • node.js在vscode的配置
  • 多线程八股
  • 【小程序】如何生成特定页面的小程序码
  • 代码审计-fastjson反序列化漏洞