夏滨修改登录
This commit is contained in:
parent
4156eea27c
commit
e0b86a230b
@ -4,17 +4,10 @@ VITE_MODE = 'DEV'
|
|||||||
VITE_APP_MIAN = 'daimp-front-main'
|
VITE_APP_MIAN = 'daimp-front-main'
|
||||||
VITE_APP_MIAN_URL = 'http://localhost:9000'
|
VITE_APP_MIAN_URL = 'http://localhost:9000'
|
||||||
VITE_APP_NAME = 'sub-government-affairs-service'
|
VITE_APP_NAME = 'sub-government-affairs-service'
|
||||||
|
|
||||||
VITE_APP_BASE_API = '/apis'
|
VITE_APP_BASE_API = '/apis'
|
||||||
VITE_APP_UPLOAD_API = '/uploadApis'
|
|
||||||
|
|
||||||
# 阿里云接口地址
|
|
||||||
# VITE_APP_BASE_URL = 'http://47.109.205.240:8080'
|
|
||||||
# VITE_APP_UPLOAD_URL = 'http://47.109.205.240:9204'
|
|
||||||
|
|
||||||
# 内网测试库接口地址
|
|
||||||
# VITE_APP_BASE_URL = 'http://192.168.18.99:8080'
|
# VITE_APP_BASE_URL = 'http://192.168.18.99:8080'
|
||||||
|
|
||||||
# 本地开发接口地址
|
|
||||||
VITE_APP_BASE_URL = 'http://192.168.18.74:8080'
|
VITE_APP_BASE_URL = 'http://192.168.18.74:8080'
|
||||||
VITE_APP_UPLOAD_URL = 'http://192.168.18.74:8080'
|
VITE_APP_UPLOAD_API = '/uploadApis'
|
||||||
|
VITE_APP_UPLOAD_URL = 'http://192.168.18.99:9300'
|
||||||
|
|
||||||
|
|
||||||
|
62
sub-government-affairs-service/src/apis/login.js
Normal file
62
sub-government-affairs-service/src/apis/login.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import request from '@/utils/axios';
|
||||||
|
|
||||||
|
// 登录方法
|
||||||
|
export function login(data) {
|
||||||
|
return request({
|
||||||
|
url: '/auth/login',
|
||||||
|
headers: {
|
||||||
|
isToken: false,
|
||||||
|
repeatSubmit: false,
|
||||||
|
},
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注册方法
|
||||||
|
export function Register(data) {
|
||||||
|
return request({
|
||||||
|
url: '/auth/register',
|
||||||
|
headers: {
|
||||||
|
isToken: false,
|
||||||
|
},
|
||||||
|
method: 'post',
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新方法
|
||||||
|
export function RefreshToken() {
|
||||||
|
return request({
|
||||||
|
url: '/auth/refresh',
|
||||||
|
method: 'post',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户详细信息
|
||||||
|
export function GetInfo() {
|
||||||
|
return request({
|
||||||
|
url: '/system/user/getInfo',
|
||||||
|
method: 'get',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 退出方法
|
||||||
|
export function Logout() {
|
||||||
|
return request({
|
||||||
|
url: '/auth/logout',
|
||||||
|
method: 'delete',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取验证码
|
||||||
|
export function GetCodeImg() {
|
||||||
|
return request({
|
||||||
|
url: '/code',
|
||||||
|
headers: {
|
||||||
|
isToken: false,
|
||||||
|
},
|
||||||
|
method: 'get',
|
||||||
|
timeout: 20000,
|
||||||
|
});
|
||||||
|
}
|
BIN
sub-government-affairs-service/src/assets/images/bg.png
Normal file
BIN
sub-government-affairs-service/src/assets/images/bg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 MiB |
@ -47,12 +47,16 @@ const logOut = async () => {
|
|||||||
UserStore.logout();
|
UserStore.logout();
|
||||||
TagsViewStore.clearVisitedView();
|
TagsViewStore.clearVisitedView();
|
||||||
PermissionStore.clearRoutes();
|
PermissionStore.clearRoutes();
|
||||||
router.push({ path: '/login' });
|
if (res.data.source !== 'main') {
|
||||||
ElMessage({
|
router.push({ path: '/sub-government-affairs-service/login' });
|
||||||
type: 'success',
|
ElMessage({
|
||||||
message: '退出登录成功!',
|
type: 'success',
|
||||||
});
|
message: '退出登录成功!',
|
||||||
localStorage.removeItem('daimp-front-main_user_store');
|
});
|
||||||
|
localStorage.removeItem('daimp-front-main_user_store');
|
||||||
|
} else {
|
||||||
|
console.log('退出到门户页');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,51 +1,262 @@
|
|||||||
<!--
|
|
||||||
* @Description:
|
|
||||||
* @Author: zenghua.wang
|
|
||||||
* @Date: 2023-06-20 14:29:45
|
|
||||||
* @LastEditors: zenghua.wang
|
|
||||||
* @LastEditTime: 2025-02-13 16:04:43
|
|
||||||
-->
|
|
||||||
<template>
|
<template>
|
||||||
<div class="logo">
|
<div class="login">
|
||||||
<!-- <img src="../../../assets/images/logo.png" class="logo-picture" />
|
<el-form ref="loginForm" :model="loginForms" :rules="loginRules" class="login-form">
|
||||||
<h2 v-show="!isCollapse" class="logo-title">{{ VITE_APP_TITLE }}</h2> -->
|
<h3 class="title">政务服务运营平台</h3>
|
||||||
|
<el-form-item prop="username">
|
||||||
|
<el-input v-model="loginForms.username" type="text" auto-complete="off" placeholder="账号">
|
||||||
|
<template #prefix>
|
||||||
|
<svg-icon icon-class="user" class="el-input__icon input-icon" />
|
||||||
|
</template>
|
||||||
|
</el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="password">
|
||||||
|
<el-input v-model="loginForms.password" type="password" auto-complete="off" placeholder="密码">
|
||||||
|
<template #prefix>
|
||||||
|
<svg-icon icon-class="password" class="el-input__icon input-icon" />
|
||||||
|
</template>
|
||||||
|
</el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<!-- <el-form-item v-if="captchaEnabled" prop="code">
|
||||||
|
<el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%">
|
||||||
|
<template #prefix>
|
||||||
|
<svg-icon icon-class="validCode" class="el-input__icon input-icon" />
|
||||||
|
</template>
|
||||||
|
</el-input>
|
||||||
|
<div class="login-code">
|
||||||
|
<img :src="codeUrl" class="login-code-img" @click="getCode" />
|
||||||
|
</div>
|
||||||
|
</el-form-item> -->
|
||||||
|
<el-checkbox v-model="loginForms.rememberMe" style="margin: 0px 0px 25px 0px">记住密码</el-checkbox>
|
||||||
|
<el-form-item style="width: 100%">
|
||||||
|
<el-button :loading="loading" size="large" type="primary" style="width: 100%" @click="goHome()">
|
||||||
|
<span v-if="!loading">登 录</span>
|
||||||
|
<span v-else>登 录 中...</span>
|
||||||
|
</el-button>
|
||||||
|
<!-- <div v-if="register" style="float: right">
|
||||||
|
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
||||||
|
</div> -->
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<!-- 底部 -->
|
||||||
|
<div class="el-login-footer">
|
||||||
|
<span>Copyright © 2025-2035 英壹集团 All Rights Reserved.</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="logo">
|
<script setup>
|
||||||
defineProps({
|
// import { encrypt, decrypt } from '@/utils';
|
||||||
isCollapse: {
|
import { useUserStore } from '@/store/modules/user';
|
||||||
type: Boolean,
|
const UserStore = useUserStore();
|
||||||
default: false,
|
import Cookies from 'js-cookie';
|
||||||
},
|
import { reactive, ref } from 'vue';
|
||||||
});
|
import { login, GetCodeImg, GetInfo } from '@/apis/login';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const { VITE_APP_TITLE } = import.meta.env;
|
let codeUrl = ref('');
|
||||||
|
let loginForms = ref({
|
||||||
|
username: 'admin',
|
||||||
|
password: 'admin123',
|
||||||
|
rememberMe: false,
|
||||||
|
code: '',
|
||||||
|
uuid: '',
|
||||||
|
});
|
||||||
|
let loginRules = ref({
|
||||||
|
username: [{ required: true, trigger: 'blur', message: '请输入您的账号' }],
|
||||||
|
password: [{ required: true, trigger: 'blur', message: '请输入您的密码' }],
|
||||||
|
code: [{ required: true, trigger: 'change', message: '请输入验证码' }],
|
||||||
|
});
|
||||||
|
let loading = ref(false);
|
||||||
|
// 验证码开关
|
||||||
|
let captchaEnabled = ref(true);
|
||||||
|
// 注册开关
|
||||||
|
let register = ref(true);
|
||||||
|
let redirect = ref('');
|
||||||
|
|
||||||
|
const getCode = () => {};
|
||||||
|
|
||||||
|
const goHome = async () => {
|
||||||
|
console.log(loginForms.value);
|
||||||
|
const res = await login(loginForms.value);
|
||||||
|
UserStore.setToken(res.data.access_token);
|
||||||
|
const userInfo = await GetInfo();
|
||||||
|
console.log(userInfo);
|
||||||
|
UserStore.setUserInfo(userInfo.user);
|
||||||
|
UserStore.setOrgList(userInfo.roles);
|
||||||
|
if (userInfo.code == 200) {
|
||||||
|
router.push('/sub-government-affairs-service/home');
|
||||||
|
history.pushState(null, null, location.href);
|
||||||
|
window.onpopstate = function () {
|
||||||
|
history.go(1);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserStore.setMenus(data.menus);
|
||||||
|
// actions.setGlobalState({
|
||||||
|
// ...initialState,
|
||||||
|
// token: res.data.access_token ?? null,
|
||||||
|
// user: data.user ?? {},
|
||||||
|
// roles: data.roles ?? [],
|
||||||
|
// auths: data.permissions ?? [],
|
||||||
|
// });
|
||||||
|
|
||||||
|
// login(loginForm).then((res) => {
|
||||||
|
// console.log(res);
|
||||||
|
// UserStore.setToken(res.data.access_token);
|
||||||
|
// GetInfo().then((data) => {
|
||||||
|
// console.log('用户信息', data);
|
||||||
|
// UserStore.setUserInfo(data.user);
|
||||||
|
// UserStore.setOrgList(data.roles);
|
||||||
|
// // UserStore.setMenus(data.menus);
|
||||||
|
// // actions.setGlobalState({
|
||||||
|
// // ...initialState,
|
||||||
|
// // token: res.data.access_token ?? null,
|
||||||
|
// // user: data.user ?? {},
|
||||||
|
// // roles: data.roles ?? [],
|
||||||
|
// // auths: data.permissions ?? [],
|
||||||
|
// // });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// router.push('/sub-government-affairs-service/home');
|
||||||
|
// window.history.go(-1);
|
||||||
|
// });
|
||||||
|
};
|
||||||
|
|
||||||
|
// import { encrypt, decrypt } from '@/utils';
|
||||||
|
// import { GetCodeImg, Login, GetInfo } from '@/apis/login';
|
||||||
|
// import { useUserStore } from '@/store/modules/user';
|
||||||
|
// import actions, { initialState } from '@/micro/actions';
|
||||||
|
|
||||||
|
// const UserStore = useUserStore();
|
||||||
|
|
||||||
|
// watch: {
|
||||||
|
// $route: {
|
||||||
|
// handler: function (route) {
|
||||||
|
// this.redirect = route.query && route.query.redirect;
|
||||||
|
// },
|
||||||
|
// immediate: true,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// const getCode = ()=> {
|
||||||
|
// GetCodeImg().then((res) => {
|
||||||
|
// this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
||||||
|
// if (this.captchaEnabled) {
|
||||||
|
// this.codeUrl = 'data:image/gif;base64,' + res.img;
|
||||||
|
// this.loginForm.uuid = res.uuid;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
// getCookie() {
|
||||||
|
// const username = Cookies.get('username');
|
||||||
|
// const password = Cookies.get('password');
|
||||||
|
// const rememberMe = Cookies.get('rememberMe');
|
||||||
|
// this.loginForm = {
|
||||||
|
// username: username === undefined ? this.loginForm.username : username,
|
||||||
|
// password: password === undefined ? this.loginForm.password : decrypt(password),
|
||||||
|
// rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
||||||
|
// };
|
||||||
|
// },
|
||||||
|
// handleLogin() {
|
||||||
|
// this.$refs.loginForm.validate(async (valid) => {
|
||||||
|
// if (valid) {
|
||||||
|
// this.loading = true;
|
||||||
|
// if (this.loginForm.rememberMe) {
|
||||||
|
// 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 });
|
||||||
|
// } else {
|
||||||
|
// Cookies.remove('username');
|
||||||
|
// Cookies.remove('password');
|
||||||
|
// Cookies.remove('rememberMe');
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// const res = await Login(this.loginForm);
|
||||||
|
// UserStore.setToken(res.data.access_token);
|
||||||
|
// const data = await GetInfo();
|
||||||
|
// UserStore.setUserInfo(data.user);
|
||||||
|
// UserStore.setOrgList(data.roles);
|
||||||
|
// // UserStore.setMenus(data.menus);
|
||||||
|
// actions.setGlobalState({
|
||||||
|
// ...initialState,
|
||||||
|
// token: res.data.access_token ?? null,
|
||||||
|
// user: data.user ?? {},
|
||||||
|
// roles: data.roles ?? [],
|
||||||
|
// auths: data.permissions ?? [],
|
||||||
|
// });
|
||||||
|
// // this.$router.push({ path: this.redirect || '/' }).catch(() => {});
|
||||||
|
// this.$router.push({ path: this.redirect || '/' });
|
||||||
|
// } catch (error) {
|
||||||
|
// this.loading = false;
|
||||||
|
// if (this.captchaEnabled) {
|
||||||
|
// this.getCode();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// },
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.logo {
|
.login {
|
||||||
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
overflow: hidden;
|
height: 100%;
|
||||||
margin-bottom: 2px;
|
background-image: url('@/assets/images/bg.png');
|
||||||
padding: 7px 5px;
|
background-size: cover;
|
||||||
box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
|
}
|
||||||
transition: all 0.28s;
|
.title {
|
||||||
@include flex-row;
|
margin: 0px auto 30px auto;
|
||||||
&-picture {
|
text-align: center;
|
||||||
margin: 0 auto;
|
font-size: 30px;
|
||||||
width: 70px;
|
color: $color-333;
|
||||||
height: 35px;
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #ffffff;
|
||||||
|
width: 400px;
|
||||||
|
padding: 25px 25px 5px 25px;
|
||||||
|
.el-input {
|
||||||
|
height: 38px;
|
||||||
|
input {
|
||||||
|
height: 38px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&-title {
|
.input-icon {
|
||||||
height: 35px;
|
height: 39px;
|
||||||
line-height: 35px;
|
width: 14px;
|
||||||
color: $color-primary;
|
margin-left: 2px;
|
||||||
}
|
|
||||||
.logo-picture {
|
|
||||||
width: 100%;
|
|
||||||
height: 50px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.login-tip {
|
||||||
|
font-size: 13px;
|
||||||
|
text-align: center;
|
||||||
|
color: #bfbfbf;
|
||||||
|
}
|
||||||
|
.login-code {
|
||||||
|
width: 33%;
|
||||||
|
height: 38px;
|
||||||
|
float: right;
|
||||||
|
img {
|
||||||
|
cursor: pointer;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.el-login-footer {
|
||||||
|
height: 40px;
|
||||||
|
line-height: 40px;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
color: #fff;
|
||||||
|
font-family: Arial;
|
||||||
|
font-size: 12px;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
.login-code-img {
|
||||||
|
height: 38px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
|
<!--
|
||||||
|
* @Description:
|
||||||
|
* @Author: zenghua.wang
|
||||||
|
* @Date: 2024-01-27 20:01:45
|
||||||
|
* @LastEditors: zenghua.wang
|
||||||
|
* @LastEditTime: 2024-03-30 14:32:07
|
||||||
|
-->
|
||||||
<template>
|
<template>
|
||||||
<div class="layout-sider" :class="{ 'has-logo': themeConfig.showLogo }">
|
<div class="layout-sider" :class="{ 'has-logo': themeConfig.showLogo }">
|
||||||
<Logo v-if="themeConfig.showLogo" :is-collapse="isCollapse" />
|
<!-- <Logo v-if="themeConfig.showLogo" :is-collapse="isCollapse" /> -->
|
||||||
<el-scrollbar wrap-class="layout-sider-scrollbar">
|
<el-scrollbar wrap-class="layout-sider-scrollbar">
|
||||||
<el-menu
|
<el-menu
|
||||||
class="layout-sider-menu"
|
class="layout-sider-menu"
|
||||||
@ -12,7 +19,7 @@
|
|||||||
:collapse-transition="false"
|
:collapse-transition="false"
|
||||||
:collapse="isCollapse"
|
:collapse="isCollapse"
|
||||||
>
|
>
|
||||||
<SubItem v-for="item in permissionRoutes" :key="item.path" :item="item" :level="1" />
|
<SubItem v-for="item in permissionRoutes" :key="item.path" :item="item" />
|
||||||
</el-menu>
|
</el-menu>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
</div>
|
</div>
|
||||||
@ -56,7 +63,7 @@ const activeMenu = computed(() => {
|
|||||||
left: 0;
|
left: 0;
|
||||||
z-index: 98;
|
z-index: 98;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
width: 240px;
|
width: 210px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
|
box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* @Description: router
|
||||||
|
* @Author: zenghua.wang
|
||||||
|
* @Date: 2023-06-20 11:48:41
|
||||||
|
* @LastEditors: zenghua.wang
|
||||||
|
* @LastEditTime: 2025-03-26 16:14:45
|
||||||
|
*/
|
||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
import Layout from '@/layouts/index.vue';
|
import Layout from '@/layouts/index.vue';
|
||||||
|
|
||||||
@ -9,6 +16,12 @@ import plantingAndBreedingRouter from './modules/plantingAndBreeding';
|
|||||||
import systemRouter from './modules/system';
|
import systemRouter from './modules/system';
|
||||||
|
|
||||||
export const constantRoutes = [
|
export const constantRoutes = [
|
||||||
|
{
|
||||||
|
path: '/sub-government-affairs-service/login',
|
||||||
|
name: 'login',
|
||||||
|
component: () => import('../layouts/component/Logo/index.vue'),
|
||||||
|
hidden: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/sub-government-affairs-service/404',
|
path: '/sub-government-affairs-service/404',
|
||||||
name: '404',
|
name: '404',
|
||||||
@ -26,7 +39,7 @@ export const constantRoutes = [
|
|||||||
name: 'layout',
|
name: 'layout',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
redirect: '/sub-government-affairs-service/home',
|
redirect: '/sub-government-affairs-service/home',
|
||||||
meta: { title: '农业产业政务平台', icon: 'House' },
|
meta: { title: '政务服务', icon: 'House' },
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '/sub-government-affairs-service/home',
|
path: '/sub-government-affairs-service/home',
|
||||||
@ -39,24 +52,9 @@ export const constantRoutes = [
|
|||||||
...resourceRouter,
|
...resourceRouter,
|
||||||
...productOperateMainRoutes,
|
...productOperateMainRoutes,
|
||||||
...inputSuppliesRoutes,
|
...inputSuppliesRoutes,
|
||||||
{
|
...plantingAndBreedingRouter,
|
||||||
path: '/sub-government-affairs-service/output-products',
|
|
||||||
name: 'outputProducts',
|
|
||||||
component: Layout,
|
|
||||||
redirect: '/sub-government-affairs-service/output-products/index',
|
|
||||||
meta: { title: '产出品管理', icon: 'Box' },
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '/sub-government-affairs-service/output-products/index',
|
|
||||||
component: () => import('@/views/outputProductsManage/index.vue'),
|
|
||||||
name: 'outputProductsIndex',
|
|
||||||
meta: { title: '产出品管理', icon: 'List' },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// ...plantingAndBreedingRouter,
|
|
||||||
...traceRouter,
|
...traceRouter,
|
||||||
// ...systemRouter,
|
...systemRouter,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,5 +70,4 @@ const router = createRouter({
|
|||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes: constantRoutes,
|
routes: constantRoutes,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* @Descripttion:
|
||||||
|
* @Author: zenghua.wang
|
||||||
|
* @Date: 2022-02-23 21:12:37
|
||||||
|
* @LastEditors: zenghua.wang
|
||||||
|
* @LastEditTime: 2025-03-26 10:02:18
|
||||||
|
*/
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { ElNotification } from 'element-plus';
|
import { ElNotification } from 'element-plus';
|
||||||
import router from '@/router';
|
import router from '@/router';
|
||||||
@ -11,7 +18,7 @@ const { VITE_APP_BASE_API, VITE_APP_UPLOAD_API, VITE_APP_DICDATA_API } = import.
|
|||||||
*/
|
*/
|
||||||
const publicAxios = axios.create({
|
const publicAxios = axios.create({
|
||||||
baseURL: VITE_APP_BASE_API, // API请求的默认前缀
|
baseURL: VITE_APP_BASE_API, // API请求的默认前缀
|
||||||
timeout: 10000, // 10秒超时
|
timeout: 30000,
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* 异常拦截处理器
|
* 异常拦截处理器
|
||||||
@ -19,17 +26,8 @@ const publicAxios = axios.create({
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const errorHandler = async (error) => {
|
const errorHandler = async (error) => {
|
||||||
const { response, code, message } = error;
|
const { response } = error;
|
||||||
const UserStore = useUserStore();
|
const UserStore = useUserStore();
|
||||||
// 1. 处理超时错误
|
|
||||||
if (error.code === 'ECONNABORTED' || error.message.includes('timeout')) {
|
|
||||||
ElNotification.error({
|
|
||||||
message: '请求超时',
|
|
||||||
description: '请检查网络或稍后重试',
|
|
||||||
});
|
|
||||||
return Promise.reject({ code: 'TIMEOUT', message: '请求超时' });
|
|
||||||
}
|
|
||||||
// 2. 处理HTTP状态码错误
|
|
||||||
if (response && response.status) {
|
if (response && response.status) {
|
||||||
switch (response.status) {
|
switch (response.status) {
|
||||||
case 401:
|
case 401:
|
||||||
@ -40,7 +38,6 @@ const errorHandler = async (error) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 3. 其他错误传递到业务层
|
|
||||||
return Promise.reject(error?.response?.data);
|
return Promise.reject(error?.response?.data);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -58,6 +55,9 @@ publicAxios.interceptors.request.use(async (config) => {
|
|||||||
config.baseURL = VITE_APP_BASE_API;
|
config.baseURL = VITE_APP_BASE_API;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('312321313');
|
||||||
|
|
||||||
|
config.headers['source'] = 'gov-pc';
|
||||||
if (UserStore.hasToken()) {
|
if (UserStore.hasToken()) {
|
||||||
config.headers['authorization'] = config.headers['authorization'] ?? UserStore.token;
|
config.headers['authorization'] = config.headers['authorization'] ?? UserStore.token;
|
||||||
config.headers['cache-control'] = 'no-cache';
|
config.headers['cache-control'] = 'no-cache';
|
||||||
@ -101,27 +101,22 @@ const formatResult = async (res) => {
|
|||||||
/**
|
/**
|
||||||
* 响应拦截器
|
* 响应拦截器
|
||||||
*/
|
*/
|
||||||
publicAxios.interceptors.response.use(
|
publicAxios.interceptors.response.use((response) => {
|
||||||
(response) => {
|
const { config } = response;
|
||||||
const { config } = response;
|
// console.info('响应拦截器', response);
|
||||||
if (config?.responseType) {
|
if (config?.responseType) {
|
||||||
return response;
|
return response;
|
||||||
}
|
|
||||||
const token = response?.headers['authorization'];
|
|
||||||
if (!isEmpty(token)) {
|
|
||||||
const UserStore = useUserStore();
|
|
||||||
UserStore.setToken(token);
|
|
||||||
}
|
|
||||||
const result = formatResult(response);
|
|
||||||
if (result) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
throw new Error(response.data.msg);
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
// 处理错误
|
|
||||||
return errorHandler(error);
|
|
||||||
}
|
}
|
||||||
);
|
const token = response?.headers['authorization'];
|
||||||
|
if (!isEmpty(token)) {
|
||||||
|
const UserStore = useUserStore();
|
||||||
|
UserStore.setToken(token);
|
||||||
|
}
|
||||||
|
const result = formatResult(response);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
throw new Error(response.data.msg);
|
||||||
|
}, errorHandler);
|
||||||
|
|
||||||
export default publicAxios;
|
export default publicAxios;
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @Description: 路由权限
|
||||||
|
* @Author: zenghua.wang
|
||||||
|
* @Date: 2022-01-26 22:04:31
|
||||||
|
* @LastEditors: zenghua.wang
|
||||||
|
* @LastEditTime: 2024-02-26 13:54:43
|
||||||
|
*/
|
||||||
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
|
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
|
||||||
import NProgress from 'nprogress';
|
import NProgress from 'nprogress';
|
||||||
import 'nprogress/nprogress.css';
|
import 'nprogress/nprogress.css';
|
||||||
@ -8,11 +15,10 @@ import { usePermissionStore } from '@/store/modules/permission';
|
|||||||
NProgress.configure({ showSpinner: false });
|
NProgress.configure({ showSpinner: false });
|
||||||
|
|
||||||
const { VITE_APP_MIAN_URL } = import.meta.env;
|
const { VITE_APP_MIAN_URL } = import.meta.env;
|
||||||
const whiteList = [];
|
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
NProgress.start();
|
NProgress.start();
|
||||||
if (typeof to.meta.title === 'string') {
|
if (typeof to.meta.title === 'string') {
|
||||||
document.title = '农业产业政务平台 | ' + to.meta.title;
|
document.title = '政务服务 | ' + to.meta.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
@ -22,33 +28,25 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
if (to.path === '/login') {
|
if (to.path === '/login') {
|
||||||
next({ path: '/' });
|
next({ path: '/' });
|
||||||
} else {
|
} else {
|
||||||
try {
|
const PermissionStore = usePermissionStore();
|
||||||
const PermissionStore = usePermissionStore();
|
if (!PermissionStore.routes.length) {
|
||||||
if (!PermissionStore.routes.length) {
|
const accessRoutes = await PermissionStore.generateRoutes(userStore.roles);
|
||||||
const accessRoutes = await PermissionStore.generateRoutes(userStore.roles);
|
accessRoutes.forEach((item) => router.addRoute(item));
|
||||||
accessRoutes.forEach((item) => router.addRoute(item));
|
return next({ ...to, replace: true });
|
||||||
return next({ ...to, replace: true });
|
} else {
|
||||||
} else {
|
if (from.path.includes('/sub') && to.path.includes('/platform')) {
|
||||||
if (from.path.includes('/sub') && to.path.includes('/platform')) {
|
window.location.reload();
|
||||||
window.location.reload();
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
next();
|
||||||
next(`/login?redirect=${to.path}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NProgress.done();
|
NProgress.done();
|
||||||
if (whiteList.indexOf(to.path) !== -1) {
|
if (to.path == '/sub-government-affairs-service/login') {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
if (qiankunWindow.__POWERED_BY_QIANKUN__) {
|
next('/sub-government-affairs-service/login');
|
||||||
window.location.href = VITE_APP_MIAN_URL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
next(`/login?redirect=${to.path}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user