|
@@ -79,6 +79,7 @@
|
|
import programType from '@/utils/program'
|
|
import programType from '@/utils/program'
|
|
import { swiper, swiperSlide } from 'vue-awesome-swiper'
|
|
import { swiper, swiperSlide } from 'vue-awesome-swiper'
|
|
import 'swiper/dist/css/swiper.css'
|
|
import 'swiper/dist/css/swiper.css'
|
|
|
|
+import { isMobile } from '@/utils'
|
|
export default {
|
|
export default {
|
|
name: 'm-try',
|
|
name: 'm-try',
|
|
components: {
|
|
components: {
|
|
@@ -97,6 +98,7 @@ export default {
|
|
},
|
|
},
|
|
data () {
|
|
data () {
|
|
return {
|
|
return {
|
|
|
|
+ isMobile: isMobile(),
|
|
clear: false,
|
|
clear: false,
|
|
active: 0,
|
|
active: 0,
|
|
canMove: false,
|
|
canMove: false,
|
|
@@ -171,13 +173,31 @@ export default {
|
|
mounted () {
|
|
mounted () {
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
this.onReload()
|
|
this.onReload()
|
|
|
|
+ if (this.isMobile) {
|
|
|
|
+ this.$refs.content.$el.addEventListener('touchmove', this.onTouchMove)
|
|
|
|
+ this.$refs.content.$el.addEventListener('touchend', this.onTouchLeave)
|
|
|
|
+ // this.$refs.cover.addEventListener('touchstart', this.onTouchStart)
|
|
|
|
+ // this.$refs.cover.addEventListener('touchend', this.onTouchEnd)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
this.$refs.content.$el.addEventListener('mousemove', this.onTouchMove)
|
|
this.$refs.content.$el.addEventListener('mousemove', this.onTouchMove)
|
|
this.$refs.content.$el.addEventListener('mouseleave', this.onTouchLeave)
|
|
this.$refs.content.$el.addEventListener('mouseleave', this.onTouchLeave)
|
|
|
|
+ // this.$refs.cover.addEventListener('mousedown', this.onTouchStart)
|
|
|
|
+ // this.$refs.cover.addEventListener('mouseup', this.onTouchEnd)
|
|
})
|
|
})
|
|
},
|
|
},
|
|
beforeDestroy () {
|
|
beforeDestroy () {
|
|
|
|
+ if (this.isMobile) {
|
|
|
|
+ this.$refs.content.$el.removeEventListener('touchmove', this.onTouchMove)
|
|
|
|
+ this.$refs.content.$el.removeEventListener('touchend', this.onTouchLeave)
|
|
|
|
+ // this.$refs.cover.removeEventListener('touchstart', this.onTouchStart)
|
|
|
|
+ // this.$refs.cover.removeEventListener('touchend', this.onTouchEnd)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
this.$refs.content.$el.removeEventListener('mousemove', this.onTouchMove)
|
|
this.$refs.content.$el.removeEventListener('mousemove', this.onTouchMove)
|
|
this.$refs.content.$el.removeEventListener('mouseleave', this.onTouchLeave)
|
|
this.$refs.content.$el.removeEventListener('mouseleave', this.onTouchLeave)
|
|
|
|
+ // this.$refs.cover.removeEventListener('mousedown', this.onTouchStart)
|
|
|
|
+ // this.$refs.cover.removeEventListener('mouseup', this.onTouchEnd)
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
// 清屏
|
|
// 清屏
|
|
@@ -210,23 +230,23 @@ export default {
|
|
return degrees
|
|
return degrees
|
|
},
|
|
},
|
|
onSlideChange () {
|
|
onSlideChange () {
|
|
- console.log(this.$refs.mySwiper.swiper)
|
|
|
|
this.active = this.$refs.mySwiper.swiper.activeIndex
|
|
this.active = this.$refs.mySwiper.swiper.activeIndex
|
|
},
|
|
},
|
|
onTouchMove (v) {
|
|
onTouchMove (v) {
|
|
if (!this.canMove) {
|
|
if (!this.canMove) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ const clientX = this.isMobile ? v.touches[0].clientX : v.clientX
|
|
|
|
+ const clientY = this.isMobile ? v.touches[0].clientY : v.clientY
|
|
// 计算点位移动距离
|
|
// 计算点位移动距离
|
|
- const moveX = v.clientX - this.moveObj.startX
|
|
|
|
- const moveY = v.clientY - this.moveObj.startY
|
|
|
|
|
|
+ const moveX = clientX - this.moveObj.startX
|
|
|
|
+ const moveY = clientY - this.moveObj.startY
|
|
// 计算点位移动后的位置
|
|
// 计算点位移动后的位置
|
|
const left = this.moveObj.left + moveX
|
|
const left = this.moveObj.left + moveX
|
|
const top = this.moveObj.top + moveY
|
|
const top = this.moveObj.top + moveY
|
|
// 更新点位位置
|
|
// 更新点位位置
|
|
this.$refs.cover.style.left = left + 'px'
|
|
this.$refs.cover.style.left = left + 'px'
|
|
this.$refs.cover.style.top = top + 'px'
|
|
this.$refs.cover.style.top = top + 'px'
|
|
- // console.log(left, top)
|
|
|
|
},
|
|
},
|
|
onTouchLeave () {
|
|
onTouchLeave () {
|
|
this.onTouchEnd()
|
|
this.onTouchEnd()
|
|
@@ -234,17 +254,16 @@ export default {
|
|
onTouchStart (e) {
|
|
onTouchStart (e) {
|
|
this.canMove = true
|
|
this.canMove = true
|
|
const cover = this.$refs.cover
|
|
const cover = this.$refs.cover
|
|
- const getContentBoundingClientRect = this.$refs.content.$el.getBoundingClientRect()
|
|
|
|
- const getGlassBoundingClientRect = cover.getBoundingClientRect()
|
|
|
|
|
|
+ const { left, top } = this.$refs.content.$el.getBoundingClientRect()
|
|
|
|
+ const { left: glassLeft, top: glassTop } = cover.getBoundingClientRect()
|
|
const clientHeight = cover.clientHeight
|
|
const clientHeight = cover.clientHeight
|
|
const clientWidth = cover.clientWidth
|
|
const clientWidth = cover.clientWidth
|
|
this.moveObj = {
|
|
this.moveObj = {
|
|
- startX: e.clientX,
|
|
|
|
- startY: e.clientY,
|
|
|
|
- left: getGlassBoundingClientRect.left - getContentBoundingClientRect.left + clientWidth / 2,
|
|
|
|
- top: getGlassBoundingClientRect.top - getContentBoundingClientRect.top + clientHeight / 2
|
|
|
|
|
|
+ startX: this.isMobile ? e.touches[0].clientX : e.clientX,
|
|
|
|
+ startY: this.isMobile ? e.touches[0].clientY : e.clientY,
|
|
|
|
+ left: glassLeft - left + clientWidth / 2,
|
|
|
|
+ top: glassTop - top + clientHeight / 2
|
|
}
|
|
}
|
|
- // console.log(this.moveObj)
|
|
|
|
},
|
|
},
|
|
onTouchEnd (e) {
|
|
onTouchEnd (e) {
|
|
this.canMove = false
|
|
this.canMove = false
|