正在显示
5 个修改的文件
包含
87 行增加
和
38 行删除
@@ -68,7 +68,6 @@ | @@ -68,7 +68,6 @@ | ||
68 | "shelljs": "^0.7.6", | 68 | "shelljs": "^0.7.6", |
69 | "url-loader": "^0.5.8", | 69 | "url-loader": "^0.5.8", |
70 | "vue-loader": "^11.1.4", | 70 | "vue-loader": "^11.1.4", |
71 | - "vue-socket.io": "^3.0.9", | ||
72 | "vue-style-loader": "^2.0.0", | 71 | "vue-style-loader": "^2.0.0", |
73 | "vue-template-compiler": "^2.2.4", | 72 | "vue-template-compiler": "^2.2.4", |
74 | "webpack": "^2.2.1", | 73 | "webpack": "^2.2.1", |
src/lib/websocket/socket.js
已删除
100644 → 0
1 | -import Vue from 'vue' | ||
2 | -import VueSocketIO from 'vue-socket.io' | ||
3 | - | ||
4 | - | ||
5 | -var a; | ||
6 | -var wesocket = { | ||
7 | - sid: sessionStorage.getItem('token'), | ||
8 | - serverIp: getWebIP(), | ||
9 | - serverPort: '9001', | ||
10 | - debug: true, | ||
11 | - connection: "ws://" + this.serverIp + ":" + this.serverPort + "/websocket/" + this.sid, | ||
12 | - vuex: {} | ||
13 | -} | ||
14 | -function getWebIP() { | ||
15 | - var curIP = window.location.hostname; | ||
16 | - return curIP; | ||
17 | -} | ||
18 | -if (wesocket.connection != "") { | ||
19 | - Vue.use(new VueSocketIO(wesocket)) | ||
20 | - | ||
21 | -} | ||
22 | -export default a; |
@@ -10,7 +10,6 @@ import axios from 'axios' | @@ -10,7 +10,6 @@ import axios from 'axios' | ||
10 | import rout from './routes' | 10 | import rout from './routes' |
11 | import Mock from './mock' | 11 | import Mock from './mock' |
12 | import i18n from './lang' | 12 | import i18n from './lang' |
13 | -import VueSocketIO from './lib/websocket/socket' | ||
14 | import 'font-awesome/css/font-awesome.min.css' | 13 | import 'font-awesome/css/font-awesome.min.css' |
15 | import '@/styles/index.scss' | 14 | import '@/styles/index.scss' |
16 | 15 | ||
@@ -29,6 +28,7 @@ Vue.use(VueRouter) | @@ -29,6 +28,7 @@ Vue.use(VueRouter) | ||
29 | Vue.use(Vuex) | 28 | Vue.use(Vuex) |
30 | Vue.prototype.$axios = axios; | 29 | Vue.prototype.$axios = axios; |
31 | 30 | ||
31 | + | ||
32 | //NProgress.configure({ showSpinner: false }); | 32 | //NProgress.configure({ showSpinner: false }); |
33 | // console.log("mainjs:"); | 33 | // console.log("mainjs:"); |
34 | // console.log(rout.routes); | 34 | // console.log(rout.routes); |
@@ -145,7 +145,6 @@ axios.interceptors.response.use( | @@ -145,7 +145,6 @@ axios.interceptors.response.use( | ||
145 | let vue = new Vue({ | 145 | let vue = new Vue({ |
146 | el: '#app', | 146 | el: '#app', |
147 | template: '<App/>', | 147 | template: '<App/>', |
148 | - VueSocketIO, | ||
149 | router, | 148 | router, |
150 | store, | 149 | store, |
151 | i18n, | 150 | i18n, |
src/utils/websocket.js
0 → 100644
1 | +const VueWebsocket = { | ||
2 | + wsuri: '', | ||
3 | + serverPort: '9001', | ||
4 | + sid: '', | ||
5 | + /** | ||
6 | + * 前后端消息定制的协议为JSON字符窜格式 | ||
7 | + * 下面是经过json转换收到的消息,重新赋值的 | ||
8 | + * 格式样例为:msgJson:{ | ||
9 | + * message:socketMessage, | ||
10 | + * status: socketStatus, | ||
11 | + * data: socketDataList | ||
12 | + * ..... | ||
13 | + * } | ||
14 | + */ | ||
15 | + socketMessage: '', | ||
16 | + socketStatus: '', | ||
17 | + socketDataList: '', | ||
18 | + msgJson: '', | ||
19 | + websocket: undefined, | ||
20 | + | ||
21 | + // eslint-disable-next-line no-console | ||
22 | + onmessage: function (event) {console.log(event.data)}, | ||
23 | + // eslint-disable-next-line no-console | ||
24 | + onclose: function (event) {console.log("websocket链接已关闭")}, | ||
25 | + // eslint-disable-next-line no-console | ||
26 | + onopen: function (event) {console.log("websocket链接已链接")}, | ||
27 | + // eslint-disable-next-line no-console | ||
28 | + onerror: function (event) {console.log("websocket链接失败,请检查URL")}, | ||
29 | + // eslint-disable-next-line no-console | ||
30 | + send: function(message){console.log("已发送消息")}, | ||
31 | + | ||
32 | + getWebIP: function () { | ||
33 | + var curIP = window.location.hostname; | ||
34 | + return curIP; | ||
35 | + }, | ||
36 | + init: function () { | ||
37 | + this.sid= sessionStorage.getItem('token'); | ||
38 | + this.wsuri = "ws://" + '192.168.1.17'+ ":" + this.serverPort + "/websocket/" + this.sid; | ||
39 | + if(this.sid!== ''){ | ||
40 | + this.websocket = new WebSocket(this.wsuri); | ||
41 | + this.websocket.onmessage = this.onmessage; | ||
42 | + this.websocket.onclose = this.onclose; | ||
43 | + this.websocket.onopen = this.onopen; | ||
44 | + this.websocket.onerror = this.onerror; | ||
45 | + this.websocket.send = this.send; | ||
46 | + | ||
47 | + } | ||
48 | + } | ||
49 | +} | ||
50 | + | ||
51 | +export default VueWebsocket; |
@@ -26,15 +26,15 @@ | @@ -26,15 +26,15 @@ | ||
26 | </el-button> | 26 | </el-button> |
27 | </el-col> | 27 | </el-col> |
28 | </el-row> | 28 | </el-row> |
29 | - <el-input v-model="message" style="width: 460px;margin-top: 20px" | 29 | + <el-input v-model="message" style="width: 460px;margin-top: 20px" type="textarea" |
30 | placeholder="获取数据进度" readonly> | 30 | placeholder="获取数据进度" readonly> |
31 | </el-input> | 31 | </el-input> |
32 | </div> | 32 | </div> |
33 | <div> | 33 | <div> |
34 | - 状态 :{{this.socketApi.socketStatus}} | 34 | + 状态 : |
35 | </div> | 35 | </div> |
36 | <div> | 36 | <div> |
37 | - 消息 :{{this.socketApi.socketMessage}} | 37 | + 消息 :{{socketResponse.message}} |
38 | </div> | 38 | </div> |
39 | <!-- 列表显示区域 --> | 39 | <!-- 列表显示区域 --> |
40 | <!-- | 40 | <!-- |
@@ -95,6 +95,8 @@ | @@ -95,6 +95,8 @@ | ||
95 | import FilenameOption from '../excel/components/FilenameOption' | 95 | import FilenameOption from '../excel/components/FilenameOption' |
96 | import AutoWidthOption from '../excel/components/AutoWidthOption' | 96 | import AutoWidthOption from '../excel/components/AutoWidthOption' |
97 | import BookTypeOption from '../excel/components/BookTypeOption' | 97 | import BookTypeOption from '../excel/components/BookTypeOption' |
98 | + import VueWebsocket from '@/utils/websocket' | ||
99 | + import {msgJson, socketDataList, socketMessage, socketStatus} from "@/api/socket"; | ||
98 | 100 | ||
99 | export default { | 101 | export default { |
100 | name: "ExitAnalysis", | 102 | name: "ExitAnalysis", |
@@ -105,7 +107,13 @@ | @@ -105,7 +107,13 @@ | ||
105 | * 出港业务统计列表 | 107 | * 出港业务统计列表 |
106 | */ | 108 | */ |
107 | exitInfoList: [], | 109 | exitInfoList: [], |
108 | - | 110 | + resultStatus: '0', |
111 | + message: '', | ||
112 | + socketResponse: { | ||
113 | + message: '', | ||
114 | + data: '', | ||
115 | + status: '' | ||
116 | + }, | ||
109 | /** | 117 | /** |
110 | * 查询列表 | 118 | * 查询列表 |
111 | */ | 119 | */ |
@@ -121,15 +129,6 @@ | @@ -121,15 +129,6 @@ | ||
121 | downloadLoading: false, | 129 | downloadLoading: false, |
122 | } | 130 | } |
123 | }, | 131 | }, |
124 | - sockets: { | ||
125 | - connect() { | ||
126 | - this.$socket.emit("sendMessageToServer", "0025520"); //监听connect事件 | ||
127 | - }, | ||
128 | - servermessage(data) { | ||
129 | - // 监听message事件,方法是后台定义和提供的 | ||
130 | - console.log(data); | ||
131 | - } | ||
132 | - }, | ||
133 | methods: { | 132 | methods: { |
134 | /** | 133 | /** |
135 | * 获取出港信息列表 | 134 | * 获取出港信息列表 |
@@ -160,8 +159,31 @@ | @@ -160,8 +159,31 @@ | ||
160 | this.$message.error(error.toString()); | 159 | this.$message.error(error.toString()); |
161 | }); | 160 | }); |
162 | }, | 161 | }, |
162 | + socket_onmessage: function (e) { | ||
163 | + // eslint-disable-next-line no-console | ||
164 | + console.log("从websocket接收到新的消息-->>"+e.data); | ||
165 | + this.message = this.message+e.data+"\n"; | ||
166 | + let msgJson = JSON.parse(e.data); | ||
167 | + this.socketResponse = JSON.parse(e.data); | ||
168 | + let socketMessage = msgJson.message; | ||
169 | + // eslint-disable-next-line no-console | ||
170 | + console.log(socketMessage) | ||
171 | + let socketStatus = msgJson.status; | ||
172 | + let socketDataList = msgJson.data; | ||
173 | + // eslint-disable-next-line no-console | ||
174 | + console.log(msgJson); | ||
175 | + }, | ||
176 | + socket_onopen: function (e) { | ||
177 | + // eslint-disable-next-line no-console | ||
178 | + console.log("websocket->>链接已链接"); | ||
179 | + } | ||
163 | }, | 180 | }, |
164 | created() { | 181 | created() { |
182 | + VueWebsocket.onopen = this.socket_onopen; | ||
183 | + VueWebsocket.onmessage = this.socket_onmessage; | ||
184 | + VueWebsocket.init(); | ||
185 | + | ||
186 | + | ||
165 | }, | 187 | }, |
166 | destroyed() { | 188 | destroyed() { |
167 | }, | 189 | }, |
-
请 注册 或 登录 后发表评论