Compare commits

..

No commits in common. "0d226b19ea40ba90597efb3f82a1c60424e14d05" and "59bf3fdb7ad4be8e96f4837b3c0b16d5e977e3e3" have entirely different histories.

17 changed files with 59 additions and 72 deletions

View File

@ -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()
// //
await this.loadHistoryMessages() this.loadHistoryMessages()
} catch (error) { } catch (error) {
console.error('初始化聊天失败', error) console.error('初始化聊天失败', error)
this.connectingStatus = '连接失败,请检查网络' this.connectingStatus = '连接失败,请检查网络'
@ -324,16 +324,15 @@ export default {
// //
// //
historyMessages.map(msg => ( const formattedMessages = 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

View File

@ -17114,6 +17114,7 @@ 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适配小程序环境
@ -17133,14 +17134,13 @@ 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('wxs://gmqt.hshuishang.com:443/mqtt', options); client = _mqtt.default.connect('wx://api.hshuishang.com:8084/mqtt', options);
console.log('WX', client); console.log('WX', client);
mqttTool.client = client; mqttTool.client = client;
@ -17248,18 +17248,7 @@ mqttTool.publish = function (params) {
}); });
}); });
}; };
mqttTool.disconnect = function () { _vue.default.prototype.$mqtt = mqttTool;
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)))

View File

@ -7,7 +7,7 @@
"urlCheck": false, "urlCheck": false,
"es6": false, "es6": false,
"postcss": false, "postcss": false,
"minified": false, "minified": true,
"newFeature": true, "newFeature": true,
"bigPackageSizeSupport": true "bigPackageSizeSupport": true
}, },

View File

@ -2,8 +2,20 @@
"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"
}
]
}
}
} }

View File

@ -1,14 +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 } else if (typeof global !== 'undefined') {
if (typeof global !== 'undefined') { global.Buffer = Buffer;
global.Buffer = Buffer }
}
let mqttTool = { let mqttTool = {
client: null client: null
@ -20,46 +19,45 @@ 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('wxs://gmqt.hshuishang.com:443/mqtt', options) client = mqtt.connect('wx://api.hshuishang.com:8084/mqtt', options)
console.log('WX', client) console.log('WX', client)
mqttTool.client = client mqttTool.client = client
// 设置连接状态回调 // 设置连接状态回调
if (callbacks.onConnect) { if (callbacks.onConnect) {
client.on('connect', callbacks.onConnect) client.on('connect', callbacks.onConnect)
} }
if (callbacks.onDisconnect) { if (callbacks.onDisconnect) {
client.on('disconnect', callbacks.onDisconnect) client.on('disconnect', callbacks.onDisconnect)
} }
if (callbacks.onError) { if (callbacks.onError) {
client.on('error', callbacks.onError) client.on('error', callbacks.onError)
} }
if (callbacks.onReconnect) { if (callbacks.onReconnect) {
client.on('reconnect', callbacks.onReconnect) client.on('reconnect', callbacks.onReconnect)
} }
client.on('connect', function(){ client.on('connect', function() {
console.log('MQTT连接成功') console.log('MQTT连接成功')
}) })
client.on('error', function(error){ client.on('error', function(error) {
console.log('MQTT连接错误:', error) console.log('MQTT连接错误:', error)
}) })
client.on('reconnect', function(){ client.on('reconnect', function() {
console.log('MQTT正在重连...') console.log('MQTT正在重连...')
}) })
return client return client
} }
@ -148,16 +146,5 @@ mqttTool.publish = function(params){
}) })
}) })
} }
mqttTool.disconnect = function(){ Vue.prototype.$mqtt = mqttTool
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