diff --git a/config/dev.env.js b/config/dev.env.js
index 648a19eb..4bd8c9b5 100644
--- a/config/dev.env.js
+++ b/config/dev.env.js
@@ -4,5 +4,5 @@ const prodEnv = require('./prod.env')
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',
- BASE_API: '"http://user.api.it120.cc"',
+ BASE_API: '"http://127.0.0.1:8082"',
})
diff --git a/src/api/centeruser.js b/src/api/centeruser.js
new file mode 100644
index 00000000..c4886a69
--- /dev/null
+++ b/src/api/centeruser.js
@@ -0,0 +1,8 @@
+import request from '@/utils/request'
+
+export function info() {
+ return request({
+ url: '/user/info',
+ method: 'get'
+ })
+}
diff --git a/src/api/login.js b/src/api/login.js
index b039e81c..096d1f45 100644
--- a/src/api/login.js
+++ b/src/api/login.js
@@ -64,6 +64,14 @@ export function resetpwd(mobile, pwd, smsCode) {
})
}
+export function checkToken() {
+ return request({
+ url: '/user/checkToken',
+ method: 'get',
+ params: { }
+ })
+}
+
export function getInfo(token) {
return request({
url: '/user/info',
@@ -74,7 +82,7 @@ export function getInfo(token) {
export function logout() {
return request({
- url: '/user/logout',
- method: 'post'
+ url: '/login/exit',
+ method: 'get'
})
}
diff --git a/src/components/Breadcrumb/index.vue b/src/components/Breadcrumb/index.vue
index b5d94716..4145c901 100644
--- a/src/components/Breadcrumb/index.vue
+++ b/src/components/Breadcrumb/index.vue
@@ -29,7 +29,7 @@ export default {
let matched = this.$route.matched.filter(item => item.name)
const first = matched[0]
if (first && first.name !== 'dashboard') {
- matched = [{ path: '/dashboard', meta: { title: 'Dashboard' }}].concat(matched)
+ matched = [{ path: '/dashboard', meta: { title: '首页' }}].concat(matched)
}
this.levelList = matched
}
diff --git a/src/icons/svg/home.svg b/src/icons/svg/home.svg
new file mode 100644
index 00000000..02ba9cf0
--- /dev/null
+++ b/src/icons/svg/home.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/icons/svg/setting.svg b/src/icons/svg/setting.svg
new file mode 100644
index 00000000..b44c8089
--- /dev/null
+++ b/src/icons/svg/setting.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/permission.js b/src/permission.js
index f0832a81..e37a1a2f 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -1,11 +1,11 @@
import router from './router'
-import store from './store'
+import { checkToken, logout } from '@/api/login'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式
import { Message } from 'element-ui'
-import { getToken } from '@/utils/auth' // 验权
+import { getToken, removeToken } from '@/utils/auth' // 验权
-const whiteList = ['/login', '/register', '/resetpwd'] // 不重定向白名单
+const whiteList = ['/login', '/register', '/resetpwd'] // 不判断权限白名单
router.beforeEach((to, from, next) => {
NProgress.start()
if (getToken()) {
@@ -13,18 +13,15 @@ router.beforeEach((to, from, next) => {
next({ path: '/' })
NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it
} else {
- if (store.getters.roles.length === 0) {
- store.dispatch('GetInfo').then(res => { // 拉取用户信息
- next()
- }).catch((err) => {
- store.dispatch('FedLogOut').then(() => {
- Message.error(err || 'Verification failed, please login again')
- next({ path: '/' })
- })
- })
- } else {
+ checkToken().then(res => { // 判断token有效性
next()
- }
+ }).catch((err) => {
+ logout().then(() => {
+ Message.error(err || '已成功退出')
+ removeToken()
+ next({ path: '/' })
+ })
+ })
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
diff --git a/src/router/index.js b/src/router/index.js
index 88fb0f44..5a4fc72f 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -28,14 +28,29 @@ export const constantRouterMap = [
{ path: '/404', component: () => import('@/views/404'), hidden: true },
{
- path: '/',
+ path: '',
component: Layout,
redirect: '/dashboard',
- name: 'Dashboard',
- hidden: true,
children: [{
path: 'dashboard',
- component: () => import('@/views/dashboard/index')
+ component: () => import('@/views/dashboard/index'),
+ meta: { title: '首页', icon: 'home' }
+ }]
+ },
+
+ {
+ path: '',
+ component: Layout,
+ meta: { title: '工厂设置', icon: 'setting' },
+ children: [{
+ path: 'dashboard2',
+ component: () => import('@/views/dashboard/index'),
+ meta: { title: '我的资源包', icon: 'setting' }
+ },
+ {
+ path: 'dashboard3',
+ component: () => import('@/views/dashboard/index'),
+ meta: { title: '我的资源包', icon: 'setting' }
}]
},
diff --git a/src/utils/auth.js b/src/utils/auth.js
index 08a43d6e..6cc22ac8 100644
--- a/src/utils/auth.js
+++ b/src/utils/auth.js
@@ -1,6 +1,6 @@
import Cookies from 'js-cookie'
-const TokenKey = 'Admin-Token'
+const TokenKey = 'apifactory-token'
export function getToken() {
return Cookies.get(TokenKey)
diff --git a/src/views/layout/components/Navbar.vue b/src/views/layout/components/Navbar.vue
index eb36b1ac..235d2910 100644
--- a/src/views/layout/components/Navbar.vue
+++ b/src/views/layout/components/Navbar.vue
@@ -4,17 +4,17 @@
-
![]()
+
当前登录: {{centeruserinfo.realName}} ( {{centeruserinfo.mobile}} )
- Home
+ 首页
- LogOut
+ 退出
@@ -25,6 +25,10 @@
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
+import { logout } from '@/api/login'
+import { info } from '@/api/centeruser'
+import { removeToken } from '@/utils/auth'
+import { Message } from 'element-ui'
export default {
components: {
@@ -37,13 +41,25 @@ export default {
'avatar'
])
},
+ data() {
+ return {
+ centeruserinfo:{}
+ }
+ },
+ mounted() {
+ info().then(res => {
+ this.centeruserinfo = res.data;
+ });
+ },
methods: {
toggleSideBar() {
this.$store.dispatch('ToggleSideBar')
},
logout() {
- this.$store.dispatch('LogOut').then(() => {
- location.reload() // 为了重新实例化vue-router对象 避免bug
+ logout().then(() => {
+ Message.error('已成功退出')
+ removeToken()
+ location.reload();
})
}
}
diff --git a/src/views/login/index.vue b/src/views/login/index.vue
index 309e96e2..3f972b6f 100644
--- a/src/views/login/index.vue
+++ b/src/views/login/index.vue
@@ -147,7 +147,7 @@ export default {
duration: 1 * 1000,
onClose: () => {
setToken(res.data);
- this.$router.push({ path: '/' })
+ this.$router.push({ path: '/' })
}
})
}).catch((err) => {
@@ -162,6 +162,7 @@ export default {
},
changeRandom() {
this.loginForm.picKey = Math.random();
+ // (document.getElementsByClassName('random'))[0].setAttribute('src', 'http://127.0.0.1:8082/code?k=' + this.loginForm.picKey)
(document.getElementsByClassName('random'))[0].setAttribute('src', 'http://user.api.it120.cc/code?k=' + this.loginForm.picKey)
}
}