lu_quan_dev
han 11 months ago
parent e01e006a12
commit b06a49f812
  1. 6
      common/config.js
  2. 123
      subPageC/Ai/index.vue
  3. 28
      subPageC/weather/index.vue

@ -51,7 +51,11 @@ 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", //原攻略列表

@ -27,7 +27,7 @@
<image src="@/static/test/icon-voice.png" mode="widthFix" class="left-icon"
@click="messageType='voice'">
</image>
<input type="text" v-model="content" class="input" @confirm="send" />
<input type="text" v-model="content" class="input" @confirm="sendMsg" />
</block>
<block v-if="messageType === 'voice'">
<image src="@/static/test/icon-text.png" mode="widthFix" class="left-icon" @click="messageType='text'">
@ -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() {
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;
},
}
}
</script>

@ -92,38 +92,32 @@
},
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,
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) {
@ -160,7 +154,7 @@
.v-weather-bar {
position: relative;
top:88rpx;
top: 88rpx;
z-index: 9;
height: 88rpx;
line-height: 88rpx;

Loading…
Cancel
Save