-
Notifications
You must be signed in to change notification settings - Fork 560
/
Copy pathindex.js
120 lines (117 loc) · 2.87 KB
/
index.js
1
2
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import Vbutton from './button/index.vue'
import { i18n, lan } from '../../unit/const'
import store from '../../vuex/store'
import todo from '../../control/todo'
export default {
props: ['filling'],
data() {
return {
fillingNum: 0
}
},
watch: {
$props: {
deep: true,
handler(nextProps) {
this.fillingNum = nextProps.filling + 20
}
}
},
computed: {
keyboard() {
return this.$store.state.keyboard
},
rotation: () => i18n.rotation[lan],
labelLeft: () => i18n.left[lan],
labelRight: () => i18n.right[lan],
labelDown: () => i18n.down[lan],
labelDropSpace: () => `${i18n.drop[lan]} (SPACE)`,
labelResetR: () => `${i18n.reset[lan]}(R)`,
labelSoundS: () => `${i18n.sound[lan]}(S)`,
labelPauseP: () => `${i18n.pause[lan]}(P)`
},
mounted() {
const touchEventCatch = {} // 对于手机操作, 触发了touchstart, 将作出记录, 不再触发后面的mouse事件
// 在鼠标触发mousedown时, 移除元素时可以不触发mouseup, 这里做一个兼容, 以mouseout模拟mouseup
const mouseDownEventCatch = {}
document.addEventListener(
'touchstart',
e => {
if (e.preventDefault) {
e.preventDefault()
}
},
true
)
document.addEventListener('touchend', (e) => {
if (e.preventDefault) {
e.preventDefault();
}
}, true);
// 阻止双指放大
document.addEventListener('gesturestart', (event) => {
event.preventDefault();
});
document.addEventListener(
'mousedown',
e => {
if (e.preventDefault) {
e.preventDefault()
}
},
true
)
Object.keys(todo).forEach(key => {
this.$refs[`dom_${key}`].$el.addEventListener(
'mousedown',
() => {
if (touchEventCatch[key] === true) {
return
}
todo[key].down(store)
mouseDownEventCatch[key] = true
},
true
)
this.$refs[`dom_${key}`].$el.addEventListener(
'mouseup',
() => {
if (touchEventCatch[key] === true) {
touchEventCatch[key] = false
return
}
todo[key].up(store)
mouseDownEventCatch[key] = false
},
true
)
this.$refs[`dom_${key}`].$el.addEventListener(
'mouseout',
() => {
if (mouseDownEventCatch[key] === true) {
todo[key].up(store)
}
},
true
)
this.$refs[`dom_${key}`].$el.addEventListener(
'touchstart',
() => {
touchEventCatch[key] = true
todo[key].down(store)
},
true
)
this.$refs[`dom_${key}`].$el.addEventListener(
'touchend',
() => {
todo[key].up(store)
},
true
)
})
},
components: {
Vbutton
}
}