mpwxs.js 1.5 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6 7 8 9 10 11
let mpMixins = {}
let is_pc = null
// #ifdef H5
import {
	isPC
} from "./isPC"
is_pc = isPC()
// #endif
// #ifdef APP-VUE|| MP-WEIXIN || H5

mpMixins = {
study夏羽's avatar
study夏羽 已提交
12 13
	data() {
		return {
study夏羽's avatar
study夏羽 已提交
14
			is_show: 'none'
study夏羽's avatar
study夏羽 已提交
15 16 17 18
		}
	},
	watch: {
		show(newVal) {
study夏羽's avatar
study夏羽 已提交
19
			this.is_show = this.show
study夏羽's avatar
study夏羽 已提交
20 21 22
		}
	},
	created() {
study夏羽's avatar
study夏羽 已提交
23
		this.swipeaction = this.getSwipeAction()
study夏羽's avatar
study夏羽 已提交
24 25 26 27 28
		if (this.swipeaction.children !== undefined) {
			this.swipeaction.children.push(this)
		}
	},
	mounted() {
study夏羽's avatar
study夏羽 已提交
29
		this.is_show = this.show
study夏羽's avatar
study夏羽 已提交
30 31
	},
	methods: {
study夏羽's avatar
study夏羽 已提交
32
		// wxs 中调用
study夏羽's avatar
study夏羽 已提交
33 34 35 36 37 38 39
		closeSwipe(e) {
			if (!this.autoClose) return
			this.swipeaction.closeOther(this)
		},

		change(e) {
			this.$emit('change', e.open)
study夏羽's avatar
study夏羽 已提交
40 41
			if (this.is_show !== e.open) {
				this.is_show = e.open
study夏羽's avatar
study夏羽 已提交
42 43 44 45
			}
		},

		appTouchStart(e) {
study夏羽's avatar
study夏羽 已提交
46
			if (is_pc) return
study夏羽's avatar
study夏羽 已提交
47 48 49 50 51 52 53
			const {
				clientX
			} = e.changedTouches[0]
			this.clientX = clientX
			this.timestamp = new Date().getTime()
		},
		appTouchEnd(e, index, item, position) {
study夏羽's avatar
study夏羽 已提交
54
			if (is_pc) return
study夏羽's avatar
study夏羽 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
			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
				})
			}
		},
		onClickForPC(index, item, position) {
study夏羽's avatar
study夏羽 已提交
70
			if (!is_pc) return
study夏羽's avatar
study夏羽 已提交
71 72 73 74 75 76
			// #ifdef H5
			this.$emit('click', {
				content: item,
				index,
				position
			})
study夏羽's avatar
study夏羽 已提交
77
			// #endif
study夏羽's avatar
study夏羽 已提交
78 79 80
		}
	}
}
study夏羽's avatar
study夏羽 已提交
81 82 83

// #endif
export default mpMixins