查看: 3711|回复: 1
打印 上一主题 下一主题

uni-app直播|仿抖音/陌陌|uniapp直播室

[复制链接]

该用户从未签到

28

主题

33

帖子

163

积分

注册会员

Rank: 2

积分
163
QQ
跳转到指定楼层
楼主
发表于 2019-11-15 10:16:56 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

项目介绍:
UniLiveShow是基于Nvue+vue+uniapp+swiper技术实现的高仿抖音短视频/陌陌直播界面的项目,效果类似抖音上下滑动切换视频播放,还有点赞、评论、商品广告等功能,支持编译到H5、小程序、App端,且兼容性一致。

预览效果:


技术框架:
  • 编辑器+技术:HBuilderX + vue/NVue/uniapp/vuex
  • iconfont图标:阿里字体图标库
  • 自定义导航栏 + 底部Tabbar
  • 弹窗组件:uniPop(uni-app封装自定义Modal弹窗)
  • 测试环境:H5端/小程序/App端/真机












自定义导航栏模式:获取状态栏高度
  1. <script>
  2.     import Vue from 'vue'
  3.     export default {
  4.         onLaunch: function() {
  5.             // console.log('App Launch')
  6.             uni.getSystemInfo({
  7.                 success:function(e){
  8.                     Vue.prototype.statusBar = e.statusBarHeight
  9.                     // #ifndef MP
  10.                     if(e.platform == 'android') {
  11.                         Vue.prototype.customBar = e.statusBarHeight + 50
  12.                     }else {
  13.                         Vue.prototype.customBar = e.statusBarHeight + 45
  14.                     }
  15.                     // #endif
  16.                     
  17.                     // #ifdef MP-WEIXIN
  18.                     let custom = wx.getMenuButtonBoundingClientRect()
  19.                     Vue.prototype.customBar = custom.bottom + custom.top - e.statusBarHeight
  20.                     // #endif
  21.                     
  22.                     // #ifdef MP-ALIPAY
  23.                     Vue.prototype.customBar = e.statusBarHeight + e.titleBarHeight
  24.                     // #endif
  25.                 }
  26.             })
  27.         },
  28.     }
  29. </script>
复制代码
引入公共组件及样式库
  1. import Vue from 'vue'
  2. import App from './App'

  3. import './static/fonts/iconfont.css'
  4. import './assets/css/reset.css'
  5. import './assets/css/layout.css'

  6. // 状态管理
  7. import store from './store'
  8. Vue.prototype.$store = store

  9. // 公共组件
  10. import headerBar from './components/header/header.vue'
  11. import tabBar from './components/tabbar/tabbar.vue'
  12. import popupWindow from './components/popupWindow.vue'
  13. Vue.component('header-bar', headerBar)
  14. Vue.component('tab-bar', tabBar)
  15. Vue.component('popup-window', popupWindow)

  16. // 自定义弹窗组件
  17. import uniPop from './components/uniPop/uniPop.vue'
  18. Vue.component('uni-pop', uniPop)

  19. Vue.config.productionTip = false
  20. App.mpType = 'app'

  21. const app = new Vue({
  22.     ...App
  23. })
  24. app.$mount()
复制代码
项目中聊天模块可参考:uni-app聊天室App|vue+uniapp仿微信聊天界面实例

uni-app+nvue技术实现仿抖音界面滑动效果,且有点赞、评论及商品等功能,可以单击、双击判断。
  1. <swiper :indicator-dots="false" :duration="200" :vertical="true" :current="videoIndex" @change="handleSlider" style="height: 100%;">
  2.     <block v-for="(item,index) in vlist" :key="index">
  3.         <swiper-item>
  4.             <view class="uni_vdplayer">
  5.                 <video :id="'myVideo' + index" :ref="'myVideo' + index" class="player-video" :src="item.src"
  6.                 :controls="false" :loop="true" :show-center-play-btn="false" objectFit="fill">
  7.                 </video>
  8.                 <!-- 中间播放按钮 -->
  9.                 <view class="vd-cover flexbox" @click="handleClicked(index)"><text v-if="!isPlay" class="iconfont icon-bofang"></text></view>
  10.                 <!-- 底部信息 -->
  11.                 <view class="vd-footToolbar flexbox flex_alignb">
  12.                     <view class="vd-info flex1">
  13.                         <view class="item at">
  14.                             <view class="kw" v-for="(kwItem,kwIndex) in item.keyword" :key="kwIndex"><text class="bold fs_18 mr_5">#</text> {{kwItem}}</view>
  15.                         </view>
  16.                         <view class="item subtext">{{item.subtitle}}</view>
  17.                         <view class="item uinfo flexbox flex_alignc">
  18.                             <image class="avator" :src="item.avator" mode="aspectFill" /><text class="name">{{item.author}}</text> <text class="btn-attention bg_linear1" :class="item.attention ? 'on' : ''" @tap="handleAttention(index)">{{item.attention ? '已关注' : '关注'}}</text>
  19.                         </view>
  20.                         <view class="item reply" @tap="handleVideoComment"><text class="iconfont icon-pinglun mr_5"></text> 写评论...</view>
  21.                     </view>
  22.                     <view class="vd-sidebar">
  23.                         <view v-if="item.cart" class="ls cart flexbox bg_linear3" @tap="handleVideoCart(index)"><text class="iconfont icon-cart"></text></view>
  24.                         <view class="ls" @tap="handleIsLike(index)"><text class="iconfont icon-like" :class="item.islike ? 'like' : ''"></text><text class="num">{{ item.likeNum+(item.islike ? 1: 0) }}</text></view>
  25.                         <view class="ls" @tap="handleVideoComment"><text class="iconfont icon-liuyan"></text><text class="num">{{item.replyNum}}</text></view>
  26.                         <view class="ls"><text class="iconfont icon-share"></text><text class="num">{{item.shareNum}}</text></view>
  27.                     </view>
  28.                 </view>
  29.             </view>
  30.         </swiper-item>
  31.     </block>
  32. </swiper>
复制代码

  1. /**
  2. * @desc 小视频JSON数据
  3. */

  4. module.exports = [
  5.     {
  6.         id: 1,
  7.         avator: '/static/uimg/u__chat_img1.jpg',
  8.         poster: '/static/placeholder/video-img4.jpg',
  9.         src: '/static/placeholder/video.mp4',
  10.         author: '猪猪佩奇',
  11.         subtitle: '稻城亚丁-人间绝美景色',
  12.         keyword: ['美好回忆', '旅游圣地'],
  13.         playNum: 3172,
  14.         likeNum: 2518,
  15.         replyNum: 292,
  16.         shareNum: 107,
  17.         islike: false,
  18.         attention: false,
  19.         cart: [
  20.             {
  21.                 name: '同款冬枣',
  22.                 image: '/static/placeholder/cart-img1.jpg',
  23.                 price: 9.90
  24.             },
  25.             {
  26.                 name: '10斤装爆甜冰糖心红富士',
  27.                 image: '/static/placeholder/cart-img2.jpg',
  28.                 price: 9.90
  29.             },
  30.             {
  31.                 name: '红心猕猴桃 单果40-70克',
  32.                 image: '/static/placeholder/cart-img3.jpg',
  33.                 price: 10.0
  34.             }
  35.         ]
  36.     },
  37.     {
  38.         id: 2,
  39.         avator: '/static/uimg/u__chat_img12.jpg',
  40.         poster: '/static/placeholder/video-img0.jpg',
  41.         src: 'https://txmov2.a.yximgs.com/bs2/newWatermark/MTg3NDYzOTY3MjM_zh_3.mp4',
  42.         author: 'Alisa',
  43.         subtitle: '不要在乎别人的流言蜚语',
  44.         keyword: ['经典老歌'],
  45.         playNum: 9432,
  46.         likeNum: 5627,
  47.         replyNum: 1285,
  48.         shareNum: 638,
  49.         islike: true,
  50.         attention: true,
  51.         cart: ''
  52.     },
  53.     {
  54.         id: 3,
  55.         avator: '/static/uimg/u__chat_img5.jpg',
  56.         poster: '/static/placeholder/video-img2.jpg',
  57.         src: 'https://txmov2.a.yximgs.com/bs2/newWatermark/MTY3NTU3MzYzMTQ_zh_4.mp4',
  58.         author: '往后余生都是你',
  59.         subtitle: '能不能给我一首歌的时间,让你拾起从前的快乐',
  60.         keyword: '',
  61.         playNum: 7268,
  62.         likeNum: 3438,
  63.         replyNum: 1105,
  64.         shareNum: 327,
  65.         islike: false,
  66.         attention: false,
  67.         cart: [
  68.             {
  69.                 name: 'YCID施蒂蓝玫瑰凝养柔滑唇膏',
  70.                 image: 'https://cbu01.alicdn.com/img/ibank/2019/218/182/12384281812_1493014487.jpg',
  71.                 price: 7.70
  72.             },
  73.             {
  74.                 name: '玛可安迪新款抖音网红推荐口红',
  75.                 image: 'https://cbu01.alicdn.com/img/ibank/2019/285/249/10457942582_1068990292.jpg',
  76.                 price: 19.9
  77.             },
  78.         ]
  79.     },
  80.    
  81.     ...
  82. ]
复制代码
开发遇到了视频video层级过高不能被其他组件覆盖,起初使用cover-view,可是不能内嵌标签,甚是麻烦,于是使用nvue页面就可以解决view覆盖在video之上。.nvue (native vue的缩写)
另外在nvue页面中使用iconfont图标库需注意引入方式
  1. beforeCreate() {
  2.     // 引入iconfont字体
  3.     // #ifdef APP-PLUS
  4.     const domModule = weex.requireModule('dom')
  5.     domModule.addRule('fontFace', {
  6.         fontFamily: "nvueIcon",
  7.         'src': "url('../../../static/fonts/iconfont.ttf')"
  8.     });
  9.     // #endif
  10. },
复制代码


uni-app开发直播聊天项目介绍到这里,后续继续为大家分享实战项目,希望能有一些许帮助!!

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖
回复

使用道具 举报

  • TA的每日心情
    奋斗
    2019-12-5 10:38
  • 签到天数: 2 天

    [LV.1]初来乍到

    1

    主题

    14

    帖子

    33

    积分

    新手上路

    Rank: 1

    积分
    33
    沙发
    发表于 2019-12-4 09:35:33 | 只看该作者
    厉害了老哥
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Swiper中文网 ( 粤ICP备15001020号

    GMT+8, 2024-4-19 12:21 , Processed in 0.079859 second(s), 30 queries .

    Powered by Discuz! X3.2

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表