pull/1/head
pnoker 4 years ago
parent d21ed8b660
commit fdd70d1829

@ -20,3 +20,4 @@ services:
networks:
dc3net:
driver: 'bridge'
...

@ -1,6 +1,6 @@
server {
listen 80;
server_name dc3.com localhost;
server_name dc3-web localhost;
location / {
root /usr/share/nginx/html;
@ -17,7 +17,7 @@ server {
server {
listen 443 ssl;
server_name dc3.com localhost;
server_name dc3-web localhost;
add_header X-Xss-Protection 1;
add_header X-Frame-Options DENY;
@ -44,6 +44,10 @@ server {
proxy_pass http://dc3-manager:8400/;
}
location ^~/data_api/ {
proxy_pass http://dc3-data:8500/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;

@ -1,10 +1,10 @@
import axios from 'axios'
import router from '@/router/router'
import store from '@/store/store';
import {Message} from 'element-ui'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import {getToken} from '@/util/auth'
import {showError} from '@/util/util'
//返回其他状态码
axios.defaults.validateStatus = function (status) {
@ -38,17 +38,13 @@ axios.interceptors.response.use(res => {
if (status === 401) store.dispatch('FedLogOut').then(() => router.push({path: '/login'}));
// 如果请求为 !ok 默认统一处理
if (!ok) {
Message({
center: true,
type: 'error',
showClose: true,
message: message
});
showError(message);
return Promise.reject(new Error(message));
}
return res.data;
}, error => {
NProgress.done();
showError('未知错误');
return Promise.reject(new Error(error));
});

@ -1,35 +0,0 @@
import router from '@/router/router'
import store from '@/store/store'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import {getToken} from '@/util/auth'
router.beforeEach((to, from, next) => {
NProgress.start();
const meta = to.meta || {};
if (getToken()) {
if (to.path === '/login') { //如果登录成功访问登录页跳转到主页
next({path: '/'})
} else {
//如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页
if (store.getters.token.length === 0) {
store.dispatch('FedLogOut').then(() => {
next({path: '/login'})
})
} else {
next()
}
}
} else {
//判断是否需要认证,没有登录访问去登录页
if (meta.isAuth === false) {
next()
} else {
next('/login')
}
}
});
router.afterEach(() => {
NProgress.done();
});

@ -5,7 +5,6 @@ import App from './App'
import router from './router/router'
import store from './store/store'
import './plugins/element/element.js'
import './config/permission';
Vue.use(VueAxios, axios);

@ -2,6 +2,10 @@ import Vue from 'vue'
import VueRouter from 'vue-router'
import CommonRouter from './common/index'
import ViewsRouter from './views/index'
import NProgress from "nprogress";
import {getToken} from "@/util/auth";
import store from "@/store/store";
import {checkTokenValid} from "@/api/user";
Vue.use(VueRouter);
@ -22,6 +26,30 @@ const router = new VueRouter({
routes: []
});
router.beforeEach((to, from, next) => {
NProgress.start();
const meta = to.meta || {};
if (meta.isAuth !== true) {
next();
} else {
checkTokenValid(getToken()).then(res => {
if (res.ok && store.getters.token.length > 0) {
next();
} else {
throw new Error(res.message);
}
}).catch(() => {
store.dispatch('ClearToken').then(() => {
next({path: '/login'})
});
});
}
});
router.afterEach(() => {
NProgress.done();
});
router.addRoutes([...CommonRouter, ...ViewsRouter]);
export default router

@ -1,6 +1,6 @@
import {getStore, setStore} from '@/util/store'
import {setToken} from '@/util/auth'
import {checkTokenValid, generateToken} from '@/api/user'
import {getStore, removeStore, setStore} from '@/util/store'
import {removeToken, setToken} from '@/util/auth'
import {generateToken} from '@/api/user'
const user = {
state: {
@ -20,14 +20,9 @@ const user = {
})
})
},
CheckTokenValid(body) {
return new Promise((resolve, reject) => {
checkTokenValid(body).then(() => {
resolve();
}).catch(error => {
reject(error)
})
})
ClearToken({commit}) {
commit('REMOVE_TOKEN');
commit('REMOVE_USER');
}
},
mutations: {
@ -39,6 +34,15 @@ const user = {
SET_USER: (state, userInfo) => {
state.userInfo = userInfo;
setStore({name: 'userInfo', content: state.userInfo})
},
REMOVE_TOKEN: (state) => {
removeToken();
state.token = '';
removeStore({name: 'token', type: 'session'});
},
REMOVE_USER: (state) => {
state.userInfo = '';
removeStore({name: 'userInfo'});
}
}
};

@ -13,4 +13,4 @@ export function setToken(token) {
export function removeToken() {
return Cookies.remove(TokenKey);
}
}

@ -375,4 +375,13 @@ export const openWindow = (url, title, w, h) => {
if (window.focus) {
newWindow.focus()
}
};
};
export const showError = (message) => {
Message({
center: true,
type: 'error',
showClose: true,
message: message
});
};

@ -189,6 +189,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -196,15 +197,13 @@
group() {
dictionaryApi.groupDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('groupId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
profile() {
dictionaryApi.profileDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('profileId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
listAdd(row, done, loading) {
@ -212,6 +211,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});
@ -233,6 +233,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -125,6 +125,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -146,6 +147,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -203,6 +203,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -210,8 +211,7 @@
driver() {
dictionaryApi.driverDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('driverId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
listAdd(row, done, loading) {
@ -219,6 +219,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});
@ -240,6 +241,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -144,6 +144,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -151,15 +152,13 @@
profile() {
dictionaryApi.profileDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('profileId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
driverAttribute() {
dictionaryApi.driverAttributeDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('driverAttributeId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
listAdd(row, done, loading) {
@ -167,6 +166,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});
@ -188,6 +188,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -115,6 +115,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -124,6 +125,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});
@ -145,6 +147,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -69,7 +69,13 @@
this.$message('click on message');
},
handleCommand(command) {
this.$message('click on item ' + command);
if (command === 'logout') {
this.$store.dispatch('ClearToken').then(() => {
this.$router.push('/login');
});
} else {
this.$message('click on item ' + command);
}
}
}
}

@ -308,6 +308,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -315,8 +316,7 @@
profile() {
dictionaryApi.profileDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('profileId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
listAdd(row, done, loading) {
@ -324,6 +324,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});
@ -345,6 +346,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -203,6 +203,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -210,8 +211,7 @@
driver() {
dictionaryApi.driverDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('driverId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
listAdd(row, done, loading) {
@ -219,6 +219,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});
@ -240,6 +241,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -161,6 +161,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -168,22 +169,19 @@
device() {
dictionaryApi.deviceDictionary('group').then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('deviceId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
point() {
dictionaryApi.pointDictionary('profile').then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('pointId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
pointAttribute() {
dictionaryApi.pointAttributeDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('pointAttributeId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
listAdd(row, done, loading) {
@ -191,6 +189,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});
@ -212,6 +211,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -136,6 +136,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -143,15 +144,13 @@
device() {
dictionaryApi.deviceDictionary('group').then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('deviceId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
point() {
dictionaryApi.pointDictionary('profile').then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('pointId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
dateChange(date) {

@ -162,6 +162,7 @@
const data = res.data;
this.page.total = data.total;
this.listData = data.records;
}).catch(() => {
}).finally(() => {
this.loading = false;
});
@ -169,8 +170,7 @@
driver() {
dictionaryApi.driverDictionary().then(res => {
this.listOption.column[this.$refs.crud.findColumnIndex('driverId')].dicData = res.data;
}).catch((e) => {
console.log(e);
}).catch(() => {
});
},
listAdd(row, done, loading) {
@ -178,6 +178,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});
@ -199,6 +200,7 @@
loading();
this.list(this.page);
successMessage();
}).catch(() => {
}).finally(() => {
done();
});

@ -4,14 +4,6 @@ module.exports = {
productionSourceMap: false,
devServer: {
proxy: {
'/api': {
target: 'http://localhost:8400',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
},
'/user_api': {
target: 'http://dc3-auth:8300',
changeOrigin: true,

Loading…
Cancel
Save