This commit is contained in:
2023-10-10 14:43:59 +08:00
parent 68f339a587
commit 8b0962781c
2 changed files with 204 additions and 82 deletions

View File

@ -1,17 +1,20 @@
import baseurl from './baseurl.js'
// Authorization: 'Bearer' + ' ' + uni.getStorageSync('token')
// Authorization: 'Bearer' + ' ' + uni.getStorageSync('token')
var request = function(config) {
return new Promise((resolve, rejected) => {
uni.showLoading({
title: ''
});
if (config.url != '/nurseApplet/chatRecord/updateReadStatus' && config.url !=
"/nurseApplet/chatRecord/sendMessage") {
uni.showLoading({
title: ''
});
}
uni.request({
url: baseurl + config.url,
data: config.data,
method: config.method,
timeout: 10000,
header:config.header,
header: config.header,
success(res) {
uni.hideLoading();
resolve(res.data)
@ -24,4 +27,4 @@ var request = function(config) {
})
}
export default request
export default request

View File

@ -6,11 +6,13 @@
</view> -->
<!-- 聊天渲染列表 -->
<!-- scroll-y scroll-into-view="placeholder" scroll-top="500" scroll-with-animation -->
<scroll-view scroll-y="true" :scroll-top='scrollTop'>
<scroll-view scroll-y="true" :scroll-top='scrollTop' id="demo"
:style="'height:calc(100vh - '+ inputboxtop +'px)'" scroll-with-animation="true">
<view style="height: 85vh; padding-top: 200rpx;" @tap='touchend'>
<view class="snedItem" v-for="(item, index) in newsList" :key="index">
<view class="ifSend" v-if="item.senderName == userName">
<view class="sendBox" v-if="item.content">{{item.content}}</view>
<view class="sendBox" v-if="item.messageType=='1'">{{item.content}}</view>
<image v-if="item.messageType=='2'" :src="baseurl+item.content" class="snedItemimage" />
<image class="head" src="@/static/headsculpture.png"></image>
</view>
<view class="doctorSend" v-else>
@ -20,10 +22,9 @@
<view class="sendBox" v-if="item.content">{{item.content}}</view>
</view>
</view>
<!-- <image v-if="item.img" :src="item.img" mode="scaleToFill" class="touch-active" />
<video v-if="item.video" :src="item.video"></video> -->
<video v-if="item.video" :src="item.video"></video>
</view>
<view class="placeholder" id="placeholder" v-if="showFunBtn"></view>
<!-- <view class="placeholder" id="placeholder" v-if="showFunBtn"></view> -->
</view>
</scroll-view>
@ -35,7 +36,7 @@
<!-- 输入框 -->
<view class="input-box-flex-grow"> <input type="text" class="contenxxt" id="input"
v-model="formData.content" :hold-keyboard="true" :confirm-type="'send'" :confirm-hold="true"
placeholder-style="color:#DDDDDD;" :cursor-spacing="10" /> </view>
placeholder-style="color:#DDDDDD;" :cursor-spacing="10" @confirm='sendconfirm' /> </view>
<!-- 选择表情包 -->
<!-- <image class=" icon_btn_add" :src="require('@/static/ico/emoji.png')" @tap="exprec"></image> -->
<!-- 发送消息按钮 -->
@ -80,9 +81,11 @@
getChatRecord,
markRead
} from '@/api/pagesC/seekadvicefrom/seekadvicefrom.js';
import baseurl from '@/api/baseurl.js'
export default {
data() {
return {
baseurl:'',
title: '',
SOCKETURL: 'ws://192.168.16.212:8088/webSocket/1',
socketOpen: false,
@ -139,6 +142,7 @@
},
],
scrollTop: 999999,
inputboxtop: undefined,
};
},
onReady() { //
@ -147,6 +151,7 @@
});
},
onLoad(options) {
this.baseurl = baseurl;
// uni.closeSocket()
this.currentItem = JSON.parse(options.item)
this.title = this.currentItem.doctorName //
@ -174,7 +179,12 @@
})
this.newsList = res.data
setTimeout(() => {
this.scrollTop = this.scrollTop + 1;
let query = uni.createSelectorQuery().in(this);
//iddemo
query.select('.input-box').boundingClientRect(data => {
this.inputboxtop = data.height //
this.scrollTop = this.scrollTop + 1;
}).exec();
}, 100)
})
},
@ -185,20 +195,41 @@
}
markRead(markReadData)
},
//
sendconfirm(value) {
this.sendout();
},
touchend() {
this.showFunBtn = false; //
this.showExpre = false; //
this.showOften = false; //
uni.hideKeyboard();
setTimeout(() => {
let query = uni.createSelectorQuery().in(this);
//iddemo
query.select('.input-box').boundingClientRect(data => {
this.inputboxtop = data.height //
this.scrollTop = this.scrollTop + 1;
}).exec();
}, 200)
},
goshowFunBtn() {
this.showFunBtn = true; //
this.showFunBtn = !this.showFunBtn; //
uni.hideKeyboard();
setTimeout(() => {
this.scrollTop = this.scrollTop + 1;
}, 100)
let query = uni.createSelectorQuery().in(this);
//iddemo
query.select('.input-box').boundingClientRect(data => {
console.log(data)
this.inputboxtop = data.height //
setTimeout(() => {
this.scrollTop = this.scrollTop + 1;
}, 200)
}).exec();
}, 300)
},
sendout() {
const that = this
if (this.socketOpen == false) {
return
}
@ -206,38 +237,53 @@
senderName: this.userName,
content: this.formData.content
})
let message = this.formData.content
try {
const that = this
uni.sendSocketMessage({
data: message,
success(res) {
console.log(that.currentItem)
let obj = {
consultationId: that.currentItem.id,
senderId: that.currentItem.patientId,
senderName: that.currentItem.patientName,
recipientId: that.currentItem.doctorId,
recipientName: that.currentItem.doctorName,
messageType: 1,
sendTime: new Date(),
// messageType: (0 1 2 3 4 5 6 )
content: message
}
sendMessage(obj).then(res => {
console.log(res);
setTimeout(() => {
that.scrollTop = that.scrollTop + 1;
}, 100)
})
}
})
} catch (e) {
console.log(e, '断线了')
// uni.closeSocket();
let obj = {
consultationId: that.currentItem.id,
senderId: that.currentItem.patientId,
senderName: that.currentItem.patientName,
recipientId: that.currentItem.doctorId,
recipientName: that.currentItem.doctorName,
messageType: 1,
sendTime: new Date(),
content: this.formData.content
}
this.formData.content = '' //
sendMessage(obj).then(res => {
that.formData.content = '' //
setTimeout(() => {
that.scrollTop = that.scrollTop + 1;
}, 100)
if (res.code != 200) {
}
})
// try {
// const that = this
// let message = this.formData.content
// uni.sendSocketMessage({
// data: message,
// success(res) {
// let obj = {
// consultationId: that.currentItem.id,
// senderId: that.currentItem.patientId,
// senderName: that.currentItem.patientName,
// recipientId: that.currentItem.doctorId,
// recipientName: that.currentItem.doctorName,
// messageType: 1,
// sendTime: new Date(),
// // messageType: (0 1 2 3 4 5 6 )
// content: message
// }
// sendMessage(obj).then(res => {
// setTimeout(() => {
// that.scrollTop = that.scrollTop + 1;
// }, 100)
// })
// }
// })
// } catch (e) {
// console.log(e, '线')
// // uni.closeSocket();
// }
},
//
oftenc(e) {
@ -248,26 +294,50 @@
this.formData.content = !this.formData.content ? e : this.formData.content + e;
},
//
switchFun() {
this.showOften = false; //
this.showExpre = false; //
this.showFunBtn = !this.showFunBtn; //
uni.hideKeyboard();
},
// switchFun() {
// this.showOften = false; //
// this.showExpre = false; //
// this.showFunBtn = !this.showFunBtn; //
// uni.hideKeyboard();
// setTimeout(() => {
// let query = uni.createSelectorQuery().in(this);
// //iddemo
// query.select('.input-box').boundingClientRect(data => {
// this.inputboxtop = data.height //
// }).exec();
// this.scrollTop = this.scrollTop + 1;
// }, 200)
// },
//
oftenx() {
this.showFunBtn = false; //
this.showExpre = false; //
this.showOften = !this.showOften; //
uni.hideKeyboard();
},
// oftenx() {
// this.showFunBtn = false; //
// this.showExpre = false; //
// this.showOften = !this.showOften; //
// uni.hideKeyboard();
// setTimeout(() => {
// let query = uni.createSelectorQuery().in(this);
// //iddemo
// query.select('.input-box').boundingClientRect(data => {
// this.inputboxtop = data.height //
// }).exec();
// this.scrollTop = this.scrollTop + 1;
// }, 100)
// },
//
exprec() {
this.showFunBtn = false; //
this.showOften = false; //
this.showExpre = !this.showExpre; //
uni.hideKeyboard();
},
// exprec() {
// this.showFunBtn = false; //
// this.showOften = false; //
// this.showExpre = !this.showExpre; //
// uni.hideKeyboard();
// setTimeout(() => {
// let query = uni.createSelectorQuery().in(this);
// //iddemo
// query.select('.input-box').boundingClientRect(data => {
// this.inputboxtop = data.height //
// }).exec();
// this.scrollTop = this.scrollTop + 1;
// }, 100)
// },
//
tapGrid(index) {
if (index == 0) {
@ -288,29 +358,70 @@
},
//
chooseImage(sourceType) {
console.log(sourceType, "sourceType");
var that = this
if (this.socketOpen == false) {
return
}
uni.chooseImage({
sourceType,
sizeType: ["compressed"],
success: (res) => {
console.log(res, "kkkk");
this.showFunBtn = false;
for (let i = 0; i < res.tempFilePaths.length; i++) {
const params = {
contentType: 3,
content: res.tempFilePaths[i],
};
this.newsList.push({
img: res.tempFilePaths[i]
that.showFunBtn = false;
setTimeout(() => {
let query = uni.createSelectorQuery().in(this);
//iddemo
query.select('.input-box').boundingClientRect(data => {
console.log(data)
this.inputboxtop = data.height //
setTimeout(() => {
this.scrollTop = this.scrollTop + 1;
}, 200)
}).exec();
}, 300)
res.tempFilePaths.forEach(e => {
that.newsList.push({
imgurl: e,
senderName: that.userName,
})
console.log(this.newsList, '图片');
}
uni.uploadFile({
url: baseurl +
'/nurseApplet/consultationInfo/uploadConsultationFile',
filePath: e,
name: 'file',
timeout: 5000,
success(resp) {
console.log(resp)
var fileurls = JSON.parse(resp.data)
let obj = {
consultationId: that.currentItem.id,
senderId: that.currentItem.patientId,
senderName: that.currentItem.patientName,
recipientId: that.currentItem.doctorId,
recipientName: that.currentItem.doctorName,
messageType: 2,
sendTime: new Date(),
content: fileurls.fileUrl
}
sendMessage(obj).then(respp => {
console.log(respp)
})
}
})
})
},
});
},
//
touchstart() {
uni.hideKeyboard();
setTimeout(() => {
let query = uni.createSelectorQuery().in(this);
//iddemo
query.select('.input-box').boundingClientRect(data => {
this.inputboxtop = data.height //
this.scrollTop = this.scrollTop + 1;
}).exec();
}, 200)
},
scoket() {
const that = this
@ -324,7 +435,6 @@
that.socketOpen = true
that.reset()
})
uni.onSocketError(err => {
console.log('webScoket连接打开失败', err);
if (err && err.code != 1000) {
@ -336,7 +446,6 @@
}, 3 * 1000)
}
})
uni.onSocketClose(err => {
console.log('webScoket连接关闭', err);
if (err && err.code !== 1000) {
@ -348,7 +457,6 @@
}, 3 * 1000)
}
})
uni.onSocketMessage(res => {
console.log("webScoket监听收到的信息", res);
that.newsList.push({
@ -373,9 +481,9 @@
},
fail(err) {
console.log('心跳发送失败,重新连接...');
socketOpen = true
that.socketOpen = true
uni.connectSocket({
url: this.SOCKETURL
url: that.SOCKETURL
})
}
})
@ -387,7 +495,6 @@
})
}
},
onUnload() {
clearInterval(this.timeoutObj);
if (this.socketOpen == true) {
@ -402,6 +509,10 @@
background-color: #f3f3f3;
}
#demo {
transition: all 0.3s ease;
}
.content {
.input-box {
position: fixed;
@ -558,6 +669,12 @@
.snedItem {
padding: 0rpx 30rpx 40rpx 30rpx;
.snedItemimage {
width: 200rpx;
height: 200rpx;
border-radius: 3rpx;
}
}
.ifSend {
@ -610,6 +727,8 @@
.placeholder {
height: 200rpx;
transition: all 0.3s ease;
transform: translateY(0%) !important;
}
.title {