Skip to content

Commit 46ec641

Browse files
committed
添加matt消息通知
1 parent e1466f3 commit 46ec641

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

config/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
'/upload': {
1919
target: 'http://216.250.107.28:' + 7001,
2020
changeOrigin: true
21-
},
21+
}
2222
},
2323

2424
// Various Dev Server settings

src/http/user.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* @Author: cnblogs.com/vipzhou
33
* @Date: 2018-02-22 21:30:19
4-
* @Last Modified by: mikey.zhaopeng
5-
* @Last Modified time: 2018-02-22 22:02:47
4+
* @Last Modified by: vipzhou
5+
* @Last Modified time: 2018-02-24 00:12:00
66
*/
77

88
import * as http from './base'
@@ -58,4 +58,14 @@ const addUser = user => {
5858
}, user))
5959
}
6060

61-
export { login, getUserList, deleteUserById, getUserDetail, updateUserInfo, addUser }
61+
/**
62+
* 退出登陆
63+
* @param {email} email
64+
*/
65+
const logout = email => {
66+
return http.post('/users/logout', {
67+
email
68+
})
69+
}
70+
71+
export { login, getUserList, deleteUserById, getUserDetail, updateUserInfo, addUser, logout }

src/views/Main.vue

+31-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686

8787
<script>
8888
import { mapState, mapMutations } from "vuex";
89+
import { logout } from "../http/user";
90+
import mqtt from "mqtt";
8991
export default {
9092
name: "Main",
9193
data() {
@@ -104,8 +106,14 @@ export default {
104106
this.centerDialogVisible = true;
105107
break;
106108
case 1: // 退出登录
107-
this.LOGOUT();
108-
this.$router.push("/");
109+
logout(this.$store.state.user.userInfo.email)
110+
.then(res => {
111+
this.LOGOUT();
112+
this.$router.push("/");
113+
})
114+
.catch(err => {
115+
console.log(err);
116+
});
109117
break;
110118
}
111119
}
@@ -124,6 +132,27 @@ export default {
124132
this.userInfo = this.user.userInfo;
125133
this.currentNav = this.$route.meta.nav;
126134
this.defaultActive = this.$route.name;
135+
var client = mqtt.connect("ws://mq.tongxinmao.com:18832/web", {
136+
clientId: "vuejs-admin-testing-project"
137+
});
138+
139+
client.on("connect", () => {
140+
console.log("链接mqtt成功");
141+
client.subscribe("msgNotice");
142+
});
143+
144+
client.on("message", (topic, message) => {
145+
// message is Buffer
146+
this.$message({
147+
type: "warning",
148+
message: JSON.parse(message.toString()).msg
149+
});
150+
});
151+
},
152+
beforeDestory() {
153+
console.log("组件已销毁");
154+
client.unsubscribe("msgNotice");
155+
client.end();
127156
}
128157
};
129158
</script>

0 commit comments

Comments
 (0)