查看: 5393|回复: 8
打印 上一主题 下一主题

uni-app仿微信聊天实战|uniapp+swiper仿微信

[复制链接]

该用户从未签到

28

主题

33

帖子

163

积分

注册会员

Rank: 2

积分
163
QQ
跳转到指定楼层
楼主
发表于 2019-10-13 11:16:08 | 显示全部楼层 |只看大图 回帖奖励 |倒序浏览 |阅读模式
今天分享的是基于UniApp+swiper+vuex+uniPop等技术实现开发的仿微信聊天App实例项目,表情滑动部分使用的是swiper组件,弹窗是自定义uniPop模态框。还实现了红包、地图定位、仿微信朋友圈等功能。



使用技术
  • 编辑器:HBuilder X
  • 技术框架:uni-app + vue
  • 状态管理:Vuex
  • iconfont图标:阿里字体图标库
  • 自定义导航栏 + 底部Tabbar
  • 弹窗组件:uniPop(基于uni-app封装模态弹窗)
  • 测试环境:H5端 + 小程序 + App端(三端均兼容)










引入公共组件及样式
  1. import Vue from 'vue'
  2. import App from './App'

  3. // >>>引入css
  4. import './assets/fonts/iconfont.css'
  5. import './assets/css/reset.css'
  6. import './assets/css/layout.css'

  7. // >>>引入状态管理
  8. import store from './store'
  9. Vue.prototype.$store = store

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

  17. // >>>引入uniPop弹窗组件
  18. import uniPop from './components/uniPop/uniPop.vue'
  19. Vue.component('uni-pop', uniPop)

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

  22. const app = new Vue({
  23.     ...App
  24. })
  25. app.$mount()
复制代码
uniapp实现仿微信朋友圈效果
实现类似微信朋友圈页面滚动一定距离顶部导航栏由透明变背景色,通过onPageScroll函数实现自定义导航上下滑动自动调整导航栏的透明度

  1. /**
  2. * @tpl 朋友圈模板
  3. */

  4. <template>
  5.     <view class="flexbox flex_col">
  6.         <header-bar :isBack="true" title="朋友圈" :bgColor="{background: headerBarBackground}" transparent>
  7.             <text slot="back" class="uni_btnIco iconfont icon-arrL"></text>
  8.             <text slot="iconfont" class="uni_btnIco iconfont icon-publish mr_5" @tap="handlePublish"></text>
  9.         </header-bar>
  10.         
  11.         <view class="uni__scrollview flex1">
  12.             <view class="uni-friendZone">
  13.                 ...
  14.             </view>
  15.         </view>
  16.     </view>
  17. </template>

  18. <script>
  19.     export default {
  20.         data() {
  21.             return {
  22.                 headerBarBackground: 'transparent'
  23.             }
  24.         },
  25.         onPageScroll : function(e) {
  26.             // console.log("滚动距离为:" + e.scrollTop);
  27.             this.headerBarBackground = 'rgba(65,168,99,'+e.scrollTop / 200+')'
  28.         },
  29.         methods: {
  30.             ...
  31.         }
  32.     }
  33. </script>

  34. <style scoped>

  35. </style>
复制代码
借助scroll-view组件将聊天信息滚动到页面底部
  1. export default {
  2.     data() {
  3.         return {
  4.             scrollTop: 0,
  5.             ...
  6.         }
  7.     },
  8.     mounted() {
  9.         this.scrollToBottom()
  10.     },
  11.     updated() {
  12.         this.scrollToBottom()
  13.     },
  14.     methods: {
  15.         // 滚动至聊天底部
  16.         scrollToBottom(t) {
  17.             let that = this
  18.             let query = uni.createSelectorQuery()
  19.             query.select('#scrollview').boundingClientRect()
  20.             query.select('#msglistview').boundingClientRect()
  21.             query.exec((res) => {
  22.                 // console.log(res)
  23.                 if(res[1].height > res[0].height){
  24.                     that.scrollTop = res[1].height - res[0].height
  25.                 }
  26.             })
  27.         },
  28.         ...
  29.     }
  30. }
复制代码
今天就介绍到这里,后续会继续为大家分享项目实战案例。
原创
react仿微信web版聊天室|仿微信客户端react版

原创
html5语音即时聊天|仿微信语音效果|表情|定位



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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-6 11:06 , Processed in 0.078518 second(s), 30 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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