mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-07 17:07:19 +08:00
fix: selector bug
This commit is contained in:
parent
78d9c17201
commit
7bd09e9899
13
src/App.vue
13
src/App.vue
@ -1,14 +1,3 @@
|
|||||||
<template>
|
<template>
|
||||||
<router-view />
|
<router-view />
|
||||||
</template>
|
</template>
|
||||||
<script lang='ts'>
|
|
||||||
|
|
||||||
import * as echarts from 'echarts'
|
|
||||||
import { provide } from 'vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
setup(){
|
|
||||||
provide('echarts', echarts)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -5,14 +5,14 @@
|
|||||||
<td
|
<td
|
||||||
v-for="(item, key) in max"
|
v-for="(item, key) in max"
|
||||||
:class="['hs-select__item' + key]"
|
:class="['hs-select__item' + key]"
|
||||||
@mousemove="setCurrentValue(key, $event)"
|
@mousemove.prevent="setCurrentValue(key, $event)"
|
||||||
@mouseleave="resetCurrentValue(key)"
|
@mouseleave.prevent="resetCurrentValue(key)"
|
||||||
@click="selectValue(key, item)"
|
@click="selectValue(key, item)"
|
||||||
:style="{ cursor: rateDisabled ? 'auto' : 'pointer', 'text-align': 'center' }"
|
:style="{ cursor: rateDisabled ? 'auto' : 'pointer', 'text-align': 'center' }"
|
||||||
:key="key"
|
:key="key"
|
||||||
>
|
>
|
||||||
<div :class="[classes[key] + key]" class="hs-item">
|
<div :class="[classes[key] + key]" class="hs-item">
|
||||||
<span>22</span>
|
<span>{{key}}</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -40,16 +40,16 @@ export default defineComponent({
|
|||||||
props: {
|
props: {
|
||||||
disabled: {
|
disabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0
|
||||||
},
|
},
|
||||||
max: {
|
max: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 10,
|
default: 10
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
let currentValue = props.value;
|
let currentValue = props.value;
|
||||||
@ -79,30 +79,32 @@ export default defineComponent({
|
|||||||
if (selectedList.length === 1) {
|
if (selectedList.length === 1) {
|
||||||
overList.push({ index });
|
overList.push({ index });
|
||||||
|
|
||||||
// let i = 0;
|
|
||||||
|
|
||||||
let firstIndex = overList[0].index;
|
let firstIndex = overList[0].index;
|
||||||
|
|
||||||
// 往左走,索引变大
|
// 往左走,索引变大
|
||||||
|
|
||||||
if (index > firstIndex) {
|
if (index > firstIndex) {
|
||||||
// console.log(index, firstIndex);
|
while (index >= firstIndex) {
|
||||||
let leftIndex = index - firstIndex;
|
addClass(
|
||||||
|
document.querySelector(".hs-select__item" + firstIndex),
|
||||||
for (var i =0; i < index; i++) {
|
inRange
|
||||||
// useDebounceFn(() => {
|
);
|
||||||
if(document.querySelector(".hs-select__item" + (i+index))) {
|
firstIndex++;
|
||||||
addClass(document.querySelector(".hs-select__item" + (i+index)), inRange);
|
|
||||||
}
|
|
||||||
// }, 100)();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
while (index <= firstIndex) {
|
||||||
|
addClass(
|
||||||
|
document.querySelector(".hs-select__item" + firstIndex),
|
||||||
|
inRange
|
||||||
|
);
|
||||||
|
firstIndex--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addClass(document.querySelector("." + voidClass + index), activeClass);
|
addClass(document.querySelector("." + voidClass + index), activeClass);
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetCurrentValue = (index) => {
|
const resetCurrentValue = index => {
|
||||||
// 移除先检查是否选中 选中则返回false 不移除
|
// 移除先检查是否选中 选中则返回false 不移除
|
||||||
const currentHsDom = document.querySelector("." + voidClass + index);
|
const currentHsDom = document.querySelector("." + voidClass + index);
|
||||||
if (currentHsDom.className.includes(stayClass)) {
|
if (currentHsDom.className.includes(stayClass)) {
|
||||||
@ -113,8 +115,22 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 当选中一个元素后,开始移除背景色
|
// 当选中一个元素后,开始移除背景色
|
||||||
if (selectedList.length === 1) {
|
if (selectedList.length === 1) {
|
||||||
for (let i = 0; i <= index; i++) {
|
let firstIndex = overList[0].index;
|
||||||
removeClass(document.querySelector(".hs-select__item" + i), inRange);
|
if (index >= firstIndex) {
|
||||||
|
for (let i = 0; i <= index; i++) {
|
||||||
|
removeClass(
|
||||||
|
document.querySelector(".hs-select__item" + i),
|
||||||
|
inRange
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (index <= firstIndex) {
|
||||||
|
removeClass(
|
||||||
|
document.querySelector(".hs-select__item" + index),
|
||||||
|
inRange
|
||||||
|
);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -129,7 +145,7 @@ export default defineComponent({
|
|||||||
// let rangeDom = document.querySelector(".hs-select__item" + index)
|
// let rangeDom = document.querySelector(".hs-select__item" + index)
|
||||||
} else {
|
} else {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
selectedList.forEach((v) => {
|
selectedList.forEach(v => {
|
||||||
removeClass(
|
removeClass(
|
||||||
document.querySelector("." + voidClass + v.index),
|
document.querySelector("." + voidClass + v.index),
|
||||||
activeClass,
|
activeClass,
|
||||||
@ -153,9 +169,9 @@ export default defineComponent({
|
|||||||
setCurrentValue,
|
setCurrentValue,
|
||||||
resetCurrentValue,
|
resetCurrentValue,
|
||||||
selectValue,
|
selectValue,
|
||||||
classes,
|
classes
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import { ref, computed, onMounted, inject, nextTick } from "vue";
|
|||||||
import { deviceDetection } from "../utils/deviceDetection";
|
import { deviceDetection } from "../utils/deviceDetection";
|
||||||
import { echartsJson } from "../api/mock";
|
import { echartsJson } from "../api/mock";
|
||||||
import { useEventListener, tryOnUnmounted } from "@vueuse/core";
|
import { useEventListener, tryOnUnmounted } from "@vueuse/core";
|
||||||
|
import * as echarts from "echarts";
|
||||||
|
|
||||||
let brokenLine: any = null; //折线图实例
|
let brokenLine: any = null; //折线图实例
|
||||||
export default {
|
export default {
|
||||||
@ -43,7 +44,6 @@ export default {
|
|||||||
let mobile = ref(deviceDetection());
|
let mobile = ref(deviceDetection());
|
||||||
let date: Date = new Date();
|
let date: Date = new Date();
|
||||||
let loading = ref(true);
|
let loading = ref(true);
|
||||||
let echarts = inject("echarts"); //引入
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
loading.value = !loading.value;
|
loading.value = !loading.value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user