├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .postcssrc.js
├── README.md
├── build
├── build.js
├── check-versions.js
├── dev-client.js
├── dev-server.js
├── utils.js
├── vue-loader.conf.js
├── webpack.base.conf.js
├── webpack.dev.conf.js
└── webpack.prod.conf.js
├── config
├── dev.env.js
├── index.js
└── prod.env.js
├── index.html
├── package.json
├── shotscreen
├── music-vue.png
├── player.png
├── rank.png
├── recommend.png
├── search.png
├── singer.png
└── song.png
├── src
├── App.vue
├── api
│ ├── config.js
│ ├── rank.js
│ ├── recommend.js
│ ├── search.js
│ ├── singer.js
│ └── song.js
├── assets
│ └── logo.png
├── base
│ ├── confirm
│ │ └── confirm.vue
│ ├── listview
│ │ └── listview.vue
│ ├── loading
│ │ ├── loading.gif
│ │ └── loading.vue
│ ├── no-result
│ │ ├── no-result.vue
│ │ ├── no-result@2x.png
│ │ └── no-result@3x.png
│ ├── progress-bar
│ │ └── progress-bar.vue
│ ├── progress-circle
│ │ └── progress-circle.vue
│ ├── scroll
│ │ └── scroll.vue
│ ├── search-box
│ │ └── search-box.vue
│ ├── search-list
│ │ └── search-list.vue
│ ├── slider
│ │ └── slider.vue
│ ├── song-list
│ │ ├── first@2x.png
│ │ ├── first@3x.png
│ │ ├── second@2x.png
│ │ ├── second@3x.png
│ │ ├── song-list.vue
│ │ ├── third@2x.png
│ │ └── third@3x.png
│ └── switches
│ │ └── switches.vue
├── common
│ ├── fonts
│ │ ├── music-icon.eot
│ │ ├── music-icon.svg
│ │ ├── music-icon.ttf
│ │ └── music-icon.woff
│ ├── image
│ │ └── default.png
│ ├── js
│ │ ├── cache.js
│ │ ├── config.js
│ │ ├── dom.js
│ │ ├── jsonp.js
│ │ ├── mixin.js
│ │ ├── singer.js
│ │ ├── song.js
│ │ └── util.js
│ └── stylus
│ │ ├── base.styl
│ │ ├── icon.styl
│ │ ├── index.styl
│ │ ├── mixin.styl
│ │ ├── reset.styl
│ │ └── variable.styl
├── components
│ ├── disc
│ │ └── disc.vue
│ ├── m-header
│ │ ├── logo@2x.png
│ │ ├── logo@3x.png
│ │ └── m-header.vue
│ ├── music-list
│ │ └── music-list.vue
│ ├── player
│ │ └── player.vue
│ ├── rank
│ │ └── rank.vue
│ ├── recommend
│ │ └── recommend.vue
│ ├── search
│ │ └── search.vue
│ ├── singer-detail
│ │ └── singer-detail.vue
│ ├── singer
│ │ └── singer.vue
│ ├── suggest
│ │ └── suggest.vue
│ ├── tab
│ │ └── tab.vue
│ ├── top-list
│ │ └── top-list.vue
│ └── user-center
│ │ └── user-center.vue
├── main.js
├── router
│ └── index.js
└── store
│ ├── actions.js
│ ├── getters.js
│ ├── index.js
│ ├── mutation-types.js
│ ├── mutations.js
│ └── state.js
└── static
└── .gitkeep
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", { "modules": false }],
4 | "stage-2"
5 | ],
6 | "plugins": ["transform-runtime"],
7 | "comments": false,
8 | "env": {
9 | "test": {
10 | "presets": ["env", "stage-2"],
11 | "plugins": [ "istanbul" ]
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // http://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parser: 'babel-eslint',
6 | parserOptions: {
7 | sourceType: 'module'
8 | },
9 | env: {
10 | browser: true,
11 | },
12 | // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
13 | extends: 'standard',
14 | // required to lint *.vue files
15 | plugins: [
16 | 'html'
17 | ],
18 | // add your custom rules here
19 | 'rules': {
20 | // allow paren-less arrow functions
21 | 'arrow-parens': 0,
22 | // allow async-await
23 | 'generator-star-spacing': 0,
24 | // allow debugger during development
25 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
26 | 'eol-last': 0,
27 | 'space-before-function-paren': 0
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
--------------------------------------------------------------------------------
/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | // to edit target browsers: use "browserlist" field in package.json
6 | "autoprefixer": {}
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | vue-music
2 | ---
3 | > 使用vue2.0构建音乐播放器
4 |
5 |
6 | 项目组成
7 | ---
8 |
9 | 
10 |
11 |
12 | 组件划分
13 | ---
14 |
15 | **基础组件**
16 |
17 | - confirm 确认对话框组件
18 | - listview 通讯录列表组件
19 | - loading 加载态组件
20 | - no-result 无结果展示页面
21 | - progress-bar 进度条组件
22 | - progress-circle 圆形进度条组件
23 | - scroll 移动端滚动组件
24 | - search-box 搜索框组件
25 | - search-list 搜索列表组件
26 | - slider 轮播图组件
27 | - switches 开关切换组件
28 | - top-list 顶部消息提示组件
29 | - song-list 歌曲列表组件
30 |
31 | **业务组件**
32 |
33 | - add-song 添加歌曲列表到组件
34 | - disc 歌单详情页组件
35 | - m-header 页面头部组件
36 | - music-list 歌曲列表页面组件
37 | - player 播放器内核组件
38 | - playlist 播放列表组件
39 | - rank 排行榜页面组件
40 | - recommend 推荐页面组件
41 | - search 搜索页面组件
42 | - singer 歌手页面组件
43 | - singer-detail 歌手详情页组件
44 | - suggest 搜索提示列表组件
45 | - tab 顶部导航栏组件
46 | - top-list 排行榜详情页组件
47 | - user-center 用户中心也组件
48 |
49 |
50 |
51 | 技术栈
52 | ---
53 |
54 | - MVVM框架:vue.js(2.0)
55 | - 状态管理:Vuex
56 | - 脚手架:ve-cli
57 | - 前端路由:Vue Router
58 | - 服务端通信:axios、jsonp
59 | - 懒加载:vue-lazyload
60 | - 移动端滚动库:better-scroll
61 | - 构建工具:webpack2.0
62 | - 源码:es6
63 | - 样式:stylus
64 | - 规范:eslint
65 |
66 |
67 |
68 |
69 | 项目结构
70 | ---
71 |
72 |
73 |
74 | 使用方法
75 | ---
76 |
77 | ```
78 | git clone https://github.com/poetries/vue-music.git
79 |
80 | # 进入根目录
81 | cd vue-music
82 |
83 | # 安装依赖
84 | npm install
85 |
86 | # 开发
87 | npm run dev
88 |
89 | # 构建
90 | npm run build
91 | ```
92 |
93 | screenshot
94 | ---
95 |
96 | - 推荐、歌手、排行页面
97 |
98 | 
99 | 
100 | 
101 |
102 |
103 | - 搜索、播放页面
104 |
105 |
106 | 
107 | 
108 | 
109 |
110 |
111 |
112 | License
113 | ---
114 |
115 | © 2017 A poetries's [Ideas](https://github.com/poetries/ideas).
116 |
117 |
--------------------------------------------------------------------------------
/build/build.js:
--------------------------------------------------------------------------------
1 | require('./check-versions')()
2 |
3 | process.env.NODE_ENV = 'production'
4 |
5 | var ora = require('ora')
6 | var rm = require('rimraf')
7 | var path = require('path')
8 | var chalk = require('chalk')
9 | var webpack = require('webpack')
10 | var config = require('../config')
11 | var webpackConfig = require('./webpack.prod.conf')
12 |
13 | var spinner = ora('building for production...')
14 | spinner.start()
15 |
16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
17 | if (err) throw err
18 | webpack(webpackConfig, function (err, stats) {
19 | spinner.stop()
20 | if (err) throw err
21 | process.stdout.write(stats.toString({
22 | colors: true,
23 | modules: false,
24 | children: false,
25 | chunks: false,
26 | chunkModules: false
27 | }) + '\n\n')
28 |
29 | console.log(chalk.cyan(' Build complete.\n'))
30 | console.log(chalk.yellow(
31 | ' Tip: built files are meant to be served over an HTTP server.\n' +
32 | ' Opening index.html over file:// won\'t work.\n'
33 | ))
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/build/check-versions.js:
--------------------------------------------------------------------------------
1 | var chalk = require('chalk')
2 | var semver = require('semver')
3 | var packageConfig = require('../package.json')
4 | var shell = require('shelljs')
5 | function exec (cmd) {
6 | return require('child_process').execSync(cmd).toString().trim()
7 | }
8 |
9 | var versionRequirements = [
10 | {
11 | name: 'node',
12 | currentVersion: semver.clean(process.version),
13 | versionRequirement: packageConfig.engines.node
14 | },
15 | ]
16 |
17 | if (shell.which('npm')) {
18 | versionRequirements.push({
19 | name: 'npm',
20 | currentVersion: exec('npm --version'),
21 | versionRequirement: packageConfig.engines.npm
22 | })
23 | }
24 |
25 | module.exports = function () {
26 | var warnings = []
27 | for (var i = 0; i < versionRequirements.length; i++) {
28 | var mod = versionRequirements[i]
29 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
30 | warnings.push(mod.name + ': ' +
31 | chalk.red(mod.currentVersion) + ' should be ' +
32 | chalk.green(mod.versionRequirement)
33 | )
34 | }
35 | }
36 |
37 | if (warnings.length) {
38 | console.log('')
39 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
40 | console.log()
41 | for (var i = 0; i < warnings.length; i++) {
42 | var warning = warnings[i]
43 | console.log(' ' + warning)
44 | }
45 | console.log()
46 | process.exit(1)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/build/dev-client.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | require('eventsource-polyfill')
3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
4 |
5 | hotClient.subscribe(function (event) {
6 | if (event.action === 'reload') {
7 | window.location.reload()
8 | }
9 | })
10 |
--------------------------------------------------------------------------------
/build/dev-server.js:
--------------------------------------------------------------------------------
1 | require('./check-versions')()
2 |
3 | var config = require('../config')
4 | if (!process.env.NODE_ENV) {
5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
6 | }
7 |
8 | var opn = require('opn')
9 | var path = require('path')
10 | var express = require('express')
11 | var webpack = require('webpack')
12 | var proxyMiddleware = require('http-proxy-middleware')
13 | var webpackConfig = require('./webpack.dev.conf')
14 | var axios = require('axios')
15 |
16 | // default port where dev server listens for incoming traffic
17 | var port = process.env.PORT || config.dev.port
18 | // automatically open browser, if not set will be false
19 | var autoOpenBrowser = !!config.dev.autoOpenBrowser
20 | // Define HTTP proxies to your custom API backend
21 | // https://github.com/chimurai/http-proxy-middleware
22 | var proxyTable = config.dev.proxyTable
23 |
24 | var app = express()
25 |
26 | var apiRoutes = express.Router()
27 |
28 | apiRoutes.get('/getDiscList', function (req, res) {
29 | var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'
30 | axios.get(url, {
31 | headers: {
32 | referer: 'https://c.y.qq.com/',
33 | host: 'c.y.qq.com'
34 | },
35 | params: req.query
36 | }).then((response) => {
37 | res.json(response.data)
38 | }).catch((e) => {
39 | console.log(e)
40 | })
41 | })
42 |
43 | apiRoutes.get('/lyric', function (req, res) {
44 | var url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg'
45 |
46 | axios.get(url, {
47 | headers: {
48 | referer: 'https://c.y.qq.com/',
49 | host: 'c.y.qq.com'
50 | },
51 | params: req.query
52 | }).then((response) => {
53 | var ret = response.data
54 | if (typeof ret === 'string') {
55 | var reg = /^\w+\(({[^()]+})\)$/
56 | var matches = ret.match(reg)
57 | if (matches) {
58 | ret = JSON.parse(matches[1])
59 | }
60 | }
61 | res.json(ret)
62 | }).catch((e) => {
63 | console.log(e)
64 | })
65 | })
66 |
67 | app.use('/api', apiRoutes)
68 |
69 | var compiler = webpack(webpackConfig)
70 |
71 | var devMiddleware = require('webpack-dev-middleware')(compiler, {
72 | publicPath: webpackConfig.output.publicPath,
73 | quiet: true
74 | })
75 |
76 | var hotMiddleware = require('webpack-hot-middleware')(compiler, {
77 | log: () => {}
78 | })
79 | // force page reload when html-webpack-plugin template changes
80 | compiler.plugin('compilation', function (compilation) {
81 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
82 | hotMiddleware.publish({ action: 'reload' })
83 | cb()
84 | })
85 | })
86 |
87 | // proxy api requests
88 | Object.keys(proxyTable).forEach(function (context) {
89 | var options = proxyTable[context]
90 | if (typeof options === 'string') {
91 | options = { target: options }
92 | }
93 | app.use(proxyMiddleware(options.filter || context, options))
94 | })
95 |
96 | // handle fallback for HTML5 history API
97 | app.use(require('connect-history-api-fallback')())
98 |
99 | // serve webpack bundle output
100 | app.use(devMiddleware)
101 |
102 | // enable hot-reload and state-preserving
103 | // compilation error display
104 | app.use(hotMiddleware)
105 |
106 | // serve pure static assets
107 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
108 | app.use(staticPath, express.static('./static'))
109 |
110 | var uri = 'http://localhost:' + port
111 |
112 | var _resolve
113 | var readyPromise = new Promise(resolve => {
114 | _resolve = resolve
115 | })
116 |
117 | console.log('> Starting dev server...')
118 | devMiddleware.waitUntilValid(() => {
119 | console.log('> Listening at ' + uri + '\n')
120 | // when env is testing, don't need open it
121 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
122 | opn(uri)
123 | }
124 | _resolve()
125 | })
126 |
127 | var server = app.listen(port)
128 |
129 | module.exports = {
130 | ready: readyPromise,
131 | close: () => {
132 | server.close()
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/build/utils.js:
--------------------------------------------------------------------------------
1 | var path = require('path')
2 | var config = require('../config')
3 | var ExtractTextPlugin = require('extract-text-webpack-plugin')
4 |
5 | exports.assetsPath = function (_path) {
6 | var assetsSubDirectory = process.env.NODE_ENV === 'production'
7 | ? config.build.assetsSubDirectory
8 | : config.dev.assetsSubDirectory
9 | return path.posix.join(assetsSubDirectory, _path)
10 | }
11 |
12 | exports.cssLoaders = function (options) {
13 | options = options || {}
14 |
15 | var cssLoader = {
16 | loader: 'css-loader',
17 | options: {
18 | minimize: process.env.NODE_ENV === 'production',
19 | sourceMap: options.sourceMap
20 | }
21 | }
22 |
23 | // generate loader string to be used with extract text plugin
24 | function generateLoaders (loader, loaderOptions) {
25 | var loaders = [cssLoader]
26 | if (loader) {
27 | loaders.push({
28 | loader: loader + '-loader',
29 | options: Object.assign({}, loaderOptions, {
30 | sourceMap: options.sourceMap
31 | })
32 | })
33 | }
34 |
35 | // Extract CSS when that option is specified
36 | // (which is the case during production build)
37 | if (options.extract) {
38 | return ExtractTextPlugin.extract({
39 | use: loaders,
40 | fallback: 'vue-style-loader'
41 | })
42 | } else {
43 | return ['vue-style-loader'].concat(loaders)
44 | }
45 | }
46 |
47 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html
48 | return {
49 | css: generateLoaders(),
50 | postcss: generateLoaders(),
51 | less: generateLoaders('less'),
52 | sass: generateLoaders('sass', { indentedSyntax: true }),
53 | scss: generateLoaders('sass'),
54 | stylus: generateLoaders('stylus'),
55 | styl: generateLoaders('stylus')
56 | }
57 | }
58 |
59 | // Generate loaders for standalone style files (outside of .vue)
60 | exports.styleLoaders = function (options) {
61 | var output = []
62 | var loaders = exports.cssLoaders(options)
63 | for (var extension in loaders) {
64 | var loader = loaders[extension]
65 | output.push({
66 | test: new RegExp('\\.' + extension + '$'),
67 | use: loader
68 | })
69 | }
70 | return output
71 | }
72 |
--------------------------------------------------------------------------------
/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils')
2 | var config = require('../config')
3 | var isProduction = process.env.NODE_ENV === 'production'
4 |
5 | module.exports = {
6 | loaders: utils.cssLoaders({
7 | sourceMap: isProduction
8 | ? config.build.productionSourceMap
9 | : config.dev.cssSourceMap,
10 | extract: isProduction
11 | })
12 | }
13 |
--------------------------------------------------------------------------------
/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path')
2 | var utils = require('./utils')
3 | var config = require('../config')
4 | var vueLoaderConfig = require('./vue-loader.conf')
5 |
6 | function resolve (dir) {
7 | return path.join(__dirname, '..', dir)
8 | }
9 |
10 | module.exports = {
11 | entry: {
12 | app: './src/main.js'
13 | },
14 | output: {
15 | path: config.build.assetsRoot,
16 | filename: '[name].js',
17 | publicPath: process.env.NODE_ENV === 'production'
18 | ? config.build.assetsPublicPath
19 | : config.dev.assetsPublicPath
20 | },
21 | resolve: {
22 | extensions: ['.js', '.vue', '.json'],
23 | alias: {
24 | 'src': resolve('src'),
25 | 'common': resolve('src/common'),
26 | 'components': resolve('src/components'),
27 | 'api': resolve('src/api'),
28 | 'base': resolve('src/base')
29 | }
30 | },
31 | module: {
32 | rules: [
33 | // {
34 | // test: /\.(js|vue)$/,
35 | // loader: 'eslint-loader',
36 | // enforce: 'pre',
37 | // include: [resolve('src'), resolve('test')],
38 | // options: {
39 | // formatter: require('eslint-friendly-formatter')
40 | // }
41 | // },
42 | {
43 | test: /\.vue$/,
44 | loader: 'vue-loader',
45 | options: vueLoaderConfig
46 | },
47 | {
48 | test: /\.js$/,
49 | loader: 'babel-loader',
50 | include: [resolve('src'), resolve('test')]
51 | },
52 | {
53 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
54 | loader: 'url-loader',
55 | options: {
56 | limit: 10000,
57 | name: utils.assetsPath('img/[name].[hash:7].[ext]')
58 | }
59 | },
60 | {
61 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
62 | loader: 'url-loader',
63 | options: {
64 | limit: 10000,
65 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
66 | }
67 | }
68 | ]
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils')
2 | var webpack = require('webpack')
3 | var config = require('../config')
4 | var merge = require('webpack-merge')
5 | var baseWebpackConfig = require('./webpack.base.conf')
6 | var HtmlWebpackPlugin = require('html-webpack-plugin')
7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
8 |
9 | // add hot-reload related code to entry chunks
10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) {
11 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
12 | })
13 |
14 | module.exports = merge(baseWebpackConfig, {
15 | module: {
16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
17 | },
18 | // cheap-module-eval-source-map is faster for development
19 | devtool: '#cheap-module-eval-source-map',
20 | plugins: [
21 | new webpack.DefinePlugin({
22 | 'process.env': config.dev.env
23 | }),
24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
25 | new webpack.HotModuleReplacementPlugin(),
26 | new webpack.NoEmitOnErrorsPlugin(),
27 | // https://github.com/ampedandwired/html-webpack-plugin
28 | new HtmlWebpackPlugin({
29 | filename: 'index.html',
30 | template: 'index.html',
31 | inject: true
32 | }),
33 | new FriendlyErrorsPlugin()
34 | ]
35 | })
36 |
--------------------------------------------------------------------------------
/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path')
2 | var utils = require('./utils')
3 | var webpack = require('webpack')
4 | var config = require('../config')
5 | var merge = require('webpack-merge')
6 | var baseWebpackConfig = require('./webpack.base.conf')
7 | var CopyWebpackPlugin = require('copy-webpack-plugin')
8 | var HtmlWebpackPlugin = require('html-webpack-plugin')
9 | var ExtractTextPlugin = require('extract-text-webpack-plugin')
10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
11 |
12 | var env = config.build.env
13 |
14 | var webpackConfig = merge(baseWebpackConfig, {
15 | module: {
16 | rules: utils.styleLoaders({
17 | sourceMap: config.build.productionSourceMap,
18 | extract: true
19 | })
20 | },
21 | devtool: config.build.productionSourceMap ? '#source-map' : false,
22 | output: {
23 | path: config.build.assetsRoot,
24 | filename: utils.assetsPath('js/[name].[chunkhash].js'),
25 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
26 | },
27 | plugins: [
28 | // http://vuejs.github.io/vue-loader/en/workflow/production.html
29 | new webpack.DefinePlugin({
30 | 'process.env': env
31 | }),
32 | new webpack.optimize.UglifyJsPlugin({
33 | compress: {
34 | warnings: false
35 | },
36 | sourceMap: true
37 | }),
38 | // extract css into its own file
39 | new ExtractTextPlugin({
40 | filename: utils.assetsPath('css/[name].[contenthash].css')
41 | }),
42 | // Compress extracted CSS. We are using this plugin so that possible
43 | // duplicated CSS from different components can be deduped.
44 | new OptimizeCSSPlugin({
45 | cssProcessorOptions: {
46 | safe: true
47 | }
48 | }),
49 | // generate dist index.html with correct asset hash for caching.
50 | // you can customize output by editing /index.html
51 | // see https://github.com/ampedandwired/html-webpack-plugin
52 | new HtmlWebpackPlugin({
53 | filename: config.build.index,
54 | template: 'index.html',
55 | inject: true,
56 | minify: {
57 | removeComments: true,
58 | collapseWhitespace: true,
59 | removeAttributeQuotes: true
60 | // more options:
61 | // https://github.com/kangax/html-minifier#options-quick-reference
62 | },
63 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin
64 | chunksSortMode: 'dependency'
65 | }),
66 | // split vendor js into its own file
67 | new webpack.optimize.CommonsChunkPlugin({
68 | name: 'vendor',
69 | minChunks: function (module, count) {
70 | // any required modules inside node_modules are extracted to vendor
71 | return (
72 | module.resource &&
73 | /\.js$/.test(module.resource) &&
74 | module.resource.indexOf(
75 | path.join(__dirname, '../node_modules')
76 | ) === 0
77 | )
78 | }
79 | }),
80 | // extract webpack runtime and module manifest to its own file in order to
81 | // prevent vendor hash from being updated whenever app bundle is updated
82 | new webpack.optimize.CommonsChunkPlugin({
83 | name: 'manifest',
84 | chunks: ['vendor']
85 | }),
86 | // copy custom static assets
87 | new CopyWebpackPlugin([
88 | {
89 | from: path.resolve(__dirname, '../static'),
90 | to: config.build.assetsSubDirectory,
91 | ignore: ['.*']
92 | }
93 | ])
94 | ]
95 | })
96 |
97 | if (config.build.productionGzip) {
98 | var CompressionWebpackPlugin = require('compression-webpack-plugin')
99 |
100 | webpackConfig.plugins.push(
101 | new CompressionWebpackPlugin({
102 | asset: '[path].gz[query]',
103 | algorithm: 'gzip',
104 | test: new RegExp(
105 | '\\.(' +
106 | config.build.productionGzipExtensions.join('|') +
107 | ')$'
108 | ),
109 | threshold: 10240,
110 | minRatio: 0.8
111 | })
112 | )
113 | }
114 |
115 | if (config.build.bundleAnalyzerReport) {
116 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
117 | webpackConfig.plugins.push(new BundleAnalyzerPlugin())
118 | }
119 |
120 | module.exports = webpackConfig
121 |
--------------------------------------------------------------------------------
/config/dev.env.js:
--------------------------------------------------------------------------------
1 | var merge = require('webpack-merge')
2 | var prodEnv = require('./prod.env')
3 |
4 | module.exports = merge(prodEnv, {
5 | NODE_ENV: '"development"'
6 | })
7 |
--------------------------------------------------------------------------------
/config/index.js:
--------------------------------------------------------------------------------
1 | // see http://vuejs-templates.github.io/webpack for documentation.
2 | var path = require('path')
3 |
4 | module.exports = {
5 | build: {
6 | env: require('./prod.env'),
7 | index: path.resolve(__dirname, '../dist/index.html'),
8 | assetsRoot: path.resolve(__dirname, '../dist'),
9 | assetsSubDirectory: 'static',
10 | assetsPublicPath: '/',
11 | productionSourceMap: true,
12 | // Gzip off by default as many popular static hosts such as
13 | // Surge or Netlify already gzip all static assets for you.
14 | // Before setting to `true`, make sure to:
15 | // npm install --save-dev compression-webpack-plugin
16 | productionGzip: false,
17 | productionGzipExtensions: ['js', 'css'],
18 | // Run the build command with an extra argument to
19 | // View the bundle analyzer report after build finishes:
20 | // `npm run build --report`
21 | // Set to `true` or `false` to always turn it on or off
22 | bundleAnalyzerReport: process.env.npm_config_report
23 | },
24 | dev: {
25 | env: require('./dev.env'),
26 | port: 8080,
27 | autoOpenBrowser: true,
28 | assetsSubDirectory: 'static',
29 | assetsPublicPath: '/',
30 | proxyTable: {},
31 | // CSS Sourcemaps off by default because relative paths are "buggy"
32 | // with this option, according to the CSS-Loader README
33 | // (https://github.com/webpack/css-loader#sourcemaps)
34 | // In our experience, they generally work as expected,
35 | // just be aware of this issue when enabling this option.
36 | cssSourceMap: false
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/config/prod.env.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | NODE_ENV: '"production"'
3 | }
4 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | vue-music
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-music",
3 | "version": "1.0.0",
4 | "description": "音乐播放器",
5 | "author": "poetries ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "node build/dev-server.js",
9 | "start": "node build/dev-server.js",
10 | "build": "node build/build.js",
11 | "lint": "eslint --ext .js,.vue src"
12 | },
13 | "dependencies": {
14 | "babel-runtime": "^6.0.0",
15 | "vue": "^2.3.3",
16 | "vue-router": "^2.5.3",
17 | "vuex": "^2.3.1",
18 | "fastclick": "^1.0.6",
19 | "vue-lazyload": "1.0.3",
20 | "axios": "^0.16.1",
21 | "jsonp": "0.2.1",
22 | "better-scroll": "^0.1.15",
23 | "create-keyframe-animation": "^0.1.0",
24 | "js-base64": "^2.1.9",
25 | "lyric-parser": "^1.0.1",
26 | "good-storage": "^1.0.1"
27 | },
28 | "devDependencies": {
29 | "autoprefixer": "^6.7.2",
30 | "babel-core": "^6.22.1",
31 | "babel-eslint": "^7.1.1",
32 | "babel-loader": "^6.2.10",
33 | "babel-plugin-transform-runtime": "^6.22.0",
34 | "babel-preset-env": "^1.3.2",
35 | "babel-preset-stage-2": "^6.22.0",
36 | "babel-register": "^6.22.0",
37 | "babel-polyfill": "^6.2.0",
38 | "chalk": "^1.1.3",
39 | "connect-history-api-fallback": "^1.3.0",
40 | "copy-webpack-plugin": "^4.0.1",
41 | "css-loader": "^0.28.0",
42 | "eslint": "^3.19.0",
43 | "eslint-friendly-formatter": "^2.0.7",
44 | "eslint-loader": "^1.7.1",
45 | "eslint-plugin-html": "^2.0.0",
46 | "eslint-config-standard": "^6.2.1",
47 | "eslint-plugin-promise": "^3.4.0",
48 | "eslint-plugin-standard": "^2.0.1",
49 | "eventsource-polyfill": "^0.9.6",
50 | "express": "^4.14.1",
51 | "extract-text-webpack-plugin": "^2.0.0",
52 | "file-loader": "^0.11.1",
53 | "friendly-errors-webpack-plugin": "^1.1.3",
54 | "html-webpack-plugin": "^2.28.0",
55 | "http-proxy-middleware": "^0.17.3",
56 | "webpack-bundle-analyzer": "^2.2.1",
57 | "semver": "^5.3.0",
58 | "shelljs": "^0.7.6",
59 | "opn": "^4.0.2",
60 | "optimize-css-assets-webpack-plugin": "^1.3.0",
61 | "ora": "^1.2.0",
62 | "rimraf": "^2.6.0",
63 | "url-loader": "^0.5.8",
64 | "vue-loader": "^11.3.4",
65 | "vue-style-loader": "^2.0.5",
66 | "vue-template-compiler": "^2.3.3",
67 | "webpack": "^2.3.3",
68 | "webpack-dev-middleware": "^1.10.0",
69 | "webpack-hot-middleware": "^2.18.0",
70 | "webpack-merge": "^4.1.0",
71 | "stylus": "^0.54.5",
72 | "stylus-loader": "^2.1.1"
73 | },
74 | "engines": {
75 | "node": ">= 4.0.0",
76 | "npm": ">= 3.0.0"
77 | },
78 | "browserslist": [
79 | "> 1%",
80 | "last 2 versions",
81 | "not ie <= 8"
82 | ]
83 | }
84 |
--------------------------------------------------------------------------------
/shotscreen/music-vue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/shotscreen/music-vue.png
--------------------------------------------------------------------------------
/shotscreen/player.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/shotscreen/player.png
--------------------------------------------------------------------------------
/shotscreen/rank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/shotscreen/rank.png
--------------------------------------------------------------------------------
/shotscreen/recommend.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/shotscreen/recommend.png
--------------------------------------------------------------------------------
/shotscreen/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/shotscreen/search.png
--------------------------------------------------------------------------------
/shotscreen/singer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/shotscreen/singer.png
--------------------------------------------------------------------------------
/shotscreen/song.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/shotscreen/song.png
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
25 |
26 |
29 |
--------------------------------------------------------------------------------
/src/api/config.js:
--------------------------------------------------------------------------------
1 | export const commonParams = {
2 | g_tk: 1928093487,
3 | inCharset: 'utf-8',
4 | outCharset: 'utf-8',
5 | notice: 0,
6 | format: 'jsonp'
7 | }
8 |
9 | export const options = {
10 | param: 'jsonpCallback'
11 | }
12 |
13 | export const ERR_OK = 0
--------------------------------------------------------------------------------
/src/api/rank.js:
--------------------------------------------------------------------------------
1 | import jsonp from 'common/js/jsonp'
2 | import {commonParams, options} from './config'
3 |
4 | export function getTopList() {
5 | const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_myqq_toplist.fcg'
6 |
7 | const data = Object.assign({}, commonParams, {
8 | uin: 0,
9 | needNewCode: 1,
10 | platform: 'h5'
11 | })
12 |
13 | return jsonp(url, data, options)
14 | }
15 |
16 | export function getMusicList(topid) {
17 | const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg'
18 |
19 | const data = Object.assign({}, commonParams, {
20 | topid,
21 | needNewCode: 1,
22 | uin: 0,
23 | tpl: 3,
24 | page: 'detail',
25 | type: 'top',
26 | platform: 'h5'
27 | })
28 |
29 | return jsonp(url, data, options)
30 | }
31 |
--------------------------------------------------------------------------------
/src/api/recommend.js:
--------------------------------------------------------------------------------
1 | import jsonp from 'common/js/jsonp'
2 | import {commonParams, options} from './config'
3 | import axios from 'axios'
4 |
5 | export function getRecommend() {
6 | const url = 'https://c.y.qq.com/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg'
7 |
8 | const data = Object.assign({}, commonParams, {
9 | platform: 'h5',
10 | uin: 0,
11 | needNewCode: 1
12 | })
13 |
14 | return jsonp(url, data, options)
15 | }
16 |
17 | export function getDiscList() {
18 | const url = '/api/getDiscList'
19 |
20 | const data = Object.assign({}, commonParams, {
21 | platform: 'yqq',
22 | hostUin: 0,
23 | sin: 0,
24 | ein: 29,
25 | sortId: 5,
26 | needNewCode: 0,
27 | categoryId: 10000000,
28 | rnd: Math.random(),
29 | format: 'json'
30 | })
31 |
32 | return axios.get(url, {
33 | params: data
34 | }).then((res) => {
35 | return Promise.resolve(res.data)
36 | })
37 | }
38 |
39 | export function getSongList(disstid) {
40 | const url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'
41 |
42 | const data = Object.assign({}, commonParams, {
43 | disstid,
44 | type: 1,
45 | json: 1,
46 | utf8: 1,
47 | onlysong: 0,
48 | platform: 'yqq',
49 | hostUin: 0,
50 | needNewCode: 0
51 | })
52 |
53 | return jsonp(url, data, options)
54 | }
--------------------------------------------------------------------------------
/src/api/search.js:
--------------------------------------------------------------------------------
1 | import jsonp from 'common/js/jsonp'
2 | import {commonParams, options} from './config'
3 |
4 | export function getHotKey() {
5 | const url = 'https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg'
6 |
7 | const data = Object.assign({}, commonParams, {
8 | uin: 0,
9 | needNewCode: 1,
10 | platform: 'h5'
11 | })
12 |
13 | return jsonp(url, data, options)
14 | }
15 |
16 | export function search(query, page, zhida, perpage) {
17 | const url = 'https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'
18 |
19 | const data = Object.assign({}, commonParams, {
20 | w: query,
21 | p: page,
22 | perpage,
23 | n: perpage,
24 | catZhida: zhida ? 1 : 0,
25 | zhidaqu: 1,
26 | t: 0,
27 | flag: 1,
28 | ie: 'utf-8',
29 | sem: 1,
30 | aggr: 0,
31 | remoteplace: 'txt.mqq.all',
32 | uin: 0,
33 | needNewCode: 1,
34 | platform: 'h5'
35 | })
36 |
37 | return jsonp(url, data, options)
38 | }
39 |
--------------------------------------------------------------------------------
/src/api/singer.js:
--------------------------------------------------------------------------------
1 | import jsonp from 'common/js/jsonp'
2 | import {commonParams, options} from './config'
3 |
4 | export function getSingerList() {
5 | const url = 'https://c.y.qq.com/v8/fcg-bin/v8.fcg'
6 |
7 | const data = Object.assign({}, commonParams, {
8 | channel: 'singer',
9 | page: 'list',
10 | key: 'all_all_all',
11 | pagesize: 100,
12 | pagenum: 1,
13 | hostUin: 0,
14 | needNewCode: 0,
15 | platform: 'yqq'
16 | })
17 |
18 | return jsonp(url, data, options)
19 | }
20 |
21 | export function getSingerDetail(singerId) {
22 | const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg'
23 |
24 | const data = Object.assign({}, commonParams, {
25 | hostUin: 0,
26 | needNewCode: 0,
27 | platform: 'yqq',
28 | order: 'listen',
29 | begin: 0,
30 | num: 80,
31 | songstatus: 1,
32 | singermid: singerId
33 | })
34 |
35 | return jsonp(url, data, options)
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/src/api/song.js:
--------------------------------------------------------------------------------
1 | import {commonParams} from './config'
2 | import axios from 'axios'
3 |
4 | export function getLyric(mid) {
5 | const url = '/api/lyric'
6 |
7 | const data = Object.assign({}, commonParams, {
8 | songmid: mid,
9 | platform: 'yqq',
10 | hostUin: 0,
11 | needNewCode: 0,
12 | categoryId: 10000000,
13 | pcachetime: +new Date(),
14 | format: 'json'
15 | })
16 |
17 | return axios.get(url, {
18 | params: data
19 | }).then((res) => {
20 | return Promise.resolve(res.data)
21 | })
22 | }
--------------------------------------------------------------------------------
/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/assets/logo.png
--------------------------------------------------------------------------------
/src/base/confirm/confirm.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
{{text}}
7 |
8 |
{{cancelBtnText}}
9 |
{{confirmBtnText}}
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
56 |
57 |
--------------------------------------------------------------------------------
/src/base/listview/listview.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
{{group.title}}
6 |
7 | -
8 |
9 | {{item.name}}
10 |
11 |
12 |
13 |
14 |
19 |
20 |
{{fixedTitle}}
21 |
22 |
23 |
24 |
25 |
156 |
157 |
224 |
--------------------------------------------------------------------------------
/src/base/loading/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/loading/loading.gif
--------------------------------------------------------------------------------
/src/base/loading/loading.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |

4 |
{{title}}
5 |
6 |
7 |
17 |
28 |
--------------------------------------------------------------------------------
/src/base/no-result/no-result.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
18 |
19 |
--------------------------------------------------------------------------------
/src/base/no-result/no-result@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/no-result/no-result@2x.png
--------------------------------------------------------------------------------
/src/base/no-result/no-result@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/no-result/no-result@3x.png
--------------------------------------------------------------------------------
/src/base/progress-bar/progress-bar.vue:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
81 |
82 |
--------------------------------------------------------------------------------
/src/base/progress-circle/progress-circle.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
11 |
12 |
36 |
37 |
--------------------------------------------------------------------------------
/src/base/scroll/scroll.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
102 |
103 |
106 |
--------------------------------------------------------------------------------
/src/base/search-box/search-box.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
42 |
43 |
--------------------------------------------------------------------------------
/src/base/search-list/search-list.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{item}}
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
32 |
33 |
--------------------------------------------------------------------------------
/src/base/slider/slider.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
116 |
117 |
--------------------------------------------------------------------------------
/src/base/song-list/first@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/song-list/first@2x.png
--------------------------------------------------------------------------------
/src/base/song-list/first@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/song-list/first@3x.png
--------------------------------------------------------------------------------
/src/base/song-list/second@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/song-list/second@2x.png
--------------------------------------------------------------------------------
/src/base/song-list/second@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/song-list/second@3x.png
--------------------------------------------------------------------------------
/src/base/song-list/song-list.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
{{song.name}}
10 |
{{getDesc(song)}}
11 |
12 |
13 |
14 |
15 |
16 |
17 |
51 |
52 |
--------------------------------------------------------------------------------
/src/base/song-list/third@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/song-list/third@2x.png
--------------------------------------------------------------------------------
/src/base/song-list/third@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/base/song-list/third@3x.png
--------------------------------------------------------------------------------
/src/base/switches/switches.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
5 | {{item.name}}
6 |
7 |
8 |
9 |
10 |
29 |
30 |
--------------------------------------------------------------------------------
/src/common/fonts/music-icon.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/common/fonts/music-icon.eot
--------------------------------------------------------------------------------
/src/common/fonts/music-icon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/common/fonts/music-icon.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/common/fonts/music-icon.ttf
--------------------------------------------------------------------------------
/src/common/fonts/music-icon.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/common/fonts/music-icon.woff
--------------------------------------------------------------------------------
/src/common/image/default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/common/image/default.png
--------------------------------------------------------------------------------
/src/common/js/cache.js:
--------------------------------------------------------------------------------
1 | import storage from 'good-storage'
2 |
3 | const SEARCH_KEY = '__search__'
4 | const SEARCH_MAX_LEN = 15
5 |
6 | const PLAY_KEY = '__play__'
7 | const PLAY_MAX_LEN = 200
8 |
9 | const FAVORITE_KEY = '__favorite__'
10 | const FAVORITE_MAX_LEN = 200
11 |
12 | function insertArray(arr, val, compare, maxLen) {
13 | const index = arr.findIndex(compare)
14 | if (index === 0) {
15 | return
16 | }
17 | if (index > 0) {
18 | arr.splice(index, 1)
19 | }
20 | arr.unshift(val)
21 | if (maxLen && arr.length > maxLen) {
22 | arr.pop()
23 | }
24 | }
25 |
26 | function deleteFromArray(arr, compare) {
27 | const index = arr.findIndex(compare)
28 | if (index > -1) {
29 | arr.splice(index, 1)
30 | }
31 | }
32 |
33 | export function saveSearch(query) {
34 | let searches = storage.get(SEARCH_KEY, [])
35 | insertArray(searches, query, (item) => {
36 | return item === query
37 | }, SEARCH_MAX_LEN)
38 | storage.set(SEARCH_KEY, searches)
39 | return searches
40 | }
41 |
42 | export function deleteSearch(query) {
43 | let searches = storage.get(SEARCH_KEY, [])
44 | deleteFromArray(searches, (item) => {
45 | return item === query
46 | })
47 | storage.set(SEARCH_KEY, searches)
48 | return searches
49 | }
50 |
51 | export function clearSearch() {
52 | storage.remove(SEARCH_KEY)
53 | return []
54 | }
55 |
56 | export function loadSearch() {
57 | return storage.get(SEARCH_KEY, [])
58 | }
59 |
60 | export function savePlay(song) {
61 | let songs = storage.get(PLAY_KEY, [])
62 | insertArray(songs, song, (item) => {
63 | return song.id === item.id
64 | }, PLAY_MAX_LEN)
65 | storage.set(PLAY_KEY, songs)
66 | return songs
67 | }
68 |
69 | export function loadPlay() {
70 | return storage.get(PLAY_KEY, [])
71 | }
72 |
73 | export function saveFavorite(song) {
74 | let songs = storage.get(FAVORITE_KEY, [])
75 | insertArray(songs, song, (item) => {
76 | return song.id === item.id
77 | }, FAVORITE_MAX_LEN)
78 | storage.set(FAVORITE_KEY, songs)
79 | return songs
80 | }
81 |
82 | export function deleteFavorite(song) {
83 | let songs = storage.get(FAVORITE_KEY, [])
84 | deleteFromArray(songs, (item) => {
85 | return item.id === song.id
86 | })
87 | storage.set(FAVORITE_KEY, songs)
88 | return songs
89 | }
90 |
91 | export function loadFavorite() {
92 | return storage.get(FAVORITE_KEY, [])
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/src/common/js/config.js:
--------------------------------------------------------------------------------
1 | export const playMode = {
2 | sequence: 0,
3 | loop: 1,
4 | random: 2
5 | }
--------------------------------------------------------------------------------
/src/common/js/dom.js:
--------------------------------------------------------------------------------
1 | export function hasClass(el, className) {
2 | let reg = new RegExp('(^|\\s)' + className + '(\\s|$)')
3 | return reg.test(el.className)
4 | }
5 |
6 | export function addClass(el, className) {
7 | if (hasClass(el, className)) {
8 | return
9 | }
10 |
11 | let newClass = el.className.split(' ')
12 | newClass.push(className)
13 | el.className = newClass.join(' ')
14 | }
15 |
16 | export function getData(el, name, val) {
17 | const prefix = 'data-'
18 | if (val) {
19 | return el.setAttribute(prefix + name, val)
20 | }
21 | return el.getAttribute(prefix + name)
22 | }
23 |
24 | let elementStyle = document.createElement('div').style
25 |
26 | let vendor = (() => {
27 | let transformNames = {
28 | webkit: 'webkitTransform',
29 | Moz: 'MozTransform',
30 | O: 'OTransform',
31 | ms: 'msTransform',
32 | standard: 'transform'
33 | }
34 |
35 | for (let key in transformNames) {
36 | if (elementStyle[transformNames[key]] !== undefined) {
37 | return key
38 | }
39 | }
40 |
41 | return false
42 | })()
43 |
44 | export function prefixStyle(style) {
45 | if (vendor === false) {
46 | return false
47 | }
48 |
49 | if (vendor === 'standard') {
50 | return style
51 | }
52 |
53 | return vendor + style.charAt(0).toUpperCase() + style.substr(1)
54 | }
55 |
--------------------------------------------------------------------------------
/src/common/js/jsonp.js:
--------------------------------------------------------------------------------
1 | import originJsonp from 'jsonp'
2 |
3 | export default function jsonp(url, data, option) {
4 | url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)
5 |
6 | return new Promise((resolve, reject) => {
7 | originJsonp(url, option, (err, data) => {
8 | if (!err) {
9 | resolve(data)
10 | } else {
11 | reject(err)
12 | }
13 | })
14 | })
15 | }
16 |
17 | export function param(data) {
18 | let url = ''
19 | for (var k in data) {
20 | let value = data[k] !== undefined ? data[k] : ''
21 | url += '&' + k + '=' + encodeURIComponent(value)
22 | }
23 | return url ? url.substring(1) : ''
24 | }
25 |
--------------------------------------------------------------------------------
/src/common/js/mixin.js:
--------------------------------------------------------------------------------
1 | import {mapGetters, mapMutations, mapActions} from 'vuex'
2 | import {playMode} from 'common/js/config'
3 | import {shuffle} from 'common/js/util'
4 |
5 | export const playlistMixin = {
6 | computed: {
7 | ...mapGetters([
8 | 'playlist'
9 | ])
10 | },
11 | mounted() {
12 | this.handlePlaylist(this.playlist)
13 | },
14 | activated() {
15 | this.handlePlaylist(this.playlist)
16 | },
17 | watch: {
18 | playlist(newVal) {
19 | this.handlePlaylist(newVal)
20 | }
21 | },
22 | methods: {
23 | handlePlaylist() {
24 | throw new Error('component must implement handlePlaylist method')
25 | }
26 | }
27 | }
28 |
29 | export const playerMixin = {
30 | computed: {
31 | iconMode() {
32 | return this.mode === playMode.sequence ? 'icon-sequence' : this.mode === playMode.loop ? 'icon-loop' : 'icon-random'
33 | },
34 | ...mapGetters([
35 | 'sequenceList',
36 | 'playlist',
37 | 'currentSong',
38 | 'mode',
39 | 'favoriteList'
40 | ])
41 | },
42 | methods: {
43 | changeMode() {
44 | const mode = (this.mode + 1) % 3
45 | this.setPlayMode(mode)
46 | let list = null
47 | if (mode === playMode.random) {
48 | list = shuffle(this.sequenceList)
49 | } else {
50 | list = this.sequenceList
51 | }
52 | this.resetCurrentIndex(list)
53 | this.setPlaylist(list)
54 | },
55 | resetCurrentIndex(list) {
56 | let index = list.findIndex((item) => {
57 | return item.id === this.currentSong.id
58 | })
59 | this.setCurrentIndex(index)
60 | },
61 | toggleFavorite(song) {
62 | if (this.isFavorite(song)) {
63 | this.deleteFavoriteList(song)
64 | } else {
65 | this.saveFavoriteList(song)
66 | }
67 | },
68 | getFavoriteIcon(song) {
69 | if (this.isFavorite(song)) {
70 | return 'icon-favorite'
71 | }
72 | return 'icon-not-favorite'
73 | },
74 | isFavorite(song) {
75 | const index = this.favoriteList.findIndex((item) => {
76 | return item.id === song.id
77 | })
78 | return index > -1
79 | },
80 | ...mapMutations({
81 | setPlayMode: 'SET_PLAY_MODE',
82 | setPlaylist: 'SET_PLAYLIST',
83 | setCurrentIndex: 'SET_CURRENT_INDEX',
84 | setPlayingState: 'SET_PLAYING_STATE'
85 | }),
86 | ...mapActions([
87 | 'saveFavoriteList',
88 | 'deleteFavoriteList'
89 | ])
90 | }
91 | }
92 |
93 | export const searchMixin = {
94 | data() {
95 | return {
96 | query: '',
97 | refreshDelay: 120
98 | }
99 | },
100 | computed: {
101 | ...mapGetters([
102 | 'searchHistory'
103 | ])
104 | },
105 | methods: {
106 | onQueryChange(query) {
107 | this.query = query
108 | },
109 | blurInput() {
110 | this.$refs.searchBox.blur()
111 | },
112 | addQuery(query) {
113 | this.$refs.searchBox.setQuery(query)
114 | },
115 | saveSearch() {
116 | this.saveSearchHistory(this.query)
117 | },
118 | ...mapActions([
119 | 'saveSearchHistory',
120 | 'deleteSearchHistory'
121 | ])
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/common/js/singer.js:
--------------------------------------------------------------------------------
1 | export default class Singer {
2 | constructor({id, name}) {
3 | this.id = id
4 | this.name = name
5 | this.avatar = `https://y.gtimg.cn/music/photo_new/T001R300x300M000${id}.jpg?max_age=2592000`
6 | }
7 | }
--------------------------------------------------------------------------------
/src/common/js/song.js:
--------------------------------------------------------------------------------
1 | import {getLyric} from 'api/song'
2 | import {ERR_OK} from 'api/config'
3 | import {Base64} from 'js-base64'
4 |
5 | export default class Song {
6 | constructor({id, mid, singer, name, album, duration, image, url}) {
7 | this.id = id
8 | this.mid = mid
9 | this.singer = singer
10 | this.name = name
11 | this.album = album
12 | this.duration = duration
13 | this.image = image
14 | this.url = url
15 | }
16 |
17 | getLyric() {
18 | if (this.lyric) {
19 | return Promise.resolve(this.lyric)
20 | }
21 |
22 | return new Promise((resolve, reject) => {
23 | getLyric(this.mid).then((res) => {
24 | if (res.retcode === ERR_OK) {
25 | this.lyric = Base64.decode(res.lyric)
26 | console.log(this.lyric)
27 | resolve(this.lyric)
28 | } else {
29 | reject('no lyric')
30 | }
31 | })
32 | })
33 | }
34 | }
35 |
36 | export function createSong(musicData) {
37 | return new Song({
38 | id: musicData.songid,
39 | mid: musicData.songmid,
40 | singer: filterSinger(musicData.singer),
41 | name: musicData.songname,
42 | album: musicData.albumname,
43 | duration: musicData.interval,
44 | image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.albummid}.jpg?max_age=2592000`,
45 | url: `http://ws.stream.qqmusic.qq.com/${musicData.songid}.m4a?fromtag=46`
46 | })
47 | }
48 |
49 | function filterSinger(singer) {
50 | let ret = []
51 | if (!singer) {
52 | return ''
53 | }
54 | singer.forEach((s) => {
55 | ret.push(s.name)
56 | })
57 | return ret.join('/')
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/src/common/js/util.js:
--------------------------------------------------------------------------------
1 | function getRandomInt(min, max) {
2 | return Math.floor(Math.random() * (max - min + 1) + min)
3 | }
4 |
5 | export function shuffle(arr) {
6 | let _arr = arr.slice()
7 | for (let i = 0; i < _arr.length; i++) {
8 | let j = getRandomInt(0, i)
9 | let t = _arr[i]
10 | _arr[i] = _arr[j]
11 | _arr[j] = t
12 | }
13 | return _arr
14 | }
15 |
16 | export function debounce(func, delay) {
17 | let timer
18 |
19 | return function (...args) {
20 | if (timer) {
21 | clearTimeout(timer)
22 | }
23 | timer = setTimeout(() => {
24 | func.apply(this, args)
25 | }, delay)
26 | }
27 | }
--------------------------------------------------------------------------------
/src/common/stylus/base.styl:
--------------------------------------------------------------------------------
1 | @import "variable.styl"
2 |
3 | body, html
4 | line-height: 1
5 | font-family: 'PingFang SC', 'STHeitiSC-Light', 'Helvetica-Light', arial, sans-serif, 'Droid Sans Fallback'
6 | user-select: none
7 | -webkit-tap-highlight-color: transparent
8 | background: $color-background
9 | color: $color-text
--------------------------------------------------------------------------------
/src/common/stylus/icon.styl:
--------------------------------------------------------------------------------
1 | @font-face
2 | font-family: 'music-icon'
3 | src: url('../fonts/music-icon.eot?2qevqt')
4 | src: url('../fonts/music-icon.eot?2qevqt#iefix') format('embedded-opentype'),
5 | url('../fonts/music-icon.ttf?2qevqt') format('truetype'),
6 | url('../fonts/music-icon.woff?2qevqt') format('woff'),
7 | url('../fonts/music-icon.svg?2qevqt#music-icon') format('svg')
8 | font-weight: normal
9 | font-style: normal
10 |
11 | [class^="icon-"], [class*=" icon-"]
12 | /* use !important to prevent issues with browser extensions that change fonts */
13 | font-family: 'music-icon' !important
14 | speak: none
15 | font-style: normal
16 | font-weight: normal
17 | font-variant: normal
18 | text-transform: none
19 | line-height: 1
20 |
21 | /* Better Font Rendering =========== */
22 | -webkit-font-smoothing: antialiased
23 | -moz-osx-font-smoothing: grayscale
24 |
25 | .icon-ok:before
26 | content: "\e900"
27 |
28 | .icon-close:before
29 | content: "\e901"
30 |
31 | .icon-add:before
32 | content: "\e902"
33 |
34 | .icon-play-mini:before
35 | content: "\e903"
36 |
37 | .icon-playlist:before
38 | content: "\e904"
39 |
40 | .icon-music:before
41 | content: "\e905"
42 |
43 | .icon-search:before
44 | content: "\e906"
45 |
46 | .icon-clear:before
47 | content: "\e907"
48 |
49 | .icon-delete:before
50 | content: "\e908"
51 |
52 | .icon-favorite:before
53 | content: "\e909"
54 |
55 | .icon-not-favorite:before
56 | content: "\e90a"
57 |
58 | .icon-pause:before
59 | content: "\e90b"
60 |
61 | .icon-play:before
62 | content: "\e90c"
63 |
64 | .icon-prev:before
65 | content: "\e90d"
66 |
67 | .icon-loop:before
68 | content: "\e90e"
69 |
70 | .icon-sequence:before
71 | content: "\e90f"
72 |
73 | .icon-random:before
74 | content: "\e910"
75 |
76 | .icon-back:before
77 | content: "\e911"
78 |
79 | .icon-mine:before
80 | content: "\e912"
81 |
82 | .icon-next:before
83 | content: "\e913"
84 |
85 | .icon-dismiss:before
86 | content: "\e914"
87 |
88 | .icon-pause-mini:before
89 | content: "\e915"
90 |
--------------------------------------------------------------------------------
/src/common/stylus/index.styl:
--------------------------------------------------------------------------------
1 | @import "./reset.styl"
2 | @import "./base.styl"
3 | @import "./icon.styl"
--------------------------------------------------------------------------------
/src/common/stylus/mixin.styl:
--------------------------------------------------------------------------------
1 | // 背景图片
2 | bg-image($url)
3 | background-image: url($url + "@2x.png")
4 | @media (-webkit-min-device-pixel-ratio: 3),(min-device-pixel-ratio: 3)
5 | background-image: url($url + "@3x.png")
6 |
7 | // 不换行
8 | no-wrap()
9 | text-overflow: ellipsis
10 | overflow: hidden
11 | white-space: nowrap
12 |
13 | // 扩展点击区域
14 | extend-click()
15 | position: relative
16 | &:before
17 | content: ''
18 | position: absolute
19 | top: -10px
20 | left: -10px
21 | right: -10px
22 | bottom: -10px
--------------------------------------------------------------------------------
/src/common/stylus/reset.styl:
--------------------------------------------------------------------------------
1 | /**
2 | * Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/)
3 | * http://cssreset.com
4 | */
5 | html, body, div, span, applet, object, iframe,
6 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
7 | a, abbr, acronym, address, big, cite, code,
8 | del, dfn, em, img, ins, kbd, q, s, samp,
9 | small, strike, strong, sub, sup, tt, var,
10 | b, u, i, center,
11 | dl, dt, dd, ol, ul, li,
12 | fieldset, form, label, legend,
13 | table, caption, tbody, tfoot, thead, tr, th, td,
14 | article, aside, canvas, details, embed,
15 | figure, figcaption, footer, header,
16 | menu, nav, output, ruby, section, summary,
17 | time, mark, audio, video, input
18 | margin: 0
19 | padding: 0
20 | border: 0
21 | font-size: 100%
22 | font-weight: normal
23 | vertical-align: baseline
24 |
25 | /* HTML5 display-role reset for older browsers */
26 | article, aside, details, figcaption, figure,
27 | footer, header, menu, nav, section
28 | display: block
29 |
30 | body
31 | line-height: 1
32 |
33 | blockquote, q
34 | quotes: none
35 |
36 | blockquote:before, blockquote:after,
37 | q:before, q:after
38 | content: none
39 |
40 | table
41 | border-collapse: collapse
42 | border-spacing: 0
43 |
44 | /* custom */
45 |
46 | a
47 | color: #7e8c8d
48 | -webkit-backface-visibility: hidden
49 | text-decoration: none
50 |
51 | li
52 | list-style: none
53 |
54 | body
55 | -webkit-text-size-adjust: none
56 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0)
57 |
--------------------------------------------------------------------------------
/src/common/stylus/variable.styl:
--------------------------------------------------------------------------------
1 | // 颜色定义规范
2 | $color-background = #222
3 | $color-background-d = rgba(0, 0, 0, 0.3)
4 | $color-highlight-background = #333
5 | $color-dialog-background = #666
6 | $color-theme = #ffcd32
7 | $color-theme-d = rgba(255, 205, 49, 0.5)
8 | $color-sub-theme = #d93f30
9 | $color-text = #fff
10 | $color-text-d = rgba(255, 255, 255, 0.3)
11 | $color-text-l = rgba(255, 255, 255, 0.5)
12 | $color-text-ll = rgba(255, 255, 255, 0.8)
13 |
14 | //字体定义规范
15 | $font-size-small-s = 10px
16 | $font-size-small = 12px
17 | $font-size-medium = 14px
18 | $font-size-medium-x = 16px
19 | $font-size-large = 18px
20 | $font-size-large-x = 22px
--------------------------------------------------------------------------------
/src/components/disc/disc.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
61 |
62 |
--------------------------------------------------------------------------------
/src/components/m-header/logo@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/components/m-header/logo@2x.png
--------------------------------------------------------------------------------
/src/components/m-header/logo@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/src/components/m-header/logo@3x.png
--------------------------------------------------------------------------------
/src/components/m-header/m-header.vue:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
14 |
15 |
--------------------------------------------------------------------------------
/src/components/music-list/music-list.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 |
146 |
147 |
--------------------------------------------------------------------------------
/src/components/player/player.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
![]()
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
27 |
28 |
![]()
29 |
30 |
31 |
32 |
{{playingLyric}}
33 |
34 |
35 |
36 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
{{format(currentTime)}}
53 |
56 |
{{format(currentSong.duration)}}
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 |
87 |
92 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
450 |
451 |
--------------------------------------------------------------------------------
/src/components/rank/rank.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
![]()
8 |
9 |
10 | -
11 | {{index + 1}}
12 | {{song.songname}}-{{song.singername}}
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
80 |
81 |
--------------------------------------------------------------------------------
/src/components/recommend/recommend.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
热门歌单推荐
16 |
17 | -
18 |
19 |
![]()
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
101 |
102 |
--------------------------------------------------------------------------------
/src/components/search/search.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
热门搜索
11 |
12 | -
13 | {{item.k}}
14 |
15 |
16 |
17 |
18 |
19 | 搜索历史
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
105 |
106 |
--------------------------------------------------------------------------------
/src/components/singer-detail/singer-detail.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
62 |
63 |
--------------------------------------------------------------------------------
/src/components/singer/singer.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
99 |
100 |
--------------------------------------------------------------------------------
/src/components/suggest/suggest.vue:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 | -
12 |
13 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
163 |
164 |
--------------------------------------------------------------------------------
/src/components/tab/tab.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 推荐
5 |
6 |
7 | 歌手
8 |
9 |
10 | 排行
11 |
12 |
13 |
14 | 搜索
15 |
16 |
17 |
18 |
19 |
22 |
23 |
--------------------------------------------------------------------------------
/src/components/top-list/top-list.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
66 |
67 |
--------------------------------------------------------------------------------
/src/components/user-center/user-center.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 |
118 |
119 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import 'babel-polyfill'
2 | import Vue from 'vue'
3 | import App from './App'
4 | import router from './router'
5 | import store from './store'
6 | import fastclick from 'fastclick'
7 | import VueLazyLoad from 'vue-lazyload'
8 |
9 | import 'common/stylus/index.styl'
10 |
11 | fastclick.attach(document.body)
12 |
13 | Vue.use(VueLazyLoad, {
14 | loading:require('common/image/default.png')
15 | })
16 |
17 | /* eslint-disable no-new */
18 | new Vue({
19 | el: '#app',
20 | render: h => h(App),
21 | store,
22 | router
23 | })
24 |
--------------------------------------------------------------------------------
/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Router from 'vue-router'
3 | import Recommend from 'components/recommend/recommend'
4 | import Singer from 'components/singer/singer'
5 | import Rank from 'components/rank/rank'
6 | import Search from 'components/search/search'
7 | import SingerDetail from 'components/singer-detail/singer-detail'
8 | import Disc from 'components/disc/disc'
9 | import TopList from 'components/top-list/top-list'
10 | import UserCenter from 'components/user-center/user-center'
11 |
12 | Vue.use(Router)
13 |
14 |
15 | export default new Router({
16 | routes: [
17 | {
18 | path: '/',
19 | redirect: '/recommend'
20 | },
21 | {
22 | path: '/recommend',
23 | component: Recommend,
24 | children: [
25 | {
26 | path: ':id',
27 | component: Disc
28 | }
29 | ]
30 | },
31 | {
32 | path: '/singer',
33 | component: Singer,
34 | children: [
35 | {
36 | path: ':id',
37 | component: SingerDetail
38 | }
39 | ]
40 | },
41 | {
42 | path: '/rank',
43 | component: Rank,
44 | children: [
45 | {
46 | path: ':id',
47 | component: TopList
48 | }
49 | ]
50 | },
51 | {
52 | path: '/search',
53 | component: Search
54 | },
55 | {
56 | path: '/user',
57 | component: UserCenter
58 | }
59 | ]
60 | })
61 |
--------------------------------------------------------------------------------
/src/store/actions.js:
--------------------------------------------------------------------------------
1 | import * as types from './mutation-types'
2 | import {playMode} from 'common/js/config'
3 | import {shuffle} from 'common/js/util'
4 | import {saveSearch, clearSearch, deleteSearch, savePlay, saveFavorite, deleteFavorite} from 'common/js/cache'
5 |
6 | function findIndex(list, song) {
7 | return list.findIndex((item) => {
8 | return item.id === song.id
9 | })
10 | }
11 |
12 | export const selectPlay = function ({commit, state}, {list, index}) {
13 | commit(types.SET_SEQUENCE_LIST, list)
14 | if (state.mode === playMode.random) {
15 | let randomList = shuffle(list)
16 | commit(types.SET_PLAYLIST, randomList)
17 | index = findIndex(randomList, list[index])
18 | } else {
19 | commit(types.SET_PLAYLIST, list)
20 | }
21 | commit(types.SET_CURRENT_INDEX, index)
22 | commit(types.SET_FULL_SCREEN, true)
23 | commit(types.SET_PLAYING_STATE, true)
24 | }
25 |
26 | export const randomPlay = function ({commit}, {list}) {
27 | commit(types.SET_PLAY_MODE, playMode.random)
28 | commit(types.SET_SEQUENCE_LIST, list)
29 | let randomList = shuffle(list)
30 | commit(types.SET_PLAYLIST, randomList)
31 | commit(types.SET_CURRENT_INDEX, 0)
32 | commit(types.SET_FULL_SCREEN, true)
33 | commit(types.SET_PLAYING_STATE, true)
34 | }
35 |
36 | export const insertSong = function ({commit, state}, song) {
37 | let playlist = state.playlist.slice()
38 | let sequenceList = state.sequenceList.slice()
39 | let currentIndex = state.currentIndex
40 | // 记录当前歌曲
41 | let currentSong = playlist[currentIndex]
42 | // 查找当前列表中是否有待插入的歌曲并返回其索引
43 | let fpIndex = findIndex(playlist, song)
44 | // 因为是插入歌曲,所以索引+1
45 | currentIndex++
46 | // 插入这首歌到当前索引位置
47 | playlist.splice(currentIndex, 0, song)
48 | // 如果已经包含了这首歌
49 | if (fpIndex > -1) {
50 | // 如果当前插入的序号大于列表中的序号
51 | if (currentIndex > fpIndex) {
52 | playlist.splice(fpIndex, 1)
53 | currentIndex--
54 | } else {
55 | playlist.splice(fpIndex + 1, 1)
56 | }
57 | }
58 |
59 | let currentSIndex = findIndex(sequenceList, currentSong) + 1
60 |
61 | let fsIndex = findIndex(sequenceList, song)
62 |
63 | sequenceList.splice(currentSIndex, 0, song)
64 |
65 | if (fsIndex > -1) {
66 | if (currentSIndex > fsIndex) {
67 | sequenceList.splice(fsIndex, 1)
68 | } else {
69 | sequenceList.splice(fsIndex + 1, 1)
70 | }
71 | }
72 |
73 | commit(types.SET_PLAYLIST, playlist)
74 | commit(types.SET_SEQUENCE_LIST, sequenceList)
75 | commit(types.SET_CURRENT_INDEX, currentIndex)
76 | commit(types.SET_FULL_SCREEN, true)
77 | commit(types.SET_PLAYING_STATE, true)
78 | }
79 |
80 | export const saveSearchHistory = function ({commit}, query) {
81 | commit(types.SET_SEARCH_HISTORY, saveSearch(query))
82 | }
83 |
84 | export const deleteSearchHistory = function ({commit}, query) {
85 | commit(types.SET_SEARCH_HISTORY, deleteSearch(query))
86 | }
87 |
88 | export const clearSearchHistory = function ({commit}) {
89 | commit(types.SET_SEARCH_HISTORY, clearSearch())
90 | }
91 |
92 | export const deleteSong = function ({commit, state}, song) {
93 | let playlist = state.playlist.slice()
94 | let sequenceList = state.sequenceList.slice()
95 | let currentIndex = state.currentIndex
96 | let pIndex = findIndex(playlist, song)
97 | playlist.splice(pIndex, 1)
98 | let sIndex = findIndex(sequenceList, song)
99 | sequenceList.splice(sIndex, 1)
100 | if (currentIndex > pIndex || currentIndex === playlist.length) {
101 | currentIndex--
102 | }
103 |
104 | commit(types.SET_PLAYLIST, playlist)
105 | commit(types.SET_SEQUENCE_LIST, sequenceList)
106 | commit(types.SET_CURRENT_INDEX, currentIndex)
107 |
108 | if (!playlist.length) {
109 | commit(types.SET_PLAYING_STATE, false)
110 | } else {
111 | commit(types.SET_PLAYING_STATE, true)
112 | }
113 | }
114 |
115 | export const deleteSongList = function ({commit}) {
116 | commit(types.SET_CURRENT_INDEX, -1)
117 | commit(types.SET_PLAYLIST, [])
118 | commit(types.SET_SEQUENCE_LIST, [])
119 | commit(types.SET_PLAYING_STATE, false)
120 | }
121 |
122 | export const savePlayHistory = function ({commit}, song) {
123 | commit(types.SET_PLAY_HISTORY, savePlay(song))
124 | }
125 |
126 | export const saveFavoriteList = function ({commit}, song) {
127 | commit(types.SET_FAVORITE_LIST, saveFavorite(song))
128 | }
129 |
130 | export const deleteFavoriteList = function ({commit}, song) {
131 | commit(types.SET_FAVORITE_LIST, deleteFavorite(song))
132 | }
133 |
--------------------------------------------------------------------------------
/src/store/getters.js:
--------------------------------------------------------------------------------
1 | export const singer = state => state.singer
2 |
3 | export const playing = state => state.playing
4 |
5 | export const fullScreen = state => state.fullScreen
6 |
7 | export const playlist = state => state.playlist
8 |
9 | export const sequenceList = state => state.sequenceList
10 |
11 | export const mode = state => state.mode
12 |
13 | export const currentIndex = state => state.currentIndex
14 |
15 | export const currentSong = (state) => {
16 | return state.playlist[state.currentIndex] || {}
17 | }
18 |
19 | export const disc = state => state.disc
20 |
21 | export const topList = state => state.topList
22 |
23 | export const searchHistory = state => state.searchHistory
24 |
25 | export const playHistory = state => state.playHistory
26 |
27 | export const favoriteList = state => state.favoriteList
28 |
--------------------------------------------------------------------------------
/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Vuex from 'vuex'
3 | import * as actions from './actions'
4 | import * as getters from './getters'
5 | import state from './state'
6 | import mutations from './mutations'
7 | import createLogger from 'vuex/dist/logger'
8 |
9 | Vue.use(Vuex)
10 |
11 | const debug = process.env.NODE_ENV !== 'production'
12 |
13 | export default new Vuex.Store({
14 | actions,
15 | getters,
16 | state,
17 | mutations,
18 | strict: debug,
19 | plugins: debug ? [createLogger()] : []
20 | })
--------------------------------------------------------------------------------
/src/store/mutation-types.js:
--------------------------------------------------------------------------------
1 | export const SET_SINGER = 'SET_SINGER'
2 |
3 | export const SET_PLAYING_STATE = 'SET_PLAYING_STATE'
4 |
5 | export const SET_FULL_SCREEN = 'SET_FULL_SCREEN'
6 |
7 | export const SET_PLAYLIST = 'SET_PLAYLIST'
8 |
9 | export const SET_SEQUENCE_LIST = 'SET_SEQUENCE_LIST'
10 |
11 | export const SET_PLAY_MODE = 'SET_PLAY_MODE'
12 |
13 | export const SET_CURRENT_INDEX = 'SET_CURRENT_INDEX'
14 |
15 | export const SET_DISC = 'SET_DISC'
16 |
17 | export const SET_TOP_LIST = 'SET_TOP_LIST'
18 |
19 | export const SET_SEARCH_HISTORY = 'SET_SEARCH_HISTORY'
20 |
21 | export const SET_PLAY_HISTORY = 'SET_PLAY_HISTORY'
22 |
23 | export const SET_FAVORITE_LIST = 'SET_FAVORITE_LIST'
--------------------------------------------------------------------------------
/src/store/mutations.js:
--------------------------------------------------------------------------------
1 | import * as types from './mutation-types'
2 |
3 | const matutaions = {
4 | [types.SET_SINGER](state, singer) {
5 | state.singer = singer
6 | },
7 | [types.SET_PLAYING_STATE](state, flag) {
8 | state.playing = flag
9 | },
10 | [types.SET_FULL_SCREEN](state, flag) {
11 | state.fullScreen = flag
12 | },
13 | [types.SET_PLAYLIST](state, list) {
14 | state.playlist = list
15 | },
16 | [types.SET_SEQUENCE_LIST](state, list) {
17 | state.sequenceList = list
18 | },
19 | [types.SET_PLAY_MODE](state, mode) {
20 | state.mode = mode
21 | },
22 | [types.SET_CURRENT_INDEX](state, index) {
23 | state.currentIndex = index
24 | },
25 | [types.SET_DISC](state, disc) {
26 | state.disc = disc
27 | },
28 | [types.SET_TOP_LIST](state, topList) {
29 | state.topList = topList
30 | },
31 | [types.SET_SEARCH_HISTORY](state, history) {
32 | state.searchHistory = history
33 | },
34 | [types.SET_PLAY_HISTORY](state, history) {
35 | state.playHistory = history
36 | },
37 | [types.SET_FAVORITE_LIST](state, list) {
38 | state.favoriteList = list
39 | }
40 | }
41 |
42 | export default matutaions
--------------------------------------------------------------------------------
/src/store/state.js:
--------------------------------------------------------------------------------
1 | import {playMode} from 'common/js/config'
2 | import {loadSearch, loadPlay, loadFavorite} from 'common/js/cache'
3 |
4 | const state = {
5 | singer: {},
6 | playing: false,
7 | fullScreen: false,
8 | playlist: [],
9 | sequenceList: [],
10 | mode: playMode.sequence,
11 | currentIndex: -1,
12 | disc: {},
13 | topList: {},
14 | searchHistory: loadSearch(),
15 | playHistory: loadPlay(),
16 | favoriteList: loadFavorite()
17 | }
18 | export default state
--------------------------------------------------------------------------------
/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/poetries/vue-music/4687c16079cf7981dfecfa11d293cf0bf10904f5/static/.gitkeep
--------------------------------------------------------------------------------