Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
adjfks committed Jul 4, 2022
1 parent 932fe75 commit 305ef3a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 48 deletions.
2 changes: 1 addition & 1 deletion components.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/core/pull/3399
// Read more: https://github.com/vuejs/vue-next/pull/3399
import '@vue/runtime-core'

declare module '@vue/runtime-core' {
Expand Down
4 changes: 2 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -e

# 构建
npm run build
npm run deploy

# 进入构建文件夹
cd dist
Expand All @@ -13,7 +13,7 @@ cd dist
# echo 'www.example.com' > CNAME

git init
git checkout -b main
git checkout main
git add -A
git commit -m 'deploy'

Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview",
"sl": "npx stylelint src/**/*.{vue,less}"
"sl": "npx stylelint src/**/*.{vue,less}",
"deploy": "vite build --base=/NeteaseCloudMusic-Website/",
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
"@element-plus/icons-vue": "^2.0.4",
Expand All @@ -23,6 +25,7 @@
"@iconify-json/carbon": "^1.1.5",
"@iconify-json/ic": "^1.1.4",
"@iconify-json/ri": "^1.1.2",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.40",
"@unocss/preset-attributify": "^0.39.3",
"@unocss/preset-icons": "^0.39.3",
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 19 additions & 23 deletions src/store/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import { getMusicUrl } from '@/api/player'
import { throttle } from 'lodash'

export interface Music {
playing: boolean,
url: string,
totalTime: number,
currentTime: number,
playing: boolean
url: string
totalTime: number
currentTime: number
}

export interface Player {
playlist: any[],
currentIdx: number,
playlist: any[]
currentIdx: number
music: Music
}


const audioEl = document.createElement('audio')
audioEl.style.display = 'none'
audioEl.setAttribute('use-credentials', 'true')
Expand All @@ -32,8 +31,8 @@ export const usePlayer = defineStore('player', {
playing: false,
url: '',
totalTime: 0,
currentTime: 0 // 以秒为单位
}
currentTime: 0, // 以秒为单位
},
} as Player
},
getters: {
Expand All @@ -42,7 +41,7 @@ export const usePlayer = defineStore('player', {
},
currentId: (state) => {
return state.playlist[state.currentIdx].id
}
},
},
actions: {
// 替换播放列表
Expand All @@ -62,19 +61,21 @@ export const usePlayer = defineStore('player', {

this.music.playing = false

this.music.totalTime = Math.floor(this.playlist[this.currentIdx].dt / 1000)
this.music.totalTime = Math.floor(
this.playlist[this.currentIdx].dt / 1000
)
this.music.currentTime = 0

audioEl.src = this.music.url

console.log('更新音乐信息成功');
console.log('更新音乐信息成功')
this.play()
})
},
// 直接自动播放播放
play() {
if (this.music.playing) return
console.log('开始play');
console.log('开始play')

audioEl.play()
this.music.playing = true
Expand All @@ -92,16 +93,15 @@ export const usePlayer = defineStore('player', {
// 实时更新当前播放时间
updateCurrentTime() {
if (!audioEl) return console.log('audioEl not found')
audioEl.ontimeupdate = throttle((event) => {
audioEl.ontimeupdate = throttle((event: any) => {
if (event.target === null) return
this.music.currentTime = (event.target as any).currentTime
}, 500)
},
// 拖拽进度条
changeCurrentTime(time: number) {
this.music.currentTime = time
if (audioEl)
audioEl.currentTime = time
if (audioEl) audioEl.currentTime = time
},
// 自动播放下一首
autoPlay() {
Expand All @@ -114,23 +114,20 @@ export const usePlayer = defineStore('player', {
// 下一首
if (this.currentIdx === this.length - 1) return
this.currentIdx++
console.log(this.currentIdx);
console.log(this.currentIdx)
// 更新音乐信息
this.updateMusic()

}
},
// 上一曲或下一曲
goMusic(step: -1 | 1) {
if (step < 0 && this.currentIdx > 0) {
this.currentIdx += step
this.updateMusic()

}
if (step > 0 && this.currentIdx < this.playlist.length - 1) {
this.currentIdx += step
this.updateMusic()

}
},
// 初始化
Expand All @@ -140,11 +137,10 @@ export const usePlayer = defineStore('player', {
audioEl.src = this.music.url
audioEl.currentTime = this.music.currentTime
}
}
}
},
},
})


/*
http://m7.music.126.net/20220630211607/b14eafd305e2a91abd324b3f25a148fb/ymusic/obj/w5zDlMODwrDDiGjCn8Ky/14051778144/74f5/2c66/b400/eab29fb52cac07613ee2f7b978c49ce2.mp3
*/
4 changes: 2 additions & 2 deletions src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import { Method } from '@/type'

const baseURL = 'http://localhost:4000/'
const baseURL = __DEV__ ? 'http://localhost:4000/' : 'http://120.25.153.83/4000'
const instance = axios.create({
baseURL,
timeout: 5000,
Expand All @@ -21,6 +21,6 @@ export default (url: string, method: Method, submitData?: any): any => {
return instance({
url,
method,
[method.toLowerCase() === 'get' ? 'params' : 'data']: submitData
[method.toLowerCase() === 'get' ? 'params' : 'data']: submitData,
})
}
35 changes: 16 additions & 19 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import presetIcons from '@unocss/preset-icons'
import presetUno from '@unocss/preset-uno'
import presetAttributify from '@unocss/preset-attributify'


// https://vitejs.dev/config/
export default defineConfig({
plugins: [
Expand All @@ -21,16 +20,14 @@ export default defineConfig({
// targets to transform
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/, /\.vue\?vue/, // .vue
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/, // .md
],

// Auto import functions from Vue, e.g. ref, reactive, toRef...
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
imports: [
'vue',
'vue-router',
],
imports: ['vue', 'vue-router'],

// Auto import functions from Element Plus, e.g. ElMessage, ElMessageBox... (with style)
// 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
Expand All @@ -44,41 +41,41 @@ export default defineConfig({
}),
],

dirs: [
'./utils'
],
dirs: ['./utils'],

dts: true
dts: true,
}),
Components({
resolvers: [
ElementPlusResolver(),
// Auto register icon components
// 自动注册图标组件
IconsResolver(),
]
],
}),
Icons({
autoInstall: true,
}),
vueJsx(),
Unocss({
presets: [
presetIcons({ /* options */ }),
presetIcons({
/* options */
}),
// ...other presets
presetUno(),
presetAttributify()
presetAttributify(),
],
}),
],
resolve: {
alias: {
'@': resolve(__dirname, './src')
}
'@': resolve(__dirname, './src'),
},
},
css: {
modules: {
scopeBehaviour: 'local'
scopeBehaviour: 'local',
},
preprocessorOptions: {
// less: {
Expand All @@ -92,13 +89,13 @@ export default defineConfig({
// },
// javascriptEnabled: true
// }
}
},
},
define: {
__DEV__: true
__DEV__: true,
},
server: {
port: 4001
port: 4001,
},
// 部署时设置
// base: '/NeteaseCloudMusic-Website/'
Expand Down

0 comments on commit 305ef3a

Please sign in to comment.