1、后端编写

1.1 Controller控制层编写

  1. package com.gmw.musicserver.controller;
  2. import com.gmw.musicserver.commonutils.R;
  3. import com.gmw.musicserver.entity.Consumer;
  4. import com.gmw.musicserver.entity.Singer;
  5. import com.gmw.musicserver.entity.Song;
  6. import com.gmw.musicserver.entity.SongSheet;
  7. import com.gmw.musicserver.service.ConsumerService;
  8. import com.gmw.musicserver.service.SingerService;
  9. import com.gmw.musicserver.service.SongService;
  10. import com.gmw.musicserver.service.SongSheetService;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.List;
  18. /**
  19. * <p>
  20. * 首页接口模块
  21. * </p>
  22. *
  23. * @author 未进化的程序猿
  24. * @since 2022-01-26
  25. */
  26. @RestController
  27. @RequestMapping("/musicserver/home")
  28. public class HomeController {
  29. public static final Logger logger = LoggerFactory.getLogger(HomeController.class);
  30. //用户service接口
  31. @Autowired
  32. public ConsumerService consumerService;
  33. //歌曲service接口
  34. @Autowired
  35. public SongService songService;
  36. //歌手service接口
  37. @Autowired
  38. public SingerService singerService;
  39. //歌单service接口
  40. @Autowired
  41. public SongSheetService songSheetService;
  42. /**
  43. * 查询所有的用户
  44. * @return
  45. */
  46. @GetMapping(value = "/allConsumer")
  47. public R allConusmer(){
  48. List<Consumer> consumerList = this.consumerService.allConsumer();
  49. return R.ok().data("list",consumerList).data("count",consumerList.size());
  50. }
  51. /**
  52. * 查询所有的歌曲
  53. * @return
  54. */
  55. @GetMapping(value = "/allSong")
  56. public R allSong(){
  57. List<Song> songList = this.songService.allSong();
  58. return R.ok().data("list",songList).data("count",songList.size());
  59. }
  60. /**
  61. * 查询所有的歌手
  62. * @return
  63. */
  64. @GetMapping(value = "/allSinger")
  65. public R allSinger(){
  66. List<Singer> singerList = this.singerService.allSinger();
  67. return R.ok().data("list",singerList).data("count",singerList.size());
  68. }
  69. /**
  70. * 查询所有的歌单
  71. * @return
  72. */
  73. @GetMapping(value = "/allSongList")
  74. public R allSongList(){
  75. List<SongSheet> songSheetList = this.songSheetService.allSongList();
  76. return R.ok().data("list",songSheetList).data("count",songSheetList.size());
  77. }
  78. }

2、前端编写

image.png

  1. <template>
  2. <div>
  3. <el-row :gutter="20" class="mgb20">
  4. <el-col :span="6">
  5. <el-card>
  6. <div class="grid-content">
  7. <div class="grid-cont-center">
  8. <div class="grid-num">{{consumerCount}}</div>
  9. <div>用户总数</div>
  10. </div>
  11. </div>
  12. </el-card>
  13. </el-col>
  14. <el-col :span="6">
  15. <el-card>
  16. <div class="grid-content">
  17. <div class="grid-cont-center">
  18. <div class="grid-num">{{songCount}}</div>
  19. <div>歌曲总数</div>
  20. </div>
  21. </div>
  22. </el-card>
  23. </el-col>
  24. <el-col :span="6">
  25. <el-card>
  26. <div class="grid-content">
  27. <div class="grid-cont-center">
  28. <div class="grid-num">{{singerCount}}</div>
  29. <div>歌手数量</div>
  30. </div>
  31. </div>
  32. </el-card>
  33. </el-col>
  34. <el-col :span="6">
  35. <el-card>
  36. <div class="grid-content">
  37. <div class="grid-cont-center">
  38. <div class="grid-num">{{songListCount}}</div>
  39. <div>歌单数量</div>
  40. </div>
  41. </div>
  42. </el-card>
  43. </el-col>
  44. </el-row>
  45. <el-row :gutter="20" class="mgb20">
  46. <el-col :span="12">
  47. <h3 class="mgb20">用户性别比例</h3>
  48. <div style="background-color:white">
  49. <ve-pie :data="consumerSex" :theme="options"></ve-pie>
  50. </div>
  51. </el-col>
  52. <el-col :span="12">
  53. <h3 class="mgb20">歌曲类型分布</h3>
  54. <div style="background-color:white">
  55. <ve-histogram :data="songStyle"></ve-histogram>
  56. </div>
  57. </el-col>
  58. </el-row>
  59. <el-row :gutter="20" class="mgb20">
  60. <el-col :span="12">
  61. <h3 class="mgb20">歌手性别比例</h3>
  62. <div style="background-color:white">
  63. <ve-pie :data="singerSex"></ve-pie>
  64. </div>
  65. </el-col>
  66. <el-col :span="12">
  67. <h3 class="mgb20">歌手国籍分布</h3>
  68. <div style="background-color:white">
  69. <ve-histogram :data="country"></ve-histogram>
  70. </div>
  71. </el-col>
  72. </el-row>
  73. </div>
  74. </template>
  75. <script>
  76. import {getAllSinger,getAllConusmer,getAllSong,getAllSongList} from '../api/home/index';
  77. export default {
  78. data(){
  79. return {
  80. consumerCount: 0, //用户总数
  81. songCount: 0, //歌曲总数
  82. singerCount: 0, //歌手数量
  83. songListCount: 0, //歌单数量
  84. consumer: [], //所有用户
  85. consumerSex:{ //按性别分类的用户数
  86. columns: ['性别','总数'],
  87. rows: [
  88. {'性别': '男','总数': 0},
  89. {'性别': '女','总数': 0}
  90. ]
  91. },
  92. options: {
  93. color: ['#87cefa','#ffc0cb']
  94. },
  95. // options1: {
  96. // color: ['yellow']
  97. // },
  98. songStyle:{ //按歌单风格分类
  99. columns: ['风格','总数'],
  100. rows: [
  101. {'风格': '华语','总数': 0},
  102. {'风格': '粤语','总数': 0},
  103. {'风格': '欧美','总数': 0},
  104. {'风格': '日韩','总数': 0},
  105. {'风格': 'BGM','总数': 0},
  106. {'风格': '轻音乐','总数': 0},
  107. {'风格': '乐器','总数': 0}
  108. ]
  109. },
  110. singerSex:{ //按性别分类的歌手数
  111. columns: ['性别','总数'],
  112. rows: [
  113. {'性别': '女','总数': 0},
  114. {'性别': '男','总数': 0},
  115. {'性别': '组合','总数': 0},
  116. {'性别': '不明','总数': 0}
  117. ]
  118. },
  119. country:{
  120. columns: ['国籍','总数'],
  121. rows: [
  122. {'国籍': '中国','总数': 0},
  123. {'国籍': '韩国','总数': 0},
  124. {'国籍': '日本','总数': 0},
  125. {'国籍': '美国','总数': 0},
  126. {'国籍': '新加坡','总数': 0},
  127. {'国籍': '意大利','总数': 0},
  128. {'国籍': '马来西亚','总数': 0},
  129. {'国籍': '西班牙','总数': 0}
  130. ]
  131. }
  132. }
  133. },
  134. created() {
  135. },
  136. mounted() {
  137. this.getConsumer();
  138. this.getSong();
  139. this.getSinger();
  140. this.getSongList();
  141. },
  142. methods: {
  143. getConsumer() { //用户总数
  144. getAllConusmer().then(res => {
  145. this.consumer = res.data.list;
  146. this.consumerCount = res.data.count;
  147. this.consumerSex.rows[0]['总数'] = this.setSex(1,this.consumer);
  148. this.consumerSex.rows[1]['总数'] = this.setSex(0,this.consumer);
  149. })
  150. },
  151. setSex(sex,val) { //根据性别获取用户数
  152. let count = 0;
  153. for(let item of val){
  154. if(sex == item.sex){
  155. count++;
  156. }
  157. }
  158. return count;
  159. },
  160. getSong() { //歌曲总数
  161. getAllSong().then(res => {
  162. this.songCount = res.data.count;
  163. })
  164. },
  165. getSinger() { //歌手数量
  166. getAllSinger().then(res => {
  167. this.singerCount = res.data.count;
  168. this.singerSex.rows[0]['总数'] = this.setSex(0,res.data.list);
  169. this.singerSex.rows[1]['总数'] = this.setSex(1,res.data.list);
  170. this.singerSex.rows[2]['总数'] = this.setSex(2,res.data.list);
  171. this.singerSex.rows[3]['总数'] = this.setSex(3,res.data.list);
  172. for(let item of res.data.list){
  173. this.getByCountry(item.location);
  174. }
  175. })
  176. },
  177. getSongList() { //歌单数量
  178. getAllSongList().then(res => {
  179. this.songListCount = res.data.count;
  180. for(let item of res.data.list){
  181. this.getByStyle(item.style);
  182. }
  183. })
  184. },
  185. getByStyle(style) { //根据歌单风格获取数量
  186. for(let item of this.songStyle.rows){
  187. if(style.includes(item['风格'])){
  188. item['总数']++;
  189. }
  190. }
  191. },
  192. getByCountry(location) { //根据国籍获取数量
  193. for(let item of this.country.rows){
  194. if(location.includes(item['国籍'])){
  195. item['总数']++;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. </script>
  202. <style scoped>
  203. .grid-content {
  204. display: flex;
  205. align-items: center;
  206. height: 50px;
  207. }
  208. .grid-cont-center {
  209. flex: 1;
  210. text-align: center;
  211. font-size: 14px;
  212. color: darkgray;
  213. }
  214. .grid-num {
  215. font-size: 30px;
  216. font-weight: bold;
  217. }
  218. </style>

2.1 用户/歌曲/歌手/歌单数量显示

image.png
image.png
定义临时变量
image.png
image.png

2.2 用户性别比例饼状图显示

image.png
image.png
image.png
动态更新性别比例数据
image.png

2.3 歌曲类型柱状图显示

image.png
image.png
image.png
动态更新歌曲比例数据
image.png

…..