xiaoyan2015 发表于 2019-10-13 11:16:08

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

今天分享的是基于UniApp+swiper+vuex+uniPop等技术实现开发的仿微信聊天App实例项目,表情滑动部分使用的是swiper组件,弹窗是自定义uniPop模态框。还实现了红包、地图定位、仿微信朋友圈等功能。



使用技术

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










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

// >>>引入css
import './assets/fonts/iconfont.css'
import './assets/css/reset.css'
import './assets/css/layout.css'

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

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

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

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

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

/**
* @tpl 朋友圈模板
*/

<template>
    <view class="flexbox flex_col">
      <header-bar :isBack="true" title="朋友圈" :bgColor="{background: headerBarBackground}" transparent>
            <text slot="back" class="uni_btnIco iconfont icon-arrL"></text>
            <text slot="iconfont" class="uni_btnIco iconfont icon-publish mr_5" @tap="handlePublish"></text>
      </header-bar>
      
      <view class="uni__scrollview flex1">
            <view class="uni-friendZone">
                ...
            </view>
      </view>
    </view>
</template>

<script>
    export default {
      data() {
            return {
                headerBarBackground: 'transparent'
            }
      },
      onPageScroll : function(e) {
            // console.log("滚动距离为:" + e.scrollTop);
            this.headerBarBackground = 'rgba(65,168,99,'+e.scrollTop / 200+')'
      },
      methods: {
            ...
      }
    }
</script>

<style scoped>

</style>借助scroll-view组件将聊天信息滚动到页面底部
export default {
    data() {
      return {
            scrollTop: 0,
            ...
      }
    },
    mounted() {
      this.scrollToBottom()
    },
    updated() {
      this.scrollToBottom()
    },
    methods: {
      // 滚动至聊天底部
      scrollToBottom(t) {
            let that = this
            let query = uni.createSelectorQuery()
            query.select('#scrollview').boundingClientRect()
            query.select('#msglistview').boundingClientRect()
            query.exec((res) => {
                // console.log(res)
                if(res.height > res.height){
                  that.scrollTop = res.height - res.height
                }
            })
      },
      ...
    }
}今天就介绍到这里,后续会继续为大家分享项目实战案例。
原创 react仿微信web版聊天室|仿微信客户端react版
原创 html5语音即时聊天|仿微信语音效果|表情|定位


abfeng112 发表于 2019-10-13 12:26:28

zheasd asagfagfadsgsdgsdgsd

林达斯 发表于 2019-10-14 17:30:02

DCloud的,还不错

jerryvv 发表于 2019-10-17 13:46:49

看着还不错啊~~~66666

氵氵海 发表于 2019-10-17 23:10:20

用的swiper是uniapp的组件还是就是swiper?

li823602243 发表于 2020-3-26 11:28:27

66666666666666666666

maolangong 发表于 2020-4-1 15:16:42

做websocket开发,可以自己搭建,也可以试试第三方的websocket框架。我近期在使用的GoEasy这个框架,在应对我们项目这种突发性的高并发需求上,表现不错。有websocket使用需求的也可以去看看,地址:https://www.goeasy.io/

sioono 发表于 2021-4-2 08:23:42

下载地址有没?

zhouzy 发表于 2021-8-12 11:47:46

66666666666666666666666
页: [1]
查看完整版本: uni-app仿微信聊天实战|uniapp+swiper仿微信