Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zacharyzlj
Yz Music
提交
bfa67ab9
Y
Yz Music
项目概览
zacharyzlj
/
Yz Music
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
Yz Music
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bfa67ab9
编写于
2月 17, 2021
作者:
Z
Zachary
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: finish most function.
上级
b25ce76d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
140 addition
and
33 deletion
+140
-33
src/common/config.js
src/common/config.js
+5
-5
src/components/common/Player.vue
src/components/common/Player.vue
+123
-17
src/store/module/music/getters.js
src/store/module/music/getters.js
+12
-11
未找到文件。
src/common/config.js
浏览文件 @
bfa67ab9
export
const
playModeMap
=
{
sequence
:
{
code
:
"
sequence
"
,
icon
:
"
sequence
"
,
name
:
"
顺序
播放
"
icon
:
"
icn-loop
"
,
name
:
"
循环
播放
"
},
loop
:
{
code
:
"
loop
"
,
icon
:
"
loop
"
,
name
:
"
循环播放
"
icon
:
"
icn-one
"
,
name
:
"
单曲循环
"
},
random
:
{
code
:
"
random
"
,
icon
:
"
random
"
,
icon
:
"
icn-shuffle
"
,
name
:
"
随机播放
"
}
};
src/components/common/Player.vue
浏览文件 @
bfa67ab9
...
...
@@ -61,8 +61,8 @@
</span>
</span>
</div>
<div
class=
"m-pbar"
data-action=
"noop"
@
click=
"clickBar"
>
<div
class=
"barbg j-flag"
>
<div
class=
"m-pbar"
data-action=
"noop"
>
<div
class=
"barbg j-flag"
@
click=
"clickBar"
>
<div
class=
"rdy"
style=
"width: 0px"
></div>
<div
class=
"cur"
:style=
"'width: ' + barPrecent + '%'"
>
<span
class=
"btn f-tdn f-alpha"
@
mousedown=
"onChangeBar"
>
...
...
@@ -93,11 +93,21 @@
>
</div>
<div
class=
"ctrl f-fl f-pr j-flag"
>
<div
class=
"m-vol"
style=
"visibility: hidden"
>
<div
class=
"m-vol"
:style=
"
{ visibility: isShowVol ? 'visible' : 'hidden' }"
>
<div
class=
"barbg"
></div>
<div
class=
"vbg j-t"
id=
"auto-id-L68XOkib47dr55Wt"
>
<div
class=
"curr j-t"
style=
"height: 74.4px"
></div>
<span
class=
"btn f-alpha j-t"
style=
"top: 16.2px"
></span>
<div
class=
"vbg j-t"
@
click=
"clickVolBar"
>
<div
class=
"curr j-t"
:style=
"
{ height: volumePrecent * 93 + 'px' }"
>
</div>
<span
class=
"btn f-alpha j-t"
:style=
"
{ top: (1 - volumePrecent) * 81 + 'px' }"
@mousedown="onChangeVolBar"
>
</span>
</div>
</div>
<a
...
...
@@ -105,13 +115,16 @@
hidefocus=
"true"
data-action=
"volume"
class=
"icn icn-vol"
@
click=
"clickVolBtn"
></a>
<a
href=
"javascript:;"
hidefocus=
"true"
data-action=
"mode"
class=
"icn icn-loop"
title=
"循环"
class=
"icn"
:class=
"currentMode.icon"
:title=
"currentMode.name"
@
click=
"onChangeMode"
></a>
<span
class=
"add f-pr"
>
<span
class=
"tip"
style=
"display: none"
>
已添加到播放列表
</span>
...
...
@@ -121,10 +134,15 @@
hidefocus=
"true"
data-action=
"panel"
class=
"icn icn-list s-fc3"
>
1
>
{{
playlist
.
length
}}
</a>
</span>
<div
class=
"tip tip-1"
style=
"display: none"
>
循环
</div>
<div
class=
"tip tip-1"
:style=
"
{ display: isShowModeTip ? '' : 'none' }"
>
{{
currentMode
.
name
}}
</div>
</div>
</div>
</div>
...
...
@@ -140,19 +158,24 @@
<
script
>
import
{
isDef
,
genSongPlayUrl
,
formatTime
}
from
"
common/utils
"
;
import
{
playModeMap
}
from
"
common/config
"
;
// import { getSong } from "api";
export
default
{
data
()
{
return
{
isLock
:
false
,
isShowVol
:
false
,
isHoldBtn
:
false
,
isShowModeTip
:
false
,
songReady
:
false
,
volumePrecent
:
1
,
volume
:
100
,
};
},
mounted
()
{
console
.
log
(
this
.
audio
);
this
.
audio
.
volume
=
this
.
volumePrecent
;
},
methods
:
{
formatTime
(
duration
)
{
...
...
@@ -192,15 +215,53 @@ export default {
},
timeupdate
(
e
)
{
const
time
=
e
.
target
.
currentTime
;
console
.
log
(
time
);
//
console.log(time);
this
.
$store
.
commit
(
"
music/setCurrentTime
"
,
time
);
},
onChangeMode
()
{
const
modeKeys
=
Object
.
keys
(
playModeMap
);
const
currentModeIndex
=
modeKeys
.
findIndex
(
(
key
)
=>
playModeMap
[
key
].
code
===
this
.
playMode
);
const
nextIndex
=
(
currentModeIndex
+
1
)
%
modeKeys
.
length
;
const
nextModeKey
=
modeKeys
[
nextIndex
];
const
nextMode
=
playModeMap
[
nextModeKey
];
this
.
$store
.
commit
(
"
music/setPlayMode
"
,
nextMode
.
code
);
this
.
showModeChangeTip
();
},
showModeChangeTip
()
{
this
.
isShowModeTip
=
true
;
if
(
this
.
ModeTipTimer
)
clearTimeout
(
this
.
ModeTipTimer
);
this
.
ModeTipTimer
=
setTimeout
(()
=>
{
this
.
isShowModeTip
=
false
;
},
1000
);
},
clickVolBtn
()
{
this
.
isShowVol
=
!
this
.
isShowVol
;
},
onChangeVolBar
(
e
)
{
let
odiv
=
e
.
target
;
let
screenH
=
document
.
documentElement
.
clientHeight
;
let
percent
;
document
.
onmousemove
=
(
e
)
=>
{
percent
=
(
screenH
-
e
.
clientY
-
44
)
/
101
;
if
(
percent
>=
0
&&
percent
<=
1
)
this
.
volumePrecent
=
percent
;
};
document
.
onmouseup
=
(
e
)
=>
{
document
.
onmousemove
=
null
;
document
.
onmouseup
=
null
;
};
},
clickVolBar
(
e
)
{
let
screenH
=
document
.
documentElement
.
clientHeight
;
let
precent
=
(
screenH
-
e
.
clientY
-
44
)
/
101
;
this
.
volumePrecent
=
precent
;
},
onChangeBar
(
e
)
{
this
.
isHoldBtn
=
true
;
console
.
log
(
e
);
let
odiv
=
e
.
target
;
//获取目标元素
console
.
log
(
odiv
.
offsetLeft
);
console
.
log
(
odiv
.
style
.
left
);
//算出鼠标相对元素的位置
let
disX
=
e
.
clientX
-
odiv
.
offsetLeft
;
console
.
log
(
disX
);
...
...
@@ -226,8 +287,7 @@ export default {
},
clickBar
(
e
)
{
if
(
!
this
.
isHoldBtn
)
{
let
percent
=
(
e
.
clientX
-
416
)
/
493
;
console
.
log
(
percent
);
let
percent
=
e
.
offsetX
/
493
;
let
targetTime
=
this
.
currentSong
.
durationSecond
*
percent
;
// this.$store.commit('music/setCurrenTime', targetTime)
this
.
audio
.
currentTime
=
targetTime
;
...
...
@@ -242,6 +302,9 @@ export default {
playing
()
{
return
this
.
$store
.
state
.
music
.
playing
;
},
playlist
()
{
return
this
.
$store
.
state
.
music
.
playlist
;
},
hasCurrentSong
()
{
return
isDef
(
this
.
currentSong
.
id
);
},
...
...
@@ -255,6 +318,12 @@ export default {
console
.
log
(
this
.
$store
.
getters
);
return
this
.
$store
.
getters
[
"
music/nextSong
"
];
},
playMode
()
{
return
this
.
$store
.
state
.
music
.
playMode
;
},
currentMode
()
{
return
playModeMap
[
this
.
playMode
];
},
currentTime
()
{
return
this
.
$store
.
state
.
music
.
currentTime
;
},
...
...
@@ -266,23 +335,36 @@ export default {
watch
:
{
currentSong
(
newSong
,
oldSong
)
{
console
.
log
(
"
new
"
,
newSong
,
"
old
"
,
oldSong
);
// 清空歌曲
if
(
!
newSong
.
id
)
{
this
.
audio
.
pause
();
this
.
audio
.
currentTime
=
0
;
return
;
}
// 单曲循环
if
(
oldSong
&&
newSong
.
id
===
oldSong
.
id
)
{
this
.
setCurrentTime
(
0
);
this
.
$store
.
commit
(
"
music/setCurrentTime
"
,
0
);
this
.
audio
.
currentTime
=
0
;
this
.
play
();
return
;
}
if
(
this
.
playing
)
{
this
.
play
();
this
.
songReady
=
false
;
if
(
this
.
timer
)
{
clearTimeout
(
this
.
timer
);
}
this
.
timer
=
setTimeout
(()
=>
{
if
(
this
.
playing
)
this
.
play
();
},
1000
);
},
playing
(
newPlaying
)
{
console
.
log
(
"
new playing
"
,
newPlaying
);
this
.
$nextTick
(()
=>
(
newPlaying
?
this
.
play
()
:
this
.
pause
()));
},
volumePrecent
(
newVol
)
{
this
.
audio
.
volume
=
newVol
;
},
},
};
</
script
>
...
...
@@ -600,9 +682,15 @@ i {
margin
:
11px
2px
0
0
;
text-indent
:
-9999px
;
}
.m-playbar
.icn-add
:hover
{
background-position
:
-88px
-189px
;
}
.m-playbar
.icn-add
{
background-position
:
-88px
-163px
;
}
.m-playbar
.icn-share
:hover
{
background-position
:
-114px
-189px
;
}
.m-playbar
.icn-share
{
background-position
:
-114px
-163px
;
}
...
...
@@ -662,6 +750,9 @@ i {
.m-playbar
.icn-vol
{
background-position
:
-2px
-248px
;
}
.m-playbar
.icn-vol
:hover
{
background-position
:
-31px
-248px
;
}
.m-playbar
.icn
{
float
:
left
;
width
:
25px
;
...
...
@@ -669,9 +760,24 @@ i {
margin
:
11px
2px
0
0
;
text-indent
:
-9999px
;
}
.m-playbar
.icn-loop
:hover
{
background-position
:
-33px
-344px
;
}
.m-playbar
.icn-loop
{
background-position
:
-3px
-344px
;
}
.m-playbar
.icn-one
:hover
{
background-position
:
-93px
-344px
;
}
.m-playbar
.icn-one
{
background-position
:
-66px
-344px
;
}
.m-playbar
.icn-shuffle
:hover
{
background-position
:
-93px
-248px
;
}
.m-playbar
.icn-shuffle
{
background-position
:
-66px
-248px
;
}
.m-playbar
.add
{
float
:
left
;
width
:
59px
;
...
...
src/store/module/music/getters.js
浏览文件 @
bfa67ab9
import
{
isDef
}
from
"
common/utils
"
;
import
{
playModeMap
}
from
"
common/config
"
;
function
getRandomIndex
(
playlist
,
currentIndex
)
{
// 防止无限循环
if
(
playlist
.
length
===
1
)
{
return
currentIndex
;
}
let
index
=
Math
.
round
(
Math
.
random
()
*
(
playlist
.
length
-
1
));
if
(
index
===
currentIndex
)
{
index
=
getRandomIndex
(
playlist
,
currentIndex
);
}
return
index
;
}
export
default
{
currentIndex
(
state
)
{
const
{
currentSong
,
playlist
}
=
state
;
return
playlist
.
findIndex
(({
id
})
=>
id
===
currentSong
.
id
);
},
getRandomIndex
(
playlist
,
currentIndex
)
{
// 防止无限循环
if
(
playlist
.
length
===
1
)
{
return
currentIndex
;
}
let
index
=
Math
.
round
(
Math
.
random
()
*
(
playlist
.
length
-
1
));
if
(
index
===
currentIndex
)
{
index
=
getRandomIndex
(
playlist
,
currentIndex
);
}
return
index
;
},
nextSong
(
state
,
getters
)
{
const
{
playlist
,
playMode
}
=
state
;
const
nextStratMap
=
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录