README.md 5.7 KB
Newer Older
AresnLiang's avatar
AresnLiang 已提交
1
# 网易云音乐(App版本)
C
update  
cpongo2 已提交
2

AresnLiang's avatar
AresnLiang 已提交
3
## 一、基本介绍
C
update  
cpongo2 已提交
4 5


View Design's avatar
View Design 已提交
6

AresnLiang's avatar
AresnLiang 已提交
7
本项目使用`vue2+vue-cli`实现了一个简易的网易云音乐(**App版本**),实现了歌曲的首页推荐展示,歌曲的搜索,评论的展示以及歌曲的播放四个主要功能模块,主要用来练手,效果如下图所示:
View Design's avatar
View Design 已提交
8 9 10 11




AresnLiang's avatar
AresnLiang 已提交
12
**音乐播放**
View Design's avatar
View Design 已提交
13

AresnLiang's avatar
AresnLiang 已提交
14
<img src="https://gitee.com/riskbaby/picgo/raw/master/blog/202210311601471.png" alt="5" style="zoom:67%;" />
慢慢走~'s avatar
慢慢走~ 已提交
15

AresnLiang's avatar
AresnLiang 已提交
16
## 二、项目使用
View Design's avatar
View Design 已提交
17

AresnLiang's avatar
AresnLiang 已提交
18
### 2.1 安装依赖
View Design's avatar
View Design 已提交
19

AresnLiang's avatar
AresnLiang 已提交
20 21 22
```
npm i
```
View Design's avatar
View Design 已提交
23

AresnLiang's avatar
AresnLiang 已提交
24
### 2.2 本地使用
View Design's avatar
View Design 已提交
25

AresnLiang's avatar
AresnLiang 已提交
26 27 28
```
npm run serve
```
View Design's avatar
View Design 已提交
29 30 31



AresnLiang's avatar
AresnLiang 已提交
32
### 2.3 打包上传
View Design's avatar
View Design 已提交
33

AresnLiang's avatar
AresnLiang 已提交
34 35 36
```
npm run build
```
慢慢走~'s avatar
慢慢走~ 已提交
37

View Design's avatar
View Design 已提交
38 39


AresnLiang's avatar
AresnLiang 已提交
40
**github地址**[cloud-music](https://github.com/bosombaby/cloud-music)
View Design's avatar
View Design 已提交
41

AresnLiang's avatar
AresnLiang 已提交
42
**在线预览:**:https://music.vrteam.top
慢慢走~'s avatar
慢慢走~ 已提交
43

AresnLiang's avatar
AresnLiang 已提交
44
## 三、开发环境
View Design's avatar
View Design 已提交
45

AresnLiang's avatar
AresnLiang 已提交
46
### 2.1 代理服务器
慢慢走~'s avatar
慢慢走~ 已提交
47

AresnLiang's avatar
AresnLiang 已提交
48
`api链接`:https://binaryify.github.io/NeteaseCloudMusicApi/#/![3](https://gitee.com/riskbaby/picgo/raw/master/blog/202210131612886.png)
慢慢走~'s avatar
慢慢走~ 已提交
49

AresnLiang's avatar
AresnLiang 已提交
50
`总结`:根据文档在后端跑起来代理服务器
View Design's avatar
View Design 已提交
51

AresnLiang's avatar
AresnLiang 已提交
52
### 2.2 搭建前端项目
View Design's avatar
View Design 已提交
53

AresnLiang's avatar
AresnLiang 已提交
54
接下来使用`yarn`代替`npm`,原因:https://blog.csdn.net/qq_39122387/article/details/109675680
View Design's avatar
View Design 已提交
55

AresnLiang's avatar
AresnLiang 已提交
56
#### 2.2.1 脚手架
View Design's avatar
View Design 已提交
57

AresnLiang's avatar
AresnLiang 已提交
58 59 60
```js
vue create music-demo
```
View Design's avatar
View Design 已提交
61

AresnLiang's avatar
AresnLiang 已提交
62
`总结`:默认选择`vue2``yarn`安装依赖的方式
View Design's avatar
View Design 已提交
63

AresnLiang's avatar
AresnLiang 已提交
64
#### 2.2.2 项目依赖
View Design's avatar
View Design 已提交
65

AresnLiang's avatar
AresnLiang 已提交
66
**进入项目文件夹**
View Design's avatar
View Design 已提交
67

AresnLiang's avatar
AresnLiang 已提交
68 69 70
```
cd  music-demo
```
View Design's avatar
View Design 已提交
71

AresnLiang's avatar
AresnLiang 已提交
72
**第三方依赖**
View Design's avatar
View Design 已提交
73

AresnLiang's avatar
AresnLiang 已提交
74 75 76
```
yarn add axios vant@latest-v2 vue-router@3
```
View Design's avatar
View Design 已提交
77

AresnLiang's avatar
AresnLiang 已提交
78
注意版本,这个是vue2的项目,对应的包有所变化
View Design's avatar
View Design 已提交
79

AresnLiang's avatar
AresnLiang 已提交
80
**生产依赖**
View Design's avatar
View Design 已提交
81

AresnLiang's avatar
AresnLiang 已提交
82 83 84 85
```
yarn add babel-plugin-import postcss postcss-pxtorem@5.1.1  -D
yarn add less less-loader@5.0.0 -D
```
View Design's avatar
View Design 已提交
86

AresnLiang's avatar
AresnLiang 已提交
87
**引入本地样式、图标**
View Design's avatar
View Design 已提交
88

AresnLiang's avatar
AresnLiang 已提交
89 90 91 92 93 94 95 96
```js
// 字体图标
import '@/assets/fonts/TsangerYuYangT_W01_W01.ttf'
//自适应
import '@/mobile/flexible'
//初始化样式
import '@/styles/reset.css'
```
View Design's avatar
View Design 已提交
97

AresnLiang's avatar
AresnLiang 已提交
98
**在babel.config.js - 添加vant按需引入插件配置**
慢慢走~'s avatar
慢慢走~ 已提交
99

AresnLiang's avatar
AresnLiang 已提交
100 101 102 103 104 105 106 107 108
```js
plugins: [
    ['import', {
      libraryName: 'vant',
      libraryDirectory: 'es',
      style: true
    }, 'vant']
  ]
```
慢慢走~'s avatar
慢慢走~ 已提交
109

AresnLiang's avatar
AresnLiang 已提交
110
**postcss.config.js自定义自适应比例**
慢慢走~'s avatar
慢慢走~ 已提交
111

AresnLiang's avatar
AresnLiang 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124
```js
module.exports = {
    plugins: {
      'postcss-pxtorem': {
        // 能够把所有元素的px单位转成Rem
        // rootValue: 转换px的基准值。
        // 例如一个元素宽是75px,则换成rem之后就是2rem。
        rootValue: 37.5,
        propList: ['*']
      }
    }
  }
```
View Design's avatar
View Design 已提交
125

AresnLiang's avatar
AresnLiang 已提交
126
`注意`:每一次改动`src`目录之外的内容需要**重启服务**
慢慢走~'s avatar
慢慢走~ 已提交
127

AresnLiang's avatar
AresnLiang 已提交
128
## 四、需求分析
View Design's avatar
View Design 已提交
129 130 131



AresnLiang's avatar
AresnLiang 已提交
132
<img src="https://gitee.com/riskbaby/picgo/raw/master/blog/202210131941184.png" alt="image-20210426212251154" style="zoom:50%;" />
View Design's avatar
View Design 已提交
133

AresnLiang's avatar
AresnLiang 已提交
134
![1](https://gitee.com/riskbaby/picgo/raw/master/blog/202210161035039.png)
View Design's avatar
View Design 已提交
135 136 137



AresnLiang's avatar
AresnLiang 已提交
138
`App`:管理所有的组件
View Design's avatar
View Design 已提交
139

AresnLiang's avatar
AresnLiang 已提交
140 141 142 143 144
-  `Layout`:管理首页和搜索
  - `Home`:主页
    - `SongItem`:负责音乐的布局
  - `Search`:搜索页
    - `SongItem`:负责音乐的布局
View Design's avatar
View Design 已提交
145

AresnLiang's avatar
AresnLiang 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
- `Play`:音乐播放

- `Comment`:评论页



`Play``Comment``Layout`平级,需要的时候直接调用就行



## 五、路由管理

```js
// 引入Vue
import Vue from 'vue'
// 引入路由
import VueRouter from "vue-router"
Vue.use(VueRouter)
// 引入组件
import Layout from '@/views/Layout'
import HomePage from '@/views/Home'
import SearchPage from '@/views/Search'
import Play from '@/views/Play'
import Comment from '@/views/Comment'


const routes = [
    {
        path: '/',
        redirect:'/layout'
    },
    {
        path: '/layout',
        redirect: '/layout/home',
        component: Layout,
        children: [
            {
                path: 'home',
                component: HomePage,
                meta: {
                    title:'首页'
                },
            },
            {
                path: 'search',
                component: SearchPage,
                meta: {
                    title:'搜索'
                },
            }
        ]
    },
    {
        path: '/play',
        component:Play
    },
    {
        path: '/comment',
        component:Comment
    }
    
]
const router = new VueRouter({ routes })

export default router
```



## 六、接口管理

```js
//所有api的管理者
import { recommendMusicAPI, newMusicAPI } from "@/api/Home";
import { hotSearchAPI, searchResultAPI } from "@/api/Search";
import { getSongByIdAPI, getLyricByIdAPI } from '@/api/Play'
import { getHotCommentAPI} from '@/api/Comment'

export { recommendMusicAPI,newMusicAPI,hotSearchAPI,searchResultAPI,getSongByIdAPI,getLyricByIdAPI,getHotCommentAPI}
```

## 七、难点分析

### 7.1  搜索页面

**防抖与节流**

`防抖`:像电梯门一样,每一次有人进来之后,电梯门就会重新计时,最终的记时完成,才会触发,相当于setTimeout

`节流`:像英雄的技能一样,触发一次之后要等待一段时间才能继续执行,相当于 setInterval

搜索歌曲避免多次发起请求,使用`防抖`实现

### 7.2 播放页面

`样式`:css的动画样式

`three.js`:打算引入`粒子特效`实现3d音乐效果的(后续需求,一开始未做好规划,不好加了)

### 7.3 评论页面

**评论的刷新与加载**

- vant组件库`List 列表`` PullRefresh `结合,List 组件通过 `loading``finished` 两个变量控制加载状态,当组件滚动到底部时,会触发 `load` 事件并将 `loading` 设置成 `true`。此时可以发起异步操作并更新数据,数据更新完毕后,将 `loading` 设置成 `false` 即可。若数据已全部加载完毕,则直接将 `finished` 设置成 `true` 即可

### 7.4 异步

`Promise`:将异步转换为同步`async await`(就近原则使用),等待数据返回之后再继续执行下面的代码

## 八、项目总结

这次主要对`vue2`的项目进行锻炼。学习了模块化处理流程,对待不同的功能模块要进行合理的分区,前期一定要做好项目规划处理,后续开始学习`vue3`以及`three.js`