Commit 8f430b6c authored by 夏敏伟's avatar 夏敏伟

增加发送公告

parent 6cf7bb37
......@@ -2,7 +2,15 @@ import { get, post, addParam } from "../../util/http_util";
const PREFIX_RECORDS = 'api/rest/chat/chatRecords';
//分页查询群聊记录
//分页查询群聊记录
//查询小群
export const getRecordsByPagingTeam = (chatRoomId, currPage, pageSize, startTime, endTime, fromUserId,teamId) => {
let url = `${PREFIX_RECORDS}/chatroomTeam/page`;
url += addParam({ chatRoomId, currPage, pageSize, startTime, endTime, fromUserId,teamId });
return get(url);
}
//查询大群
export const getRecordsByPaging = (chatRoomId, currPage, pageSize, startTime, endTime, fromUserId,teamId) => {
let url = `${PREFIX_RECORDS}/chatroom/page`;
url += addParam({ chatRoomId, currPage, pageSize, startTime, endTime, fromUserId,teamId });
......
import { get, post, addParam } from "../../util/http_util";
import { get, post, fileUpload, addParam } from "../../util/http_util";
const PREFIX_CHATROOM = 'api/rest/chat/chatroom';
......@@ -13,7 +13,7 @@ export const createChatRoom = data => {
}
//查询某个聊天室(群组)详情信息
export const getChatRoomInfo = (id,userId) => {
export const getChatRoomInfo = (id, userId) => {
return get(`${PREFIX_CHATROOM}/info?id=${id}&userId=${userId}`);
}
......@@ -33,12 +33,12 @@ export const getChatRoomList = (userId) => {
}
//阅读(群组)信息
export const readChatRoom = (chatRoomId,userId) => {
export const readChatRoom = (chatRoomId, userId) => {
return get(`${PREFIX_CHATROOM}/readChatRoom?chatRoomId=${chatRoomId}&userId=${userId}`);
}
//设置聊天室(群组)当前议题
export const setChatRoomCurrentIssue = (chatRoomId,currentIssue) => {
export const setChatRoomCurrentIssue = (chatRoomId, currentIssue) => {
return get(`${PREFIX_CHATROOM}/setChatRoomCurrentIssue?chatRoomId=${chatRoomId}&currentIssue=${currentIssue}`);
}
......@@ -47,7 +47,10 @@ export const setChatRoomStatus = (chatRoomId) => {
return get(`${PREFIX_CHATROOM}/setChatRoomStatus?chatRoomId=${chatRoomId}`);
}
//上传文件
export const upLoadFiles = (bucket, data) => {
return fileUpload(`api/rest/file/upload?bucket=${bucket}`, data)
}
......
......@@ -43,8 +43,7 @@
<script>
import avatar from '../../../assets/img/ddkz/headPhoto.jpg';
import '../../../util/stomp.min.js'
import { getRecordsByPaging } from '../../../api/chat/chatRecords';
import { getRecordsByPagingTeam } from '../../../api/chat/chatRecords';
export default {
data() {
return {
......@@ -56,16 +55,19 @@ export default {
},
sendMessage: '',
chatMessageList: [],
stompClient: '',
ws: null,
// stompClient: '',
// ws: null,
analogDataList: [],
currentChatRoom: {}
currentChatRoom: {},
myStompClient: null
}
},
props: {
visible: Boolean,
analogData: Array,
stompClient: Object,
currentChatRoomInfo: Object
},
methods: {
handleClose() {
......@@ -73,7 +75,7 @@ export default {
},
sendMessageFn() {
if (this.sendMessage.trim().length > 0) {
this.stompClient.send("/app/sendToChatRoomTeam/" + this.currentChatRoom.id + '/' + this.currentChatRoom.teamId, {}, JSON.stringify({
this.myStompClient.send("/app/sendToChatRoomTeam/" + this.currentChatRoom.id + '/' + this.currentChatRoom.teamId, {}, JSON.stringify({
'content': this.sendMessage
}));
......@@ -89,24 +91,6 @@ export default {
const divscll = document.getElementById('chatContent');
divscll.scrollTop = divscll.scrollHeight;
},
connect() {
return new Promise((resolve, reject) => {
this.ws = new WebSocket(`ws://192.168.168.110:8081/websocket/my-websocket`);
this.stompClient && this.stompClient.connected && this.stompClient.disconnect();
this.stompClient = Stomp.over(this.ws);
this.stompClient.heartbeat.outgoing = 20000; //若使用STOMP 1.1 版本,默认开启了心跳检测机制(默认值都是10000ms)
this.stompClient.heartbeat.incoming = 0; //客户端不从服务端接收心跳包
this.stompClient.connect({ name: this.userInfo.account }, frame => {
this.listChatroom(this.analogDataList);
resolve("连接成功")
}, err => {
console.log(typeof err == "string" ? err : err.headers.message)
reject(typeof err == "string" ? err : err.headers.message)
});
})
},
listChatroom(data) {
//取消群聊的订阅
for (const sub in this.stompClient.subscriptions) {
......@@ -116,10 +100,6 @@ export default {
}
data.forEach(e => {
//订阅聊天室主题,订阅功能中设置ID:
this.stompClient.subscribe('/topic/multicast/' + e.id, data => {
debugger
}, { id: "multicast" + e.id + new Date().getTime() });
this.stompClient.subscribe('/topic/multicast/' + e.id + '/' + e.teamId, data => {
this.chatMessageList.push({
content: JSON.parse(data.body).content,
......@@ -131,7 +111,7 @@ export default {
},
getCurrentMessageList(item) {
//查询我方聊天记录
getRecordsByPaging(item.id, 1, 100, '2020-01-01 00:00:00', '2023-10-01 00:00:00', null, item.teamId).then(res1 => {
getRecordsByPagingTeam(item.id, 1, 100, '2020-01-01 00:00:00', '2023-10-01 00:00:00', null, item.teamId).then(res1 => {
this.chatMessageList = res1.records;
})
}
......@@ -151,7 +131,9 @@ export default {
this.dialogVisible = this.$props.visible;
this.analogDataList = this.$props.analogData;
this.currentChatRoom = this.$props.currentChatRoomInfo;
this.connect();
this.myStompClient = this.$props.stompClient;
//订阅
this.listChatroom(this.analogDataList);
this.getCurrentMessageList(this.$props.currentChatRoomInfo);
setTimeout(() => {
this.keepBottom();
......
......@@ -3,21 +3,21 @@
<div class="notice">
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="标题">
<el-input v-model="form.name"></el-input>
<el-input v-model="form.title"></el-input>
</el-form-item>
<el-form-item label="内容">
<el-input type="textarea" v-model="form.content"></el-input>
</el-form-item>
<el-form-item label="附件">
<el-upload class="upload-demo" drag action="https://jsonplaceholder.typicode.com/posts/" multiple>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">只能上传jpg/png文件,且不超过500kb</div>
<el-upload class="upload-demo" action="" :on-change="handleChange" :on-remove="handleRemove"
:file-list="form.fileList" :auto-upload="false" multiple :accept="formatFile">
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">支持导入word,pdf,ppt,mlf,xls!!!</div>
</el-upload>
</el-form-item>
<el-form-item style="text-align: center;">
<el-button type="default">取消</el-button>
<el-button type="success">发送</el-button>
<el-button type="success" @click="sendNotice">发送</el-button>
</el-form-item>
</el-form>
</div>
......@@ -26,27 +26,66 @@
<script>
import { upLoadFiles } from '../../../api/chat/chatRoom';
import { format_file } from '../../../util/http_util';
export default {
data() {
return {
dialogVisible: false,
form: {
name: '',
title: '',
content: '',
}
attachment: ''
},
formatFile: format_file(),
myStompClient: null,
currentChatRoom: {},
analogDataList: [],
}
},
props: {
visible: Boolean
visible: Boolean,
stompClient: Object,
currentChatRoomInfo: Object,
analogData: Array
},
methods: {
handleClose() {
this.$emit('handleCancel');
}
},
handleChange(file, fileList) {
let fd = new FormData();
fd.append('file', file.raw);
upLoadFiles('CHAT', fd).then(res => {
this.form.attachment = res;
});
},
handleRemove() { },
sendNotice() {
this.myStompClient.send(`/app/sendToChatRoom/${this.currentChatRoom.id}/${this.currentChatRoom.teamId}`, {}, JSON.stringify(this.form));
},
listChatroom(data) {
//取消群聊的订阅
for (const sub in this.stompClient.subscriptions) {
if (sub.startsWith("multicast")) {
this.stompClient.unsubscribe(sub);
}
}
data.forEach(e => {
//订阅聊天室主题,订阅功能中设置ID:
this.stompClient.subscribe('/topic/multicast/' + e.id, data => {
this.$emit('handleCancel');
this.$emit('showInfo',true, this.currentChatRoom);
}, { id: "multicast" + e.id + new Date().getTime() });
})
},
},
mounted() {
this.dialogVisible = this.$props.visible;
this.myStompClient = this.$props.stompClient;
this.currentChatRoom = this.$props.currentChatRoomInfo;
this.analogDataList = this.$props.analogData;
this.listChatroom(this.analogDataList);
}
}
</script>
......@@ -67,7 +106,8 @@ export default {
.el-dialog__header {
text-align: center;
.el-dialog__headerbtn{
.el-dialog__headerbtn {
top: 40px;
}
}
......@@ -79,8 +119,12 @@ export default {
background-color: transparent;
}
.el-upload-dragger{
.el-upload-dragger {
background-color: transparent;
}
}
.el-upload-list__item-name [class^="el-icon"] {
height: unset !important;
}
}
</style>
\ No newline at end of file
......@@ -142,9 +142,10 @@
</div>
</div>
</transition>
<noticeDialog-a v-if="visible" :visible="visible" @handleCancel="closeDialog"></noticeDialog-a>
<NoticeDialog v-if="visible" :visible="visible" @handleCancel="closeDialog" :stompClient="stompClient"
:currentChatRoomInfo="currentChatRoomInfo" :analogData="analogData" @showInfo="showInfo"></NoticeDialog>
<ChatRoomDialog v-if="chatRoomVisible" :visible="chatRoomVisible" @handleCancel="closeDialogChatRoom"
:analogData="analogData" :currentChatRoomInfo="currentChatRoomInfo">
:analogData="analogData" :currentChatRoomInfo="currentChatRoomInfo" :stompClient="stompClient">
</ChatRoomDialog>
<ChatRoomPeople v-if="chatRoomPeopleVisible" :visible="chatRoomPeopleVisible"
@handleCancel="closeDialogChatRoomPeople" :peopleList="peopleList"></ChatRoomPeople>
......@@ -177,6 +178,7 @@ import ChatRoomDialog from "./components/chatRoomDialog.vue";
import ChatRoomPeople from "./components/chatRoomPeople.vue";
import { getChatRoomList, getChatRoomInfo } from "../../api/chat/chatRoom";
import { getRecordsByPaging } from '../../api/chat/chatRecords';
import '../../util/stomp.min.js'
export default {
data() {
return {
......@@ -397,11 +399,13 @@ export default {
chatRoomPeopleVisible: false,
peopleList: [],
// chatMessageList: [],
currentChatRoomInfo: {}
currentChatRoomInfo: {},
stompClient: '',
ws: null
}
},
components: {
'noticeDialog-a': NoticeDialog,
NoticeDialog: NoticeDialog,
ChatRoomDialog: ChatRoomDialog,
ChatRoomPeople: ChatRoomPeople
},
......@@ -416,7 +420,6 @@ export default {
//查询聊天组的人员
getChatRoomInfo(item.id, this.userInfo.account).then(res => {
this.peopleList = res.chatRoomMemberRelationBOList;
});
//分页查询群聊天记录
getRecordsByPaging(item.id, 1, 100, '2020-01-01 00:00:00', '2023-10-01 00:00:00').then(res1 => {
......@@ -483,6 +486,23 @@ export default {
},
sendEmail() {
alert('敬请期待');
},
connect() {
return new Promise((resolve, reject) => {
this.ws = new WebSocket(`ws://192.168.168.106:8081/websocket/my-websocket`);
this.stompClient && this.stompClient.connected && this.stompClient.disconnect();
this.stompClient = Stomp.over(this.ws);
this.stompClient.heartbeat.outgoing = 20000; //若使用STOMP 1.1 版本,默认开启了心跳检测机制(默认值都是10000ms)
this.stompClient.heartbeat.incoming = 0; //客户端不从服务端接收心跳包
this.stompClient.connect({ name: this.userInfo.account }, frame => {
resolve("连接成功")
}, err => {
console.log(typeof err == "string" ? err : err.headers.message)
reject(typeof err == "string" ? err : err.headers.message)
});
})
}
},
computed: {
......@@ -496,6 +516,7 @@ export default {
},
mounted() {
this.queryChatRoomListFn();
this.connect();
}
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment