|
@@ -59,6 +59,7 @@
|
|
</template>
|
|
</template>
|
|
<script>
|
|
<script>
|
|
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex';
|
|
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex';
|
|
|
|
+import { createSocket } from '@/utils/websoket';
|
|
import envConfig from '@/config';
|
|
import envConfig from '@/config';
|
|
import vTags from './Tags.vue';
|
|
import vTags from './Tags.vue';
|
|
export default {
|
|
export default {
|
|
@@ -176,6 +177,12 @@ export default {
|
|
},
|
|
},
|
|
//初始化websoket
|
|
//初始化websoket
|
|
initWebSocket(id) {
|
|
initWebSocket(id) {
|
|
|
|
+ // createSocket('ws://' + this.envConfig.websoketUrl + '/sc-message/webSocket/' + id);
|
|
|
|
+ // const getsocketData = (e) => {
|
|
|
|
+ // const data = e && e.detail.data;
|
|
|
|
+ // console.log(data);
|
|
|
|
+ // };
|
|
|
|
+ // window.addEventListener('onmessageWS', getsocketData);
|
|
if ('WebSocket' in window) {
|
|
if ('WebSocket' in window) {
|
|
var serviceIp = this.envConfig.websoketUrl;
|
|
var serviceIp = this.envConfig.websoketUrl;
|
|
|
|
|
|
@@ -203,34 +210,37 @@ export default {
|
|
// this.send('addsocket');
|
|
// this.send('addsocket');
|
|
};
|
|
};
|
|
|
|
|
|
- //接收到消息的回调方法
|
|
|
|
|
|
+ // 接收到消息的回调方法
|
|
this.websocket.onmessage = function (event) {
|
|
this.websocket.onmessage = function (event) {
|
|
- debugger;
|
|
|
|
- let msg = JSON.parse(event.data);
|
|
|
|
- let i = msg.typeId - 1;
|
|
|
|
- if (msg.userId) {
|
|
|
|
- that.$notify({
|
|
|
|
- dangerouslyUseHTMLString: true,
|
|
|
|
- showClose: true,
|
|
|
|
- customClass: 'notice_icon',
|
|
|
|
- offset: 60,
|
|
|
|
- duration: 3000,
|
|
|
|
- message:
|
|
|
|
- "<div class='notice'><img src=" +
|
|
|
|
- that.imgList[i] +
|
|
|
|
- " class='img'/><div class='notice-content'><span class='title'>新消息通知</span><span class='nowrap'>" +
|
|
|
|
- '【' +
|
|
|
|
- msg.type +
|
|
|
|
- '】' +
|
|
|
|
- msg.content +
|
|
|
|
- '</span></div></div>'
|
|
|
|
- });
|
|
|
|
- that.getMessageList();
|
|
|
|
- that.getUnreadNumber();
|
|
|
|
|
|
+ if (typeof event.data == 'string') {
|
|
|
|
+ console.log(event.data);
|
|
|
|
+ } else {
|
|
|
|
+ let msg = JSON.parse(event.data);
|
|
|
|
+ let i = msg.typeId - 1;
|
|
|
|
+ if (msg.userId) {
|
|
|
|
+ that.$notify({
|
|
|
|
+ dangerouslyUseHTMLString: true,
|
|
|
|
+ showClose: true,
|
|
|
|
+ customClass: 'notice_icon',
|
|
|
|
+ offset: 60,
|
|
|
|
+ duration: 3000,
|
|
|
|
+ message:
|
|
|
|
+ "<div class='notice'><img src=" +
|
|
|
|
+ that.imgList[i] +
|
|
|
|
+ " class='img'/><div class='notice-content'><span class='title'>新消息通知</span><span class='nowrap'>" +
|
|
|
|
+ '【' +
|
|
|
|
+ msg.type +
|
|
|
|
+ '】' +
|
|
|
|
+ msg.content +
|
|
|
|
+ '</span></div></div>'
|
|
|
|
+ });
|
|
|
|
+ that.getMessageList();
|
|
|
|
+ that.getUnreadNumber();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- //连接关闭的回调方法
|
|
|
|
|
|
+ // 连接关闭的回调方法
|
|
this.websocket.onclose = function (ev) {
|
|
this.websocket.onclose = function (ev) {
|
|
console.log('WebSocket连接关闭');
|
|
console.log('WebSocket连接关闭');
|
|
this.websocket = null;
|
|
this.websocket = null;
|