receptionTrackMixin.js
945 Bytes
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
export default {
watch: {
id: {
immediate: true,
handler (key) {
if (!key) return
let item = this.media.find(e => e.id == key),
value = this.receptionTrack[key]
if (value) {
value.openCount += 1
value.entryTime = Date.now()
} else {
value = {
openCount: 1,
name: item.title,
id: item.id,
stayTime: 0,
entryTime: Date.now()
}
}
this.$store.dispatch("setReceptionTrack", { key, value })
}
}
},
computed:{
receptionTrack () {
return this.$store.state.user.receptionTrack
}
},
methods: {
receptionTrackLeave () {
let key = this.id,
value = this.receptionTrack[key]
value.stayTime += Number(((Date.now() - value.entryTime) / 1000).toFixed(2))
this.$store.dispatch("setReceptionTrack", { key, value })
}
}
}