This commit is contained in:
熊丽君
2021-08-17 08:41:17 +08:00
parent d27bf459d1
commit 96054835fd
5 changed files with 127 additions and 103 deletions

View File

@ -34,3 +34,11 @@ export function getPolicyMatch(params) {
params params
}); });
} }
// 中转图片
export function handlePic(data) {
return request({
url: '/mobile/handlePic',
method: 'post',
data
});
}

10
src/api/service.js Normal file
View File

@ -0,0 +1,10 @@
import request from '@/utils/request';
// 给某人发送信息
export function send(data) {
return request({
url: '/chat/send',
method: 'post',
data
});
}

View File

@ -12,10 +12,8 @@ export function formatRichText(url, id) {
for (let i = 0; i < src.length; i++) { for (let i = 0; i < src.length; i++) {
const string = src[i].getAttribute('src'); const string = src[i].getAttribute('src');
endUrl.push(string); endUrl.push(string);
const flag = string.includes('http://'); }
// 域名存在 if (endUrl.length) {
if (status) {
if (i == src.length - 1) {
const data = { const data = {
startUrl: url, startUrl: url,
policyId: id, policyId: id,
@ -28,11 +26,6 @@ export function formatRichText(url, id) {
} }
}); });
} }
} else {
// 域名不存在并且不包含http
if (!flag) src[i].setAttribute('src', url + string);
}
}
// let src2 = document.querySelectorAll('#text .ql-editor a'); // let src2 = document.querySelectorAll('#text .ql-editor a');
let src2 = document.querySelectorAll('#text a'); let src2 = document.querySelectorAll('#text a');
for (let i = 0; i < src2.length; i++) { for (let i = 0; i < src2.length; i++) {

View File

@ -87,36 +87,18 @@
<div class="sendBtn" @click="send">发送</div> <div class="sendBtn" @click="send">发送</div>
</div> </div>
</div> </div>
<!-- 辅助工具 -->
<!-- <div class="tools">
<div class="toolsBox" v-if="tool_show == -1">
<img
v-for="(item, index) in tools"
:key="index"
:src="item.img"
:alt="item.name"
@click="getTool(index)"
/>
</div>
<legislation v-else-if="tool_show == 0"></legislation>
<lawcase v-else-if="tool_show == 1"></lawcase>
<dispute v-else-if="tool_show == 2"></dispute>
<aidedtools v-else-if="tool_show == 3"></aidedtools>
<replayDetail
:detail="replyDetail"
v-else-if="tool_show == -2"
></replayDetail>
</div> -->
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { send } from '@/api/service';
export default { export default {
data() { data() {
return { return {
path: 'ws://192.168.0.125:1919/webStock/1425648094011330560',
socket: '',
userid: '23941', userid: '23941',
// 待发送信息 // 待发送信息
message: '', message: '',
@ -152,13 +134,44 @@ export default {
this.getIsShowTime(); this.getIsShowTime();
} }
}, },
computed: {
...mapGetters(['avatar'])
},
mounted() { mounted() {
this.chatWindowActive(); this.chatWindowActive();
this.init();
}, },
methods: { methods: {
init: function() {
if (typeof WebSocket === 'undefined') {
alert('您的浏览器不支持socket');
} else {
// 实例化socket
this.socket = new WebSocket(this.path);
console.log(this.socket);
// 监听socket连接
this.socket.onopen = this.open;
// 监听socket错误信息
this.socket.onerror = this.error;
// 监听socket消息
this.socket.onmessage = this.getMessage;
}
},
open: function() {
console.log('socket连接成功');
},
error: function() {
console.log('连接错误');
},
getMessage(msg) {
console.log(msg.data);
console.log(JSON.parse(msg.data));
this.a = JSON.parse(msg.data);
// sendUserId
},
send: function(params) {
this.socket.send(params);
},
close: function() {
console.log('socket已经关闭');
},
// 原回车键失去回车功能 // 原回车键失去回车功能
stopEnter(event) { stopEnter(event) {
if (event.keyCode === 13) { if (event.keyCode === 13) {
@ -274,14 +287,9 @@ export default {
let message = this.message; let message = this.message;
this.message = ''; this.message = '';
this.isLoading = 1; //加载中 this.isLoading = 1; //加载中
this.$axios({ send({ sendText: message, sendUserId: '1422032951604023296' }).then(
url: 'http://rpai.365lawhelp.com/api/Reply/getReply', res => {
method: 'post', console.log(res);
data: {
message,
appuid: '23941' //测试使用id
}
}).then(res => {
var that = this; var that = this;
if ( if (
res.data.replayType == 'NEEDCONTRACTUSER' || res.data.replayType == 'NEEDCONTRACTUSER' ||
@ -335,7 +343,8 @@ export default {
that.updateHistory(that.chats.length); that.updateHistory(that.chats.length);
}, 1000); }, 1000);
} }
}); }
);
}, },
// 更新聊天记录 // 更新聊天记录
updateHistory(len) { updateHistory(len) {
@ -353,6 +362,10 @@ export default {
getTool(index) { getTool(index) {
this.tool_show = index; this.tool_show = index;
} }
},
destroyed() {
// 销毁监听
this.socket.onclose = this.close;
} }
}; };
</script> </script>

View File

@ -191,7 +191,7 @@ export default {
formData: { formData: {
handler: function() { handler: function() {
this.$nextTick(() => { this.$nextTick(() => {
this.formatRichText(this.formData.downloadUrl); this.formatRichText(this.formData.downloadUrl, this.formData.id);
}); });
} }
}, },