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

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

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

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

study夏羽's avatar
update  
study夏羽 已提交
82 83
// #endif
export default mpMixins