Compare commits
2 Commits
59bf3fdb7a
...
0d226b19ea
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d226b19ea | |||
| febc3e82f3 |
@ -57,7 +57,7 @@ packages/customerService/index/index
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { menuButtonInfo, picUrl, request } from '../../../utils'
|
import { menuButtonInfo, picUrl, request } from '@/utils'
|
||||||
import { apiArr } from '@/api/customerService'
|
import { apiArr } from '@/api/customerService'
|
||||||
import mqttTool from '@/utils/mqtt'
|
import mqttTool from '@/utils/mqtt'
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ export default {
|
|||||||
// 连接成功后启动心跳包
|
// 连接成功后启动心跳包
|
||||||
this.startKeepalive()
|
this.startKeepalive()
|
||||||
// 连接成功后立即加载历史消息
|
// 连接成功后立即加载历史消息
|
||||||
this.loadHistoryMessages()
|
await this.loadHistoryMessages()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('初始化聊天失败', error)
|
console.error('初始化聊天失败', error)
|
||||||
this.connectingStatus = '连接失败,请检查网络'
|
this.connectingStatus = '连接失败,请检查网络'
|
||||||
@ -324,15 +324,16 @@ export default {
|
|||||||
|
|
||||||
// 将获取到的历史消息添加到消息列表开头
|
// 将获取到的历史消息添加到消息列表开头
|
||||||
// 这里需要根据消息的发送方判断是否是自己发送的消息
|
// 这里需要根据消息的发送方判断是否是自己发送的消息
|
||||||
const formattedMessages = historyMessages.map(msg => ({
|
historyMessages.map(msg => (
|
||||||
|
this.messages = [{
|
||||||
content: msg.content,
|
content: msg.content,
|
||||||
time: new Date(msg.create_time).getTime(),
|
time: new Date(msg.create_time).getTime(),
|
||||||
isSelf: msg.send_client === this.chatTarget.openId,
|
isSelf: msg.send_client === this.chatTarget.openId,
|
||||||
isLoading: false
|
isLoading: false
|
||||||
})).reverse() // 因为是按时间降序获取的,所以需要反转
|
}, ...this.messages])) // 因为是按时间降序获取的,所以需要反转
|
||||||
|
|
||||||
// 添加到消息列表开头
|
// 添加到消息列表开头
|
||||||
this.messages = [...formattedMessages, ...this.messages]
|
// this.messages = [...formattedMessages, ...this.messages]
|
||||||
|
|
||||||
// 增加页码
|
// 增加页码
|
||||||
this.pageNum++
|
this.pageNum++
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
17
unpackage/dist/dev/mp-weixin/common/vendor.js
vendored
17
unpackage/dist/dev/mp-weixin/common/vendor.js
vendored
@ -17114,7 +17114,6 @@ Object.defineProperty(exports, "__esModule", {
|
|||||||
});
|
});
|
||||||
exports.default = void 0;
|
exports.default = void 0;
|
||||||
var _mqtt = _interopRequireDefault(__webpack_require__(/*! mqtt/dist/mqtt */ 300));
|
var _mqtt = _interopRequireDefault(__webpack_require__(/*! mqtt/dist/mqtt */ 300));
|
||||||
var _vue = _interopRequireDefault(__webpack_require__(/*! vue */ 25));
|
|
||||||
var _buffer = __webpack_require__(/*! buffer */ 53);
|
var _buffer = __webpack_require__(/*! buffer */ 53);
|
||||||
// 引入Buffer,适配小程序环境
|
// 引入Buffer,适配小程序环境
|
||||||
|
|
||||||
@ -17134,13 +17133,14 @@ mqttTool.connect = function (params) {
|
|||||||
username: 'dev01',
|
username: 'dev01',
|
||||||
password: '211561',
|
password: '211561',
|
||||||
clean: true,
|
clean: true,
|
||||||
|
useSSL: true,
|
||||||
reconnectPeriod: 1000,
|
reconnectPeriod: 1000,
|
||||||
protocolVersion: 4,
|
protocolVersion: 4,
|
||||||
connectTimeout: 600000,
|
connectTimeout: 600000,
|
||||||
cleanSession: false
|
cleanSession: false
|
||||||
};
|
};
|
||||||
var client = null;
|
var client = null;
|
||||||
client = _mqtt.default.connect('wx://api.hshuishang.com:8084/mqtt', options);
|
client = _mqtt.default.connect('wxs://gmqt.hshuishang.com:443/mqtt', options);
|
||||||
console.log('WX', client);
|
console.log('WX', client);
|
||||||
mqttTool.client = client;
|
mqttTool.client = client;
|
||||||
|
|
||||||
@ -17248,7 +17248,18 @@ mqttTool.publish = function (params) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
_vue.default.prototype.$mqtt = mqttTool;
|
mqttTool.disconnect = function () {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
if (mqttTool.client == null) {
|
||||||
|
resolve('未连接');
|
||||||
|
console.log('App_text' + ':unconnect 未连接');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mqttTool.client.end();
|
||||||
|
mqttTool.client = null;
|
||||||
|
resolve('连接终止');
|
||||||
|
});
|
||||||
|
};
|
||||||
var _default = mqttTool;
|
var _default = mqttTool;
|
||||||
exports.default = _default;
|
exports.default = _default;
|
||||||
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../HBuilderX/plugins/uniapp-cli/node_modules/webpack/buildin/global.js */ 3)))
|
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../HBuilderX/plugins/uniapp-cli/node_modules/webpack/buildin/global.js */ 3)))
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
"urlCheck": false,
|
"urlCheck": false,
|
||||||
"es6": false,
|
"es6": false,
|
||||||
"postcss": false,
|
"postcss": false,
|
||||||
"minified": true,
|
"minified": false,
|
||||||
"newFeature": true,
|
"newFeature": true,
|
||||||
"bigPackageSizeSupport": true
|
"bigPackageSizeSupport": true
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,20 +2,8 @@
|
|||||||
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
||||||
"projectname": "uniapp-ZHSQ",
|
"projectname": "uniapp-ZHSQ",
|
||||||
"setting": {
|
"setting": {
|
||||||
"compileHotReLoad": true
|
"compileHotReLoad": true,
|
||||||
|
"urlCheck": true
|
||||||
},
|
},
|
||||||
"libVersion": "3.9.1",
|
"libVersion": "3.9.1"
|
||||||
"condition": {
|
|
||||||
"miniprogram": {
|
|
||||||
"list": [
|
|
||||||
{
|
|
||||||
"name": "packages/customerService/changeService/index",
|
|
||||||
"pathName": "packages/customerService/changeService/index",
|
|
||||||
"query": "",
|
|
||||||
"scene": null,
|
|
||||||
"launchMode": "default"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,12 +1,13 @@
|
|||||||
import mqtt from 'mqtt/dist/mqtt'
|
import mqtt from 'mqtt/dist/mqtt'
|
||||||
import Vue from 'vue'
|
|
||||||
// 引入Buffer,适配小程序环境
|
// 引入Buffer,适配小程序环境
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer'
|
||||||
|
|
||||||
// 挂载到全局,确保所有文件可访问
|
// 挂载到全局,确保所有文件可访问
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
window.Buffer = Buffer;
|
window.Buffer = Buffer
|
||||||
} else if (typeof global !== 'undefined') {
|
} else
|
||||||
global.Buffer = Buffer;
|
if (typeof global !== 'undefined') {
|
||||||
|
global.Buffer = Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
let mqttTool = {
|
let mqttTool = {
|
||||||
@ -19,13 +20,14 @@ mqttTool.connect = function(params, callbacks = {}){
|
|||||||
username: 'dev01',
|
username: 'dev01',
|
||||||
password: '211561',
|
password: '211561',
|
||||||
clean: true,
|
clean: true,
|
||||||
|
useSSL: true,
|
||||||
reconnectPeriod: 1000,
|
reconnectPeriod: 1000,
|
||||||
protocolVersion: 4,
|
protocolVersion: 4,
|
||||||
connectTimeout: 600000,
|
connectTimeout: 600000,
|
||||||
cleanSession: false
|
cleanSession: false
|
||||||
}
|
}
|
||||||
let client = null
|
let client = null
|
||||||
client = mqtt.connect('wx://api.hshuishang.com:8084/mqtt', options)
|
client = mqtt.connect('wxs://gmqt.hshuishang.com:443/mqtt', options)
|
||||||
console.log('WX', client)
|
console.log('WX', client)
|
||||||
mqttTool.client = client
|
mqttTool.client = client
|
||||||
|
|
||||||
@ -146,5 +148,16 @@ mqttTool.publish = function(params){
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Vue.prototype.$mqtt = mqttTool
|
mqttTool.disconnect = function(){
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (mqttTool.client == null) {
|
||||||
|
resolve('未连接')
|
||||||
|
console.log('App_text' + ':unconnect 未连接')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mqttTool.client.end()
|
||||||
|
mqttTool.client = null
|
||||||
|
resolve('连接终止')
|
||||||
|
})
|
||||||
|
}
|
||||||
export default mqttTool
|
export default mqttTool
|
||||||
Loading…
x
Reference in New Issue
Block a user