Skip to content

Commit 2a79c77

Browse files
committed
(clean) audio player code
1 parent d00f7bb commit 2a79c77

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/ChatWindow/Message/AudioControl.vue

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<template>
22
<div
3-
:ref="refId"
3+
ref="progress"
44
class="vac-player-bar"
55
@mousedown="onMouseDown"
66
@mouseover="$emit('hover-audio-progress', true)"
77
@mouseout="$emit('hover-audio-progress', false)"
88
>
99
<div class="vac-player-progress">
10-
<div class="vac-line-container">
11-
<div class="vac-line-progress" :style="{ width: calculateSize }" />
10+
<div ref="line" class="vac-line-container">
11+
<div class="vac-line-progress" :style="{ width: `${percentage}%` }" />
1212
<div
1313
class="vac-line-dot"
1414
:class="{ 'vac-line-dot__active': isMouseDown }"
15-
:style="{ left: calculateSize }"
15+
:style="{ left: `${percentage}%` }"
1616
/>
1717
</div>
1818
</div>
@@ -22,7 +22,6 @@
2222
<script>
2323
export default {
2424
props: {
25-
refId: { type: String, default: null },
2625
percentage: { type: Number, default: 0 }
2726
},
2827
@@ -32,16 +31,10 @@ export default {
3231
}
3332
},
3433
35-
computed: {
36-
calculateSize() {
37-
return this.percentage < 1 ? this.percentage * 100 : this.percentage + '%'
38-
}
39-
},
40-
4134
methods: {
4235
onMouseDown(ev) {
4336
this.isMouseDown = true
44-
const seekPos = this.calculateLineHeadPosition(ev, this.$refs[this.refId])
37+
const seekPos = this.calculateLineHeadPosition(ev, this.$refs['progress'])
4538
this.$emit('change-linehead', seekPos)
4639
document.addEventListener('mousemove', this.onMouseMove)
4740
document.addEventListener('mouseup', this.onMouseUp)
@@ -50,11 +43,11 @@ export default {
5043
this.isMouseDown = false
5144
document.removeEventListener('mouseup', this.onMouseUp)
5245
document.removeEventListener('mousemove', this.onMouseMove)
53-
const seekPos = this.calculateLineHeadPosition(ev, this.$refs[this.refId])
46+
const seekPos = this.calculateLineHeadPosition(ev, this.$refs['progress'])
5447
this.$emit('change-linehead', seekPos)
5548
},
5649
onMouseMove(ev) {
57-
const seekPos = this.calculateLineHeadPosition(ev, this.$refs[this.refId])
50+
const seekPos = this.calculateLineHeadPosition(ev, this.$refs['progress'])
5851
this.$emit('change-linehead', seekPos)
5952
},
6053
calculateLineHeadPosition(ev, element) {
@@ -99,7 +92,7 @@ export default {
9992
.vac-line-dot {
10093
position: absolute;
10194
top: -6px;
102-
margin-left: -8px;
95+
margin-left: -15px;
10396
height: 15px;
10497
width: 15px;
10598
border-radius: 50%;

src/ChatWindow/Message/AudioPlayer.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
</slot>
1111
</div>
1212
<audio-control
13-
ref-id="progress"
1413
:percentage="progress"
1514
@change-linehead="onUpdateProgress"
1615
@hover-audio-progress="$emit('hover-audio-progress', $event)"

0 commit comments

Comments
 (0)