From b06a49f8125fba4bdd50b08481295ffde1e37cf7 Mon Sep 17 00:00:00 2001
From: han <151435705@qq.com>
Date: Thu, 12 Dec 2024 08:56:50 +0800
Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=9F=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
common/config.js | 10 ++-
subPageC/Ai/index.vue | 125 +++++++++++++++++++------------------
subPageC/weather/index.vue | 44 ++++++-------
3 files changed, 90 insertions(+), 89 deletions(-)
diff --git a/common/config.js b/common/config.js
index d98ed01..11b91d5 100644
--- a/common/config.js
+++ b/common/config.js
@@ -51,9 +51,13 @@ module.exports = {
userCancelUpdateOrder: REAUEST_ROOTPATH + "/admin-api/homestay/HotelOrder/userCancelUpdateOrder",//民宿订单取消
getDictDataList: REAUEST_ROOTPATH + "/admin-api/homestay/HotelOrder/getDictDataList",//民宿订单原因
- getWeatherForecast: 'http://192.168.130.157:48080/app-api' + "/wechatshop/weather/getWeatherForecast",//工具-天气预报
-
-
+
+ aiSendMsg: REAUEST_ROOTPATH + "/app-api/wechatshop/ai/sendMsg",//Ai发送
+ getWeatherForecast: REAUEST_ROOTPATH + "/app-api/wechatshop/weather/getWeatherForecast",//天气预报
+ getRealTimeWeather: REAUEST_ROOTPATH + "/app-api/wechatshop/weather/getRealTimeWeather",//Ai发送
+
+
+
// getMethodList: REAUEST_ROOTPATH + "/mobile/method/getMethodList", //原攻略列表
getMethodList: REAUEST_ROOTPATH + "/mobile/WalkthroughType/selectWalkthroughType",//攻略列表
getMethodRecommendList: REAUEST_ROOTPATH + "/mobile/WalkthroughType/selectMessageRecommend",//攻略推荐列表
diff --git a/subPageC/Ai/index.vue b/subPageC/Ai/index.vue
index 08f2826..82bb05c 100644
--- a/subPageC/Ai/index.vue
+++ b/subPageC/Ai/index.vue
@@ -27,7 +27,7 @@
-
+
@@ -60,8 +60,9 @@
//发送类型
messageType: 'voice', // text 发送文本;voice 发送语音
recordStart: false,
+ identity: "",
//websocket
- headers: {},
+ Token:null ,
userInfo: {},
wsInfo: {
ws: null, // ws对象
@@ -78,21 +79,16 @@
}
}
},
- onReady() {
- const userInfo = uni.getStorageSync("userInfo");
+
+ onShow() {
+ const userInfo = uni.getStorageSync("userInfo");
this.userInfo = {
"message": "",
"dialogId": "",
- "identity": userInfo.openid,
+ "identity": "",
"userId": userInfo.userId
};
- const tok = userInfo.accessToken;
- this.headers = {
- "content-type": 'application/json',
- 'Authorization': 'Bearer ' + '3e803f812b5c4bba8a0d6864d011cf28'
- };
- },
- onShow() {
+ this.Token = userInfo.accessToken;
this.connectWs()
},
methods: {
@@ -101,7 +97,7 @@
const $this = this
this.wsInfo.ws = null;
this.wsInfo.ws = uni.connectSocket({
- url: 'wss://192.168.130.157:48080/infra/ws?token=3e803f812b5c4bba8a0d6864d011cf28',
+ url: 'wss://eluyou.ailuquan.cn/prod-api/infra/ws?token='+this.Token,
success() {
$this.wsInfo.alive = true;
console.log("ws连接成功!");
@@ -111,51 +107,36 @@
console.log("ws连接失败!");
},
});
+
console.log("ws信息:", this.wsInfo.ws);
+ // ws打开
this.wsInfo.ws.onOpen((res) => {
$this.wsInfo.alive = true;
// 开启心跳
$this.heartBeat();
- console.log("ws开启成功!");
+ console.log("ws开启成功!",$this.wsInfo.alive);
});
// ws消息
this.wsInfo.ws.onMessage((res) => {
- console.log("===", res)
+ console.log("ws接收消息:", res);
+ $this.heartBeat();
+ // 处理消息
let data = JSON.parse(res.data);
- $this.handlerMessage($this.userInfo);
+ $this.handlerMessage(data);
console.log("ws接收消息:", data);
});
-
-
-
- // console.log("ws信息:", this.wsInfo.ws);
- // // ws打开
- // this.wsInfo.ws.onOpen((res) => {
- // this.wsInfo.alive = true;
- // // 开启心跳
- // this.heartBeat();
- // console.log("ws开启成功!");
- // });
- // // ws消息
- // this.wsInfo.ws.onMessage((res) => {
- // this.heartBeat();
- // // 处理消息
- // let data = JSON.parse(res.data);
- // this.handlerMessage(data);
- // console.log("ws接收消息:", data);
- // });
- // // ws关闭
- // this.wsInfo.ws.onClose((res) => {
- // this.wsInfo.alive = false;
- // this.reConnect();
- // console.log("ws连接关闭:", res);
- // });
- // // ws错误
- // this.wsInfo.ws.onError((err) => {
- // this.wsInfo.alive = false;
- // this.reConnect();
- // console.log("ws连接错误:", res);
- // });
+ // ws关闭
+ this.wsInfo.ws.onClose((res) => {
+ $this.wsInfo.alive = false;
+ $this.reConnect();
+ console.log("ws连接关闭:", res);
+ });
+ // ws错误
+ this.wsInfo.ws.onError((err) => {
+ $this.wsInfo.alive = false;
+ $this.reConnect();
+ console.log("ws连接错误:", res);
+ });
},
// 心跳检测
heartBeat() {
@@ -163,11 +144,11 @@
clearTimeout(this.wsInfo.clientTimer);
clearTimeout(this.wsInfo.serverTimer);
this.wsInfo.clientTimer = setTimeout(() => {
- if (this.wsInfo.ws) {
+ if ($this.wsInfo.ws) {
let pong = {
type: "ping",
};
- this.wsInfo.ws.send({
+ $this.wsInfo.ws.send({
data: JSON.stringify(pong),
fail() {
$this.wsInfo.serverTimer = setTimeout(() => {
@@ -176,7 +157,7 @@
},
});
}
- }, this.wsInfo.clientTime);
+ }, $this.wsInfo.clientTime);
},
//发送消息
handlerMessage(data) {
@@ -204,23 +185,34 @@
this.wsInfo.ws.close();
},
-
// 发送消息
- send() {
+ sendMsg() {
+ const $this = this
this.list.push({
content: this.content,
userType: 'self',
})
+
+ if (this.userInfo.identity == "") {
+ this.userInfo.identity = this.generateRandomString(8);
+ }
+ this.userInfo.message = this.content
+
+ this.$Request.post(this.$config.aiSendMsg, $this.userInfo, "json", null, false, true)
+ .then(res => {
+ console.log("---", res)
+ });
+
this.content = ''
this.scrollToBottom()
- // 模拟对方回复
- setTimeout(() => {
- this.list.push({
- content: '好的',
- userType: 'friend',
- })
- this.scrollToBottom()
- }, 1500)
+ // // 模拟对方回复
+ // setTimeout(() => {
+ // this.list.push({
+ // content: '好的',
+ // userType: 'friend',
+ // })
+ // this.scrollToBottom()
+ // }, 1500)
},
//屏幕滚动
scrollToBottom() {
@@ -361,7 +353,18 @@
}
});
})
- }
+ },
+ //获取当前对话 key
+ generateRandomString(length) {
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ let result = '';
+ for (let i = 0; i < length; i++) {
+ const randomIndex = Math.floor(Math.random() * characters.length);
+ result += characters.charAt(randomIndex);
+ }
+ return result;
+ },
+
}
}
diff --git a/subPageC/weather/index.vue b/subPageC/weather/index.vue
index 30c3128..6f0c643 100644
--- a/subPageC/weather/index.vue
+++ b/subPageC/weather/index.vue
@@ -60,15 +60,15 @@
tempTotal: undefined,
};
},
- computed: {
+ computed: {
TodayClass() {
switch (true) {
case this.today_data.text.includes("晴"):
return "sunny"
break;
- case this.today_data.text.includes("阴"):
- return "rainy"
- break;
+ case this.today_data.text.includes("阴"):
+ return "rainy"
+ break;
case this.today_data.text.includes("雨"):
return "rainy"
break;
@@ -92,39 +92,33 @@
},
methods: {
initPages() {
- uni.request({
- url: 'http://192.168.130.157:48080/app-api/wechatshop/weather/getWeatherForecast',
- success: (res) => {
+ this.$Request.get(this.$config.getWeatherForecast, null, null, null, false, true)
+ .then(res => {
let data = res.data
- this.tempMax = Math.max.apply(Math, data.data.map(item => {
+ this.tempMax = Math.max.apply(Math, data.map(item => {
return item.tempMax
}))
- this.tempMin = Math.min.apply(Math, data.data.map(item => {
+ this.tempMin = Math.min.apply(Math, data.map(item => {
return item.tempMin
}))
this.tempTotal = this.tempMax - this.tempMin
- data.data.forEach((item, index, arr) => {
+ data.forEach((item, index, arr) => {
let data = {
week: this.getWeekday(item.fxDate[0] + '-' + item.fxDate[1] +
'-' +
item.fxDate[2]),
- iconDay: item.iconDay,
- tempMin:item.tempMin,
- tempMax:item.tempMax,
+ iconDay: item.iconDay,
+ tempMin: item.tempMin,
+ tempMax: item.tempMax,
}
this.days_data.push(data);
})
- console.log("asdf",this.days_data)
-
- }
- });
- uni.request({
- url: 'http://192.168.130.157:48080/app-api/wechatshop/weather/getRealTimeWeather',
- success: (res) => {
+ });
+ this.$Request.get(this.$config.getRealTimeWeather, null, null, null, false, true)
+ .then(res => {
let data = res.data
- this.today_data = data.data
- }
- });
+ this.today_data = data
+ });
},
getTempBar(Min, Max) {
let left = ((Min - this.tempMin) / this.tempTotal) * 100
@@ -150,7 +144,7 @@
return weekdays[weekday];
}
},
-
+
}
}
@@ -160,7 +154,7 @@
.v-weather-bar {
position: relative;
- top:88rpx;
+ top: 88rpx;
z-index: 9;
height: 88rpx;
line-height: 88rpx;