<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<!-- 引入 vue 入口文件 -->
<script type="module" src="./main.js"></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
index.html
main.js
App.vue
global.css
package.json
现在支持上传本地图片了!
index.html
main.js
import { createApp } from 'vue'
import './global.css'
import App from './App.vue'
createApp(App).mount('#app')
console.log(["Hello 笔.COOL 控制台"])
编辑器加载中
App.vue
<!-- 参数范围 -->
<template>
<div class="container-range">
<div class="range-up">
<template v-for="(item, indxe) in $prop.upRange">
<div :style="{ width: item.width + 'px' }">
{{ item.val }}
</div>
</template>
</div>
<div class="range-up-flag">
<template v-for="(item, indxe) in $prop.valRange">
<div :style="{ width: item.width + 'px' }"></div>
</template>
</div>
<div class="range-val">
<template v-for="(item, indxe) in $prop.valRange">
<div :style="{ background: item.color, width: item.width + 'px' }"></div>
</template>
</div>
<div class="range-down-flag">
<template v-for="(item, indxe) in $prop.valRange">
<div :style="{ width: item.width + 'px' }"></div>
</template>
</div>
<div class="range-down">
<template v-for="(item, indxe) in $prop.downRange">
<div :style="{ width: item.width + 'px' }">
{{ item.val }}
</div>
</template>
</div>
<div class="range-spot" :style="{ left: spotLeft + 'px' }"></div>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
const $prop = ref({
target: 1.2,
valRange: [
{
width: 35,
color: "#F88773",
val: 0.42,
},
{
width: 90,
color: "#FECE40",
val: 4.23,
},
{
width: 35,
color: "#BCDD6B",
val: 10,
},
],
upRange: [
{
width: 25,
val: "",
},
{
width: 85,
val: "0.42",
},
{
width: 40,
val: "4.23",
},
],
downRange: [
{
width: 2,
val: "",
},
{
width: 40,
val: "",
},
{
width: 40,
val: "",
},
],
});
const spotLeft = ref(0);
comSpotPos();
//计算位置
function comSpotPos() {
let size = 8; //黑点大小
let target = $prop.value.target;
let valRange = $prop.value.valRange;
let l = 0;
let pre = 0;
for (let i = 0; i < valRange.length; i++) {
let item = valRange[i];
let val = Number(item.val);
let w = item.width;
if (target <= val) {
l += (w / (val - pre)) * (target - pre);
break;
} else {
pre = val;
l += w;
}
}
spotLeft.value = l - size/2;
}
</script>
<style scope>
.container-range {
position: relative;
}
.range-up,
.range-val,
.range-down {
display: flex;
color: #4a4a53;
height: 18px;
}
.range-up,
.range-down {
align-items: center;
}
.range-val {
height: 23px;
}
.range-up-flag,
.range-down-flag {
display: flex;
height: 3px;
}
.range-up-flag > div,
.range-down-flag > div {
position: relative;
}
.range-up-flag > div:not(:last-child)::after {
position: absolute;
content: "";
width: 1px;
height: 2px;
background: black;
right: 0;
bottom: 0;
}
.range-down-flag > div:not(:last-child)::after {
position: absolute;
content: "";
width: 1px;
height: 2px;
background: black;
right: 0;
top: 0;
}
.range-spot {
position: absolute;
width: 8px;
height: 8px;
background: #4a4a53;
border-radius: 50%;
top: 28px;
}
</style>
编辑器加载中
global.css
body {
background-color: #fefefe;
}
#app{
display: fles;
justify-items: center;
align-items: center;
}
编辑器加载中
package.json
注意:新添加的依赖包首次加载可能会报错,稍后再次刷新即可
{
"dependencies": {
"vue": "3.5.15"
}
}
编辑器加载中
预览页面