|
@@ -1,289 +1,350 @@
|
|
|
<template>
|
|
|
- <div class="header" :class="[collapse ? 'collapse' : 'expand']">
|
|
|
- <v-tags></v-tags>
|
|
|
- <div class="header-right">
|
|
|
- <div class="header-user-con">
|
|
|
- <div class="formulation" @click="formulationToPage" v-if="permissionFiltering">
|
|
|
- <img src="@assets/img/formulation/icon_diygzt@2x.png" alt="" />
|
|
|
- 工作台自拟定 <span class="border"></span>
|
|
|
- </div>
|
|
|
- <div>欢迎你,{{ cruUserInfo.username }}</div>
|
|
|
- <!-- 用户头像 -->
|
|
|
- <div class="user-avator" @click="editUserInfo">
|
|
|
- <el-tooltip v-show="!cruUserInfo.photo" placement="bottom" content="编辑用户信息">
|
|
|
- <img src="@assets/img/formulation/icon_avatar@2x.png" alt="" />
|
|
|
- </el-tooltip>
|
|
|
- <img v-show="cruUserInfo.photo" :src="envConfig.baseImgApi + cruUserInfo.photo" style="object-fit: cover" />
|
|
|
- </div>
|
|
|
- <div class="message">
|
|
|
- <span class="main" @click="goMessage('unread')">
|
|
|
- <img src="@assets/img/btn_news.png" alt="" />
|
|
|
- <span class="iconfont point" v-if="messageNumber"></span>
|
|
|
- </span>
|
|
|
- <div class="msg-content" v-if="messageList && messageList.length">
|
|
|
- <p>消息通知</p>
|
|
|
- <ul>
|
|
|
- <li v-for="(items, index) in messageList" :key="index" @click="toUrl(items.typeId)" style="cursor: pointer">
|
|
|
- <img :src="imgList[items.typeId]" style="width: 30px; height: 30px" />
|
|
|
- <div>
|
|
|
- <span class="cont">【{{ items.shortName }}】{{ items.messageContent }}</span>
|
|
|
- <span class="time">{{ items.dateCreate }}</span>
|
|
|
- </div>
|
|
|
- </li>
|
|
|
- </ul>
|
|
|
- <el-button type="text" class="more" @click="goMessage('more')">查看更多</el-button>
|
|
|
- </div>
|
|
|
- <div class="msg-content" v-else>
|
|
|
- <p>消息通知</p>
|
|
|
- <ul>
|
|
|
- <li style="text-align: center; display: block; padding: 0 rem(20); line-height: rem(60)">暂无消息</li>
|
|
|
- </ul>
|
|
|
- <el-button type="text" class="more" disabled>查看更多</el-button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <span class="border"></span>
|
|
|
- <div class="logout" @click="logOut">
|
|
|
- <el-tooltip placement="bottom" content="退出">
|
|
|
- <i class="zoniot_font zoniot-icon-tuichu"></i>
|
|
|
- </el-tooltip>
|
|
|
+ <div
|
|
|
+ class="header"
|
|
|
+ :class="[collapse ? 'collapse' : 'expand']"
|
|
|
+ >
|
|
|
+ <v-tags></v-tags>
|
|
|
+ <div class="header-right">
|
|
|
+ <div class="header-user-con">
|
|
|
+ <div
|
|
|
+ class="formulation"
|
|
|
+ @click="formulationToPage"
|
|
|
+ v-if="permissionFiltering"
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ src="@assets/img/formulation/icon_diygzt@2x.png"
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+ 工作台自拟定 <span class="border"></span>
|
|
|
+ </div>
|
|
|
+ <div>欢迎你,{{ cruUserInfo.username }}</div>
|
|
|
+ <!-- 用户头像 -->
|
|
|
+ <div
|
|
|
+ class="user-avator"
|
|
|
+ @click="editUserInfo"
|
|
|
+ >
|
|
|
+ <el-tooltip
|
|
|
+ v-show="!cruUserInfo.photo"
|
|
|
+ placement="bottom"
|
|
|
+ content="编辑用户信息"
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ src="@assets/img/formulation/icon_avatar@2x.png"
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+ </el-tooltip>
|
|
|
+ <img
|
|
|
+ v-show="cruUserInfo.photo"
|
|
|
+ :src="envConfig.baseImgApi + cruUserInfo.photo"
|
|
|
+ style="object-fit: cover"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div class="message">
|
|
|
+ <span
|
|
|
+ class="main"
|
|
|
+ @click="goMessage('unread')"
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ src="@assets/img/btn_news.png"
|
|
|
+ alt=""
|
|
|
+ />
|
|
|
+ <span
|
|
|
+ class="iconfont point"
|
|
|
+ v-if="messageNumber"
|
|
|
+ ></span>
|
|
|
+ </span>
|
|
|
+ <div
|
|
|
+ class="msg-content"
|
|
|
+ v-if="messageList && messageList.length"
|
|
|
+ >
|
|
|
+ <p>消息通知</p>
|
|
|
+ <ul>
|
|
|
+ <li
|
|
|
+ v-for="(items, index) in messageList"
|
|
|
+ :key="index"
|
|
|
+ @click="toUrl(items.typeId)"
|
|
|
+ style="cursor: pointer"
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ :src="imgList[items.typeId]"
|
|
|
+ style="width: 30px; height: 30px"
|
|
|
+ />
|
|
|
+ <div>
|
|
|
+ <span class="cont">【{{ items.shortName }}】{{ items.messageContent }}</span>
|
|
|
+ <span class="time">{{ items.dateCreate }}</span>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </li>
|
|
|
+ </ul>
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ class="more"
|
|
|
+ @click="goMessage('more')"
|
|
|
+ >查看更多</el-button>
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ class="msg-content"
|
|
|
+ v-else
|
|
|
+ >
|
|
|
+ <p>消息通知</p>
|
|
|
+ <ul>
|
|
|
+ <li style="text-align: center; display: block; padding: 0 rem(20); line-height: rem(60)">暂无消息</li>
|
|
|
+ </ul>
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ class="more"
|
|
|
+ disabled
|
|
|
+ >查看更多</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <span class="border"></span>
|
|
|
+ <div
|
|
|
+ class="logout"
|
|
|
+ @click="logOut"
|
|
|
+ >
|
|
|
+ <el-tooltip
|
|
|
+ placement="bottom"
|
|
|
+ content="退出"
|
|
|
+ >
|
|
|
+ <i class="zoniot_font zoniot-icon-tuichu"></i>
|
|
|
+ </el-tooltip>
|
|
|
</div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
<script>
|
|
|
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex';
|
|
|
import envConfig from '@/config';
|
|
|
import vTags from './Tags.vue';
|
|
|
export default {
|
|
|
- data() {
|
|
|
- return {
|
|
|
- name: '',
|
|
|
- envConfig: envConfig,
|
|
|
- imgList: {
|
|
|
- 1: require('@/assets/img/icon_msg1.png'),
|
|
|
- 2: require('@/assets/img/icon_msg7.png'),
|
|
|
- 10: require('@/assets/img/icon_msg9.png'),
|
|
|
- 11: require('@/assets/img/icon_msg9.png'),
|
|
|
- 13: require('@/assets/img/icon_msg9.png')
|
|
|
- }
|
|
|
- };
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ name: '',
|
|
|
+ envConfig: envConfig,
|
|
|
+ imgList: {
|
|
|
+ 1: require('@/assets/img/icon_msg1.png'),
|
|
|
+ 2: require('@/assets/img/icon_msg7.png'),
|
|
|
+ 10: require('@/assets/img/icon_msg9.png'),
|
|
|
+ 11: require('@/assets/img/icon_msg9.png'),
|
|
|
+ 13: require('@/assets/img/icon_msg9.png')
|
|
|
+ }
|
|
|
+ };
|
|
|
+ },
|
|
|
+ components: {
|
|
|
+ vTags
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ cruUserInfo () {
|
|
|
+ return this.$store.getters['getCruUserInfo'];
|
|
|
},
|
|
|
- components: {
|
|
|
- vTags
|
|
|
+ collapse () {
|
|
|
+ return this.$store.getters['getCollapse'];
|
|
|
},
|
|
|
- computed: {
|
|
|
- cruUserInfo() {
|
|
|
- return this.$store.getters['getCruUserInfo'];
|
|
|
- },
|
|
|
- collapse() {
|
|
|
- return this.$store.getters['getCollapse'];
|
|
|
- },
|
|
|
- permissionFiltering() {
|
|
|
- let arr = this.$store.getters['getMenuList'] || [];
|
|
|
- if (arr.length !== 0) {
|
|
|
- return this.filterFuntion(false, arr);
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- },
|
|
|
- ...mapState(['messageNumber']),
|
|
|
- ...mapState(['messageList'])
|
|
|
+ permissionFiltering () {
|
|
|
+ let arr = this.$store.getters['getMenuList'] || [];
|
|
|
+ if (arr.length !== 0) {
|
|
|
+ return this.filterFuntion(false, arr);
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
},
|
|
|
- methods: {
|
|
|
- filterFuntion(status, arr) {
|
|
|
- arr.some((item, index) => {
|
|
|
- if (item.children == null && item.name == '工作台' && item.linkPath == 'newWorkBench/index') {
|
|
|
- status = true;
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
- return status;
|
|
|
- },
|
|
|
- toUrl(type) {
|
|
|
- this.$router.push({
|
|
|
- path: '/msg'
|
|
|
- });
|
|
|
- },
|
|
|
- formulationToPage() {
|
|
|
- this.$router.push({
|
|
|
- path: '/editWorkbench'
|
|
|
- });
|
|
|
- },
|
|
|
- // 退出登录
|
|
|
- logOut() {
|
|
|
- var access_token = localStorage.getItem('SC_token');
|
|
|
- this.$http.postForm('/user-auth/user/logout', { access_token: access_token }).then(({ status, data, msg }) => {
|
|
|
- if (0 === status) {
|
|
|
- this.$message({
|
|
|
- type: 'success',
|
|
|
- message: '您已退出登录'
|
|
|
- });
|
|
|
- localStorage.removeItem('SC_token');
|
|
|
- sessionStorage.removeItem('SC_listMuen');
|
|
|
- this.$store.commit('setloginInfo', '');
|
|
|
- this.$store.dispatch('tags', []);
|
|
|
+ ...mapState(['messageNumber']),
|
|
|
+ ...mapState(['messageList'])
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ filterFuntion (status, arr) {
|
|
|
+ arr.some((item, index) => {
|
|
|
+ if (item.children == null && item.name == '工作台' && item.linkPath == 'newWorkBench/index') {
|
|
|
+ status = true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return status;
|
|
|
+ },
|
|
|
+ toUrl (type) {
|
|
|
+ this.$router.push({
|
|
|
+ path: '/msg'
|
|
|
+ });
|
|
|
+ },
|
|
|
+ formulationToPage () {
|
|
|
+ this.$router.push({
|
|
|
+ path: '/editWorkbench'
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 退出登录
|
|
|
+ logOut () {
|
|
|
+ var access_token = localStorage.getItem('SC_token');
|
|
|
+ this.$http.postForm('/user-auth/user/logout', { access_token: access_token }).then(({ status, data, msg }) => {
|
|
|
+ if (0 === status) {
|
|
|
+ this.$message({
|
|
|
+ type: 'success',
|
|
|
+ message: '您已退出登录'
|
|
|
+ });
|
|
|
+ localStorage.removeItem('SC_token');
|
|
|
+ sessionStorage.removeItem('SC_listMuen');
|
|
|
+ this.$store.commit('setloginInfo', '');
|
|
|
+ this.$store.dispatch('tags', []);
|
|
|
|
|
|
- sessionStorage.removeItem('tabs');
|
|
|
- location.href = this.envConfig.loginUrl;
|
|
|
- } else {
|
|
|
- this.$message.error(msg);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- getUserInfo(resolve) {
|
|
|
- this.$http.postForm('/sc-user-center/user/findLoginUserById').then(({ status, data, msg }) => {
|
|
|
- if (status === 0) {
|
|
|
- this.$store.commit('setcCruUserInfo', data);
|
|
|
- } else {
|
|
|
- this.$message.error('获取用户信息失败');
|
|
|
- }
|
|
|
- resolve && resolve(true);
|
|
|
- });
|
|
|
- },
|
|
|
- editUserInfo() {
|
|
|
- new Promise((resolve) => {
|
|
|
- this.$store.dispatch('addPopup', {
|
|
|
- url: '/system/users/popups/edituser.vue',
|
|
|
- width: '500px',
|
|
|
- height: '500px',
|
|
|
- props: {
|
|
|
- data: JSON.parse(JSON.stringify(this.cruUserInfo)),
|
|
|
- callback: resolve
|
|
|
- },
|
|
|
- title: '编辑用户信息'
|
|
|
- });
|
|
|
- }).then(() => {
|
|
|
- this.getUserInfo();
|
|
|
- });
|
|
|
- },
|
|
|
- goMessage(msg) {
|
|
|
- let messageStatus = 2; //全部
|
|
|
- if (msg == 'unread') {
|
|
|
- messageStatus = 0; //未读
|
|
|
- }
|
|
|
- this.$store.commit('setmessageStatus', messageStatus);
|
|
|
- this.$router.push({
|
|
|
- path: '/msg'
|
|
|
- });
|
|
|
- },
|
|
|
- //获取最新消息列表
|
|
|
- getMessageList() {
|
|
|
- this.$http.postForm('/sc-message/message/queryLastMessage', { num: '5' }).then(({ status, data, msg }) => {
|
|
|
- if (status === 0) {
|
|
|
- this.$store.commit('setmessageList', data);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- //查询未读消息数量
|
|
|
- getUnreadNumber() {
|
|
|
- this.$http.postForm('/sc-message/message/queryUnreadMessageStatic').then(({ status, data, msg }) => {
|
|
|
- if (status === 0) {
|
|
|
- data.map((item, index) => {
|
|
|
- if (item.cn) {
|
|
|
- this.$store.commit('setmessageNumber', true);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- //初始化websoket
|
|
|
- initWebSocket(id) {
|
|
|
- if ('WebSocket' in window) {
|
|
|
- var serviceIp = this.envConfig.websoketUrl;
|
|
|
- this.websocket = new WebSocket('ws://' + serviceIp + '/sc-message/webSocket/' + id);
|
|
|
- } else {
|
|
|
- console.log('当前浏览器 Not support websocket');
|
|
|
+ sessionStorage.removeItem('tabs');
|
|
|
+ location.href = this.envConfig.loginUrl;
|
|
|
+ } else {
|
|
|
+ this.$message.error(msg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getUserInfo (resolve) {
|
|
|
+ this.$http.postForm('/sc-user-center/user/findLoginUserById').then(({ status, data, msg }) => {
|
|
|
+ if (status === 0) {
|
|
|
+ this.$store.commit('setcCruUserInfo', data);
|
|
|
+ } else {
|
|
|
+ this.$message.error('获取用户信息失败');
|
|
|
+ }
|
|
|
+ resolve && resolve(true);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ editUserInfo () {
|
|
|
+ new Promise((resolve) => {
|
|
|
+ this.$store.dispatch('addPopup', {
|
|
|
+ url: '/system/users/popups/edituser.vue',
|
|
|
+ width: '500px',
|
|
|
+ height: '500px',
|
|
|
+ props: {
|
|
|
+ data: JSON.parse(JSON.stringify(this.cruUserInfo)),
|
|
|
+ callback: resolve
|
|
|
+ },
|
|
|
+ title: '编辑用户信息'
|
|
|
+ });
|
|
|
+ }).then(() => {
|
|
|
+ this.getUserInfo();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ goMessage (msg) {
|
|
|
+ let messageStatus = 2; //全部
|
|
|
+ if (msg == 'unread') {
|
|
|
+ messageStatus = 0; //未读
|
|
|
+ }
|
|
|
+ this.$store.commit('setmessageStatus', messageStatus);
|
|
|
+ this.$router.push({
|
|
|
+ path: '/msg'
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //获取最新消息列表
|
|
|
+ getMessageList () {
|
|
|
+ this.$http.postForm('/sc-message/message/queryLastMessage', { num: '5' }).then(({ status, data, msg }) => {
|
|
|
+ if (status === 0) {
|
|
|
+ this.$store.commit('setmessageList', data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //查询未读消息数量
|
|
|
+ getUnreadNumber () {
|
|
|
+ this.$http.postForm('/sc-message/message/queryUnreadMessageStatic').then(({ status, data, msg }) => {
|
|
|
+ if (status === 0) {
|
|
|
+ data.map((item, index) => {
|
|
|
+ if (item.cn) {
|
|
|
+ this.$store.commit('setmessageNumber', true);
|
|
|
}
|
|
|
- let that = this;
|
|
|
- this.interval = window.setInterval(function () {
|
|
|
- //每隔30秒钟发送一次心跳,避免websocket连接因超时而自动断开
|
|
|
- if (that.websocket != null) {
|
|
|
- // that.websocket.send('HeartBeat');
|
|
|
- // console.log('发送心跳包:HeartBeat');
|
|
|
- }
|
|
|
- }, 30000);
|
|
|
- //连接发生错误的回调方法
|
|
|
- this.websocket.onerror = function (ev) {
|
|
|
- console.log('WebSocket连接发生错误');
|
|
|
- };
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //初始化websoket
|
|
|
+ initWebSocket (id) {
|
|
|
+ if ('WebSocket' in window) {
|
|
|
+ var serviceIp = this.envConfig.websoketUrl;
|
|
|
+ this.websocket = new WebSocket('ws://' + serviceIp + '/sc-message/webSocket/' + id);
|
|
|
+ } else {
|
|
|
+ console.log('当前浏览器 Not support websocket');
|
|
|
+ }
|
|
|
+ let that = this;
|
|
|
+ this.interval = window.setInterval(function () {
|
|
|
+ //每隔30秒钟发送一次心跳,避免websocket连接因超时而自动断开
|
|
|
+ if (that.websocket != null) {
|
|
|
+ // that.websocket.send('HeartBeat');
|
|
|
+ // console.log('发送心跳包:HeartBeat');
|
|
|
+ }
|
|
|
+ }, 30000);
|
|
|
+ //连接发生错误的回调方法
|
|
|
+ this.websocket.onerror = function (ev) {
|
|
|
+ console.log('WebSocket连接发生错误');
|
|
|
+ };
|
|
|
|
|
|
- //连接成功建立的回调方法
|
|
|
- this.websocket.onopen = function (ev) {
|
|
|
- console.log('WebSocket连接成功');
|
|
|
- // this.send('addsocket');
|
|
|
- };
|
|
|
+ //连接成功建立的回调方法
|
|
|
+ this.websocket.onopen = function (ev) {
|
|
|
+ console.log('WebSocket连接成功');
|
|
|
+ // this.send('addsocket');
|
|
|
+ };
|
|
|
|
|
|
- //接收到消息的回调方法
|
|
|
- this.websocket.onmessage = function (event) {
|
|
|
- try {
|
|
|
- let msg = JSON.parse(event.data);
|
|
|
- // let i = msg.typeId - 1;
|
|
|
- let i = msg.typeId;
|
|
|
- if (msg.userId) {
|
|
|
- that.$notify({
|
|
|
- dangerouslyUseHTMLString: true,
|
|
|
- showClose: true,
|
|
|
- customClass: 'notice_icon',
|
|
|
- offset: 50,
|
|
|
- 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();
|
|
|
- }
|
|
|
- } catch (e) {}
|
|
|
- };
|
|
|
+ //接收到消息的回调方法
|
|
|
+ this.websocket.onmessage = function (event) {
|
|
|
+ try {
|
|
|
+ let msg = JSON.parse(event.data);
|
|
|
+ // let i = msg.typeId - 1;
|
|
|
+ let i = msg.typeId;
|
|
|
+ if (msg.userId) {
|
|
|
+ that.$notify({
|
|
|
+ dangerouslyUseHTMLString: true,
|
|
|
+ showClose: true,
|
|
|
+ customClass: 'notice_icon',
|
|
|
+ offset: 50,
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ } catch (e) { }
|
|
|
+ };
|
|
|
|
|
|
- //连接关闭的回调方法
|
|
|
- this.websocket.onclose = function (ev) {
|
|
|
- console.log('WebSocket连接关闭');
|
|
|
- this.websocket = null;
|
|
|
- };
|
|
|
- },
|
|
|
- send(message) {
|
|
|
- if (this.websocket && this.websocket != null) {
|
|
|
- // this.websocket.send(message);
|
|
|
- console.log('发送的消息:' + message);
|
|
|
- }
|
|
|
- },
|
|
|
- //关闭WebSocket连接
|
|
|
- closeWebSocket() {
|
|
|
- if (this.websocket != null) {
|
|
|
- this.websocket.close();
|
|
|
- }
|
|
|
- if (this.interval) {
|
|
|
- window.clearInterval(this.interval);
|
|
|
- }
|
|
|
- }
|
|
|
+ //连接关闭的回调方法
|
|
|
+ this.websocket.onclose = function (ev) {
|
|
|
+ console.log('WebSocket连接关闭');
|
|
|
+ this.websocket = null;
|
|
|
+ };
|
|
|
},
|
|
|
- mounted() {
|
|
|
- let vm = this;
|
|
|
- window.onbeforeunload = function () {
|
|
|
- vm.closeWebSocket();
|
|
|
- };
|
|
|
+ send (message) {
|
|
|
+ if (this.websocket && this.websocket != null) {
|
|
|
+ // this.websocket.send(message);
|
|
|
+ console.log('发送的消息:' + message);
|
|
|
+ }
|
|
|
},
|
|
|
- destoryed() {
|
|
|
- this.closeWebSocket();
|
|
|
- },
|
|
|
- created() {
|
|
|
- new Promise((resolve) => {
|
|
|
- this.getUserInfo(resolve);
|
|
|
- }).then((_) => {
|
|
|
- let id = this.$store.state.cruUserInfo.id;
|
|
|
- this.initWebSocket(id);
|
|
|
- this.getMessageList();
|
|
|
- this.getUnreadNumber();
|
|
|
- });
|
|
|
+ //关闭WebSocket连接
|
|
|
+ closeWebSocket () {
|
|
|
+ if (this.websocket != null) {
|
|
|
+ this.websocket.close();
|
|
|
+ }
|
|
|
+ if (this.interval) {
|
|
|
+ window.clearInterval(this.interval);
|
|
|
+ }
|
|
|
}
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+ let vm = this;
|
|
|
+ window.onbeforeunload = function () {
|
|
|
+ vm.closeWebSocket();
|
|
|
+ };
|
|
|
+ },
|
|
|
+ destoryed () {
|
|
|
+ this.closeWebSocket();
|
|
|
+ },
|
|
|
+ created () {
|
|
|
+ new Promise((resolve) => {
|
|
|
+ this.getUserInfo(resolve);
|
|
|
+ }).then((_) => {
|
|
|
+ let id = this.$store.state.cruUserInfo.id;
|
|
|
+ this.initWebSocket(id);
|
|
|
+ this.getMessageList();
|
|
|
+ this.getUnreadNumber();
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
</script>
|
|
|
<style lang='scss' scoped>
|