|
|
|
@ -3,9 +3,7 @@ var isApp = userAgent.indexOf('isapp') !== -1;
|
|
|
|
|
var localStoreMsg = false; // 是否本地存储消息
|
|
|
|
|
/* API 网关 */
|
|
|
|
|
var apigateway = config.apigateway;
|
|
|
|
|
console.log('config:');
|
|
|
|
|
console.log(apigateway);
|
|
|
|
|
|
|
|
|
|
/* 从存储载入消息 */
|
|
|
|
|
var isLoadedMSG = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -21,7 +19,6 @@ axios.interceptors.request.use(
|
|
|
|
|
config.headers['x-requested-with'] = 'XMLHttpRequest';
|
|
|
|
|
config.headers['Authorization'] = 'Bearer ' + store.state.accessToken;
|
|
|
|
|
config.headers['X-APP-VERSION'] = '2.0.0';
|
|
|
|
|
console.log('url:' + config.url + 'auth token:' + config.headers['Authorization']);
|
|
|
|
|
}
|
|
|
|
|
// 绝对路径替换为网关+路径 (防止多次请求重复拼接URL)
|
|
|
|
|
config.url = config.url.indexOf('/') == 0 ? apigateway + config.url : config.url;
|
|
|
|
@ -32,8 +29,6 @@ axios.interceptors.request.use(
|
|
|
|
|
return config;
|
|
|
|
|
},
|
|
|
|
|
function (error) {
|
|
|
|
|
console.log('axios.interceptors.request.error:');
|
|
|
|
|
console.log(error);
|
|
|
|
|
$('#loading').fadeOut(100);
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
}
|
|
|
|
@ -44,8 +39,6 @@ axios.interceptors.request.use(
|
|
|
|
|
* 前端网络请求异常统一处理
|
|
|
|
|
*/
|
|
|
|
|
axios.interceptors.response.use(function (response) {
|
|
|
|
|
console.log('axios.interceptors.response:');
|
|
|
|
|
console.log(response);
|
|
|
|
|
$('#loading').fadeOut(100);
|
|
|
|
|
//根据config内容动态设置url
|
|
|
|
|
|
|
|
|
@ -88,7 +81,7 @@ axios.interceptors.response.use(function (response) {
|
|
|
|
|
error.config.headers['Authorization'] = 'Bearer ' + store.state.accessToken;
|
|
|
|
|
console.log('刷新token后重发api请求');
|
|
|
|
|
/* 重新发送原请求 */
|
|
|
|
|
delete error.config.headers.Authorization //移除旧的AccessToken信息,避免拦截器无法设置新AccessToken
|
|
|
|
|
delete error.config.headers.Authorization // 移除旧的AccessToken信息,避免拦截器无法设置新AccessToken
|
|
|
|
|
axios.request(error.config);
|
|
|
|
|
})
|
|
|
|
|
.catch(function (error) { // 如果为RefreshToken失败则跳转登录页面
|
|
|
|
@ -111,11 +104,7 @@ const router = new VueRouter({
|
|
|
|
|
});
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
$('#loading').show();
|
|
|
|
|
console.log('before...')
|
|
|
|
|
console.log('store.state.accessToken', store.state.accessToken)
|
|
|
|
|
console.log('to.path', to.path)
|
|
|
|
|
if (!store.state.accessToken && to.path !== '/pages/login') {
|
|
|
|
|
console.log('router.push')
|
|
|
|
|
router.push('/pages/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -128,14 +117,10 @@ router.beforeEach((to, from, next) => {
|
|
|
|
|
route = routeList[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log('route', route)
|
|
|
|
|
if (!route) {
|
|
|
|
|
console.log('<<<!route to.path>>>', to.path)
|
|
|
|
|
var path = to.path === '/' ? '/pages/home' : to.path;
|
|
|
|
|
|
|
|
|
|
var url = path + '.js';
|
|
|
|
|
var method = path.replace(/\//g, '_').substr(1) + "()";
|
|
|
|
|
console.log('preRoute:from ' + from.path + ' to path ' + to.path);
|
|
|
|
|
$.getScript(url, function () {
|
|
|
|
|
var response = eval(method);
|
|
|
|
|
var route = {
|
|
|
|
@ -149,8 +134,6 @@ router.beforeEach((to, from, next) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.log('!route else', route)
|
|
|
|
|
console.log('route from:' + from.path + ' to:' + to.path);
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -185,7 +168,6 @@ if(indexedDB){
|
|
|
|
|
console.log('不支持');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(indexedDB);
|
|
|
|
|
var db = null;
|
|
|
|
|
var request = indexedDB.open('app', 1);
|
|
|
|
|
request.onupgradeneeded = function(e) {
|
|
|
|
@ -201,29 +183,22 @@ request.onsuccess = function() {
|
|
|
|
|
/**
|
|
|
|
|
* 初始化消息列表
|
|
|
|
|
*/
|
|
|
|
|
console.log('loading message');
|
|
|
|
|
|
|
|
|
|
//loadMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveMessage(msg){
|
|
|
|
|
if(db){
|
|
|
|
|
console.log("数据库打开");
|
|
|
|
|
console.log(db);
|
|
|
|
|
var transaction = db.transaction('message','readwrite');
|
|
|
|
|
var objectStore = transaction.objectStore('message');
|
|
|
|
|
console.log("数据:");
|
|
|
|
|
console.log(msg);
|
|
|
|
|
console.log("类型:");
|
|
|
|
|
var jsonMsg = JSON.parse(msg);
|
|
|
|
|
console.log(typeof JSON.parse(msg));
|
|
|
|
|
// 校验数据格式(当前只存储带key的消息,后续会有调整)
|
|
|
|
|
if( jsonMsg.key ){
|
|
|
|
|
console.log('IS MSG');
|
|
|
|
|
// 本地存储
|
|
|
|
|
if(localStoreMsg){
|
|
|
|
|
objectStore.add({data: jsonMsg});
|
|
|
|
|
}
|
|
|
|
|
// objectStore.delete(store.state.messages[0]._id);
|
|
|
|
|
store.commit('setMessages', [{data: jsonMsg}]);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
@ -231,50 +206,32 @@ function saveMessage(msg){
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadMessage(callback, limit = 10){
|
|
|
|
|
function loadMessage(callback, limit = 99){
|
|
|
|
|
if(db){
|
|
|
|
|
console.log("数据库打开");
|
|
|
|
|
console.log(db);
|
|
|
|
|
var transaction = db.transaction('message','readwrite');
|
|
|
|
|
var objectStore = transaction.objectStore('message');
|
|
|
|
|
console.log('objectStore:')
|
|
|
|
|
console.log(objectStore);
|
|
|
|
|
var req = objectStore.openCursor();
|
|
|
|
|
console.log('req:')
|
|
|
|
|
console.log(req);
|
|
|
|
|
var items = [];
|
|
|
|
|
// 回调会被多次调用
|
|
|
|
|
req.onsuccess = function (evt) {
|
|
|
|
|
var cursor = evt.target.result;
|
|
|
|
|
console.log('cursor:')
|
|
|
|
|
console.log(cursor);
|
|
|
|
|
if(cursor){ // 必要检查
|
|
|
|
|
var item = cursor.value;
|
|
|
|
|
//console.log(item);
|
|
|
|
|
if(item.data.device){
|
|
|
|
|
items.push(item);
|
|
|
|
|
console.log('append item !!!');
|
|
|
|
|
//console.log(items);
|
|
|
|
|
console.log('####### item #######');
|
|
|
|
|
console.log('displayName: ' + item.data.device.displayName);
|
|
|
|
|
console.log('Name: ' + item.data.name);
|
|
|
|
|
console.log('Value: ' + item.data.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cursor.continue(); // 移动到下一项
|
|
|
|
|
}else{
|
|
|
|
|
// 回调函数
|
|
|
|
|
console.log('call back!!!');
|
|
|
|
|
callback(items);
|
|
|
|
|
// 加载后删除数据库,只缓存上次应用开启数据
|
|
|
|
|
//indexedDB.deleteDatabase('app');
|
|
|
|
|
objectStore.clear();
|
|
|
|
|
//alert(items.length -100)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
console.log(limit);
|
|
|
|
|
var req = objectStore.get(limit);
|
|
|
|
|
req.onerror = function(event) {
|
|
|
|
|
console.log('事务失败');
|
|
|
|
@ -292,7 +249,6 @@ const app = new Vue({
|
|
|
|
|
data: {
|
|
|
|
|
},
|
|
|
|
|
mounted: function () {
|
|
|
|
|
console.log('mounted:app');
|
|
|
|
|
// 判断是否登录
|
|
|
|
|
if(localStorage.getItem('accessToken') === null){
|
|
|
|
|
//
|
|
|
|
@ -300,8 +256,9 @@ const app = new Vue({
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
destroyed: function(){
|
|
|
|
|
alert('des');
|
|
|
|
|
//Todo
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
//Todo
|
|
|
|
|
},
|
|
|
|
|
}).$mount('#app');
|