Quellcode durchsuchen

3 消息发送页面 图片 自适应大小

4 消息页 图片 点击预览
5 消息页 文字 能长按复制
6 修改首页我关注的类型时的显示问题
7 处理收到信息时 消息右上角有红点
release/210823_需求对对碰
王饶冀 vor 3 Jahren
Ursprung
Commit
17ac8b1d68

+ 2
- 0
app.js Datei anzeigen

@@ -92,6 +92,8 @@ App({
suiteCode: "",
customerId: null,
businessCommunicationCustomer:null,
// websocket 是否已连接 用于底部tab收到新消息时消息有红点
isOnSocketOpen:false,
},
// 跳转登录页
goLogin(e) {

+ 0
- 1
components/listItem/listItem.js Datei anzeigen

@@ -40,7 +40,6 @@ Component({
value: null,
},
},

/**
* 组件的初始数据
*/

+ 82
- 1
components/tabbar/tabbar.js Datei anzeigen

@@ -15,6 +15,7 @@ Component({
* 组件的初始数据
*/
data: {
customerId: null,
list: [
{
text: "首页",
@@ -33,6 +34,7 @@ Component({
pagePath: "/pages/msgModule/index",
iconPath: "/images/tabbar/msg-bar.png",
selectedIconPath: "/images/tabbar/msg-bar.png",
dot: false,
},
{
text: "我的",
@@ -42,11 +44,90 @@ Component({
},
]
},
/*
*
* 小程序自定义组件挂载后执行
*
*/
ready() {
const businessCommunicationCustomer = wx.getStorageSync('businessCommunicationCustomer') || null;
if (businessCommunicationCustomer) {
this.setData({
customerId: businessCommunicationCustomer.customerId
})
}
// 获取当前路由,如果是消息页的话要把消息的红点取消
this.getCurrentRouter();

// 如果 websocket 没有连接,连接
if (!app.globalData.isOnSocketOpen) {
this.initWebSocket();
}

},
/**
* 组件的方法列表
*/
methods: {
// 获取当前路由
getCurrentRouter() {
let pages = getCurrentPages();
let currentPage = null;
if (pages.length) {
currentPage = pages[pages.length - 1];
}
// 如果是消息页,置空红点
if (currentPage.route == "pages/msgModule/index") {
this.setListDot(false);
}
},
// init websocket
initWebSocket() {
let _this = this;
let customerId = this.data.customerId;
//建立连接
wx.connectSocket({
url: `ws://192.168.18.138/webSocket/{"userno":${customerId},"messageModule":"010"}`,//本地
success: function () {
console.log('消息页-websocket连接成功~')
},
fail: function () {
console.log('消息页-websocket连接失败~')
},
})

//连接成功
wx.onSocketOpen(function () {
console.log('tabbar-连接成功,真正的成功', 'onSocketOpen');
// 连接成功后,设置为 true 放置反复连接
app.globalData.isOnSocketOpen = true;
})

// 接收服务器的消息事件
wx.onSocketMessage(function (res) {
// 收到消息让tabbar消息有红点
_this.setListDot(true);
})

// 监听连接关闭
wx.onSocketClose(function () {
console.log('监听 WebSocket 连接关闭事件')
})

},
// 设置tabbar消息红点显示与否
setListDot(isShow) {
let list = this.data.list;
list.forEach(el => {
if (el.text == '消息') {
el.dot = isShow;
}
})
this.setData({
list
})
},
// tab切换
tabChange(e) {
console.log(e);
if (e.detail.item.text == "发布需求" || e.detail.item.text == "消息") {
@@ -58,7 +139,7 @@ Component({
return
}
}
const url = e.detail.item.pagePath;
// wx.redirectTo({ url });
wx.navigateTo({

+ 8
- 0
pages/index/index.js Datei anzeigen

@@ -87,6 +87,8 @@ Page({
let attentionTypeIds = businessCommunicationCustomer.attentionTypeIds;
if (attentionTypeIds) {
attentionTypeIds = attentionTypeIds.split(',');
}else{
attentionTypeIds = [];
}
this.setData({
attentionTypeIds,
@@ -203,6 +205,12 @@ Page({
if (currentTab == 'my') {
if (app.globalData.businessCommunicationCustomer) {
type = app.globalData.businessCommunicationCustomer.attentionTypeIds;
if(!type){
this.setData({
listLoading: false
})
return
}
}
}
let paramIsInterest = 0;

+ 12
- 1
pages/msgModule/index.js Datei anzeigen

@@ -21,7 +21,6 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad() {
},
onShow() {
this.setData({
@@ -33,6 +32,10 @@ Page({
customerId: businessCommunicationCustomer.customerId
})
}
// 如果全局的 websocket 是连接的,需要关闭连接 调用自身的
if(app.globalData.isOnSocketOpen){
wx.closeSocket();
}
// 初始化websocket
this.initWebSocket();
// 初始化数据
@@ -185,6 +188,10 @@ Page({
*/
onHide: function () {
wx.closeSocket();
// 检测到全局的 websocket 是连接的 关闭
if(app.globalData.isOnSocketOpen){
app.globalData.isOnSocketOpen = false;
}
},

/**
@@ -192,6 +199,10 @@ Page({
*/
onUnload: function () {
wx.closeSocket();
// 检测到全局的 websocket 是连接的 关闭
if(app.globalData.isOnSocketOpen){
app.globalData.isOnSocketOpen = false;
}
},
/**
* 用户点击右上角分享给朋友

+ 14
- 0
pages/msgModule/wechat2/wechat2.js Datei anzeigen

@@ -91,6 +91,10 @@ Page({
sendAvatar,
connectemoji: $faces.getfaces(),
})
// 如果全局的 websocket 是连接的,需要关闭连接 调用自身的
if(app.globalData.isOnSocketOpen){
wx.closeSocket();
}
// 获取内存中的数据
this.getStorageBaseInfo()
// 设置滚动区域的高度
@@ -295,8 +299,13 @@ Page({
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
// 如果是发送图片就不触发
if (!this.data.isSendImg) {
wx.closeSocket();
// 检测到全局的 websocket 是连接的 关闭
if(app.globalData.isOnSocketOpen){
app.globalData.isOnSocketOpen = false;
}
}
},

@@ -304,8 +313,13 @@ Page({
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
// 如果是发送图片就不触发
if (!this.data.isSendImg) {
wx.closeSocket();
// 检测到全局的 websocket 是连接的 关闭
if(app.globalData.isOnSocketOpen){
app.globalData.isOnSocketOpen = false;
}
}
},


+ 3
- 2
pages/myModule/index.js Datei anzeigen

@@ -91,18 +91,19 @@ Page({
},
// 退出登录
exitLogin() {
let _this = this;
wx.showModal({
title: '提示',
content: "是否确认退出账号?",
confirmText: "确认",
cancelText: "取消",
success(res) {
success(res){
if (res.confirm) {
wx.removeStorageSync('userInfo');
wx.removeStorageSync('businessCommunicationCustomer');
app.globalData.businessCommunicationCustomer = null;
app.globalData.customerId = null;
this.setData({
_this.setData({
user: {},
isLogin: false
})

Laden…
Abbrechen
Speichern