├── .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 ├── src ├── App.vue ├── api │ ├── config.js │ ├── recommend.js │ ├── singer.js │ └── song.js ├── base │ ├── listView │ │ └── listview.vue │ ├── loading │ │ ├── loading.gif │ │ └── loading.vue │ ├── progress-bar │ │ └── progress-bar.vue │ ├── progress-circle │ │ └── progress-circle.vue │ ├── scroll │ │ └── scroll.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 ├── common │ ├── fonts │ │ ├── music-icon.eot │ │ ├── music-icon.svg │ │ ├── music-icon.ttf │ │ └── music-icon.woff │ ├── image │ │ ├── default.png │ │ ├── music1.gif │ │ ├── music2.gif │ │ ├── music3.gif │ │ ├── vueDir.jpg │ │ └── vueDir2.jpg │ ├── js │ │ ├── config.js │ │ ├── congif.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 │ ├── 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 │ └── tab │ │ └── tab.vue ├── main.js ├── router │ └── index.js └── store │ ├── actions.js │ ├── getters.js │ ├── index.js │ ├── mutation-types.js │ ├── mutations.js │ └── state.js └── static ├── .gitkeep └── music1.gif /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": ["transform-runtime"], 12 | "env": { 13 | "test": { 14 | "presets": ["env", "stage-2"], 15 | "plugins": ["istanbul"] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.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 | 27 | 'eol-last': 0, 28 | 'space-before-function-paren': 0 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Editor directories and files 9 | .idea 10 | *.suo 11 | *.ntvs* 12 | *.njsproj 13 | *.sln 14 | -------------------------------------------------------------------------------- /.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.js的音乐播放器(Webapp) 2 | 3 | -------- 4 | ### 概述 5 | 项目是基于Vue2.x的一个Web Music App,目前实现数据获取,推荐页,歌手页和播发器功能,待持续完善。。。 6 | 项目的大致流程是Vue-cli构建开发环境,分析需求,设计构思,规划目录结构,开始编码。 7 | 8 | ### 演示demo图 9 | ![](./src/common/image/music1.gif) 10 | ![](./src/common/image/music2.gif) 11 | ![](./src/common/image/music3.gif) 12 | 13 | #### 视图层 14 | > 15 | * 推荐页 16 | * 歌手页 17 | * 歌手详情 18 | * 歌曲排行榜 19 | * 排行榜详情 20 | * 搜索页 21 | * 用户中心 22 | 23 | #### 数据来源 24 | 所有数据都来自于QQ音乐,抓取自QQ音乐的接口,大部分接口都是JSONP,抓取比较容易,其中一些接口限制了`host`,不能直接抓取,采用的方法是用`Axios+webpack-dev-server`代理,设置`header`,以此绕过`host`的限制。 25 | 26 | #### 技术栈 27 | 主要是Vue全家桶加一些周边插件 28 | > 29 | * [x] Vue 2 30 | * [x] Vuex 31 | * [x] Vue-Router 32 | * [x] Vue-cli 33 | * [x] Stylus 34 | * [x] Axios 35 | * [x] JSONP 36 | * [x] Better-Scroll 37 | * [x] Webpack 38 | 39 | 40 | #### src目录结构 41 | ![](./src/common/image/vueDir.jpg) 42 | 43 | ### 难点 44 | 45 | #### player组件 46 | `player` 播放器组件是整个项目的核心,另外是数据处理和用户体验。 47 | 播放器是全局组件,放在`App.vue`下面,通过`Vuex`传递数据,触发`action`提交`mutation`,从而使播放器开始工作。`player`组件由多个基础组件构成,具体请看项目代码,下面上图 48 | ![](./src/common/image/vueDir2.jpg) 49 | 50 | > 51 | 为了防止切换歌曲时点击速度过快导致歌曲播放错误,使用了`audio`的`onplay`API,结合`Vuex`获取到数据,判断当前歌曲数据请求到才可以切换下一首歌曲。 52 | #### 数据处理 53 | 通过调用QQ音乐的JSONP接口,获取的数据并不能直接拿来用,需要做进一步的规格化,达到我们使用的要求,所以在这方面单独封装了一个`class`来处理这方面的数据,具体请看`src/common/js/song.js` 54 | 55 | 在请求JSONP的时候,用到了一个JSONP库,这个库代码十分简短,只有几十行,有兴趣的同学可以[学习](https://github.com/webmodules/jsonp)下。 56 | 57 | 使用时,就是将请求的参数拼接在请求url上,然后调用这个库的`jsonp`方法。所以,在此封装了两个函数,一个是将参数拼接在url上,另一个是将库里面的`jsonp`方法Promise化,方便我们使用,具体请查看`src/common/js/jsonp.js`。 58 | 59 | 将请求的数据格式化后再通过`Vuex`传递,组件间共享,实现歌曲的播放切换等。 60 | 61 | #### 交互体验 62 | 该项目的很多地方都涉及到滚动,包括下拉滚动,下拉滚动刷新等。这里面用到了一个库(`better-scroll`),来实现所有涉及到的滚动,建议学习下它的[API](https://github.com/ustbhuangyi/better-scroll)。 63 | 64 | 其他动画包括了`Vue`的`transition`动画,路由之间切换时的简单动画,播放器打开时的动画,这个地方比较难,也比较好玩。 65 | 66 | 打开页面时的加载Loading效果,其实就是一个Loading组件,也比较简单。 67 | 68 | 为了减少流量,图片加载使用了懒加载的方式,滚动时再加载真实的图片。 69 | 具体效果请自身体验:) 70 | 71 | ### 构建 72 | #### 开发环境 73 | 74 | ``` bash 75 | # install dependencies 76 | npm install 77 | 78 | # serve with hot reload at localhost:8080 79 | npm run dev 80 | 81 | # run e2e tests 82 | npm run e2e 83 | 84 | # run all tests 85 | npm test 86 | ``` 87 | #### 生产环境 88 | 89 | ``` bash 90 | # build for production with minification 91 | npm run build 92 | # run 93 | node prod.server.js 94 | ``` 95 | ### 总结 96 | 通过该项目,自己收获了许多,实践中也遇到了大大小小许多问题,通过查找相关资料学习以及断点调试等逐个解决。目前功能待持续优化。。。 97 | -------------------------------------------------------------------------------- /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 | // default port where dev server listens for incoming traffic 16 | var port = process.env.PORT || config.dev.port 17 | // automatically open browser, if not set will be false 18 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 19 | // Define HTTP proxies to your custom API backend 20 | // https://github.com/chimurai/http-proxy-middleware 21 | var proxyTable = config.dev.proxyTable 22 | 23 | var app = express() 24 | 25 | var apiRoutes = express.Router() 26 | 27 | apiRoutes.get('/getDiscList', function (req, res) { 28 | var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg' 29 | axios.get(url, { 30 | headers: { 31 | referer: 'https://c.y.qq.com/', 32 | host: 'c.y.qq.com' 33 | }, 34 | params: req.query 35 | }).then((response) => { 36 | res.json(response.data) 37 | }).catch((e) => { 38 | console.log(e) 39 | }) 40 | }) 41 | 42 | apiRoutes.get('/lyric', function (req, res) { 43 | var url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg' 44 | 45 | axios.get(url, { 46 | headers: { 47 | referer: 'https://c.y.qq.com/', 48 | host: 'c.y.qq.com' 49 | }, 50 | params: req.query 51 | }).then((response) => { 52 | var ret = response.data 53 | if (typeof ret === 'string') { 54 | var reg = /^\w+\(({[^()]+})\)$/ 55 | var matches = ret.match(reg) 56 | if (matches) { 57 | ret = JSON.parse(matches[1]) 58 | } 59 | } 60 | res.json(ret) 61 | }).catch((e) => { 62 | console.log(e) 63 | }) 64 | }) 65 | 66 | apiRoutes.get('/lyric', function (req, res) { 67 | var url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg' 68 | 69 | axios.get(url, { 70 | headers: { 71 | referer: 'https://c.y.qq.com/', 72 | host: 'c.y.qq.com' 73 | }, 74 | params: req.query 75 | }).then((response) => { 76 | var ret = response.data 77 | if (typeof ret === 'string') { 78 | var reg = /^\w+\(({[^()]+})\)$/ 79 | var matches = ret.match(reg) 80 | if (matches) { 81 | ret = JSON.parse(matches[1]) 82 | } 83 | } 84 | res.json(ret) 85 | }).catch((e) => { 86 | console.log(e) 87 | }) 88 | }) 89 | 90 | app.use('/api', apiRoutes) 91 | 92 | var compiler = webpack(webpackConfig) 93 | 94 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 95 | publicPath: webpackConfig.output.publicPath, 96 | quiet: true 97 | }) 98 | 99 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 100 | log: () => {} 101 | }) 102 | // force page reload when html-webpack-plugin template changes 103 | compiler.plugin('compilation', function (compilation) { 104 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 105 | hotMiddleware.publish({ action: 'reload' }) 106 | cb() 107 | }) 108 | }) 109 | 110 | // proxy api requests 111 | Object.keys(proxyTable).forEach(function (context) { 112 | var options = proxyTable[context] 113 | if (typeof options === 'string') { 114 | options = { target: options } 115 | } 116 | app.use(proxyMiddleware(options.filter || context, options)) 117 | }) 118 | 119 | // handle fallback for HTML5 history API 120 | app.use(require('connect-history-api-fallback')()) 121 | 122 | // serve webpack bundle output 123 | app.use(devMiddleware) 124 | 125 | // enable hot-reload and state-preserving 126 | // compilation error display 127 | app.use(hotMiddleware) 128 | 129 | // serve pure static assets 130 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 131 | app.use(staticPath, express.static('./static')) 132 | 133 | var uri = 'http://localhost:' + port 134 | 135 | var _resolve 136 | var readyPromise = new Promise(resolve => { 137 | _resolve = resolve 138 | }) 139 | 140 | console.log('> Starting dev server...') 141 | devMiddleware.waitUntilValid(() => { 142 | console.log('> Listening at ' + uri + '\n') 143 | // when env is testing, don't need open it 144 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 145 | opn(uri) 146 | } 147 | _resolve() 148 | }) 149 | 150 | var server = app.listen(port) 151 | 152 | module.exports = { 153 | ready: readyPromise, 154 | close: () => { 155 | server.close() 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /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 | // 'vue$': 'vue/dist/vue.esm.js', 25 | // '@': resolve('src'), 26 | 'src': resolve('src'), 27 | 'common': resolve('src/common'), 28 | 'components': resolve('src/components'), 29 | 'api': resolve('src/api'), 30 | 'base': resolve('src/base') 31 | } 32 | }, 33 | module: { 34 | rules: [ 35 | { 36 | test: /\.vue$/, 37 | loader: 'vue-loader', 38 | options: vueLoaderConfig 39 | }, 40 | { 41 | test: /\.js$/, 42 | loader: 'babel-loader', 43 | include: [resolve('src'), resolve('test')] 44 | }, 45 | { 46 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 47 | loader: 'url-loader', 48 | options: { 49 | limit: 10000, 50 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 51 | } 52 | }, 53 | { 54 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 55 | loader: 'url-loader', 56 | options: { 57 | limit: 10000, 58 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 59 | } 60 | } 61 | ] 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /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 | 6 | 7 | 8 | demo 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazing-Music", 3 | "version": "1.0.0", 4 | "description": "A Music APP", 5 | "author": "RickFang666 ", 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 | "axios": "^0.16.2", 15 | "better-scroll": "^0.4.0", 16 | "create-keyframe-animation": "^0.1.0", 17 | "fastclick": "^1.0.6", 18 | "js-base64": "^2.1.9", 19 | "jsonp": "^0.2.1", 20 | "lyric-parser": "^1.0.1", 21 | "vue": "^2.3.3", 22 | "vue-lazyload": "^1.0.6", 23 | "vue-router": "^2.3.1", 24 | "vuex": "^2.3.1" 25 | }, 26 | "devDependencies": { 27 | "autoprefixer": "^6.7.2", 28 | "babel-core": "^6.22.1", 29 | "babel-eslint": "^7.1.1", 30 | "babel-loader": "^6.2.10", 31 | "babel-plugin-transform-runtime": "^6.22.0", 32 | "babel-polyfill": "^6.23.0", 33 | "babel-preset-env": "^1.3.2", 34 | "babel-preset-stage-2": "^6.22.0", 35 | "babel-register": "^6.22.0", 36 | "chalk": "^1.1.3", 37 | "connect-history-api-fallback": "^1.3.0", 38 | "copy-webpack-plugin": "^4.0.1", 39 | "css-loader": "^0.28.0", 40 | "eslint": "^3.19.0", 41 | "eslint-config-standard": "^6.2.1", 42 | "eslint-friendly-formatter": "^2.0.7", 43 | "eslint-loader": "^1.7.1", 44 | "eslint-plugin-html": "^2.0.0", 45 | "eslint-plugin-promise": "^3.4.0", 46 | "eslint-plugin-standard": "^2.0.1", 47 | "eventsource-polyfill": "^0.9.6", 48 | "express": "^4.14.1", 49 | "extract-text-webpack-plugin": "^2.0.0", 50 | "file-loader": "^0.11.1", 51 | "friendly-errors-webpack-plugin": "^1.1.3", 52 | "html-webpack-plugin": "^2.28.0", 53 | "http-proxy-middleware": "^0.17.3", 54 | "opn": "^4.0.2", 55 | "optimize-css-assets-webpack-plugin": "^1.3.0", 56 | "ora": "^1.2.0", 57 | "rimraf": "^2.6.0", 58 | "semver": "^5.3.0", 59 | "shelljs": "^0.7.6", 60 | "stylus": "^0.54.5", 61 | "stylus-loader": "^3.0.1", 62 | "url-loader": "^0.5.8", 63 | "vue-loader": "^12.1.0", 64 | "vue-style-loader": "^3.0.1", 65 | "vue-template-compiler": "^2.3.3", 66 | "webpack": "^2.6.1", 67 | "webpack-bundle-analyzer": "^2.2.1", 68 | "webpack-dev-middleware": "^1.10.0", 69 | "webpack-hot-middleware": "^2.18.0", 70 | "webpack-merge": "^4.1.0" 71 | }, 72 | "engines": { 73 | "node": ">= 4.0.0", 74 | "npm": ">= 3.0.0" 75 | }, 76 | "browserslist": [ 77 | "> 1%", 78 | "last 2 versions", 79 | "not ie <= 8" 80 | ] 81 | } 82 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 24 | 25 | 28 | -------------------------------------------------------------------------------- /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 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | const data = Object.assign({}, commonParams, { 7 | channel: 'singer', 8 | page: 'list', 9 | key: 'all_all_all', 10 | pagesize: 100, 11 | pagenum: 1, 12 | gostUin: 0, 13 | needNewCode: 0, 14 | platform: 'yqq', 15 | g_tk: 1664029744 16 | }, 17 | ) 18 | 19 | return jsonp(url, data, options) 20 | } 21 | 22 | export function getSingerDetail(singerId) { 23 | const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg' 24 | 25 | const data = Object.assign({}, commonParams, { 26 | hostUin: 0, 27 | needNewCode: 0, 28 | platform: 'yqq', 29 | order: 'listen', 30 | begin: 0, 31 | num: 80, 32 | songstatus: 1, 33 | singermid: singerId 34 | }) 35 | 36 | return jsonp(url, data, options) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /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 | } 23 | 24 | -------------------------------------------------------------------------------- /src/base/listView/listview.vue: -------------------------------------------------------------------------------- 1 | 37 | 38 | 168 | 169 | 237 | -------------------------------------------------------------------------------- /src/base/loading/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/base/loading/loading.gif -------------------------------------------------------------------------------- /src/base/loading/loading.vue: -------------------------------------------------------------------------------- 1 | 7 | 17 | 26 | -------------------------------------------------------------------------------- /src/base/progress-bar/progress-bar.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 81 | 112 | -------------------------------------------------------------------------------- /src/base/progress-circle/progress-circle.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 37 | 38 | 53 | -------------------------------------------------------------------------------- /src/base/scroll/scroll.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 90 | 91 | 94 | -------------------------------------------------------------------------------- /src/base/slider/slider.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 118 | 119 | 162 | -------------------------------------------------------------------------------- /src/base/song-list/first@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/base/song-list/first@2x.png -------------------------------------------------------------------------------- /src/base/song-list/first@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/base/song-list/first@3x.png -------------------------------------------------------------------------------- /src/base/song-list/second@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/base/song-list/second@2x.png -------------------------------------------------------------------------------- /src/base/song-list/second@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/base/song-list/second@3x.png -------------------------------------------------------------------------------- /src/base/song-list/song-list.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 32 | 33 | 75 | -------------------------------------------------------------------------------- /src/base/song-list/third@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/base/song-list/third@2x.png -------------------------------------------------------------------------------- /src/base/song-list/third@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/base/song-list/third@3x.png -------------------------------------------------------------------------------- /src/common/fonts/music-icon.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/fonts/music-icon.eot -------------------------------------------------------------------------------- /src/common/fonts/music-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Generated by IcoMoon 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 | -------------------------------------------------------------------------------- /src/common/fonts/music-icon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/fonts/music-icon.ttf -------------------------------------------------------------------------------- /src/common/fonts/music-icon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/fonts/music-icon.woff -------------------------------------------------------------------------------- /src/common/image/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/image/default.png -------------------------------------------------------------------------------- /src/common/image/music1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/image/music1.gif -------------------------------------------------------------------------------- /src/common/image/music2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/image/music2.gif -------------------------------------------------------------------------------- /src/common/image/music3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/image/music3.gif -------------------------------------------------------------------------------- /src/common/image/vueDir.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/image/vueDir.jpg -------------------------------------------------------------------------------- /src/common/image/vueDir2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/common/image/vueDir2.jpg -------------------------------------------------------------------------------- /src/common/js/config.js: -------------------------------------------------------------------------------- 1 | export const playMode = { 2 | sequence: 0, 3 | loop: 1, 4 | random: 2 5 | } 6 | -------------------------------------------------------------------------------- /src/common/js/congif.js: -------------------------------------------------------------------------------- 1 | export const playMode = { 2 | sequence: 0, 3 | loop: 1, 4 | random: 2 5 | } 6 | -------------------------------------------------------------------------------- /src/common/js/dom.js: -------------------------------------------------------------------------------- 1 | export function addClass(el, className){ 2 | if (hasClass(el,className)){ 3 | return 4 | } 5 | let newClass = el.className.split(' ') 6 | newClass.push(className) 7 | el.className = newClass.join(' ') 8 | } 9 | 10 | export function hasClass(el,className){ 11 | let reg = new RegExp('(^|\\s)'+className+'(\\s|$)') 12 | return reg.test(el.className) 13 | } 14 | 15 | export function getData(el, name, val){ 16 | const prefix = 'data-' 17 | name = prefix + name 18 | if(val) { 19 | return el.setAttribute(name, val) 20 | }else { 21 | return el.getAttribute(name) 22 | } 23 | } 24 | 25 | let elementStyle = document.createElement('div').style 26 | 27 | let vendor = (() => { 28 | let transformNames = { 29 | webkit: 'webkitTransform', 30 | Moz: 'MozTransform', 31 | O: 'OTransform', 32 | ms: 'msTransform', 33 | standard: 'transform' 34 | } 35 | for (let key in transformNames) { 36 | if(elementStyle[transformNames[key]]!== undefined) { 37 | return key 38 | } 39 | } 40 | return false 41 | })() 42 | 43 | export function prefixStyle(style){ 44 | if (vendor === false) { 45 | return false 46 | } 47 | if (vendor === 'standard') { 48 | return style 49 | } 50 | 51 | return vendor + style.charAt(0).toUpperCase() + style.substr(1) 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/common/js/jsonp.js: -------------------------------------------------------------------------------- 1 | import originJSONP from 'jsonp' 2 | 3 | export default function jsonp(url, data, option){ 4 | url += (url.indexOf('?')==-1? '?' : "&") + param(data) 5 | return new Promise((resolve, reject) => { 6 | originJSONP(url, option, (err, data) => { 7 | if(!err) { 8 | resolve(data) 9 | } 10 | else { 11 | reject(err) 12 | } 13 | }) 14 | }) 15 | } 16 | 17 | 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) //es5 22 | url += `&${k}=${encodeURIComponent(value)}` 23 | } 24 | return url ? url.substring(1) : '' 25 | } 26 | -------------------------------------------------------------------------------- /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 | } 8 | -------------------------------------------------------------------------------- /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 | resolve(this.lyric) 27 | } else { 28 | reject('no lyric') 29 | } 30 | }) 31 | }) 32 | } 33 | } 34 | 35 | export function createSong(musicData) { 36 | return new Song({ 37 | id: musicData.songid, 38 | mid: musicData.songmid, 39 | singer: filterSinger(musicData.singer), 40 | name: musicData.songname, 41 | album: musicData.albumname, 42 | duration: musicData.interval, 43 | image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.albummid}.jpg?max_age=2592000`, 44 | url: `http://ws.stream.qqmusic.qq.com/${musicData.songid}.m4a?fromtag=46` 45 | }) 46 | } 47 | 48 | function filterSinger(singer) { 49 | let ret = [] 50 | if (!singer) { 51 | return '' 52 | } 53 | singer.forEach((s) => { 54 | ret.push(s.name) 55 | }) 56 | return ret.join('/') 57 | } 58 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 10 | -------------------------------------------------------------------------------- /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 = #c7edcc 3 | $color-background-d = rgba(155, 233, 166, 0.3) 4 | $color-highlight-background = #9beda6 5 | $color-miniPlay-background = #15af29 6 | $color-dialog-background = #666 7 | $color-theme = #ffcd32 8 | $color-theme-d = rgba(255, 205, 49, 0.5) 9 | $color-sub-theme = #d93f30 10 | $color-text = #000 11 | $color-text-d = rgba(0, 0, 0, 0.3) 12 | $color-text-l = rgba(0, 0, 0, 0.5) 13 | $color-text-ll = rgba(0, 0, 0, 0.8) 14 | 15 | //字体定义规范 16 | $font-size-small-s = 10px 17 | $font-size-small = 12px 18 | $font-size-medium = 14px 19 | $font-size-medium-x = 16px 20 | $font-size-large = 18px 21 | $font-size-large-x = 22px 22 | -------------------------------------------------------------------------------- /src/components/m-header/logo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/components/m-header/logo@2x.png -------------------------------------------------------------------------------- /src/components/m-header/logo@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/src/components/m-header/logo@3x.png -------------------------------------------------------------------------------- /src/components/m-header/m-header.vue: -------------------------------------------------------------------------------- 1 | 7 | 10 | 46 | -------------------------------------------------------------------------------- /src/components/music-list/music-list.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 147 | 148 | 238 | -------------------------------------------------------------------------------- /src/components/player/player.vue: -------------------------------------------------------------------------------- 1 | 101 | 102 | 463 | 464 | 708 | -------------------------------------------------------------------------------- /src/components/rank/rank.vue: -------------------------------------------------------------------------------- 1 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /src/components/recommend/recommend.vue: -------------------------------------------------------------------------------- 1 | 36 | 93 | 143 | -------------------------------------------------------------------------------- /src/components/search/search.vue: -------------------------------------------------------------------------------- 1 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /src/components/singer-detail/singer-detail.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 63 | 64 | 71 | -------------------------------------------------------------------------------- /src/components/singer/singer.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 99 | 100 | 107 | 108 | -------------------------------------------------------------------------------- /src/components/tab/tab.vue: -------------------------------------------------------------------------------- 1 | 17 | 20 | 38 | 39 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import 'babel-polyfill' 4 | import Vue from 'vue' 5 | import App from './App' 6 | import router from './router' 7 | import store from './store' 8 | import fastclick from 'fastclick' 9 | import VueLazyLoad from 'vue-lazyload' 10 | 11 | import 'common/stylus/index.styl' 12 | // Vue.config.productionTip = false 13 | 14 | fastclick.attach(document.body) 15 | 16 | Vue.use(VueLazyLoad, { 17 | loading: require('common/image/default.png') 18 | }) 19 | 20 | /* eslint-disable no-new */ 21 | new Vue({ 22 | el: '#app', 23 | router, 24 | store, 25 | render: h => h(App) 26 | }) 27 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import Recommend from 'src/components/recommend/recommend' 4 | import Singer from 'src/components/singer/singer' 5 | import Search from 'src/components/search/search' 6 | import Rank from 'src/components/rank/rank' 7 | import SingerDetail from 'src/components/singer-detail/singer-detail' 8 | 9 | Vue.use(Router) 10 | 11 | export default new Router({ 12 | routes: [ 13 | { 14 | path: '/', 15 | redirect: '/Recommend' 16 | }, 17 | { 18 | path: '/recommend', 19 | component: Recommend 20 | }, 21 | { 22 | path: '/singer', 23 | component: Singer, 24 | children: [ 25 | { 26 | path: ':id', 27 | component: SingerDetail 28 | } 29 | ] 30 | }, 31 | { 32 | path: '/search', 33 | component: Search 34 | }, 35 | { 36 | path: '/rank', 37 | component: Rank 38 | } 39 | 40 | ] 41 | }) 42 | -------------------------------------------------------------------------------- /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 | 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | }) 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/store/mutations.js: -------------------------------------------------------------------------------- 1 | import * as types from './mutation-types' 2 | 3 | const mutations = { 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 | } 26 | 27 | export default mutations 28 | -------------------------------------------------------------------------------- /src/store/state.js: -------------------------------------------------------------------------------- 1 | import {playMode} from 'common/js/config' 2 | 3 | const state = { 4 | singer: {}, 5 | playing: false, 6 | fullScreen: false, 7 | playlist: [], 8 | sequenceList: [], 9 | mode: playMode.sequence, 10 | currentIndex: -1, 11 | } 12 | 13 | export default state 14 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/static/.gitkeep -------------------------------------------------------------------------------- /static/music1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickFang666/Vue.js-Music-WebApp/9a2aff2bd0e558e8a8fe2c4ff7aeafeffc28de0b/static/music1.gif --------------------------------------------------------------------------------