Browse Source

Merge branch 'songjie/feature-20251023161635-首页' into milestone-20251031-简版功能开发

maziyang/feature-20251025172218-智能客服中台
宋杰 4 weeks ago
parent
commit
7cca04c21e
  1. 2
      .hbuilderx/launch.json
  2. 92
      api/tcpConnection.js
  3. 4
      utils/http.js
  4. 22
      vue.config.js

2
.hbuilderx/launch.json

@ -3,7 +3,7 @@
"configurations" : [
{
"customPlaygroundType" : "local",
"playground" : "standard",
"playground" : "custom",
"type" : "uni-app:app-android"
}
]

92
api/tcpConnection.js

@ -6,7 +6,7 @@
*/
// 引用TCP插件
//const TCPSocket = uni.requireNativePlugin('Aimer-TCPPlugin');
const TCPSocket = uni.requireNativePlugin('Aimer-TCPPlugin');
// const TCPSocket = uni.requireNativePlugin("Aimer-TCPPlugin");
// TCP连接配置
@ -67,52 +67,52 @@ class TCPConnection {
}
console.log('开始建立TCP连接:', connectionConfig);
// TCPSocket.connect(
// connectionConfig,
// result => {
// /**
// * status : 0 连接成功
// * status : 1 断开连接
// * receivedMsg : 服务器返回字符串(普通的字符串交互)
// * receivedHexMsg : 服务器返回字节数组(单片机、智能家居等硬件数据交互)
// */
// if (result.status == '0') {
// // TCP连接成功
// this.channelConnections.set(connectionConfig.channel, true);
// console.log(`TCP连接成功 - Channel ${connectionConfig.channel}`);
// this._notifyConnectionCallbacks('connected', result, connectionConfig.channel);
// } else if (result.status == '1') {
// // TCP断开连接
// this.channelConnections.set(connectionConfig.channel, false);
// console.log(`TCP断开连接 - Channel ${connectionConfig.channel}`);
// this._notifyConnectionCallbacks('disconnected', result, connectionConfig.channel);
// }
// if (result.receivedMsg) {
// // 服务器返回字符串
// console.log('收到字符串消息:', result.receivedMsg);
// this._notifyMessageCallbacks('string', result.receivedMsg, null, connectionConfig.channel);
// }
TCPSocket.connect(
connectionConfig,
result => {
/**
* status : 0 连接成功
* status : 1 断开连接
* receivedMsg : 服务器返回字符串(普通的字符串交互)
* receivedHexMsg : 服务器返回字节数组(单片机智能家居等硬件数据交互)
*/
if (result.status == '0') {
// TCP连接成功
this.channelConnections.set(connectionConfig.channel, true);
console.log(`TCP连接成功 - Channel ${connectionConfig.channel}`);
this._notifyConnectionCallbacks('connected', result, connectionConfig.channel);
} else if (result.status == '1') {
// TCP断开连接
this.channelConnections.set(connectionConfig.channel, false);
console.log(`TCP断开连接 - Channel ${connectionConfig.channel}`);
this._notifyConnectionCallbacks('disconnected', result, connectionConfig.channel);
}
// // if (result.receivedHexMsg) {
// // // 硬件服务器返回16进制数据
// // console.log('收到16进制消息:', result.receivedHexMsg);
// // let msg = result.receivedHexMsg;
// // let sum = msg.length / 2;
// // let arr = [];
// // for (let k = 0; k < sum; k++) {
// // let i = msg.substring(k * 2, k * 2 + 2);
// // arr.push(i);
// // }
// // console.log('解析后的16进制数组:', arr);
// // this._notifyMessageCallbacks('hex', result.receivedHexMsg, arr);
// // }
if (result.receivedMsg) {
// 服务器返回字符串
console.log('收到字符串消息:', result.receivedMsg);
this._notifyMessageCallbacks('string', result.receivedMsg, null, connectionConfig.channel);
}
// // 执行回调函数
// if (callback && typeof callback === "function") {
// callback(result);
// if (result.receivedHexMsg) {
// // 硬件服务器返回16进制数据
// console.log('收到16进制消息:', result.receivedHexMsg);
// let msg = result.receivedHexMsg;
// let sum = msg.length / 2;
// let arr = [];
// for (let k = 0; k < sum; k++) {
// let i = msg.substring(k * 2, k * 2 + 2);
// arr.push(i);
// }
// console.log('解析后的16进制数组:', arr);
// this._notifyMessageCallbacks('hex', result.receivedHexMsg, arr);
// }
// });
// 执行回调函数
if (callback && typeof callback === "function") {
callback(result);
}
});
}
/**
@ -144,7 +144,7 @@ class TCPConnection {
sendConfig.charsetname = config.charsetname;
}
//TCPSocket.send(sendConfig);
TCPSocket.send(sendConfig);
console.log("js成功发送TCP消息:", messageStr);
return true;
}
@ -159,7 +159,7 @@ class TCPConnection {
channel: channel
};
//TCPSocket.disconnect(disconnectConfig);
TCPSocket.disconnect(disconnectConfig);
this.channelConnections.set(channel, false);
console.log(`TCP连接已断开 - Channel ${channel}`, disconnectConfig);
}

4
utils/http.js

@ -2,8 +2,8 @@ import { useUserStore } from "../stores/modules/userInfo"
import { useDeviceStore } from "../stores/modules/deviceInfo"
import { useLoginStore } from "../stores/modules/login"
// const baseURL = "https://dbqb.nfdxy.net/testApi"
const baseURL = "http://192.168.40.8:9000"
const baseURL = "https://dbqb.nfdxy.net/testApi"
// const baseURL = "http://192.168.40.8:9000"
const httpInterceptor = {
// 拦截前触发

22
vue.config.js

@ -1,18 +1,8 @@
module.exports = {
devServer: {
/* proxy: {
'/api': { // 你的目标服务器的请求路径前缀
target: 'https://hwjb.homilychart.com', // 目标服务器的地址
changeOrigin: true, // 是否跨域
secure: false, // 如果是https接口,需要配置这个参数
pathRewrite: {
'^/api': '' // 将 /api 替换为 /testApi,以便正确请求目标服务器的资源
}
}
} */
proxy: {
'/api': { // 你的目标服务器的请求路径前缀
target: 'http://192.168.40.8:9000', // 目标服务器的地址
target: 'https://hwjb.homilychart.com', // 目标服务器的地址
changeOrigin: true, // 是否跨域
secure: false, // 如果是https接口,需要配置这个参数
pathRewrite: {
@ -20,5 +10,15 @@ module.exports = {
}
}
}
// proxy: {
// '/api': { // 你的目标服务器的请求路径前缀
// target: 'http://192.168.40.8:9000', // 目标服务器的地址
// changeOrigin: true, // 是否跨域
// secure: false, // 如果是https接口,需要配置这个参数
// pathRewrite: {
// '^/api': '' // 将 /api 替换为 /testApi,以便正确请求目标服务器的资源
// }
// }
// }
}
}
Loading…
Cancel
Save