vue实现进度条带指针

效果最终

复制代码
function calculatePointerPosition(value) {
    if (value < 2.6) return 12.5;  // 非常差位置
    if (value < 5.1) return 37.5;  // 较差位置
    if (value < 7.1) return 62.5;  // 良好位置
    return 90;  // 非常满意位置
}

function getStatusText(value) {
    if (value < 2.6) return '非常差';
    if (value < 5.1) return '较差';
    if (value < 7.1) return '良好';
    return '非常满意';
}

function getStatusColor(value) {
    if (value < 2.6) return '#F2F2F2';
    if (value < 5.1) return '#FF4D4F';
    if (value < 7.1) return '#FFAB2C';
    return '#67C23A';
}

function getProgressBackground(value) {
    if (value < 2.6) return 'linear-gradient(90deg, rgba(242,242,242,0) 0%, #F2F2F2 100%)';
    if (value < 5.1) return 'linear-gradient(90deg, rgba(255,77,79,0) 0%, #FF4D4F 100%)';
    if (value < 7.1) return 'linear-gradient(90deg, rgba(255,171,44,0) 0%, #FFAB2C 100%)';
    return 'linear-gradient(90deg, rgba(103,194,58,0) 0%, #67C23A 100%)';
}

function getStatusImage(value) {
    if (value < 2.6) return new URL(
        "../../../assets/images/tijian/gray.png",
        import.meta.url
    ).href;
    if (value < 5.1) return new URL(
        "../../../assets/images/tijian/error.png",
        import.meta.url
    ).href;
    if (value < 7.1) return new URL(
        "../../../assets/images/tijian/waring.png",
        import.meta.url
    ).href;
    return new URL(
        "../../../assets/images/tijian/success.png",
        import.meta.url
    ).href;
}

<!-- 进度条组件 -->
                <div style="padding: 20px; background: #fff; border-radius: 8px; margin-top: 20px;">
                    <!-- 指针在上方 -->
                    <div style="position: relative; height: 50px; margin-bottom: -5px;">
                        <img
                            :style="{
                                position: 'absolute',
                                left: `${(score/10)*100}%`,
                                bottom: '10px',
                                width: '60px',
                                height: '28px',
                                transform: 'translateX(-50%)'
                            }"
                            :src="getStatusImage(score)"
                        />
                    </div>
                    <!-- 进度条 -->
                    <div style="position: relative; height: 10px; background: #f0f0f0; border-radius: 5px;">
                        <div :style="{
                            position: 'absolute',
                            height: '100%',
                            width: `${(score/10)*100}%`,
                            borderRadius: '5px',
                            background: getProgressBackground(score)
                        }">
                        </div>
                    </div>
                    <!-- 状态值在下方 -->
                    <div style="margin-top: 10px; display: flex; justify-content: space-between;">
                        <span>非常差</span>
                        <span>较差</span>
                        <span>良好</span>
                        <span>非常满意</span>
                    </div>

                    <div style="margin-top: 30px; text-align: center; font-size: 14px;">
                        当前状态: <span :style="{ color: getStatusColor(score) }">{{ getStatusText(score) }}</span>
                    </div>
                </div>
相关推荐
一周七喜h16 分钟前
在Vue3和TypeScripts中使用pinia
前端·javascript·vue.js
weixin_3954489122 分钟前
main.c_cursor_0202
前端·网络·算法
摘星编程37 分钟前
用React Native开发OpenHarmony应用:Calendar日期范围选择
javascript·react native·react.js
东东5161 小时前
基于vue的电商购物网站vue +ssm
java·前端·javascript·vue.js·毕业设计·毕设
MediaTea1 小时前
<span class=“js_title_inner“>Python:实例对象</span>
开发语言·前端·javascript·python·ecmascript
雨季6661 小时前
Flutter 三端应用实战:OpenHarmony “微光笔记”——在灵感消逝前,为思想点一盏灯
开发语言·javascript·flutter·ui·dart
编码者卢布2 小时前
【Azure Stream Analytic】用 JavaScript UDF 解决 JSON 字段被转成 Record 的关键点
javascript·json·azure
梦梦代码精2 小时前
开源、免费、可商用:BuildingAI一站式体验报告
开发语言·前端·数据结构·人工智能·后端·开源·知识图谱
松树戈2 小时前
滥用AI生图引起的JavaScript heap out of memory排查记录
vue.js·ai编程
0思必得02 小时前
[Web自动化] Selenium执行JavaScript语句
前端·javascript·爬虫·python·selenium·自动化