|
|
@@ -21,13 +21,23 @@ export default {
|
|
|
default: Infinity
|
|
|
},
|
|
|
isGradient:{
|
|
|
- type: Boolean,
|
|
|
- default: false
|
|
|
+ type: Number,
|
|
|
+ default: 0
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
+ let gradientArr = []
|
|
|
+ if(this.max > this.isGradient){
|
|
|
+ let temp = Array(Math.ceil(this.max / this.isGradient)).fill(0)
|
|
|
+ gradientArr = temp.map((item,i)=>{
|
|
|
+ return [i*this.isGradient,(i+1)*this.isGradient]
|
|
|
+ })
|
|
|
+ console.log(gradientArr);
|
|
|
+ }
|
|
|
return {
|
|
|
- current: Number(this.value)
|
|
|
+ current: Number(this.value),
|
|
|
+ isLegal:this.max > this.isGradient && this.isGradient,
|
|
|
+ gradientArr
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
@@ -40,9 +50,30 @@ export default {
|
|
|
this.$refs.bar.removeEventListener('touchstart', this.downHandle, false)
|
|
|
},
|
|
|
methods: {
|
|
|
+
|
|
|
+ toChangeNum(tmp){
|
|
|
+
|
|
|
+ let max = [0,0]
|
|
|
+ if (this.isLegal) {
|
|
|
+ max = this.gradientArr.find(item=>{
|
|
|
+ return tmp >= item[0] && tmp < item[1]
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tmp == 0 || tmp == this.max) {
|
|
|
+ this.current = tmp
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return Number(this.isLegal ? (max ? max[1] : tmp) : tmp)
|
|
|
+
|
|
|
+ },
|
|
|
clickHandle(ev) {
|
|
|
let tmp = this.min + this.len * (ev.offsetX / this.width)
|
|
|
- this.current = this.isGradient ? Math.ceil(tmp) : tmp
|
|
|
+
|
|
|
+
|
|
|
+ this.current = this.toChangeNum(tmp)
|
|
|
+
|
|
|
},
|
|
|
downHandle(ev) {
|
|
|
let $layer = document.documentElement
|
|
|
@@ -50,7 +81,7 @@ export default {
|
|
|
let initV = this.current
|
|
|
let move = ev => {
|
|
|
let tmp = initV - ((startX - (ev.pageX || ev.touches[0].pageX)) / this.width) * this.len
|
|
|
- this.current = this.isGradient ? Math.ceil(tmp) : tmp
|
|
|
+ this.current = this.toChangeNum(tmp)
|
|
|
}
|
|
|
let end = ev => {
|
|
|
$layer.removeEventListener('touchmove', move, false)
|
|
|
@@ -80,7 +111,7 @@ export default {
|
|
|
},
|
|
|
watch: {
|
|
|
current() {
|
|
|
- let current = Number(this.current.toFixed(2))
|
|
|
+ let current = Number(this.current ? this.current.toFixed(2) : this.current)
|
|
|
if (current !== this.current) return this.current = current
|
|
|
|
|
|
if (!this.current.toString()) {
|