This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
App.vue
227 lines (191 loc) · 5.34 KB
/
App.vue
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<script setup>
import { message, theme } from 'ant-design-vue'
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import { onMounted, provide, reactive, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { checkLogin } from '/src/js/users'
const route = useRoute()
const router = useRouter()
//当前用户的信息 组入给子组件,便于根据当前登录的用户获取一些接口信息
const user = reactive({
id: null,
avatar: '',
name: '',
profile: '',
gender: 0
})
onMounted(async () => {
await checkLogin(user)
})
//底层音频播放器
const audio = new Audio()
audio.crossOrigin = 'anonymous'
//简单封装一下播放器 注入给子组件
const player = reactive({
id: null,
src: null,
cover: null,
percent: 0,
currSec: 0,
play(newId, newSrc, cover) {
this.id = newId
audio.src = newSrc
if (this.src && this.src.startsWith('blob:')) {
URL.revokeObjectURL(this.src)
}
this.src = newSrc
this.cover = cover
audio.play()
},
stop() {
audio.pause()
if (this.src && this.src.startsWith('blob:')) {
URL.revokeObjectURL(this.src)
}
this.id = null
this.src = null
this.cover = null
this.percent = 0
this.currSec = 0
}
})
audio.onended = e => player.stop()
audio.ontimeupdate = e => {
player.currSec = Math.floor(audio.currentTime)
player.percent = audio.currentTime * 100 / audio.duration
}
audio.onerror = e => {
message.warn('播放失败,可能是' + (player.src.startsWith('blob:') ? '浏览器不支持当前的音频格式(但可能不影响上传)' : '浏览器不支持的格式或网易云返回的地址访问失败所致'))
player.stop()
}
const current = ref('list')
watch(current, (name,old) => {
if (name != 'lite') {
router.replace({ name })
} else {
current.value = old
let width = 400, height = 680
window.open('lite.html', 'ncu_lite', `popup=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,width=${width},height=${height},left=${(window.screen.width - width) / 2},top=${(window.screen.height - height) / 2}`)
window.close()
}
})
watch(route, route => current.value = route.name)
//系统深色主题自动监听探测 并注入给下游组件使用
const themeMedia = window.matchMedia("(prefers-color-scheme: dark)")
const isDark = ref(themeMedia.matches)
themeMedia.addEventListener('change', e => isDark.value = e.matches)
provide('player', player)
provide('user', user)
provide('isDark', isDark)//后续如果有一些自定义的元素需要根据深色主题定制效果可以使用这个
</script>
<template>
<a-config-provider :locale="zhCN"
:theme="{ token: { fontFamily: 'jbt', fontSize: 16, controlHeight: 36 }, algorithm: isDark ? [theme.compactAlgorithm, theme.darkAlgorithm] : theme.compactAlgorithm }">
<template v-if="user.name && user.avatar">
<app-head />
<a-tabs v-model:activeKey="current" animated>
<a-tab-pane key="list" tab="网盘音乐列表"/>
<a-tab-pane key="uploader" tab="本地音乐上传"/>
<a-tab-pane key="lite" tab="Lite版"/>
</a-tabs>
<router-view v-slot="{ Component }">
<transition name="page">
<keep-alive>
<component :is="Component" />
</keep-alive>
</transition>
</router-view>
<spectrum :audio="audio" />
</template>
<login v-else />
</a-config-provider>
</template>
<style>
@font-face {
font-family: jbt;
src: url('/fonts/jbt.woff2');
}
#app {
position: relative;
max-width: 1440px;
min-width: 960px;
width: 90%;
min-height: 100%;
margin: auto;
}
.page-enter-active,
.page-leave-active {
transition: all .3s ease;
position: absolute !important;
}
.page-enter-from,
.page-leave-to {
transform: translateY(20px);
opacity: 0;
}
.ant-page-header {
padding: 0;
}
.ant-page-header-heading-left,
.ant-tabs-nav-list{
backdrop-filter: blur(3px);
}
.ant-tabs-nav {
margin-bottom: 5px !important;
}
.ant-page-header {
padding-top: 10px;
}
.userinfo img {
border: 1px solid #aaa;
border-radius: 50%;
}
.ant-table-row:nth-child(even) {
background-color: #fafafa;
}
.icn {
display: inline-block;
box-sizing: border-box;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px;
transition: all .3s ease;
color: #666;
}
.ant-progress:hover .icn {
color: #1890ff
}
.ant-page-header {
background: transparent;
}
.ant-page-header .ant-page-header-back {
margin-right: 0;
}
.playing .ant-page-header-heading-left .ant-avatar img {
animation: turn 5s linear infinite;
}
#multi-user .ant-avatar {
cursor: pointer;
opacity: .3;
transition: all .2s ease-in-out;
}
#multi-user .ant-avatar:hover {
opacity: 1;
}
@keyframes turn {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@media (prefers-color-scheme: dark) {
:root {
background-color: #141414;
}
.ant-table-row:nth-child(even) {
background-color: rgb(29, 29, 29);
}
}</style>