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,26 +12,19 @@ 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) { const data = {
if (i == src.length - 1) { startUrl: url,
const data = { policyId: id,
startUrl: url, endUrl
policyId: id, };
endUrl handlePic(data).then(({ data: res }) => {
}; console.log(res);
handlePic(data).then(({ data: res }) => { for (let i = 0; i < src.length; i++) {
console.log(res); src[i].setAttribute('src', res[i].name);
for (let i = 0; i < src.length; i++) {
src[i].setAttribute('src', res[i].name);
}
});
} }
} 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');

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,68 +287,64 @@ 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: { var that = this;
message, if (
appuid: '23941' //测试使用id res.data.replayType == 'NEEDCONTRACTUSER' ||
} res.data.replayType == 'MSG' ||
}).then(res => { res.data.replayType == 'UNKNOWN'
var that = this; ) {
if ( setTimeout(function() {
res.data.replayType == 'NEEDCONTRACTUSER' || that.chats.push({
res.data.replayType == 'MSG' || sender: 0,
res.data.replayType == 'UNKNOWN' send_con: res.data.msgInfos,
) { send_timestamp: that.getTime(),
setTimeout(function() { type: res.data.replayType
that.chats.push({ });
sender: 0, that.isLoading = 0;
send_con: res.data.msgInfos, that.getIsShowTime();
send_timestamp: that.getTime(), that.chatWindowActive();
type: res.data.replayType that.updateHistory(that.chats.length);
}); }, 1000);
that.isLoading = 0; } else {
that.getIsShowTime(); let all;
that.chatWindowActive(); if (res.data.replayType == 'QA') {
that.updateHistory(that.chats.length); //输入"你能做些什么"测试,右侧进入问答页面
}, 1000); all = res.data.replyQADatas;
} else { } else if (res.data.replayType == 'CONTRACT') {
let all; //输入"劳动合同"测试,跳转下载链接
if (res.data.replayType == 'QA') { all = res.data.replyContractDatas;
//输入"你能做些什么"测试,右侧进入问答页面 } else if (res.data.replayType == 'LAW') {
all = res.data.replyQADatas; //输入"宪法"测试,右侧进入法律页面
} else if (res.data.replayType == 'CONTRACT') { all = res.data.replyLawDatas;
//输入"劳动合同"测试,跳转下载链接 } else if (res.data.replayType == 'CASE') {
all = res.data.replyContractDatas; //输入"强奸案案例"测试,右侧进入案例页面
} else if (res.data.replayType == 'LAW') { all = res.data.replyCaseDatas;
//输入"宪法"测试,右侧进入法律页面
all = res.data.replyLawDatas;
} else if (res.data.replayType == 'CASE') {
//输入"强奸案案例"测试,右侧进入案例页面
all = res.data.replyCaseDatas;
}
let list = [];
for (let i = 0; i < 5; i++) {
if (all[i]) {
list.push(all[i]);
} }
let list = [];
for (let i = 0; i < 5; i++) {
if (all[i]) {
list.push(all[i]);
}
}
setTimeout(function() {
that.chats.push({
sender: 0,
send_con: res.data.msgInfos,
send_timestamp: that.getTime(),
type: res.data.replayType,
list
});
that.isLoading = 0;
that.getIsShowTime();
that.chatWindowActive();
that.updateHistory(that.chats.length);
}, 1000);
} }
setTimeout(function() {
that.chats.push({
sender: 0,
send_con: res.data.msgInfos,
send_timestamp: that.getTime(),
type: res.data.replayType,
list
});
that.isLoading = 0;
that.getIsShowTime();
that.chatWindowActive();
that.updateHistory(that.chats.length);
}, 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);
}); });
} }
}, },