Commit 564248a6 by 前端

重连

1 parent 7d521468
......@@ -51,9 +51,9 @@ if (systemInfo.platform != "devtools") {
export const env = envName;
export const envIndex = index;
export const ALIYUN = {
AKID: "LTAIhu9ItBSzi16S",
AKKEY: "Esmj7USmypZPDtA7mPpAEkmcOtTLjx",
APPKEY: "7cJdzPPBWB9XmU6T",
AKID: "LTAI5tJday6R4sng1jgrgH3N",
AKKEY: "TWvwaQqwjxw7Tj7RlnTxyEXjOjQgFh",
APPKEY: "a1HmjrmQNv6yT8zb",
URL: "wss://nls-gateway-cn-shanghai.aliyuncs.com/ws/v1",
};
const createQuotedUrl = {
......
......@@ -9,7 +9,13 @@ Component({
* 组件的属性列表
*/
properties: {
isSend: Boolean
isSend: {
type: Boolean,
value: true,
observer: function(n) {
this.setData({isClear:n})
}
}
},
/**
......@@ -147,8 +153,9 @@ Component({
this.data.sr = sr
},
sendMsg() {
this.triggerEvent('send',this.data.inputValue)
this.setData({inputValue:''})
const {isClear} = this.data;
this.triggerEvent('send',this.data.inputValue);
if(isClear)this.setData({inputValue:''})
},
input(e) {
let { value:inputValue } = e.detail
......
......@@ -4,7 +4,7 @@
<view class="input-icon">
<gl-image data-type="2" webp src="/equity/keyboard.png" bind:tap="tabType" />
</view>
<view class="input-s" bind:tap="onPress">按住说话</view>
<view class="input-s" bind:tap="onPress">点击说话</view>
</block>
<block wx:else>
<view class="input-icon">
......
......@@ -81,9 +81,9 @@ Page({
taskStaffId,
tryCount,
user_tips,
promptOnOff:promptOnOff === 'true',
promptOnOff: promptOnOff === 'true',
avatar
},()=>{
}, () => {
this.getChatH()
})
WebSocketUtil.connect(`${scoket_url}/ai/sparring/${taskStaffId}_${(Math.random() + '').slice(2)}`, () => {
......@@ -195,7 +195,15 @@ Page({
})
}
}
if (history.length == 14) {
if (history.length == 8) {
this.setData({
contentList: [...this.data.contentList, {
role: 2,
spkTime: new Date().format('yyyy-MM-dd hh:mm:ss'),
content: item
}]
});
this.sparringCommit()
return
}
......@@ -286,13 +294,13 @@ Page({
JSON.stringify({
type,
question: question_d,
history: JSON.stringify([i % 2 == 0 ? {
history: JSON.stringify([...history, i % 2 == 0 ? {
role: 'system',
content: `以女性的口吻回复,建议${i+45}个字以内`
} : {
role: 'system',
content: `以男性的口吻回复,建议${i+45}个字以内`
}, ...history])
}])
})
)
}
......@@ -348,6 +356,10 @@ Page({
})
},
sparringCommit() {
this.setData({isEnd:true,promptOnOff:false},()=>{
this.getChatH();
})
const history = []
if (this.data.contentList.length) {
for (let i = 0; i < this.data.contentList.length; i++) {
......@@ -400,9 +412,6 @@ Page({
}, () => {
this.showRemind('结束提醒', () => {
this.sparringCommit();
this.setData({
isEnd: true
})
}, () => {
console.log(this)
});
......@@ -457,11 +466,13 @@ Page({
promptOnOff,
isEnd
} = _this.data;
let h1 = 240,h2=850,h3=370
if(isPad) {
h2=90
let h1 = 240,
h2 = 600,
h3 = 104
if (isPad) {
h2 = 90
}
let chat_H = `calc(100vh - var(--fontSize${( promptOnOff ? 0 : -h1) + h2 + (isEnd ? 0 : h3)}) - var(--envSafeAreaInsetBottom))`;
let chat_H = `calc(100vh - var(--fontSize${( promptOnOff ? h1 : 0) + h2 + (isEnd ? 0 : h3)}) - var(--envSafeAreaInsetBottom))`;
_this.setData({
chat_H
})
......
......@@ -3,14 +3,16 @@ page {
background: #f7f8fa;
}
.avatar-box {
height: var(--fontSize750);
height: var(--fontSize380);
width: 100%;
position: fixed;
top: var(--fontSize90);
top: var(--fontSize180);
background: #333333;
left: 0;
text-align: center;
.avatar {
width: 100%;
height: 100%;
height: var(--fontSize380);
width: var(--fontSize380);
}
}
.camera-box {
......@@ -44,7 +46,7 @@ page {
position: fixed;
left: 0;
width: 100%;
top: var(--fontSize840);
top: var(--fontSize560);
padding: var(--fontSize24) 0;
padding-bottom: 10rpx;
.chat-item {
......
......@@ -55,7 +55,7 @@
</scroll-view>
</view>
<view class="input-box" wx:if="{{!isEnd}}">
<input-box bindsend="send" bind:speech="speech"></input-box>
<input-box bindsend="send" bind:speech="speech" isSend="{{isSend}}"></input-box>
</view>
<view class="tips-box" wx:if="{{promptOnOff && showTips && !isEnd}}">
......
let socket = null;
let connected = false;
let messageCallback = null
function connect(url,callback) {
let connected_url = null
function connect(url,callback,msg) {
connected_url = url
socket = wx.connectSocket({
url: url
url: connected_url
});
socket.onOpen(() => {
connected = true;
callback && callback()
if(msg) {
send(msg)
}
});
socket.onClose(() => {
......@@ -29,6 +34,8 @@ function send(message) {
socket.send({
data: message
});
}else {
connect(connected_url,null,message)
}
}
function disconnect() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!