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.
125 lines
3.1 KiB
125 lines
3.1 KiB
//配置:
|
|
var config = {
|
|
baseUrl: '',
|
|
url: function (path) {
|
|
return this.baseUrl + path;
|
|
}
|
|
};
|
|
|
|
//添加通用组件:
|
|
addVueComponents({
|
|
prefix: "/components/views/shared/",
|
|
list: [
|
|
'layout',
|
|
'nav'
|
|
]
|
|
});
|
|
|
|
//添加设备组件:
|
|
addVueComponents({
|
|
prefix: "/components/devices/",
|
|
list: [
|
|
'gateway',
|
|
'humiture',
|
|
'light',
|
|
'infrared',
|
|
'smoke',
|
|
'switch1',
|
|
'socket',
|
|
'curtain',
|
|
'door',
|
|
]
|
|
});
|
|
|
|
//message:
|
|
var connectionId;
|
|
var connection = new signalR.HubConnectionBuilder().withUrl(config.url('hub?group=page')).build();
|
|
connection.onclose(function () {
|
|
console.log('connect closed');
|
|
connect();
|
|
});
|
|
|
|
connection.on('Connected', function (id) {
|
|
connectionId = id;
|
|
PubSub.publish('Connected');
|
|
});
|
|
|
|
connection.on("ServerToClient", function (method, message, to, from) {
|
|
console.log(method);
|
|
PubSub.publish(method, { message: message, to: to, from: from });
|
|
});
|
|
//connect();
|
|
|
|
//router:
|
|
var routes = [];
|
|
var home = '/components/views/areas/default/index.html';
|
|
var login = '/components/views/account/login.html';
|
|
const router = new VueRouter();
|
|
router.beforeEach((to, from, next) => {
|
|
var url = to.path === '/' ? home : to.path;
|
|
var name = url.substring(1, url.length - 5).replace(/\//g, "-");
|
|
var route = routes[name];
|
|
if (!route) {
|
|
axios.get(url, { headers: { 'Cache-Control': 'no-cache' } }).then(function (response) {
|
|
var model = parseModel(response);
|
|
route = {
|
|
name: name,
|
|
path: to.path,
|
|
component: model,
|
|
meta: model.meta
|
|
};
|
|
router.addRoutes([route]);
|
|
routes[name] = route;
|
|
router.push({ path: to.path, query: to.query });
|
|
});
|
|
}
|
|
else {
|
|
next();
|
|
}
|
|
});
|
|
|
|
//vuex
|
|
Vue.use(Vuex);
|
|
const store = new Vuex.Store({
|
|
strict: true,
|
|
state: {
|
|
//token: {
|
|
// accessToken: localStorage.getItem("accessToken"),
|
|
// refreshToken: localStorage.getItem("refreshToken")
|
|
//},
|
|
layout: null
|
|
},
|
|
mutations: {
|
|
set(state, data) {
|
|
state[data.key] = data.value;
|
|
},
|
|
//login(state, data) {
|
|
// localStorage.setItem('accessToken', data.accessToken);
|
|
// localStorage.setItem('refreshToken', data.refreshToken);
|
|
// state.token.accessToken = data.accessToken;
|
|
// state.token.refreshToken = data.refreshToken;
|
|
//},
|
|
//logout(state) {
|
|
// localStorage.removeItem('accessToken');
|
|
// localStorage.removeItem('refreshToken');
|
|
// state.token.accessToken = null;
|
|
// state.token.refreshToken = null;
|
|
//}
|
|
}
|
|
});
|
|
store.set = function(key, value)
|
|
{
|
|
store.commit('set', { key: key, value: value });
|
|
}
|
|
|
|
//start:
|
|
const app = new Vue({
|
|
el: '#app',
|
|
router,
|
|
store: store,
|
|
mounted: function () {
|
|
//router.push('/components/views/home/index.html')
|
|
connect();
|
|
console.log('app start');
|
|
}
|
|
}); |