Parcourir la source

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

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

+ 2
- 0
app.js Voir le fichier

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

+ 0
- 1
components/listItem/listItem.js Voir le fichier

value: null, value: null,
}, },
}, },

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

+ 82
- 1
components/tabbar/tabbar.js Voir le fichier

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


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

},
/** /**
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { 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) { tabChange(e) {
console.log(e); console.log(e);
if (e.detail.item.text == "发布需求" || e.detail.item.text == "消息") { if (e.detail.item.text == "发布需求" || e.detail.item.text == "消息") {
return return
} }
} }
const url = e.detail.item.pagePath; const url = e.detail.item.pagePath;
// wx.redirectTo({ url }); // wx.redirectTo({ url });
wx.navigateTo({ wx.navigateTo({

+ 8
- 0
pages/index/index.js Voir le fichier

let attentionTypeIds = businessCommunicationCustomer.attentionTypeIds; let attentionTypeIds = businessCommunicationCustomer.attentionTypeIds;
if (attentionTypeIds) { if (attentionTypeIds) {
attentionTypeIds = attentionTypeIds.split(','); attentionTypeIds = attentionTypeIds.split(',');
}else{
attentionTypeIds = [];
} }
this.setData({ this.setData({
attentionTypeIds, attentionTypeIds,
if (currentTab == 'my') { if (currentTab == 'my') {
if (app.globalData.businessCommunicationCustomer) { if (app.globalData.businessCommunicationCustomer) {
type = app.globalData.businessCommunicationCustomer.attentionTypeIds; type = app.globalData.businessCommunicationCustomer.attentionTypeIds;
if(!type){
this.setData({
listLoading: false
})
return
}
} }
} }
let paramIsInterest = 0; let paramIsInterest = 0;

+ 12
- 1
pages/msgModule/index.js Voir le fichier

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


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

+ 14
- 0
pages/msgModule/wechat2/wechat2.js Voir le fichier

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


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



+ 3
- 2
pages/myModule/index.js Voir le fichier

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

Chargement…
Annuler
Enregistrer