当前位置:   article > 正文

对Uni-app学习总结_uniapp使用总结

uniapp使用总结

目录

前言

一、学习总结

二、uni-app项目的创建

三、创建相关子页

pages.json页面路由的配置

使用循环骨架m-for-skeleton

对于实现播放器的启动和停止动画的方法

​编辑

四、api接口的调用



前言

        uni-app 是一个使用 Vue.js 开发所有前端应用的框架,用nui-app仿网易云的学习与总结

一、学习总结

  1. 让跨平台开发变得更简单。Uni-app使用Vue.js语法,可以使用同一份代码编译出iOS、Android、Web等多个平台的应用,减少了开发者的工作量。

  2. 减少开发难度。Uni-app提供了一套完整的开发生态圈,包括开发工具、UI组件库、API插件等,减少了开发者的投入。

  3. 性能表现良好。Uni-app使用了优化的渲染引擎,可以让应用在不同平台上都有流畅的性能表现。

  4. 社区活跃度高。Uni-app拥有一个庞大的开发社区,开发者可以在社区中获取资源、交流经验、解决问题。

  5. 可扩展性强。Uni-app提供了许多插件和组件,同时也支持第三方插件和组件,开发者可以根据需要进行扩展。

 现将用nui-app仿网易云的相关步骤和代码分享和大家共同学习,若有不足之处,请见谅!

二、uni-app项目的创建

        1. 创建uni-app空项目并分别运行到浏览器、Android模拟器和微信开发者工具

        2. 创建uni-app的hello项目并分别运行到浏览器、Android模拟器和微信开发者工具,以查看官方的组件、接口、模板等示例

        3. 项目结构

                · pages文件夹存放页面

                · static内的文件不会进行编译,不要放js文件,可放到common中(注意体积限制)

                · unpackage文件夹存放打包的文件

                · components文件夹存放各种组件

                · App.vue代表应用,包括应用层的生命周期方法,全局样式等

                · pages.json整个应用的页面集合,第一项为启动页,可配置页面路由及样式和标题

                · manifest.json应用配置,包括图标配置、启动界面配置、权限配置及其他开发配置

                · main.js应用入口文件

 

三、创建相关子页

 在文件pages中分别创建index、list、player、search父文件和子页面index.vue、list.vue、player.vue、search.vue.

pages.json页面路由的配置

  1. {
  2. "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
  3. {
  4. "path": "pages/index/index",
  5. "style": {
  6. }
  7. },
  8. {
  9. "path" : "pages/list/list",
  10. "style" :
  11. {
  12. "enablePullDownRefresh": false
  13. }
  14. }
  15. ,{
  16. "path" : "pages/search/search",
  17. "style" :
  18. {
  19. "enablePullDownRefresh": false
  20. }
  21. }
  22. ,{
  23. "path" : "pages/player/player",
  24. "style" :
  25. {
  26. "navigationBarTitleText": "",
  27. "enablePullDownRefresh": false
  28. }
  29. }
  30. ],
  31. "globalStyle": {
  32. "navigationBarTextStyle": "black",
  33. "navigationBarTitleText": "UAMusic-guo",
  34. "navigationBarBackgroundColor": "#F8F8F8",
  35. "backgroundColor": "#F8F8F8"
  36. },
  37. "uniIdRouter": {}
  38. }

使用循环骨架m-for-skeleton

循环骨架m-for-skeleton是一个第三方组件,用于在Vue.js应用程序中展示 loading 骨架屏。

安装循环骨架m-for-skeleton使用案例,可以通过以下步骤实现:

  1. 在终端中进入Vue.js项目的根目录。
  2. 运行以下命令安装m-for-skeleton组件:
    npm install m-for-skeleton --save
    

  3. 在Vue.js项目的入口文件中引入组件:
    import MforSkeleton from 'm-for-skeleton'
    

  4. 将组件注册为全局组件:
    Vue.component('m-for-skeleton', MforSkeleton)
    

  5. 在需要展示 loading 骨架屏的组件中使用m-for-skeleton组件,例如:
    1. <template>
    2. <div>
    3. <m-for-skeleton :count="5">
    4. <div class="card">
    5. <h2>Card Title</h2>
    6. <p>Card description goes here</p>
    7. </div>
    8. </m-for-skeleton>
    9. </div>
    10. </template>

    在这个例子中,我们在一个具有 class 名称为“card”的 div 元素上使用了m-for-skeleton组件,并指定了要展示 5 个骨架卡片。

现在你可以在应用程序中使用循环骨架m-for-skeleton组件展示 loading 骨架屏。

1.使用了骨架屏框架的index.vu页面和效果图

  1. <template>
  2. <view class="content">
  3. <uamhead :title="title"></uamhead>
  4. <!-- <image class="logo" src="/static/long2.npg"></image>
  5. <view class="text-area">
  6. <text class="title">{{title}}</text>
  7. </view> -->
  8. <scroll-view scroll-y="true" >
  9. <view>
  10. <m-for-skeleton
  11. :avatarSize="200"
  12. :row="3"
  13. :title="false"
  14. :loading="loading"
  15. isarc="square"
  16. :titleStyle="{}"
  17. v-for="(item,key) in 4"
  18. :key="key">
  19. </m-for-skeleton>
  20. </view>
  21. <view class="index-list" v-for="(item,index) in playlist" :key="index" @click="handleToList(item.id)">
  22. <view class="index-list-item">
  23. <view class="index-list-img">
  24. <image :src="item.coverImgUrl" mode=""></image>
  25. <text>{{item.updateFrequency}}</text>
  26. </view>
  27. <view class="index-list-text">
  28. <view v-for="(musicItem,index) in item.tracks" :key="index">
  29. {{index+1}}.{{musicItem.first}}-{{musicItem.second}}
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. </view>
  36. </template>
  37. <script>
  38. import { topList } from '../../common/api.js'
  39. // const toplistdata=require('@/static/toplist.json')
  40. import mForSkeleton from "@/components/m-for-skeleton/m-for-skeleton";
  41. import uamhead from "../../components/uamhead/uamhead.vue"
  42. export default {
  43. components: {
  44. mForSkeleton
  45. },
  46. data() {
  47. return {
  48. playlist:[],
  49. title: 'UAMusic',
  50. loading: true
  51. }
  52. },
  53. onLoad() {
  54. // this.playlist= toplistdata;
  55. topList().then((res)=>{
  56. if(res.length){
  57. setTimeout(()=>{
  58. this.playlist = res;
  59. this.loading=false
  60. },2000);
  61. console.log(res)
  62. }
  63. });
  64. },
  65. methods: {
  66. handleToList(id){
  67. uni.navigateTo({
  68. url:'/pages/list/list?listid='+id
  69. })
  70. }
  71. }
  72. }
  73. </script>
  74. <style>
  75. .content {
  76. display: flex;
  77. flex-direction: column;
  78. align-items: center;
  79. justify-content: center;
  80. }
  81. .logo {
  82. height: 200rpx;
  83. width: 200rpx;
  84. margin-top: 200rpx;
  85. margin-left: auto;
  86. margin-right: auto;
  87. margin-bottom: 50rpx;
  88. }
  89. .text-area {
  90. display: flex;
  91. justify-content: center;
  92. }
  93. .title {
  94. font-size: 36rpx;
  95. color: #8f8f94;
  96. }
  97. .index-list{ margin:0 30rpx;;width: 95%}
  98. .index-list-item{ display: flex; margin-bottom: 35rpx;}
  99. .index-list-img{ width:212rpx; height:212rpx; margin-right:20rpx; border-radius: 15rpx; overflow: hidden; position: relative;}
  100. .index-list-img image{ width:100%; height:100%;}
  101. .index-list-img text{ position: absolute; font-size:22rpx; color:white; bottom: 15rpx; left:15rpx;}
  102. .index-list-text{ flex:1; font-size:24rpx; line-height: 68rpx;}
  103. </style>

2.list.vue页面和效果图

  1. <template>
  2. <view>
  3. <uamhead :title="title"></uamhead>
  4. <view class="list-head">
  5. <view class="list-head-img">
  6. <image :src="playlist.coverImgUrl" mode=""></image>
  7. <text class="iconfont iconyousanjiao">{{ playlist.playCount }}</text>
  8. </view>
  9. <view class="list-head-text">
  10. <view>{{ playlist.name }}</view>
  11. <view>{{ playlist.description }}</view>
  12. </view>
  13. </view>
  14. <scroll-view scroll-y="true" class="scroll-Y">
  15. <view v-show="isShow" class="list-music-title">
  16. <text class="iconfont iconbofang1"></text>
  17. <text>播放全部</text>
  18. <text>(共{{ playlist.trackCount }}首)</text>
  19. </view>
  20. <view class="list-music">
  21. <view class="list-music-item" v-for="(item,index) in playlist.tracks" :key="item.id"
  22. @tap="navPlayer(item.id)">
  23. <view class="list-music-top">{{ index + 1 }}</view>
  24. <view class="list-music-song">
  25. <view>{{ item.name }}</view>
  26. <view>
  27. <image v-if=" privileges[index].flag > 60 && privileges[index].flag < 70"
  28. src="../../static/独家.png" mode=""></image>
  29. <image v-if="privileges[index].maxbr == 999000" src="../../static/sq.png" mode=""></image>
  30. {{ item.ar[0].name }} - {{ item.name }}
  31. </view>
  32. </view>
  33. <text class="iconfont iconbofang"></text>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. </view>
  38. </template>
  39. <script>
  40. import {uamhead} from '../../components/uamhead/uamhead.vue'
  41. import {
  42. list
  43. } from '../../common/api.js'
  44. export default {
  45. data() {
  46. return {
  47. title: "榜单列表",
  48. playlist: {
  49. coverImgUrl: '',
  50. trackCount: '',
  51. creator: ''
  52. },
  53. privileges: [],
  54. isShow: false
  55. }
  56. },
  57. onLoad(options) {
  58. let listid = options.listid;
  59. list(listid).then((res) => {
  60. if (res.data.code == '200') {
  61. this.title = res.data.playlist.name
  62. this.playlist = res.data.playlist
  63. this.privileges = res.data.privileges
  64. this.isShow = true
  65. }
  66. })
  67. },
  68. methods: {
  69. navPlayer(id) {
  70. console.log(id)
  71. uni.navigateTo({
  72. url:'/pages/player/player?songId='+id
  73. })
  74. }
  75. }
  76. }
  77. </script>
  78. <style>
  79. .list-head {
  80. display: flex;
  81. margin: 30rpx;
  82. }
  83. .list-head-img {
  84. width: 265rpx;
  85. height: 265rpx;
  86. border-radius: 15rpx;
  87. margin-right: 40rpx;
  88. overflow: hidden;
  89. position: relative;
  90. }
  91. .list-head-img image {
  92. width: 100%;
  93. height: 100%;
  94. }
  95. .list-head-img text {
  96. position: absolute;
  97. font-size: 26rpx;
  98. color: white;
  99. right: 8rpx;
  100. top: 8rpx;
  101. }
  102. .list-head-text {
  103. flex: 1;
  104. font-size: 24rpx;
  105. color: #c3d1e3;
  106. }
  107. .list-head-text image {
  108. width: 52rpx;
  109. height: 52rpx;
  110. border-radius: 50%;
  111. }
  112. .list-music {
  113. background: white;
  114. border-radius: 50rpx;
  115. overflow: hidden;
  116. margin-top: 45rpx;
  117. }
  118. .list-music-item {
  119. display: flex;
  120. margin: 0 30rpx 60rpx 44rpx;
  121. align-items: center;
  122. }
  123. .list-music-top {
  124. width: 56rpx;
  125. font-size: 28rpx;
  126. color: #979797;
  127. }
  128. .list-music-song {
  129. flex: 1;
  130. line-height: 40rpx;
  131. }
  132. .scroll-Y {
  133. height: 700rpx;
  134. }
  135. .list-music-title {
  136. height: 58rpx;
  137. line-height: 58rpx;
  138. margin: 30rpx 30rpx 70rpx 30rpx;
  139. }
  140. .list-music-song image {
  141. width: 34rpx;
  142. height: 22rpx;
  143. margin-right: 10rpx;
  144. }
  145. </style>

3.player.vue页面和效果图

  1. <template>
  2. <view>
  3. <uamhead :title="title"></uamhead>
  4. <view class="player">
  5. <image :src="song.picUrl" :class="{'run' : isplayrotate}" mode=""></image>
  6. <text class="iconfont iconpause" v-if="isplayrotate" @tap="noplaying"></text>
  7. <text class="iconfont iconbofang" v-else="" @tap="playing"></text>
  8. <view></view>
  9. </view>
  10. <scroll-view class="lyric" scroll-y="true">
  11. <view class= "wrap" :style="{ transform : ' translateY(' + -(lyricIndex - 1)*82 + 'rpx)' }">
  12. <view class="item" :class="{ active : lyricIndex == index}" v-for="(item, index) in song.lyric" :key="index" >
  13. {{item. lyric}}
  14. </view>
  15. </view>
  16. </scroll-view>
  17. <view>{{song.artist}}:{{song.name}}</view>
  18. </view>
  19. </template>
  20. <script>
  21. const innerAudioContext = uni.createInnerAudioContext();
  22. import uamhead from '../../components/uamhead/uamhead.vue'
  23. import {
  24. songDetail,
  25. songLyric,
  26. songUrl
  27. } from '../../common/api.js';
  28. export default {
  29. data() {
  30. return {
  31. title: "黑胶唱片",
  32. song: {
  33. id: '',
  34. name: '',
  35. artist: '',
  36. picUrl: '',
  37. songUrl: '',
  38. lyric: ''
  39. },
  40. isplayrotate: false,
  41. lyricIndex: 0
  42. }
  43. },
  44. onLoad(options) {
  45. let sId =options.songId;
  46. songDetail(sId).then(res => {
  47. let s = res.data.songs[0]
  48. this.song.name = s.name
  49. this.song.id = s.id
  50. this.song.artist = s.ar[0].name
  51. this.song.picUrl = s.al.picUrl
  52. //获取音乐的地址
  53. songUrl(this.song.id).then(res => {
  54. this.song.songUrl = res.data.data[0].url;
  55. console.log(this.song.songUrl)
  56. })
  57. songLyric(sId).then(res=>{
  58. var lyric=res.data.lrc.lyric;
  59. var result=[];
  60. let re = /\[([^\]]+)\]([^[]+)/g;
  61. // console.log('this.song.lyric')
  62. lyric.replace(re,($0,$1,$2)=>{
  63. result.push({time : this.formatTimeToSec($1),lyric : $2});
  64. });
  65. this.song.lyric=result;
  66. })
  67. })
  68. },
  69. methods: {
  70. playing() {
  71. innerAudioContext.autoplay = true;
  72. innerAudioContext.src = this.song.songUrl;
  73. innerAudioContext.onPlay(() => {
  74. this.isplayrotate = true;
  75. this.listenLyricIndex();
  76. this.innerAudioContext = innerAudioContext
  77. });
  78. innerAudioContext.onEnded(()=>{
  79. this.isplayrotate=false;
  80. })
  81. },
  82. noplaying() {
  83. innerAudioContext.pause();
  84. this.isplayrotate = false;
  85. innerAudioContext.onPause(() => { //暂停时调用的方法
  86. innerAudioContext.startTime = innerAudioContext.currentTime //startTime 设置开始时间 currentTime 暂停时的秒数
  87. });
  88. },
  89. formatTimeToSec(time){
  90. var arr=time.split(':');
  91. return (parseFloat(arr[0]) *60 + parseFloat(arr[1])).toFixed(2);
  92. },
  93. listenLyricIndex(){
  94. clearInterval(this.timer);
  95. this.timer= setInterval(()=>{
  96. for(var i=0;i<this.song.lyric.length;i++){
  97. if(this.song.lyric[this.song.lyric.length-1].time < this.innerAudioContext.currentTime ){
  98. this.lyricIndex=this.song.lyric.length-1;
  99. break;
  100. }
  101. if(this.song.lyric[i].time<this.innerAudioContext.currentTime && this.song.lyric[i+1].time > this.innerAudioContext.currentTime ){
  102. this.lyricIndex=i;
  103. }
  104. }
  105. });
  106. }
  107. }
  108. }
  109. </script>
  110. <style>
  111. .player {
  112. width: 480rpx;
  113. height: 480rpx;
  114. background: url(~@/static/disc.png);
  115. background-size: cover;
  116. margin: 210rpx auto 44rpx auto;
  117. position: relative;
  118. z-index: 2;
  119. }
  120. .player image {
  121. width: 480rpx;
  122. height: 480rpx;
  123. border-radius: 50%;
  124. position: absolute;
  125. left: 0;
  126. top: 0;
  127. right: 0;
  128. bottom: 0;
  129. margin: auto;
  130. z-index: 3;
  131. }
  132. .player text {
  133. width: 100rpx;
  134. height: 100rpx;
  135. font-size: 100rpx;
  136. position: absolute;
  137. left: 0;
  138. top: 0;
  139. right: 0rpx;
  140. bottom: 0;
  141. margin: 180rpx auto;
  142. color: white;
  143. z-index: 4;
  144. }
  145. .player view {
  146. position: absolute;
  147. width: 170rpx;
  148. height: 266rpx;
  149. position: absolute;
  150. left: 60rpx;
  151. right: 0;
  152. margin: auto;
  153. top: -170rpx;
  154. background: url(~@/static/needle.png);
  155. background-size: cover;
  156. }
  157. .player image {
  158. width: 295rpx;
  159. height: 295rpx;
  160. border-radius: 50%;
  161. position: absolute;
  162. left: 0;
  163. top: 0;
  164. right: 0;
  165. bottom: 0;
  166. margin: auto;
  167. z-index: 3;
  168. animation: 10s linear infinite move;
  169. animation-play-state: paused;
  170. }
  171. @keyframes move {
  172. from {
  173. transform: rotate(0deg);
  174. }
  175. to {
  176. transform: rotate(360deg);
  177. }
  178. }
  179. .player .run {
  180. animation-play-state: running;
  181. }
  182. .lyric{height: 260rpx;line-height: 82rpx;font-size: 32rpx;text-align: center;color: #949495;overflow: hidden;}
  183. .active{ color:blue;}
  184. .lyric .wrap{ transition:.5s;}
  185. .lyric .item{ /*
  186. */
  187. /* overflow: hidden */;
  188. }
  189. </style>

对于实现播放器的启动和停止动画的方法

需要使用JavaScript来启动和停止动画。你可以使用JavaScript来动态地应用CSS类名来触发或停止动画。你可以使用以下代码来启动动画:

document.getElementById('yourElement').classList.add('yourAnimationClass');

这将向具有id“yourElement”的元素添加一个类名为“yourAnimationClass”的CSS类,该类定义了你的CSS动画。

停止动画时,你可以使用以下代码:

document.getElementById('yourElement').classList.remove('yourAnimationClass');

这将从具有id“yourElement”的元素中删除所添加的类名,从而停止动画。

可以使用任何JavaScript事件来触发这些方法,例如单击按钮或滚动到页面底部。

4.search.vue页面和效果页面

  1. <template>
  2. <view class="search">
  3. <uamhead :title="title"></uamhead>
  4. <view title="搜索" :icon="true" :iconBlack="true"></view>
  5. <view class="container">
  6. <scroll-view scroll-y="true">
  7. <view class="search-search">
  8. <text class="iconfont iconsearch"></text>
  9. <input type="text" placeholder="搜索歌曲" v-model="searchWord" @confirm="handleToSearch"
  10. @input="handleToSuggest" />
  11. <text v-show="searchType == 2" @tap="handleToClose" class="iconfont iconguanbi"></text>
  12. </view>
  13. <block v-if="searchType == 1">
  14. <view class="search-history">
  15. <view class="search-history-head">
  16. <text>历史记录</text>
  17. <text class="iconfont iconlajitong" @tap="handleToClear"></text>
  18. </view>
  19. <view class="search-history-list">
  20. <view v-for="(item,index) in historyList" :key="index" @tap="handleToWord(item)">{{ item }}
  21. </view>
  22. </view>
  23. </view>
  24. <view class="search-hot">
  25. <view class="search-hot-title">热搜榜</view>
  26. <view class="search-hot-item" v-for="(item,index) in searchHot" :key="index"
  27. @tap="handleToWord(item.searchWord)">
  28. <view class="search-hot-top">{{ index + 1 }}</view>
  29. <view class="search-hot-word">
  30. <view>
  31. {{ item.searchWord }}
  32. <image :src="item.iconType ? item.iconUrl : ''" mode="aspectFit"></image>
  33. </view>
  34. <view>{{ item.content }}</view>
  35. <!-- <text class="search-hot-count">{{ item.score}}</text>2222222222222222 -->
  36. </view>
  37. </view>
  38. </view>
  39. </block>
  40. <block v-else-if="searchType == 2">
  41. <view class="search-result">
  42. <view class="search-result-item" v-for="(item,index) in searchList" :key="index"
  43. @tap="handleToDetail(item.id)">
  44. <view class="search-result-word">
  45. <view>{{ item.name }}</view>
  46. <view>{{ item.artists[0].name }} - {{ item.album.name }}</view>
  47. </view>
  48. <text class="iconfont iconbofang"></text>
  49. </view>
  50. </view>
  51. </block>
  52. <block v-else-if="searchType == 3">
  53. <view class="search-suggest">
  54. <view class="search-suggest-title">搜索"{{ this.searchWord }}"</view>
  55. <view class="search-suggest-item" v-for="(item,index) in suggestList" :key="index"
  56. @tap="handleToWord(item.keyword)">
  57. <text class="iconfont iconsearch"></text>
  58. {{ item.keyword }}
  59. </view>
  60. </view>
  61. </block>
  62. </scroll-view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. searchHot,
  69. searchWord,
  70. searchSuggest
  71. } from '../../common/api.js'
  72. import '../../common/iconfont.css'
  73. export default {
  74. data() {
  75. return {
  76. title: '',
  77. searchHot: [],
  78. searchWord: '',
  79. historyList: [],
  80. searchType: 1,
  81. searchList: [],
  82. suggestList: []
  83. }
  84. },
  85. onLoad() {
  86. searchHot().then((res) => {
  87. if (res.data.code == '200') {
  88. this.searchHot = res.data.data;
  89. // console.log(res)
  90. }
  91. });
  92. uni.getStorage({
  93. key: 'searchHistory',
  94. success: (res) => {
  95. this.historyList = res.data;
  96. console.log(res)
  97. }
  98. });
  99. },
  100. methods: {
  101. handleToSearch() {
  102. this.historyList.unshift(this.searchWord);
  103. this.historyList = [...new Set(this.historyList)];
  104. if (this.historyList.length > 10) {
  105. this.historyList.length = 10;
  106. }
  107. uni.setStorage({
  108. key: 'searchHistory',
  109. data: this.historyList
  110. });
  111. this.getSearchList(this.searchWord);
  112. },
  113. handleToClear() {
  114. uni.removeStorage({
  115. key: 'searchHistory',
  116. success: () => {
  117. this.historyList = [];
  118. }
  119. });
  120. },
  121. getSearchList(word) {
  122. searchWord(word).then((res) => {
  123. if (res.data.code == '200') {
  124. this.searchList = res.data.result.songs;
  125. this.searchType = 2;
  126. }
  127. });
  128. },
  129. handleToClose() {
  130. this.searchWord = '';
  131. this.searchType = 1;
  132. },
  133. handleToSuggest(ev) {
  134. let value = ev.detail.value;
  135. if (!value) {
  136. this.searchType = 1;
  137. return;
  138. }
  139. searchSuggest(value).then((res) => {
  140. if (res.data.code == '200') {
  141. this.suggestList = res.data.result.allMatch;
  142. this.searchType = 3;
  143. }
  144. });
  145. },
  146. handleToWord(word) {
  147. this.searchWord = word;
  148. this.handleToSearch();
  149. },
  150. handleToDetail(id) {
  151. uni.navigateTo({
  152. url: '/pages/player/player?songId=' + id
  153. });
  154. }
  155. }
  156. }
  157. </script>
  158. <style scoped>
  159. .search-search {
  160. display: flex;
  161. background: #f7f7f7;
  162. height: 73rpx;
  163. margin: 28rpx 30rpx 30rpx 30rpx;
  164. border-radius: 50rpx;
  165. align-items: center;
  166. }
  167. .search-search text {
  168. margin: 0 27rpx;
  169. }
  170. .search-search input {
  171. font-size: 26rpx;
  172. flex: 1;
  173. }
  174. .search-history {
  175. margin: 0 30rpx;
  176. font-size: 26rpx;
  177. }
  178. .search-history-head {
  179. display: flex;
  180. justify-content: space-between;
  181. }
  182. .search-history-list {
  183. display: flex;
  184. margin-top: 36rpx;
  185. flex-wrap: wrap;
  186. }
  187. .search-history-list view {
  188. padding: 20rpx 40rpx;
  189. background: #f7f7f7;
  190. border-radius: 50rpx;
  191. margin-right: 30rpx;
  192. margin-bottom: 20rpx;
  193. }
  194. .search-hot {
  195. margin: 30rpx 30rpx;
  196. font-size: 26rpx;
  197. color: #bebebe;
  198. }
  199. .search-hot-title {}
  200. .search-hot-item {
  201. display: flex;
  202. align-items: center;
  203. margin-top: 40rpx;
  204. }
  205. .search-hot-top {
  206. width: 60rpx;
  207. color: #fb2221;
  208. font-size: 34rpx;
  209. }
  210. .search-hot-word {
  211. flex: 1;
  212. }
  213. .search-hot-word view:nth-child(1) {
  214. color: black;
  215. }
  216. .search-hot-word image {
  217. width: 48rpx;
  218. height: 22rpx;
  219. }
  220. .search-hot-count {}
  221. .search-result {
  222. border-top: 2rpx #e5e5e5 solid;
  223. padding: 30rpx;
  224. }
  225. .search-result-item {
  226. display: flex;
  227. align-items: center;
  228. border-bottom: 2rpx #e5e5e5 solid;
  229. padding-bottom: 30rpx;
  230. margin-bottom: 30rpx;
  231. }
  232. .search-result-item text {
  233. font-size: 50rpx;
  234. }
  235. .search-result-word {
  236. flex: 1;
  237. }
  238. .search-result-word view:nth-child(1) {
  239. font-size: 28rpx;
  240. color: #3e6694;
  241. }
  242. .search-result-word view:nth-child(2) {
  243. font-size: 26rpx;
  244. }
  245. .search-suggest {
  246. border-top: 2rpx #e5e5e5 solid;
  247. padding: 30rpx;
  248. font-size: 26rpx;
  249. }
  250. .search-suggest-title {
  251. color: #537caa;
  252. margin-bottom: 40rpx;
  253. }
  254. .search-suggest-item {
  255. color: #666666;
  256. margin-bottom: 70rpx;
  257. }
  258. .search-suggest-item text {
  259. color: #c2c2c2;
  260. font-size: 26rpx;
  261. margin-right: 26rpx;
  262. }
  263. </style>

四、api接口的调用

在common中创建api.js和config.js

api.js页面

  1. import { baseUrl } from './config.js';
  2. export function topList(){
  3. return new Promise(function(resolve,reject){
  4. uni.request({
  5. url: `${baseUrl}/toplist/detail`,
  6. method: 'GET',
  7. data: {},
  8. success: res => {
  9. let result = res.data.list;
  10. resolve(result.splice(0,4));
  11. },
  12. fail: (err) => {
  13. console.log(err);
  14. },
  15. complete: () => {}
  16. });
  17. });
  18. }
  19. export function list(listId){
  20. return uni.request({
  21. url: `${baseUrl}/playlist/detail?id=${listId}`,
  22. method: 'GET'
  23. });
  24. }
  25. export function songDetail(id){
  26. return uni.request({
  27. url : `${baseUrl}/song/detail?ids=${id}`,
  28. method : 'GET'
  29. })
  30. }
  31. export function songUrl(id){
  32. return uni.request({
  33. url : `${baseUrl}/song/url?id=${id}`,
  34. method : 'GET'
  35. })
  36. }
  37. export function songLyric(id){
  38. return uni.request({
  39. url : `${baseUrl}/lyric?id=${id}`,
  40. method : 'GET'
  41. })
  42. }
  43. export function songSimi(id){
  44. return uni.request({
  45. url : `${baseUrl}/simi/song?id=${id}`,
  46. method : 'GET'
  47. })
  48. }
  49. export function songComment(id){
  50. return uni.request({
  51. url : `${baseUrl}/comment/music?id=${id}`,
  52. method : 'GET'
  53. })
  54. }
  55. export function searchHot(){
  56. return uni.request({
  57. url : `${baseUrl}/search/hot/detail`,
  58. method : 'GET'
  59. })
  60. }
  61. export function searchWord(word){
  62. return uni.request({
  63. url : `${baseUrl}/search?keywords=${word}`,
  64. method : 'GET'
  65. })
  66. }
  67. export function searchSuggest(word){
  68. return uni.request({
  69. url : `${baseUrl}/search/suggest?keywords=${word}&type=mobile`,
  70. method : 'GET'
  71. })
  72. }

config.js页面

export const baseUrl = 'https://flask-web-frak-shishn-kvmjsphrif.cn-shenzhen.fcapp.run';

以上也只是对网易云播放器的模仿与学习,若有侵权请及时联系作者。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/445045
推荐阅读
相关标签
  

闽ICP备14008679号