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>
相关推荐
随风一样自由7 小时前
【前端独角兽】刚进入前端领域的前端开发用jQuery还是Vue3?
前端·javascript·vue3·jquery
IMPYLH8 小时前
HTML 的 <data> 元素
前端·html
YHHLAI8 小时前
[特殊字符] 面试中的 Promise —— 从入门到精通
前端·javascript·面试
weixin_BYSJ19879 小时前
SpringBoot + MySQL 乒乓球运动员信息管理系统项目实战--附源码04954
java·javascript·spring boot·python·django·flask·php
沪飘大军10 小时前
ll-llm:一个零依赖、可插拔的 OpenAI 兼容 LLM 代理
javascript
leoZ23110 小时前
Claude 驱动的全栈开发:Spring Boot + Vue 的 BS 架构实践
vue.js·spring boot·架构
kyriewen10 小时前
我扒了 GPT-5.6 的全部编程跑分——有一项 OpenAI 没敢放出来
前端·gpt·ai编程
前端H11 小时前
微前端 v3 架构升级:从加载隔离到状态协同
前端·架构·状态模式
山河木马11 小时前
GPU自动处理专题3-NDC怎么映射成屏幕像素坐标(视口变换)
javascript·webgl·图形学
陆枫Larry12 小时前
小程序包体积优化:用 SVG 图片替换 iconfont,并保留 CSS 控色能力
前端