-
Notifications
You must be signed in to change notification settings - Fork 98
/
Progress.tsx
77 lines (71 loc) 路 2.02 KB
/
Progress.tsx
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
import * as Vue from 'vue-tsx-support';
import Comopnent from 'vue-class-component';
import { Inject } from 'vue-property-decorator';
import Touch from '@moefe/vue-touch';
import Icon from './Icon';
@Comopnent
export default class Progress extends Vue.Component<{}> {
public $refs!: {
progressBar: HTMLElement;
};
@Inject()
private readonly aplayer!: APlayer.Options & {
currentTheme: string;
currentLoaded: number;
currentPlayed: number;
};
@Inject()
private readonly handleChangeProgress!: (
e: MouseEvent | TouchEvent,
percent: number
) => void;
private handleChange(e: MouseEvent | TouchEvent) {
const target = this.$refs.progressBar;
const targetLeft = target.getBoundingClientRect().left;
const clientX = !e.type.startsWith('touch')
? (e as MouseEvent).clientX
: (e as TouchEvent).changedTouches[0].clientX;
const offsetLeft = clientX - targetLeft;
let percent = offsetLeft / target.offsetWidth;
percent = Math.min(percent, 1);
percent = Math.max(percent, 0);
this.handleChangeProgress(e, percent);
}
render() {
const { currentTheme, currentLoaded, currentPlayed } = this.aplayer;
return (
<Touch
class="aplayer-bar-wrap"
onPanMove={this.handleChange}
onPanEnd={this.handleChange}
>
<div ref="progressBar" class="aplayer-bar">
<div
class="aplayer-loaded"
style={{
width: `${currentLoaded * 100}%`,
}}
/>
<div
class="aplayer-played"
style={{
width: `${currentPlayed * 100}%`,
backgroundColor: currentTheme,
}}
>
<span
class="aplayer-thumb"
style={{
backgroundColor: currentTheme,
}}
>
<span class="aplayer-loading-icon">
<Icon type="loading" />
</span>
</span>
</div>
</div>
</Touch>
);
}
}