index.vue
9.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<template>
<div class="home">
<el-container class="home-box">
<el-header class="headers">
<!-- <img class="logoImg" src="../../assets/img/home/logo.png" alt="" /> -->
<span class="logotitle">AI视频分析平台</span>
<span
:class="{
'el-icon-s-fold': isopen,
'el-icon-s-unfold': !isopen,
'menu-switch': true,
}"
@click="openmenu"
></span>
<div class="headRight">
<span class="timerbox">{{ curdate }}</span>
<el-dropdown class="zt-box" @command="handleCommand">
<div class="zt-btn">
<i class="el-icon-arrow-down el-icon-menu"></i>主题切换
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="light">白色主题</el-dropdown-item>
<el-dropdown-item command="dark">深色主题</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<span class="uname-box">{{ uname }}</span>
<img @click="resetpass" src="../../assets/img/home/user.png" alt="" />
<span class="exit" @click="logout()"
>退出<i class="el-icon-arrow-down"></i
></span>
</div>
</el-header>
<el-container style="min-height: calc(100vh - 64px)">
<menus @setTopBar="setTopBar" ref="leftmenu" v-show="isfull"></menus>
<el-main>
<div class="nav" id="topnav" v-show="isfull">
<div class="nav-tag-box">
<el-tag
v-for="(tag, index) in topbarArr"
:key="index"
closable
@close="closetag(tag, index)"
@click="toPath(tag)"
>
<!-- <i :class="tag.icon"></i> -->
{{ tag.name }}
</el-tag>
</div>
</div>
<router-view></router-view>
</el-main>
</el-container>
</el-container>
</div>
</template>
<script>
import types from "../../store/types.js";
// import {config} from "../../../public/js/config";
import menus from "./menu";
export default {
name: "x",
data() {
return {
curdate: "",
isopen: true,
conHeight: 0,
menuwidth: "300px",
isfull: true,
headertitle: "",
topbarArr: [],
uname: "",
};
},
methods: {
setTopBar(data) {
if (this.topbarArr.length < 1) {
this.topbarArr.push(data);
}
let hasBar = false;
for (let i = 0; i < this.topbarArr.length; i++) {
if (this.topbarArr[i].path == data.path) {
hasBar = true;
}
}
if (!hasBar) {
this.topbarArr.push(data);
}
},
openmenu() {
this.isopen = !this.isopen;
this.$refs.leftmenu.collapsemenu();
let date = new Date().getTime();
this.$store.commit("setmapopen", date);
},
toPath(data) {
this.$refs.leftmenu.handleSelect(data.path);
},
closetag(data, index) {
this.topbarArr.splice(index, 1);
},
getDate() {
let date = new Date();
let Y = date.getFullYear();
let M = date.getMonth() > 9 ? date.getMonth() : `0${date.getMonth() + 1}`;
let D = date.getDate() > 9 ? date.getDate() : `0${date.getDate()}`;
let h = date.getHours() > 9 ? date.getHours() : `0${date.getHours()}`;
let m =
date.getMinutes() > 9 ? date.getMinutes() : `0${date.getMinutes()}`;
let s = date.getSeconds();
let w = date.getDay();
let wtext = "";
switch (w) {
case 1:
wtext = "星期一";
break;
case 2:
wtext = "星期二";
break;
case 3:
wtext = "星期三";
break;
case 4:
wtext = "星期四";
break;
case 5:
wtext = "星期五";
break;
case 6:
wtext = "星期六";
break;
case 7:
wtext = "星期日";
break;
}
this.curdate = `${Y}/${M}/${D} ${h}:${m}:${s} ${wtext}`;
},
handleCommand(command) {
window.document.documentElement.setAttribute("data-theme", command);
localStorage.setItem("fxtheme", command);
},
ddlogout() {
let params = {
access_token: localStorage.getItem("access_token"),
};
this.$api.login.ddlogout(params).then((res) => {
console.log("dingding", res);
});
},
logout() {
localStorage.removeItem("menu");
localStorage.removeItem("curmenu");
let uid = localStorage.getItem("user_unid");
this.$api.login.logout(uid).then((res) => {
this.$store.commit(types.ATOKEN, "");
this.$logs.oplogs("", "serv_login", `登出了平台`);
localStorage.removeItem("atoken");
this.$router.push("/login").catch((err) => {
err;
});
});
if (window.config.isdd) {
this.ddlogout();
localStorage.removeItem("atoken");
this.$router.push("/login").catch((err) => {
err;
});
}
// location.reload();
},
resetpass() {
this.$router.push("/resetpass").catch((err) => {
err;
});
},
},
created() {
this.headertitle = window.config.hadertitle;
this.uname = localStorage.getItem("uname");
this.$api.device.getDev().then((m) => {
if (m.length < 1) {
this.$message({
message: "未发现运维服务,请联系相关人员",
type: "error",
});
this.setDevunid("9cb6e39adc5176b81879f6c22f1d963");
return;
}
this.setDevunid(m[0].dev_unid);
});
},
components: {
menus,
},
mounted() {
let theme = localStorage.getItem("fxtheme") || "light";
window.document.documentElement.setAttribute("data-theme", theme);
console.log(this.permission_routers);
this.conHeight = window.innerHeight - 65;
console.log(this.conHeight);
//监听退出全屏事件
var that = this;
document.onkeydown = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && e.keyCode == 122) {
if (that.isfull) {
that.isfull = false;
console.log(1);
} else {
that.isfull = true;
console.log(2);
}
}
};
let app = document.getElementById("app");
app.addEventListener("mousemove", () => {
if (window.mousetimer) {
clearTimeout(window.mousetimer);
}
window.mousetimer = setTimeout(() => {
clearTimeout(window.mousetimer);
window.mousetimer = null;
this.$message({
message: "由于您长时间未操作,将退出平台!",
type: "warning",
});
this.logout();
}, 600000);
});
// window.onresize = function() {
// console.log("full",that.isfull)
// if (that.isfull) {
// that.isfull = false;
// console.log(1)
// } else {
// that.isfull = true;
// console.log(2)
// }
// };
// function checkFull() {
// var isFull =
// document.fullscreenEnabled ||
// window.fullScreen ||
// document.webkitIsFullScreen ||
// document.msFullscreenEnabled;
// //to fix : false || undefined == undefined
// if (isFull === undefined) {
// isFull = false;
// }
// return isFull;
// }
setInterval(() => {
this.getDate();
}, 1000);
},
beforeMount() {
//建立ws连接
let uid = localStorage.getItem("user_unid");
let clientid = localStorage.getItem("client_unid");
this.$api.device.getGlobalWs(uid, clientid).then((data) => {
if (window.config.https) {
let url = data.ws_url.replace("ws://", "wss://");
this.globalWs = new WebSocket(url.replace("20080", "20070"));
} else {
let url = data.ws_url;
this.globalWs = new WebSocket(url);
}
let ary = data.ws_url.split("/");
localStorage.setItem("cennect_unid", ary[ary.length - 1]);
//监听成功
this.globalWs.onopen = function () {
console.log("全局推送服务连接成功");
};
//监听断开
this.globalWs.onclose = function () {
console.log("全局推送服务连接断开");
};
//监听推送信息
// this.globalWs.onmessage = this.wsdeal;
//保持连接
var $this = this;
setInterval(function () {
var send_mesage =
'{"type":"request","id":"' +
new Date().getTime() +
'","mts":"' +
new Date().getTime() +
'","command": "get /wsapi/v1/users/' +
localStorage.getItem("cennect_unid") +
'/keep_alive"}';
$this.globalWs.send(send_mesage);
}, 20000);
});
},
};
</script>
<style lang="stylus" scoped>
.menu-switch {
color: #fff;
font-size: 25px;
margin-left: 25px;
margin-top: 20px;
}
.headRight img {
cursor: pointer;
}
.zt-box {
margin-right: 80px;
}
.zt-btn {
// vertical-align middle
color: #fff;
font-size: 14px;
height: 50px;
line-height: 50px;
i {
font-size: 16px;
padding-right: 10px;
padding-top: 6px;
vertical-align: text-bottom;
}
}
.logotitle {
overflow: hidden;
font-size: 20px;
color: #ffffff;
display: inline-block;
line-height: 65px;
font-weight: 600;
letter-spacing: 2px;
float: left;
}
.timerbox {
padding-right: 30px;
}
.uname-box {
padding-right: 10px;
}
</style>