Skip to content

Commit

Permalink
字体更换;虾米音乐api优化;播放控制优化
Browse files Browse the repository at this point in the history
  • Loading branch information
sunzongzheng committed Nov 8, 2017
1 parent d994be7 commit af0ff8c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
8 changes: 6 additions & 2 deletions src/main/ipcEvent/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import musicAPI from 'music-api'

export default {
async on (mainWindow, {op, vendor, query}) {
let data = await musicAPI[op](vendor, query)
mainWindow.webContents.send(op, data)
try {
let data = await musicAPI[op](vendor, query)
mainWindow.webContents.send(op, data)
} catch (e) {
mainWindow.webContents.send(op, e)
}
}
}
47 changes: 35 additions & 12 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
</template>

<script>
import { mapState } from 'vuex'
export default {
computed: {
...mapState('api', ['play'])
},
methods: {
// 登录成功回调
loginSuccessed (event, info) {
Expand All @@ -20,19 +25,35 @@
},
// 获取歌曲回调
getSong (event, arg) {
let lyric = arg.lyric || []
lyric = lyric.map(item => {
let arr = item[0].match(/^(\d+):(\d+).(\d+)$/)
if (arr) {
item[0] = parseInt(arr[1]) * 60 * 1000 + parseInt(arr[2]) * 1000 + parseInt(arr[3].padEnd(3, '0'))
console.log(arg)
if (arg.success) {
let lyric = arg.lyric || []
lyric = lyric.map(item => {
let arr = item[0].match(/^(\d+):(\d+).(\d+)$/)
if (arr) {
item[0] = parseInt(arr[1]) * 60 * 1000 + parseInt(arr[2]) * 1000 + parseInt(arr[3].padEnd(3, '0'))
}
return item
})
this.$store.commit('api/updatePlay', {
url: arg.file || arg.url,
lyric,
pause: false
})
} else {
if (this.play.info.source === 'xiami' && this.play.info.file) {
this.$store.commit('api/updatePlay', {
url: this.play.info.file,
lyric: [],
pause: false
})
} else {
this.$message({
message: arg.message,
type: 'warning'
})
}
return item
})
this.$store.commit('api/updatePlay', {
url: arg.url,
lyric,
pause: false
})
}
},
// 搜索歌曲回调
searchSong (event, data) {
Expand Down Expand Up @@ -82,6 +103,8 @@
margin: 0;
padding: 0;
height: 100%;
font-family: arial, "Hiragino Sans GB", "Microsoft YaHei",
"WenQuanYi Micro Hei", sans-serif;
}
ul, li {
Expand Down
14 changes: 10 additions & 4 deletions src/renderer/view/home/components/lyrics/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
<div :class="{[s.app]:true,[s.active]:show}">
<div :class="s.wrap"></div>
<div :class="s.cover" :style="style"></div>
<ul :class="s.main" ref="main" @wheel="scrollBarWheel">
<ul :class="s.main" ref="main" @wheel="scrollBarWheel" v-if="play.lyric.length">
<li v-for="(item,index) in play.lyric" :class="{[s.item]:true,[s.active]:activeIndex === index}">
{{item[1]}}
</li>
</ul>
<div :class="s.main" v-else>
<span :class="[s.item,s.nolyric,s.active]">暂无歌词信息...</span>
</div>
</div>
</template>
<script>
Expand Down Expand Up @@ -60,7 +63,6 @@
const main = this.$refs.main
if (main && main.children[answer]) {
if (!this.userScrolling) {
// main.scrollTop = main.children[answer].offsetTop - main.offsetHeight / 2
$(main).clearQueue().stop().animate({
scrollTop: main.children[answer].offsetTop - main.offsetHeight / 2
}, 300, 'linear')
Expand Down Expand Up @@ -104,9 +106,9 @@
width: 100%;
height: 100%;
padding-bottom: 60px;
transition: all .3s;
transition: all .4s;
&.active {
transition: all .3s;
transition: all .4s;
transform: translateY(0);
}
.wrap,
Expand Down Expand Up @@ -142,6 +144,10 @@
color: #26B36C;
}
}
.nolyric {
display: inline-flex;
margin-top: 20px;
}
&::-webkit-scrollbar {
display: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default {
},
watch: {
'play.pause' (val) {
window.clearInterval(this.timer)
this.$nextTick(() => {
const audio = this.$refs.audio
if (val) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<!-- 打开列表 !-->
<Icon type="musiclist" :class="s.icon" style="margin-top: 2px;" :disabled="!playlist.length"
@click.native="playlist.length?$emit('showPlaylist'):''"></Icon>
<audio :src="play.url" ref="audio" autoplay></audio>
<audio :src="play.url" ref="audio"></audio>
</div>
</template>
<script src="./index.js"></script>
Expand Down

0 comments on commit af0ff8c

Please sign in to comment.