[技术分享]基于 Vue+uniApp 聊天实战|uni-app 仿微信
xiaoyan2015发布于1 年前 • 647 次阅读
使用uni-app+vue+vuex+uniPop+swiper等技术开发的仿微信聊天室uniChatRoom项目,已经基本实现了发送图文消息、表情(gif动图),图片预览、地图位置、红包、仿微信朋友圈等功能
https://www.cnblogs.com/xiaoyan2017/p/11645467.html
预览图
在h5、小程序、App端效果一致,亲测有效。
技术实现
- 编辑器: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()
基于uni-app实现的弹窗组件UniPop
由于项目中很多地方需要用到弹窗,android原生弹窗又不能很好的支持自定义样式,如是就自己开发了个uniPop模态框组件。 uni-app自定义Modal弹窗组件|仿ios、微信弹窗效果
在uni-app中如何实现微信朋友圈沉浸式顶部功能呢?类似 页面向下滚动,顶部导航又透明变背景色。可通过uniapp提供的onPageScroll函数来实现透明控制。
<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>
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[1].height > res[0].height){
that.scrollTop = res[1].height - res[0].height
}
})
},
...
}
}
好了,以上就是今天的介绍,后续会继续为大家分享项目实战案例。
最后为大家分享最近使用vue和angular开发的聊天项目