You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.2 KiB
83 lines
2.2 KiB
var userAgent = navigator.userAgent;
|
|
var isApp = userAgent.indexOf('isapp') !== -1;
|
|
var hubUrl = "/IoTCenter/hub?group=page";
|
|
var connection = new signalR.HubConnectionBuilder().withUrl(hubUrl).build();
|
|
connection.on('Connected', function (id) {
|
|
connectionId = id;
|
|
console.log(connectionId);
|
|
});
|
|
connection.on("ServerToClient", function (method, json, to, from) {
|
|
console.log(method + ':' + json);
|
|
});
|
|
function connect() {
|
|
if (connection.state === signalR.HubConnectionState.Disconnected) {
|
|
connection.start().then(function () {
|
|
console.log('客户端与服务器连接成功!');
|
|
}).catch(function (err) {
|
|
console.log(err);
|
|
setTimeout(connect, 15 * 1000);
|
|
});
|
|
}
|
|
}
|
|
|
|
///
|
|
var token=localStorage.getItem('accessToken');
|
|
var refreshToken= localStorage.getItem('refreshToken');
|
|
const routes = [
|
|
];
|
|
var routeList = routes.concat();
|
|
const router = new VueRouter({
|
|
routes
|
|
});
|
|
router.beforeEach((to, from, next) => {
|
|
$('#loadingToast').show();
|
|
if (!token && to.path !== '/login') {
|
|
router.push('/login');
|
|
return;
|
|
}
|
|
if (token) {
|
|
connect();
|
|
}
|
|
var route;
|
|
for (var i = 0; i < routeList.length; i++) {
|
|
if (routeList[i].path == to.path) {
|
|
route = routeList[i];
|
|
}
|
|
}
|
|
if (!route) {
|
|
var path = to.path === '/' ? '/pchome' : to.path;
|
|
var url = path + '.js';
|
|
var method = path.replace(/\//g, '_').substr(1) + "()";
|
|
console.log('preRoute:'+path+ '|'+url+'|' + method);
|
|
$.getScript(url, function () {
|
|
var route = {
|
|
path: to.path,
|
|
component: eval(method),
|
|
};
|
|
router.addRoutes([route]);
|
|
routeList.push(route);
|
|
router.push(to.fullPath);
|
|
});
|
|
}
|
|
else {
|
|
console.log('route from:'+from.path +' to:'+to.path);
|
|
next();
|
|
}
|
|
});
|
|
router.afterEach((route, redirect) => {
|
|
Vue.nextTick(() => {
|
|
$('#loadingToast').fadeOut(100);
|
|
})
|
|
})
|
|
///
|
|
const app = new Vue({
|
|
router,
|
|
data: {
|
|
},
|
|
mounted: function () {
|
|
console.log('mounted:app');
|
|
},
|
|
methods: {
|
|
}
|
|
}).$mount('#app');
|