|
@@ -7,18 +7,20 @@
|
|
|
<view class="time" v-if="index == 0 || item.time - list[index-1].time >= 300000">
|
|
|
<text>{{formatDate(item.time)}}</text>
|
|
|
</view>
|
|
|
- <view class="list" :id="item.speaker != user._id ? 'left' : 'right'">
|
|
|
- <image class="avatar" :src="item.avatar"></image>
|
|
|
+ <view class="list" :id="item.speaker._id != user._id ? 'left' : 'right'">
|
|
|
+ <image class="avatar"
|
|
|
+ :src="item.speaker&&item.speaker.icon.length>0?item.speaker.icon[0].url:config.user_url[0].url"
|
|
|
+ mode=""></image>
|
|
|
<text class="record" v-if="item.type == 'text'">{{item.content}}</text>
|
|
|
<image :src="item.content" v-if="item.type == 'image'" @tap="onPreview(item.content)"
|
|
|
mode="widthFix">
|
|
|
</image>
|
|
|
<view class="record" v-if="item.type == 'record'" @tap="onPlay(item.voice,index)">
|
|
|
- <uni-icons v-if="item.speaker != user._id" custom-prefix="iconfont"
|
|
|
+ <uni-icons v-if="item.speaker._id != user._id" custom-prefix="iconfont"
|
|
|
type="icon-zuobofang" size="15" color="#333333">
|
|
|
</uni-icons>
|
|
|
<text class="voice">{{item.content}}</text>"
|
|
|
- <uni-icons v-if="item.speaker == user._id" custom-prefix="iconfont"
|
|
|
+ <uni-icons v-if="item.speaker._id == user._id" custom-prefix="iconfont"
|
|
|
type="icon-youbofang" size="15" color="#ffffff">
|
|
|
</uni-icons>
|
|
|
</view>
|
|
@@ -29,24 +31,9 @@
|
|
|
</scroll-view>
|
|
|
</view>
|
|
|
<view class="bottom">
|
|
|
- <uni-icons v-if="!isRecorder" @tap="onRecorderchange" type="mic" size="25" color="#333333"></uni-icons>
|
|
|
- <uni-icons v-else @tap="onRecorderchange" type="mic-filled" size="25" color="#333333"></uni-icons>
|
|
|
- <view class="onRecorder" v-if="isRecorder" @touchstart="onStart" @touchend="onEnd"
|
|
|
- :id="inrecord ? 'inRecorder' : ''">
|
|
|
- 按住说话
|
|
|
- </view>
|
|
|
- <input type="text" placeholder="输入你想说的话" v-model="chat" confirm-type="send" @confirm="onSend" v-else>
|
|
|
- <uni-icons @tap="showPopup" type="plus" size="30" color="#333333"></uni-icons>
|
|
|
+ <submit_1 :record="record" :inrecord="inrecord" :isRecorder="isRecorder" @toSend="toSend" @heights="heights"
|
|
|
+ @onRecorderchange="onRecorderchange" @onStart="onStart" @onEnd="onEnd"></submit_1>
|
|
|
</view>
|
|
|
- <!-- 底部弹出层 -->
|
|
|
- <uni-popup ref="popup" background-color="#fff">
|
|
|
- <view class="other">
|
|
|
- <view class="list" @tap="chooseImage">
|
|
|
- <uni-icons type="image-filled" size="26" color="#8183F2"></uni-icons>
|
|
|
- <text>图片</text>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </uni-popup>
|
|
|
<!-- 语音 -->
|
|
|
<uni-popup ref="voice" background-color="#fff">
|
|
|
<view class="image">
|
|
@@ -57,7 +44,11 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+ import submit_1 from './common/submit_1.vue';
|
|
|
export default {
|
|
|
+ components: {
|
|
|
+ submit_1,
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
id: '',
|
|
@@ -70,51 +61,14 @@
|
|
|
user: {},
|
|
|
config: {},
|
|
|
// 聊天列表数据
|
|
|
- list: [{
|
|
|
- content: "这是一条虚拟消息",
|
|
|
- speaker: '6535c8a6fbaf18f8aa656800',
|
|
|
- type: 'text',
|
|
|
- avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
|
|
- time: 1683791638972
|
|
|
- },
|
|
|
- {
|
|
|
- content: "哈哈",
|
|
|
- speaker: '6535c8a6fbaf18f8aa656800',
|
|
|
- type: 'text',
|
|
|
- avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
|
|
- time: 1683793245623
|
|
|
- },
|
|
|
- {
|
|
|
- content: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png",
|
|
|
- speaker: '6535c8a6fbaf18f8aa656800',
|
|
|
- type: 'image',
|
|
|
- avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
|
|
- time: 1683793315399
|
|
|
- },
|
|
|
- {
|
|
|
- content: "这是一条虚拟消息",
|
|
|
- speaker: '6535c8a6fbaf18f8aa65680c',
|
|
|
- type: 'text',
|
|
|
- avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
|
|
- time: 1683793764803
|
|
|
- },
|
|
|
- {
|
|
|
- content: "10",
|
|
|
- voice: "http://tmp/PlLDxzC6sRZc42d3f3f69e818a1612ed8917a6dff9eb.durationTime=2906.aac",
|
|
|
- speaker: '6535c8a6fbaf18f8aa656800',
|
|
|
- type: 'record',
|
|
|
- avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
|
|
- time: 1683795488873
|
|
|
- },
|
|
|
- ],
|
|
|
+ list: [],
|
|
|
total: 0,
|
|
|
skip: 0,
|
|
|
limit: 20,
|
|
|
- bgAudioManager: '', // 全局音频播放
|
|
|
record: '', // 全局唯一录音管理区
|
|
|
inrecord: false, // 是否处于录音状态
|
|
|
- chat: '', // 用户在聊天框中输入的内容
|
|
|
isRecorder: false, // 是否处于语音状态
|
|
|
+ bgAudioManager: '', // 全局音频播放
|
|
|
poaMessgae: 'poaMessgae',
|
|
|
}
|
|
|
},
|
|
@@ -202,6 +156,11 @@
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ //输入框高度
|
|
|
+ heights(e) {
|
|
|
+ const that = this;
|
|
|
+ that.poalast()
|
|
|
+ },
|
|
|
// 切换语音 or 键盘
|
|
|
onRecorderchange() {
|
|
|
const that = this
|
|
@@ -235,19 +194,13 @@
|
|
|
return that.global.toast('请说话久一点')
|
|
|
}
|
|
|
let mess = {
|
|
|
- speaker: that.user._id,
|
|
|
- speaker_type: that.user.role,
|
|
|
- group: that.groupId,
|
|
|
- patient: that.patientId,
|
|
|
- doctor: that.doctorId,
|
|
|
- avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
|
|
type: 'record',
|
|
|
voice: res.tempFilePath,
|
|
|
content: Math.round(res.duration / 1000), // 时长
|
|
|
time: new Date() - 0
|
|
|
}
|
|
|
// 写在上传回调内
|
|
|
- that.sendmessage(JSON.stringify(mess))
|
|
|
+ that.toSend(mess)
|
|
|
})
|
|
|
that.record.onError(err => {
|
|
|
that.global.toast('获取录音失败')
|
|
@@ -265,75 +218,40 @@
|
|
|
that.bgAudioManager = null
|
|
|
})
|
|
|
},
|
|
|
- // 点击更多
|
|
|
- showPopup() {
|
|
|
- const that = this
|
|
|
- that.$refs.popup.open('bottom')
|
|
|
- },
|
|
|
// 预览图片
|
|
|
onPreview(e) {
|
|
|
uni.previewImage({
|
|
|
urls: [e]
|
|
|
})
|
|
|
},
|
|
|
- // input 输入框 回车发送消息事件
|
|
|
- onSend() {
|
|
|
- const that = this
|
|
|
- // 发送消息需要将 对象转换成字符串格式 接收消息在转换成对象
|
|
|
- let mess = {
|
|
|
+ // 发送消息
|
|
|
+ async toSend(e) {
|
|
|
+ const that = this;
|
|
|
+ const mess = {
|
|
|
speaker: that.user._id,
|
|
|
speaker_type: that.user.role,
|
|
|
group: that.groupId,
|
|
|
patient: that.patientId,
|
|
|
doctor: that.doctorId,
|
|
|
- avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
|
|
- type: 'text',
|
|
|
- content: that.chat,
|
|
|
- time: new Date() - 0
|
|
|
}
|
|
|
- that.sendmessage(JSON.stringify(mess))
|
|
|
- that.chat = ''
|
|
|
- },
|
|
|
- // 发送图片
|
|
|
- chooseImage() {
|
|
|
- const that = this;
|
|
|
- let serverFile = that.$config.serverFile;
|
|
|
- uni.chooseImage({
|
|
|
- count: 1,
|
|
|
- sizeType: ['original', 'compressed'],
|
|
|
- sourceType: ['album', 'camera'],
|
|
|
- success: async function(res) {
|
|
|
- let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
|
|
|
- const arr = await that.$apifile(`/applet/upload`, 'file', tempFile[0],
|
|
|
- 'file');
|
|
|
- if (arr.errcode == '0') {
|
|
|
- let mess = {
|
|
|
- speaker: that.user._id,
|
|
|
- speaker_type: that.user.role,
|
|
|
- group: that.groupId,
|
|
|
- patient: that.patientId,
|
|
|
- doctor: that.doctorId,
|
|
|
- avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
|
|
- type: 'image',
|
|
|
- content: serverFile + arr.data.uri,
|
|
|
- time: new Date() - 0
|
|
|
- }
|
|
|
- that.sendmessage(JSON.stringify(mess))
|
|
|
- that.$refs.popup.close()
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: arr.errmsg,
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- // 发送消息
|
|
|
- sendmessage(e) {
|
|
|
- const that = this;
|
|
|
- that.list.push(JSON.parse(e))
|
|
|
- that.poalast() // 定位消息最后一行
|
|
|
+ const data = {
|
|
|
+ ...e,
|
|
|
+ ...mess
|
|
|
+ }
|
|
|
+ let res = await that.$api(`/chat`, 'POST', data)
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ that.list.push({
|
|
|
+ ...e,
|
|
|
+ ...mess
|
|
|
+ });
|
|
|
+ that.$set(that, `isRecorder`, false);
|
|
|
+ that.poalast() // 定位消息最后一行
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
// 定位到消息最后一行
|
|
|
poalast() {
|
|
@@ -365,7 +283,7 @@
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
flex-direction: column;
|
|
|
- margin-bottom: 2vw;
|
|
|
+ margin: 2vw 0;
|
|
|
|
|
|
text {
|
|
|
background: rgba(0, 0, 0, 0.6);
|
|
@@ -439,51 +357,7 @@
|
|
|
}
|
|
|
|
|
|
.bottom {
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- justify-content: space-between;
|
|
|
- padding: 3vw;
|
|
|
background: var(--mainColor);
|
|
|
-
|
|
|
- input {
|
|
|
- width: 75vw;
|
|
|
- height: 6vh;
|
|
|
- background: #F7F7F9;
|
|
|
- border-radius: 2vw;
|
|
|
- padding: 0 2vw;
|
|
|
- font-size: var(--font14Size);
|
|
|
- box-sizing: border-box;
|
|
|
- }
|
|
|
-
|
|
|
- .onRecorder {
|
|
|
- width: 75vw;
|
|
|
- height: 6vh;
|
|
|
- line-height: 6vh;
|
|
|
- text-align: center;
|
|
|
- background: #F7F7F9;
|
|
|
- border-radius: 2vw;
|
|
|
- padding: 0 2vw;
|
|
|
- font-size: var(--font14Size);
|
|
|
- box-sizing: border-box;
|
|
|
- }
|
|
|
-
|
|
|
- #inRecorder {
|
|
|
- background: #cdcdcd;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- .scroll-view {
|
|
|
- position: absolute;
|
|
|
- top: 0;
|
|
|
- left: 0;
|
|
|
- right: 0;
|
|
|
- bottom: 0;
|
|
|
-
|
|
|
- .list-scroll-view {
|
|
|
- display: flex;
|
|
|
- flex-direction: column;
|
|
|
- margin: 2vw;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -497,23 +371,17 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- .other {
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- padding: 6vw;
|
|
|
- box-sizing: border-box;
|
|
|
+ .scroll-view {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
|
|
|
- .list {
|
|
|
+ .list-scroll-view {
|
|
|
display: flex;
|
|
|
- align-items: center;
|
|
|
flex-direction: column;
|
|
|
- margin-right: 2vw;
|
|
|
-
|
|
|
- text {
|
|
|
- font-size: var(--font13Size);
|
|
|
- color: var(--f33Color);
|
|
|
- margin-top: 1vw;
|
|
|
- }
|
|
|
+ margin: 0 2vw;
|
|
|
}
|
|
|
}
|
|
|
</style>
|