diff --git a/main/src/utils/axios.js b/main/src/utils/axios.js index 1726b8b..773f65a 100644 --- a/main/src/utils/axios.js +++ b/main/src/utils/axios.js @@ -46,6 +46,7 @@ const errorHandler = async (error) => { */ publicAxios.interceptors.request.use(async (config) => { const UserStore = useUserStore(); + config.headers['source'] = 'main'; if (UserStore.hasToken()) { config.headers['authorization'] = config.headers['authorization'] ?? UserStore.token; config.headers['cache-control'] = 'no-cache'; diff --git a/main/src/views/login/index.vue b/main/src/views/login/index.vue index 473afad..02d4e96 100644 --- a/main/src/views/login/index.vue +++ b/main/src/views/login/index.vue @@ -117,10 +117,12 @@ export default { Cookies.set('username', this.loginForm.username, { expires: 30 }); Cookies.set('password', encrypt(this.loginForm.password), { expires: 30 }); Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); + localStorage.setItem('source', 'main'); } else { Cookies.remove('username'); Cookies.remove('password'); Cookies.remove('rememberMe'); + localStorage.removeItem('source'); } try { const res = await Login(this.loginForm); diff --git a/sub-government-affairs-service/src/App.vue b/sub-government-affairs-service/src/App.vue index 7a2b418..f4a4aaf 100644 --- a/sub-government-affairs-service/src/App.vue +++ b/sub-government-affairs-service/src/App.vue @@ -12,11 +12,25 @@ diff --git a/sub-operation-service/src/layouts/component/Header/index.vue b/sub-operation-service/src/layouts/component/Header/index.vue index 2264d43..9b0d11a 100644 --- a/sub-operation-service/src/layouts/component/Header/index.vue +++ b/sub-operation-service/src/layouts/component/Header/index.vue @@ -14,6 +14,10 @@
+ +
+ 返回首页 +
@@ -24,10 +28,7 @@ 商家中心 个人中心 - -
- 返回首页 -
+ 退出登录
@@ -74,6 +75,8 @@ import { useRouter } from 'vue-router'; import { getAssetsFile } from '@/utils'; import { getGoodNum } from '@/apis/agricultural.js'; import { useMethodsStore } from '@/store/modules/methods'; +import { ElMessage, ElMessageBox } from 'element-plus'; +import { Logout } from '../../../apis/login'; const router = useRouter(); @@ -134,6 +137,41 @@ onBeforeUnmount(() => { methodsStore.registerOuterMethod(null); }); +const loginOut = () => { + ElMessageBox.confirm('您是否确认退出登录?', '温馨提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }).then(() => { + Logout().then((res) => { + if (res.code === 200) { + if (res.data.source !== 'main') { + router.push({ path: '/sub-operation-service/login' }); + ElMessage({ + type: 'success', + message: '退出登录成功!', + }); + localStorage.removeItem('daimp-front-main_user_store'); + } else { + console.log('退出到门户页'); + } + } + }); + }); + + // if (res.data.source !== 'main') { + // router.push({ path: '/sub-government-affairs-service/login' }); + // ElMessage({ + // type: 'success', + // message: '退出登录成功!', + // }); + // localStorage.removeItem('daimp-front-main_user_store'); + // } else { + // console.log('退出到门户页'); + // } + // router.push('/sub-operation-service/login'); +}; + function Search() { console.log(keyword.value, 'search'); } @@ -338,6 +376,7 @@ const toCart = () => { margin-top: 0; } .layout-header-top-right { + align-items: center; display: flex; .item { margin-left: 25px; diff --git a/sub-operation-service/src/router/index.js b/sub-operation-service/src/router/index.js index 5a7408d..ea58377 100644 --- a/sub-operation-service/src/router/index.js +++ b/sub-operation-service/src/router/index.js @@ -12,6 +12,12 @@ import Views from '@/layouts/Views.vue'; import userCentre from '@/layouts/userCentre.vue'; export const constantRoutes = [ + { + path: '/sub-operation-service/login', + name: 'login', + component: () => import('@/layouts/Logo/index.vue'), + hidden: true, + }, { path: '/sub-operation-service/404', name: '404', diff --git a/sub-operation-service/src/utils/axios.js b/sub-operation-service/src/utils/axios.js index 3200d9b..01c41f8 100644 --- a/sub-operation-service/src/utils/axios.js +++ b/sub-operation-service/src/utils/axios.js @@ -44,6 +44,12 @@ const errorHandler = async (error) => { */ publicAxios.interceptors.request.use(async (config) => { const UserStore = useUserStore(); + + if (localStorage.getItem('source')) { + config.headers['source'] = 'main'; + } else { + config.headers['source'] = 'indus-pc'; + } switch (config.apisType) { case 'upload': { config.baseURL = VITE_APP_UPLOAD_API; diff --git a/sub-operation-service/src/utils/permission.js b/sub-operation-service/src/utils/permission.js index 68d91ec..aa59d5b 100644 --- a/sub-operation-service/src/utils/permission.js +++ b/sub-operation-service/src/utils/permission.js @@ -26,33 +26,58 @@ router.beforeEach(async (to, from, next) => { console.log('sub-operation-service************hasToken', hasToken); if (hasToken) { if (to.path === '/login') { - // 如果已登录,请重定向到主页 next({ path: '/' }); } else { - try { - const PermissionStore = usePermissionStore(); - if (!PermissionStore.routes.length) { - const accessRoutes = await PermissionStore.generateRoutes(userStore.roles); - accessRoutes.forEach((item) => router.addRoute(item)); - return next({ ...to, replace: true }); - } else { - if (from.path.includes('/sub') && to.path.includes('/platform')) { - window.location.reload(); - return; - } - next(); + const PermissionStore = usePermissionStore(); + if (!PermissionStore.routes.length) { + const accessRoutes = await PermissionStore.generateRoutes(userStore.roles); + accessRoutes.forEach((item) => router.addRoute(item)); + return next({ ...to, replace: true }); + } else { + if (from.path.includes('/sub') && to.path.includes('/platform')) { + window.location.reload(); + return; } - } catch (error) { - next(`/login?redirect=${to.path}`); + next(); } } } else { - if (whiteList.indexOf(to.path) !== -1) { + NProgress.done(); + if (to.path == '/sub-operation-service/login') { next(); } else { - next(`/login?redirect=${to.path}`); + next('/sub-operation-service/login'); } } + // if (hasToken) { + // if (to.path === '/login') { + // // 如果已登录,请重定向到主页 + // next({ path: '/' }); + // } else { + // try { + // const PermissionStore = usePermissionStore(); + // if (!PermissionStore.routes.length) { + // const accessRoutes = await PermissionStore.generateRoutes(userStore.roles); + // accessRoutes.forEach((item) => router.addRoute(item)); + // return next({ ...to, replace: true }); + // } else { + // if (from.path.includes('/sub') && to.path.includes('/platform')) { + // window.location.reload(); + // return; + // } + // next(); + // } + // } catch (error) { + // next(`/login?redirect=${to.path}`); + // } + // } + // } else { + // if (whiteList.indexOf(to.path) !== -1) { + // next(); + // } else { + // next(`/login?redirect=${to.path}`); + // } + // } }); router.afterEach(() => {