|
@@ -10,22 +10,27 @@ Page({
|
|
id: 0,
|
|
id: 0,
|
|
socketOpen: false,
|
|
socketOpen: false,
|
|
chatContent: [],
|
|
chatContent: [],
|
|
- myWrite: ''
|
|
|
|
|
|
+ inputValue: ''
|
|
},
|
|
},
|
|
// videoErrorCallback: function (e) {
|
|
// videoErrorCallback: function (e) {
|
|
// console.log('视频错误信息:')
|
|
// console.log('视频错误信息:')
|
|
// console.log(e.detail.errMsg)
|
|
// console.log(e.detail.errMsg)
|
|
// },
|
|
// },
|
|
onReady: function () {},
|
|
onReady: function () {},
|
|
|
|
+ bindKeyInput: function (e) {
|
|
|
|
+ this.setData({
|
|
|
|
+ inputValue: e.detail.value
|
|
|
|
+ })
|
|
|
|
+ },
|
|
hands() {
|
|
hands() {
|
|
this.sendSocketMessage("put up hands")
|
|
this.sendSocketMessage("put up hands")
|
|
},
|
|
},
|
|
// console.log(this.data.myWrite)
|
|
// console.log(this.data.myWrite)
|
|
// this.sendSocketMessage(this.data.myWrite)
|
|
// this.sendSocketMessage(this.data.myWrite)
|
|
// this.sendSocketMessage(this.data.myWrite)
|
|
// this.sendSocketMessage(this.data.myWrite)
|
|
- bindFormSubmit: function (e) {
|
|
|
|
- var _this = this;
|
|
|
|
- var input_val = e.detail.value.textarea;
|
|
|
|
|
|
+ submit: function () {
|
|
|
|
+ let _this = this;
|
|
|
|
+ let input_val = _this.data.inputValue;
|
|
_this.sendSocketMessage(input_val)
|
|
_this.sendSocketMessage(input_val)
|
|
},
|
|
},
|
|
getZbArr(sessionKey) {
|
|
getZbArr(sessionKey) {
|
|
@@ -68,6 +73,9 @@ Page({
|
|
wx.onSocketError(function () {
|
|
wx.onSocketError(function () {
|
|
console.log("我连接出错了")
|
|
console.log("我连接出错了")
|
|
})
|
|
})
|
|
|
|
+ wx.onSocketClose(function () {
|
|
|
|
+ console.log("我关了")
|
|
|
|
+ })
|
|
wx.onSocketMessage(function (data) {
|
|
wx.onSocketMessage(function (data) {
|
|
let res = JSON.parse(data.data);
|
|
let res = JSON.parse(data.data);
|
|
console.log(res)
|
|
console.log(res)
|
|
@@ -90,13 +98,6 @@ Page({
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- // _this.setData({
|
|
|
|
- // chatContent: res.msg
|
|
|
|
- // })
|
|
|
|
- // if (res.messageType == "system") {
|
|
|
|
-
|
|
|
|
- // // this.data.chatContent = data.data.msg
|
|
|
|
- // }
|
|
|
|
})
|
|
})
|
|
},
|
|
},
|
|
sendSocketMessage(msg) {
|
|
sendSocketMessage(msg) {
|
|
@@ -105,23 +106,70 @@ Page({
|
|
data: msg
|
|
data: msg
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
- // socketMsgQueue.push(msg)
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- // onclose() {
|
|
|
|
- // wx.onSocketClose(function () {
|
|
|
|
- // console.log("我关了")
|
|
|
|
- // })
|
|
|
|
- // },
|
|
|
|
- onHide() {
|
|
|
|
- wx.onSocketClose(function () {
|
|
|
|
- console.log("我关了")
|
|
|
|
|
|
+ onShow() {
|
|
|
|
+ let _this=this;
|
|
|
|
+ wx.checkSession({
|
|
|
|
+ success: () => {
|
|
|
|
+ console.log("我有缓存")
|
|
|
|
+ var sessionKey = wx.getStorageSync('sessionKey');
|
|
|
|
+ console.log(sessionKey)
|
|
|
|
+ if (sessionKey == "") {
|
|
|
|
+ wx.login({
|
|
|
|
+ success(res) {
|
|
|
|
+ console.log(res);
|
|
|
|
+ var code = res.code
|
|
|
|
+ wx.request({
|
|
|
|
+ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
|
+ method: "get",
|
|
|
|
+ data: {
|
|
|
|
+ code
|
|
|
|
+ },
|
|
|
|
+ success: function (res) {
|
|
|
|
+ sessionKey = res.data.sessionKey;
|
|
|
|
+ wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
|
|
+ _this.socketConnect(sessionKey);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ _this.socketConnect(sessionKey);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail() {
|
|
|
|
+ console.log("我没有缓存并去登录请求")
|
|
|
|
+ wx.login({
|
|
|
|
+ success(res) {
|
|
|
|
+ console.log(res);
|
|
|
|
+ var code = res.code
|
|
|
|
+ wx.request({
|
|
|
|
+ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
|
|
|
|
+ method: "get",
|
|
|
|
+ data: {
|
|
|
|
+ code
|
|
|
|
+ },
|
|
|
|
+ success: function (res) {
|
|
|
|
+ wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
|
|
+ var sessionKey = res.data.sessionKey;
|
|
|
|
+ _this.socketConnect(sessionKey);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+ onHide() {
|
|
|
|
+ if (this.data.socketOpen) {
|
|
|
|
+ wx.closeSocket()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
onUnload() {
|
|
onUnload() {
|
|
- wx.onSocketClose(function () {
|
|
|
|
- console.log("我关了")
|
|
|
|
- })
|
|
|
|
|
|
+ if (this.data.socketOpen) {
|
|
|
|
+ wx.closeSocket()
|
|
|
|
+ }
|
|
},
|
|
},
|
|
onLoad: function (options) {
|
|
onLoad: function (options) {
|
|
var _this = this;
|
|
var _this = this;
|
|
@@ -148,14 +196,14 @@ Page({
|
|
sessionKey = res.data.sessionKey;
|
|
sessionKey = res.data.sessionKey;
|
|
wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
_this.getZbArr(sessionKey);
|
|
_this.getZbArr(sessionKey);
|
|
- _this.socketConnect(sessionKey);
|
|
|
|
|
|
+ // _this.socketConnect(sessionKey);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
_this.getZbArr(sessionKey);
|
|
_this.getZbArr(sessionKey);
|
|
- _this.socketConnect(sessionKey);
|
|
|
|
|
|
+ // _this.socketConnect(sessionKey);
|
|
}
|
|
}
|
|
|
|
|
|
},
|
|
},
|
|
@@ -175,7 +223,7 @@ Page({
|
|
wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
wx.setStorageSync('sessionKey', res.data.sessionKey);
|
|
var sessionKey = res.data.sessionKey;
|
|
var sessionKey = res.data.sessionKey;
|
|
_this.getZbArr(sessionKey);
|
|
_this.getZbArr(sessionKey);
|
|
- _this.socketConnect(sessionKey);
|
|
|
|
|
|
+ // _this.socketConnect(sessionKey);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|