|
@@ -36,8 +36,9 @@ class Index extends Component {
|
|
let pages = getCurrentPages()
|
|
let pages = getCurrentPages()
|
|
let prevPage = pages[ pages.length - 2 ]
|
|
let prevPage = pages[ pages.length - 2 ]
|
|
if (prevPage.$component.getNotifycount) prevPage.$component.getNotifycount()
|
|
if (prevPage.$component.getNotifycount) prevPage.$component.getNotifycount()
|
|
|
|
+ if (prevPage.$component.getNewData) prevPage.$component.getNewData()
|
|
}
|
|
}
|
|
-
|
|
+
|
|
closeSocket () {
|
|
closeSocket () {
|
|
Taro.closeSocket()
|
|
Taro.closeSocket()
|
|
const { socketTimer } = this.state
|
|
const { socketTimer } = this.state
|
|
@@ -133,14 +134,13 @@ class Index extends Component {
|
|
const { uObj } = this.state
|
|
const { uObj } = this.state
|
|
const that = this
|
|
const that = this
|
|
Taro.connectSocket({
|
|
Taro.connectSocket({
|
|
- url: 'ws://192.168.101.147:8089/acc',
|
|
+ url: 'wss://chat.honglouplus.com/acc',
|
|
success: function () {
|
|
success: function () {
|
|
console.log('connect success')
|
|
console.log('connect success')
|
|
}
|
|
}
|
|
}).then(task => {
|
|
}).then(task => {
|
|
task.onOpen(function () {
|
|
task.onOpen(function () {
|
|
// console.log('onOpen')
|
|
// console.log('onOpen')
|
|
- // const { to_user_id } = that.$router.params
|
|
|
|
let token = Taro.getStorageSync('APP_token')
|
|
let token = Taro.getStorageSync('APP_token')
|
|
task.send({ data: '{"seq":"' + that.sendId() + '","cmd":"login","data":{"userId":"' + uObj.user_id + '","appId":101,"serviceToken":"' + token + '"}}' })
|
|
task.send({ data: '{"seq":"' + that.sendId() + '","cmd":"login","data":{"userId":"' + uObj.user_id + '","appId":101,"serviceToken":"' + token + '"}}' })
|
|
const socketTimer = setInterval(() => {
|
|
const socketTimer = setInterval(() => {
|
|
@@ -161,11 +161,18 @@ class Index extends Component {
|
|
if (data.cmd === 'login') {
|
|
if (data.cmd === 'login') {
|
|
msgSocketList.push({msg: '登录成功~'})
|
|
msgSocketList.push({msg: '登录成功~'})
|
|
} else {
|
|
} else {
|
|
- msgSocketList.push(res.data)
|
|
+ const { to_user_id } = that.$router.params
|
|
|
|
+ if (to_user_id === res.data.from) {
|
|
|
|
+ msgSocketList.push(res.data)
|
|
|
|
+ } else {
|
|
|
|
+ msgSocketList.push({msg: '有其他人给你发消息啦,返回消息列表查看'})
|
|
|
|
+ }
|
|
}
|
|
}
|
|
that.setState({
|
|
that.setState({
|
|
msgSocketList
|
|
msgSocketList
|
|
}, () => {
|
|
}, () => {
|
|
|
|
+ const { qTitle } = that.$router.params
|
|
|
|
+ if (qTitle) that.sendHandle('text', `你好,我想了解一下# ${qTitle} #这个房源`)
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
that.setState({
|
|
that.setState({
|
|
viewId: `item${msgSocketList.length - 1}`
|
|
viewId: `item${msgSocketList.length - 1}`
|
|
@@ -289,22 +296,24 @@ class Index extends Component {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- sendHandle () {
|
|
+ sendHandle (type, defaultMsg) {
|
|
const that = this
|
|
const that = this
|
|
const { uObj } = this.state
|
|
const { uObj } = this.state
|
|
const { commentVal } = this.state
|
|
const { commentVal } = this.state
|
|
let { msgSocketList } = this.state
|
|
let { msgSocketList } = this.state
|
|
const { to_user_id } = this.$router.params
|
|
const { to_user_id } = this.$router.params
|
|
let apiStr = 'apiusersendmessage'
|
|
let apiStr = 'apiusersendmessage'
|
|
- if (commentVal) {
|
|
+ let msg = commentVal
|
|
|
|
+ if (type === 'text') msg = defaultMsg
|
|
|
|
+ if (msg) {
|
|
Taro.api.room[apiStr]({
|
|
Taro.api.room[apiStr]({
|
|
- message: commentVal,
|
|
+ message: msg,
|
|
type: 'text',
|
|
type: 'text',
|
|
to_user: to_user_id,
|
|
to_user: to_user_id,
|
|
}).then(res => {
|
|
}).then(res => {
|
|
msgSocketList.push({
|
|
msgSocketList.push({
|
|
from: uObj.user_id,
|
|
from: uObj.user_id,
|
|
- msg: commentVal
|
|
+ msg
|
|
})
|
|
})
|
|
this.setState({
|
|
this.setState({
|
|
msgSocketList,
|
|
msgSocketList,
|