mpwxs.js 1.5 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1
// #ifdef APP-VUE|| MP-WEIXIN || H5
雪洛's avatar
雪洛 已提交
2
import { isPC } from "./isPC"
DCloud_JSON's avatar
DCloud_JSON 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
export default {
	data() {
		return {
			is_show:'none'
		}
	},
	watch: {
		show(newVal){
			this.is_show = this.show
		}
	},
	created() {
		this.swipeaction = this.getSwipeAction()
		if (this.swipeaction.children !== undefined) {
			this.swipeaction.children.push(this)
		}
	},
	mounted(){
		this.is_show = this.show
	},
	methods: {
		// wxs 中调用
		closeSwipe(e) {
			if (!this.autoClose) return
			this.swipeaction.closeOther(this)
		},

		change(e) {
			this.$emit('change', e.open)
			if (this.is_show !== e.open) {
				this.is_show = e.open
			}
		},

雪洛's avatar
雪洛 已提交
37 38 39
		appTouchStart(e) {
			// #ifdef H5
			if(isPC()) return
DCloud_JSON's avatar
DCloud_JSON 已提交
40 41 42 43 44 45 46
			// #endif
			const {
				clientX
			} = e.changedTouches[0]
			this.clientX = clientX
			this.timestamp = new Date().getTime()
		},
雪洛's avatar
雪洛 已提交
47 48 49
		appTouchEnd(e, index, item, position) {
			// #ifdef H5
			if(isPC()) return
DCloud_JSON's avatar
DCloud_JSON 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62
			// #endif
			const {
				clientX
			} = e.changedTouches[0]
			// fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
			let diff = Math.abs(this.clientX - clientX)
			let time = (new Date().getTime()) - this.timestamp
			if (diff < 40 && time < 300) {
				this.$emit('click', {
					content: item,
					index,
					position
				})
雪洛's avatar
雪洛 已提交
63 64 65 66
			}
		},
		onClickForPC(index, item, position) {
			// #ifdef H5
DCloud_JSON's avatar
DCloud_JSON 已提交
67 68 69 70 71 72 73
			if(!isPC()) return
			this.$emit('click', {
				content: item,
				index,
				position
			})
			// #endif
雪洛's avatar
雪洛 已提交
74
		}
DCloud_JSON's avatar
DCloud_JSON 已提交
75 76 77
	}
}

雪洛's avatar
雪洛 已提交
78
// #endif
DCloud_JSON's avatar
DCloud_JSON 已提交
79 80
// #ifndef APP-VUE|| MP-WEIXIN || H5
export default {}
雪洛's avatar
雪洛 已提交
81
// #endif