@gonsin/gview 1.0.1 → 1.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fonts/element-icons.313f7dac.woff +0 -0
- package/dist/fonts/element-icons.45201881.ttf +0 -0
- package/dist/index.js +335 -0
- package/package.json +6 -2
- package/.browserslistrc +0 -2
- package/babel.config.js +0 -5
- package/gonsin-gview-1.0.1.tgz +0 -0
- package/postcss.config.js +0 -5
- package/public/css/theme/animate.min.css +0 -7
- package/public/css/theme/brownishTheme.css +0 -10
- package/public/css/theme/coffeeTheme.css +0 -10
- package/public/css/theme/cyanTheme.css +0 -10
- package/public/css/theme/defaultTheme.css +0 -10
- package/public/css/theme/greenTheme.css +0 -16
- package/public/css/theme/greyTheme.css +0 -10
- package/public/css/theme/orangeTheme.css +0 -10
- package/public/css/theme/purpleTheme.css +0 -10
- package/public/css/theme/skyblueTheme.css +0 -10
- package/public/favicon.ico +0 -0
- package/public/imgs/antOutline-border.png +0 -0
- package/public/imgs/bg.png +0 -0
- package/public/imgs/logo.png +0 -0
- package/public/imgs/menu.png +0 -0
- package/public/index.html +0 -17
- package/src/App.vue +0 -143
- package/src/api/api.js +0 -28
- package/src/api/index.js +0 -31
- package/src/api/request.js +0 -210
- package/src/assets/font/font.scss +0 -12
- package/src/assets/font/font_dev.scss +0 -12
- package/src/assets/font/icon.scss +0 -179
- package/src/assets/images/svg/color.svg +0 -1
- package/src/assets/logo.png +0 -0
- package/src/assets/scss/common.scss +0 -338
- package/src/assets/scss/themeColor.scss +0 -35
- package/src/components/MyDialog.vue +0 -251
- package/src/components/MyForm.vue +0 -324
- package/src/components/MyFormAutocomplete.vue +0 -135
- package/src/components/MyFormCascader.vue +0 -107
- package/src/components/MyFormCheckBox.vue +0 -67
- package/src/components/MyFormEditor.vue +0 -85
- package/src/components/MyFormInput.vue +0 -68
- package/src/components/MyFormLine.vue +0 -49
- package/src/components/MyFormRadio.vue +0 -92
- package/src/components/MyFormSelect.vue +0 -122
- package/src/components/MyFormSelectDate.vue +0 -72
- package/src/components/MyFormSelectDateTime.vue +0 -82
- package/src/components/MyFormSelectTime.vue +0 -84
- package/src/components/MyFormSwitch.vue +0 -60
- package/src/components/MyFormTag.vue +0 -67
- package/src/components/MyFormTree.vue +0 -137
- package/src/components/MyFormUploads.vue +0 -91
- package/src/components/MyHeader.vue +0 -176
- package/src/components/MyMenus.vue +0 -150
- package/src/components/MyPageHeader.vue +0 -344
- package/src/components/MyTab.vue +0 -69
- package/src/components/MyTable.vue +0 -244
- package/src/components/Templatess.vue +0 -630
- package/src/index.js +0 -23
- package/src/main.js +0 -86
- package/src/router.js +0 -52
- package/src/store/index.js +0 -71
- package/src/utils/common.js +0 -96
- package/src/utils/permission.js +0 -36
- package/src/views/GView.vue +0 -185
- package/src/views/Home.vue +0 -26
- package/src/views/Login.vue +0 -249
- package/src/websocket/test.js +0 -140
- package/src/websocket/websocket.js +0 -141
- package/src/websocket/websocket1.js +0 -117
- package/src/websocket/websocket2.js +0 -128
- package/vue.config.js +0 -42
package/src/views/Login.vue
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
* @Author: your name
|
|
3
|
-
* @Date: 2020-06-30 18:26:00
|
|
4
|
-
* @LastEditTime: 2022-11-07 17:31:24
|
|
5
|
-
* @LastEditors: lrm lrm@gonsin.cn
|
|
6
|
-
* @Description: In User Settings Edit
|
|
7
|
-
* @FilePath: \client\src\views\Login.vue
|
|
8
|
-
-->
|
|
9
|
-
<template>
|
|
10
|
-
<!-- 登录页面 -->
|
|
11
|
-
<div class="login" :style="back">
|
|
12
|
-
<div class="login_box">
|
|
13
|
-
<div class="logo" :style="logo"></div>
|
|
14
|
-
<div class="form">
|
|
15
|
-
<el-form :model="form" ref="form" :rules="formRules">
|
|
16
|
-
<el-form-item prop="username">
|
|
17
|
-
<el-input
|
|
18
|
-
placeholder="请输入用户名"
|
|
19
|
-
v-model.trim="form.username"
|
|
20
|
-
onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;"
|
|
21
|
-
></el-input>
|
|
22
|
-
</el-form-item>
|
|
23
|
-
<el-form-item prop="password">
|
|
24
|
-
<el-input
|
|
25
|
-
type="password"
|
|
26
|
-
placeholder="请输入密码"
|
|
27
|
-
v-model.trim="form.password"
|
|
28
|
-
onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;"
|
|
29
|
-
></el-input>
|
|
30
|
-
</el-form-item>
|
|
31
|
-
<el-form-item>
|
|
32
|
-
<el-button
|
|
33
|
-
type="primary"
|
|
34
|
-
style="width: 100%"
|
|
35
|
-
@click="loginHandle('form')"
|
|
36
|
-
>登录</el-button
|
|
37
|
-
>
|
|
38
|
-
</el-form-item>
|
|
39
|
-
</el-form>
|
|
40
|
-
</div>
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
</template>
|
|
44
|
-
|
|
45
|
-
<script>
|
|
46
|
-
// import CommonForm from '../components/CommonForm';
|
|
47
|
-
import { setLogin } from "../websocket/test";
|
|
48
|
-
export default {
|
|
49
|
-
components: {
|
|
50
|
-
// CommonForm,
|
|
51
|
-
},
|
|
52
|
-
data() {
|
|
53
|
-
return {
|
|
54
|
-
sessionId: sessionStorage.getItem("sessionId"),
|
|
55
|
-
loginUrl: "/api/handle_login",
|
|
56
|
-
form: {
|
|
57
|
-
username: "",
|
|
58
|
-
password: "",
|
|
59
|
-
},
|
|
60
|
-
formRules: {
|
|
61
|
-
username: [
|
|
62
|
-
{
|
|
63
|
-
required: true,
|
|
64
|
-
message: "请输入用户名",
|
|
65
|
-
trigger: "blur",
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
pattern: /^[_a-zA-Z0-9\s+]{1,255}$/,
|
|
69
|
-
message: "您输入的用户名格式不合法",
|
|
70
|
-
trigger: "blur",
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
password: [
|
|
74
|
-
{
|
|
75
|
-
required: true,
|
|
76
|
-
message: "请输入密码",
|
|
77
|
-
trigger: "blur",
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
pattern: /^[_a-zA-Z0-9\s+]{1,255}$/,
|
|
81
|
-
message: "您输入的密码格式不合法",
|
|
82
|
-
trigger: "blur",
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
|
-
// 为了解决线上打包路径解析错误加载不出的问题,这里使用node中提供的方法
|
|
87
|
-
back: {
|
|
88
|
-
backgroundImage:
|
|
89
|
-
"url(" + require("../../public/imgs/bg.png") + ")",
|
|
90
|
-
backgroundRepeat: "no-repeat",
|
|
91
|
-
backgroundSize: "100% 100%",
|
|
92
|
-
},
|
|
93
|
-
logo: {
|
|
94
|
-
backgroundImage:
|
|
95
|
-
"url(" + require("../../public/imgs/logo.png") + ")",
|
|
96
|
-
backgroundRepeat: "no-repeat",
|
|
97
|
-
backgroundSize: " 100%",
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
mounted() {
|
|
102
|
-
window.addEventListener("keydown", (e) => {
|
|
103
|
-
if (e.keyCode == 13) {
|
|
104
|
-
// this.handleEnterLogin()
|
|
105
|
-
this.loginHandle("form");
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
methods: {
|
|
110
|
-
/**
|
|
111
|
-
* @description: 登录处理:1、成功后将res.data保存至sessionStorage中,key名:user
|
|
112
|
-
2、建立websocket连接
|
|
113
|
-
* @param {type}
|
|
114
|
-
* @return:
|
|
115
|
-
*/
|
|
116
|
-
loginHandle(formName) {
|
|
117
|
-
this.$refs[formName].validate((valida) => {
|
|
118
|
-
if (valida) {
|
|
119
|
-
this.$api
|
|
120
|
-
.handleLogin({
|
|
121
|
-
username: this.form.username,
|
|
122
|
-
password: this.form.password,
|
|
123
|
-
})
|
|
124
|
-
.then((res) => {
|
|
125
|
-
switch (res.data.state) {
|
|
126
|
-
case 200:
|
|
127
|
-
// console.log(res)
|
|
128
|
-
sessionStorage.setItem(
|
|
129
|
-
"user",
|
|
130
|
-
JSON.stringify(res.data.data)
|
|
131
|
-
);
|
|
132
|
-
this.saveAdminState();
|
|
133
|
-
setLogin(true);
|
|
134
|
-
this.$parent.getPermissions((list) => {
|
|
135
|
-
let arr = res.data.data.permissions;
|
|
136
|
-
if (list.length != 0) {
|
|
137
|
-
let url = "";
|
|
138
|
-
arr.forEach((target) => {
|
|
139
|
-
let filterList =
|
|
140
|
-
list[0].children.filter(
|
|
141
|
-
(ele) => {
|
|
142
|
-
return (
|
|
143
|
-
ele.name ==
|
|
144
|
-
target
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
if (filterList.length != 0) {
|
|
149
|
-
if (url == "") {
|
|
150
|
-
url =
|
|
151
|
-
"/" +
|
|
152
|
-
filterList[0].url;
|
|
153
|
-
}
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
sessionStorage.setItem(
|
|
158
|
-
"menu",
|
|
159
|
-
JSON.stringify(list)
|
|
160
|
-
);
|
|
161
|
-
this.$router.push({
|
|
162
|
-
path: url,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
break;
|
|
167
|
-
case 303:
|
|
168
|
-
this.$alert("密码错误,请重试", "提示", {
|
|
169
|
-
confirmButtonText: "确定",
|
|
170
|
-
type: "warning",
|
|
171
|
-
});
|
|
172
|
-
break;
|
|
173
|
-
case 307:
|
|
174
|
-
this.$alert(
|
|
175
|
-
"您的帐号已被冻结,请联系管理员处理",
|
|
176
|
-
"提示",
|
|
177
|
-
{
|
|
178
|
-
confirmButtonText: "确定",
|
|
179
|
-
type: "warning",
|
|
180
|
-
}
|
|
181
|
-
);
|
|
182
|
-
break;
|
|
183
|
-
case 404:
|
|
184
|
-
this.$alert(
|
|
185
|
-
"您输入的账号不存在,请联系管理员",
|
|
186
|
-
"提示",
|
|
187
|
-
{
|
|
188
|
-
confirmButtonText: "确定",
|
|
189
|
-
type: "warning",
|
|
190
|
-
}
|
|
191
|
-
);
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
} else {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
},
|
|
200
|
-
/**
|
|
201
|
-
* @description: 保存当前用户是否是管理员账号的状态判断,防止刷新页面丢失该状态
|
|
202
|
-
* @param {type}
|
|
203
|
-
* @return {type}
|
|
204
|
-
*/
|
|
205
|
-
saveAdminState() {
|
|
206
|
-
this.$store.commit(
|
|
207
|
-
"isAdmin",
|
|
208
|
-
JSON.parse(sessionStorage.getItem("user")).admin
|
|
209
|
-
);
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
</script>
|
|
214
|
-
|
|
215
|
-
<style lang="scss" scoped>
|
|
216
|
-
.login {
|
|
217
|
-
height: 100vh;
|
|
218
|
-
|
|
219
|
-
.login_box {
|
|
220
|
-
width: 500px;
|
|
221
|
-
height: 400px;
|
|
222
|
-
position: absolute;
|
|
223
|
-
background-color: #fff;
|
|
224
|
-
border-radius: 15px;
|
|
225
|
-
top: 50%;
|
|
226
|
-
left: 50%;
|
|
227
|
-
transform: translate(-50%, -50%);
|
|
228
|
-
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.4);
|
|
229
|
-
|
|
230
|
-
.logo {
|
|
231
|
-
width: 314px;
|
|
232
|
-
height: 79px;
|
|
233
|
-
margin: 54px auto;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
.form {
|
|
237
|
-
width: 250px;
|
|
238
|
-
margin: 0 auto;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
</style>
|
|
243
|
-
<style lang="scss">
|
|
244
|
-
.login_btn {
|
|
245
|
-
position: absolute;
|
|
246
|
-
left: 50%;
|
|
247
|
-
transform: translateX(-50%);
|
|
248
|
-
}
|
|
249
|
-
</style>
|
package/src/websocket/test.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: lzx lzx@gonsin.cn
|
|
3
|
-
* @Date: 2022-06-28 15:27:45
|
|
4
|
-
* @LastEditors: lrm lrm@gonsin.cn
|
|
5
|
-
* @LastEditTime: 2022-11-29 15:08:50
|
|
6
|
-
* @FilePath: \client\src\websocket\test.js
|
|
7
|
-
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
8
|
-
*/
|
|
9
|
-
let pre = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
10
|
-
|
|
11
|
-
let webSocketIP = process.env.NODE_ENV !== 'development' ? window.location.origin.replace(window.location.protocol, pre) + '/gview/websocket' : "http://192.168.2.192:8088/gview/websocket".replace('http', 'ws');
|
|
12
|
-
|
|
13
|
-
let socket = '';
|
|
14
|
-
|
|
15
|
-
let isFirst = true;
|
|
16
|
-
|
|
17
|
-
let Interval = null;
|
|
18
|
-
|
|
19
|
-
let isLogin = true;//是否已经登录
|
|
20
|
-
|
|
21
|
-
let isLink = false;//是否正在链接中
|
|
22
|
-
|
|
23
|
-
let isReSet = false;//是否重连
|
|
24
|
-
|
|
25
|
-
export const createSocket = () => {
|
|
26
|
-
isLink = true;
|
|
27
|
-
isFirst = true;
|
|
28
|
-
// console.log('establish websocket connection')
|
|
29
|
-
socket = new WebSocket(webSocketIP);
|
|
30
|
-
socket.onopen = onopenWs;
|
|
31
|
-
socket.onclose = oncloseWs;
|
|
32
|
-
socket.onerror = onerrorWs;
|
|
33
|
-
socket.onmessage = onmessageWs;
|
|
34
|
-
isLink = false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const onopenWs = event => {
|
|
38
|
-
// console.log("链接", event);
|
|
39
|
-
let model = {
|
|
40
|
-
head: "gonsin",
|
|
41
|
-
cmd: {
|
|
42
|
-
cmd: "client",
|
|
43
|
-
subcmd: "heart",
|
|
44
|
-
respone: 0,
|
|
45
|
-
},
|
|
46
|
-
args: {},
|
|
47
|
-
};
|
|
48
|
-
Interval = setInterval(function () {
|
|
49
|
-
//这里发送一个心跳,后端收到后,返回一个心跳消息,
|
|
50
|
-
//onmessage拿到返回的心跳就说明连接正常
|
|
51
|
-
socket.send(JSON.stringify(model));
|
|
52
|
-
}, 40000);
|
|
53
|
-
// socket.send("websocket client connect testss");
|
|
54
|
-
if(isReSet){
|
|
55
|
-
let dataId = localStorage.getItem('dataId');
|
|
56
|
-
if(dataId){
|
|
57
|
-
onsendregisterWs(dataId)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const onsendregisterWs = (dataId) => {
|
|
64
|
-
// console.log("发送", dataId);
|
|
65
|
-
let params = {
|
|
66
|
-
head: "gonsin",
|
|
67
|
-
cmd: {
|
|
68
|
-
cmd: "gview_client",
|
|
69
|
-
subcmd: "register",
|
|
70
|
-
},
|
|
71
|
-
args: {
|
|
72
|
-
dataId: dataId,
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
socket.send(JSON.stringify(params));
|
|
76
|
-
isReSet = false;
|
|
77
|
-
// socket.send("websocket client connect testss");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const onsendunregisterWs = (dataId) => {
|
|
81
|
-
// console.log("发送", dataId);
|
|
82
|
-
let params = {
|
|
83
|
-
head: "gonsin",
|
|
84
|
-
cmd: {
|
|
85
|
-
cmd: "gview_client",
|
|
86
|
-
subcmd: "unregister",
|
|
87
|
-
},
|
|
88
|
-
args: {
|
|
89
|
-
dataId: dataId,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
socket.send(JSON.stringify(params));
|
|
93
|
-
// socket.send("websocket client connect testss");
|
|
94
|
-
}
|
|
95
|
-
const oncloseWs = event => {
|
|
96
|
-
console.log("断开链接", event);
|
|
97
|
-
if(isLogin && !isLink){
|
|
98
|
-
clearInterval(Interval)
|
|
99
|
-
isReSet = true;
|
|
100
|
-
socket = null;
|
|
101
|
-
Interval = null;
|
|
102
|
-
let timeout = setTimeout(() => {
|
|
103
|
-
console.log("断开链接重连");
|
|
104
|
-
createSocket();
|
|
105
|
-
clearTimeout(timeout)
|
|
106
|
-
}, 5000);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const onerrorWs = event => {
|
|
111
|
-
console.log("出现错误", event);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const onmessageWs = event => {
|
|
115
|
-
// console.log(event.data)
|
|
116
|
-
let data = JSON.parse(event.data)
|
|
117
|
-
// console.log(data);
|
|
118
|
-
window.dispatchEvent(new CustomEvent('onmessageWS', {
|
|
119
|
-
detail: {
|
|
120
|
-
data: data,
|
|
121
|
-
isFirst: isFirst
|
|
122
|
-
}
|
|
123
|
-
}))
|
|
124
|
-
|
|
125
|
-
if(isFirst) {
|
|
126
|
-
isFirst = false;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export const setLogin = (bool) => {
|
|
131
|
-
isLogin = bool;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export const closeWebsocket = () =>{
|
|
135
|
-
socket.close()
|
|
136
|
-
clearInterval(Interval)
|
|
137
|
-
socket = null;
|
|
138
|
-
Interval = null;
|
|
139
|
-
isReSet = false;
|
|
140
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: lzx lzx@gonsin.cn
|
|
3
|
-
* @Date: 2022-06-27 13:55:43
|
|
4
|
-
* @LastEditors: lrm lrm@gonsin.cn
|
|
5
|
-
* @LastEditTime: 2022-11-22 16:17:58
|
|
6
|
-
* @FilePath: \client\src\websocket\websocket.js
|
|
7
|
-
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
8
|
-
*/
|
|
9
|
-
// import { mapActions,mapState } from "vuex";
|
|
10
|
-
export default {
|
|
11
|
-
computed: {
|
|
12
|
-
// 映射 state 中的数据为计算属性
|
|
13
|
-
},
|
|
14
|
-
data() {
|
|
15
|
-
return {
|
|
16
|
-
//websocket
|
|
17
|
-
ip: process.env.NODE_ENV !== 'development' ? window.location.origin.replace(window.location.protocol, 'ws:') + '/gview/websocket' : "http://192.168.2.192:8088/gview/websocket".replace('http', 'ws'),
|
|
18
|
-
webSocket: null,
|
|
19
|
-
lockReconnect: false,
|
|
20
|
-
tt: false,
|
|
21
|
-
sendParams: {
|
|
22
|
-
head: "gonsin",
|
|
23
|
-
cmd: {
|
|
24
|
-
cmd: "client",
|
|
25
|
-
subcmd: "heart",
|
|
26
|
-
respone: 0,
|
|
27
|
-
},
|
|
28
|
-
args: {},
|
|
29
|
-
},
|
|
30
|
-
// 心跳发送指令,超过40s未发送则断开连接
|
|
31
|
-
//心跳检测
|
|
32
|
-
heartCheck: null,
|
|
33
|
-
timeoutObj: null,
|
|
34
|
-
serverTimeoutObj: null,
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
methods: {
|
|
38
|
-
// 初始化websockey,登录成功后建立连接 new WebSocket(url)
|
|
39
|
-
initWebSocket() {
|
|
40
|
-
let that = this;
|
|
41
|
-
try {
|
|
42
|
-
if (typeof WebSocket === "undefined") {
|
|
43
|
-
alert("您的浏览器不支持WebSocket,请尽快升级");
|
|
44
|
-
} else {
|
|
45
|
-
console.log(that.ip)
|
|
46
|
-
that.webSocket = new WebSocket(that.ip);
|
|
47
|
-
that.init(); // 封装有websocket监听方法
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.log(error);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
init() {
|
|
54
|
-
let that = this;
|
|
55
|
-
that.webSocket.onopen = () => {
|
|
56
|
-
// this.$notify.success('Websocket successfully connected')
|
|
57
|
-
console.log("webSocket连接成功至:" + that.websocketIp);
|
|
58
|
-
clearInterval(that.timeoutObj);
|
|
59
|
-
clearTimeout(that.serverTimeoutObj);
|
|
60
|
-
let model = {
|
|
61
|
-
head: "gonsin",
|
|
62
|
-
cmd: {
|
|
63
|
-
cmd: "client",
|
|
64
|
-
subcmd: "heart",
|
|
65
|
-
respone: 0,
|
|
66
|
-
},
|
|
67
|
-
args: {},
|
|
68
|
-
};
|
|
69
|
-
that.timeoutObj = setInterval(function () {
|
|
70
|
-
//这里发送一个心跳,后端收到后,返回一个心跳消息,
|
|
71
|
-
//onmessage拿到返回的心跳就说明连接正常
|
|
72
|
-
that.webSocket.send(JSON.stringify(model));
|
|
73
|
-
}, 40000);
|
|
74
|
-
// // 连接成功,注册dataId
|
|
75
|
-
// that.registerMessage();
|
|
76
|
-
};
|
|
77
|
-
that.webSocket.onmessage = (msg) => {
|
|
78
|
-
console.log("onmessage....................");
|
|
79
|
-
// console.log('on_message:',msg);
|
|
80
|
-
let data = JSON.parse(msg.data);
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
that.webSocket.onerror = () => {
|
|
84
|
-
console.log("websocket连接错误...");
|
|
85
|
-
};
|
|
86
|
-
that.webSocket.onclose = () => {
|
|
87
|
-
console.log("websocket断开连接...");
|
|
88
|
-
that.msg = that.msg + "websocket断开连接...; ";
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
/**
|
|
92
|
-
* 注册站内信指令
|
|
93
|
-
*/
|
|
94
|
-
registerMessage(dataId, fun) {
|
|
95
|
-
let params = {
|
|
96
|
-
head: "gonsin",
|
|
97
|
-
cmd: {
|
|
98
|
-
cmd: "gview_client",
|
|
99
|
-
subcmd: "register",
|
|
100
|
-
},
|
|
101
|
-
args: {
|
|
102
|
-
dataId: dataId,
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
console.log(this.websocket)
|
|
106
|
-
// this.webSocket.send(JSON.stringify(params));
|
|
107
|
-
// this.$store.dispatch('setUpdateFunction', dataId,fun);
|
|
108
|
-
},
|
|
109
|
-
/**
|
|
110
|
-
* 注销站内信指令
|
|
111
|
-
*/
|
|
112
|
-
unregisterMessage(dataId) {
|
|
113
|
-
let params = {
|
|
114
|
-
head: "gonsin",
|
|
115
|
-
cmd: {
|
|
116
|
-
cmd: "gview_client",
|
|
117
|
-
subcmd: "unregister",
|
|
118
|
-
},
|
|
119
|
-
args: {
|
|
120
|
-
dataId: dataId,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
this.webSocket.send(JSON.stringify(params));
|
|
124
|
-
},
|
|
125
|
-
/**
|
|
126
|
-
* 处理站内消息回调
|
|
127
|
-
*/
|
|
128
|
-
handleMessageCallback(data) {
|
|
129
|
-
console.log(data);
|
|
130
|
-
console.log("处理站内消息................");
|
|
131
|
-
this.$notify({
|
|
132
|
-
title: data.args.message,
|
|
133
|
-
message: data.args.message,
|
|
134
|
-
type: "success",
|
|
135
|
-
offset: 100,
|
|
136
|
-
});
|
|
137
|
-
},
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: lzx lzx@gonsin.cn
|
|
3
|
-
* @Date: 2022-06-27 13:55:43
|
|
4
|
-
* @LastEditors: lzx lzx@gonsin.cn
|
|
5
|
-
* @LastEditTime: 2022-06-28 13:59:41
|
|
6
|
-
* @FilePath: \client\src\websocket\websocket.js
|
|
7
|
-
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
8
|
-
*/
|
|
9
|
-
export default {
|
|
10
|
-
//websocket
|
|
11
|
-
ip: process.env.NODE_ENV !== 'development' ? window.location.origin.replace(window.location.protocol, pre) + '/gview/websocket' : "http://192.168.2.192:8089/gview/websocket".replace('http', 'ws'),
|
|
12
|
-
webSocket: null,
|
|
13
|
-
lockReconnect: false,
|
|
14
|
-
tt: false,
|
|
15
|
-
sendParams: {
|
|
16
|
-
head: "gonsin",
|
|
17
|
-
cmd: {
|
|
18
|
-
cmd: "client",
|
|
19
|
-
subcmd: "heart",
|
|
20
|
-
respone: 0,
|
|
21
|
-
},
|
|
22
|
-
args: {},
|
|
23
|
-
},
|
|
24
|
-
// 心跳发送指令,超过40s未发送则断开连接
|
|
25
|
-
//心跳检测
|
|
26
|
-
heartCheck: null,
|
|
27
|
-
timeoutObj: null,
|
|
28
|
-
serverTimeoutObj: null,
|
|
29
|
-
// 初始化websockey,登录成功后建立连接 new WebSocket(url)
|
|
30
|
-
initWebSocket() {
|
|
31
|
-
try {
|
|
32
|
-
if (typeof WebSocket === "undefined") {
|
|
33
|
-
alert("您的浏览器不支持WebSocket,请尽快升级");
|
|
34
|
-
} else {
|
|
35
|
-
this.webSocket = new WebSocket(this.ip);
|
|
36
|
-
this.init(); // 封装有websocket监听方法
|
|
37
|
-
}
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.log(error);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
init() {
|
|
43
|
-
let that = this;
|
|
44
|
-
that.webSocket.onopen = () => {
|
|
45
|
-
// this.$notify.success('Websocket successfully connected')
|
|
46
|
-
console.log("webSocket连接成功至:" + that.ip);
|
|
47
|
-
clearInterval(that.timeoutObj);
|
|
48
|
-
clearTimeout(that.serverTimeoutObj);
|
|
49
|
-
let model = {
|
|
50
|
-
head: "gonsin",
|
|
51
|
-
cmd: {
|
|
52
|
-
cmd: "client",
|
|
53
|
-
subcmd: "heart",
|
|
54
|
-
respone: 0,
|
|
55
|
-
},
|
|
56
|
-
args: {},
|
|
57
|
-
};
|
|
58
|
-
that.timeoutObj = setInterval(function () {
|
|
59
|
-
//这里发送一个心跳,后端收到后,返回一个心跳消息,
|
|
60
|
-
//onmessage拿到返回的心跳就说明连接正常
|
|
61
|
-
that.webSocket.send(JSON.stringify(model));
|
|
62
|
-
}, 40000);
|
|
63
|
-
// // 连接成功,注册dataId
|
|
64
|
-
// that.registerMessage();
|
|
65
|
-
};
|
|
66
|
-
that.webSocket.onmessage = (msg) => {
|
|
67
|
-
console.log('this.$store')
|
|
68
|
-
console.log(this.$store)
|
|
69
|
-
console.log("onmessage....................");
|
|
70
|
-
// console.log('on_message:',msg);
|
|
71
|
-
let data = JSON.parse(msg.data);
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
that.webSocket.onerror = () => {
|
|
75
|
-
console.log("websocket连接错误...");
|
|
76
|
-
};
|
|
77
|
-
that.webSocket.onclose = () => {
|
|
78
|
-
console.log("websocket断开连接...");
|
|
79
|
-
that.msg = that.msg + "websocket断开连接...; ";
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* 注册站内信指令
|
|
84
|
-
*/
|
|
85
|
-
registerMessage(dataId, fun) {
|
|
86
|
-
let params = {
|
|
87
|
-
head: "gonsin",
|
|
88
|
-
cmd: {
|
|
89
|
-
cmd: "gview_client",
|
|
90
|
-
subcmd: "register",
|
|
91
|
-
},
|
|
92
|
-
args: {
|
|
93
|
-
dataId: dataId,
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
this.webSocket.send(JSON.stringify(params));
|
|
97
|
-
},
|
|
98
|
-
/**
|
|
99
|
-
* 注销站内信指令
|
|
100
|
-
*/
|
|
101
|
-
unregisterMessage(dataId) {
|
|
102
|
-
let params = {
|
|
103
|
-
head: "gonsin",
|
|
104
|
-
cmd: {
|
|
105
|
-
cmd: "gview_client",
|
|
106
|
-
subcmd: "unregister",
|
|
107
|
-
},
|
|
108
|
-
args: {
|
|
109
|
-
dataId: dataId,
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
this.webSocket.send(JSON.stringify(params));
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|