修改登录完成

This commit is contained in:
13713575202 2025-06-26 10:54:53 +08:00
parent e0b86a230b
commit f91e7e0f13
13 changed files with 466 additions and 27 deletions

View File

@ -46,6 +46,7 @@ const errorHandler = async (error) => {
*/ */
publicAxios.interceptors.request.use(async (config) => { publicAxios.interceptors.request.use(async (config) => {
const UserStore = useUserStore(); const UserStore = useUserStore();
config.headers['source'] = 'main';
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';

View File

@ -117,10 +117,12 @@ export default {
Cookies.set('username', this.loginForm.username, { expires: 30 }); Cookies.set('username', this.loginForm.username, { expires: 30 });
Cookies.set('password', encrypt(this.loginForm.password), { expires: 30 }); Cookies.set('password', encrypt(this.loginForm.password), { expires: 30 });
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
localStorage.setItem('source', 'main');
} else { } else {
Cookies.remove('username'); Cookies.remove('username');
Cookies.remove('password'); Cookies.remove('password');
Cookies.remove('rememberMe'); Cookies.remove('rememberMe');
localStorage.removeItem('source');
} }
try { try {
const res = await Login(this.loginForm); const res = await Login(this.loginForm);

View File

@ -12,11 +12,25 @@
</template> </template>
<script setup name="app"> <script setup name="app">
import { computed } from 'vue'; import { computed, onMounted } from 'vue';
import { useSettingStore } from '@/store/modules/setting'; import { useSettingStore } from '@/store/modules/setting';
// element // element
import zhCn from 'element-plus/es/locale/lang/zh-cn'; import zhCn from 'element-plus/es/locale/lang/zh-cn';
import { useRouter } from 'vue-router';
const router = useRouter();
onMounted(() => {
if (localStorage.getItem('source')) {
router.push('/sub-government-affairs-service/home');
} else {
if (JSON.parse(localStorage.getItem('daimp-front-main_userStore')).token) {
router.push('/sub-government-affairs-service/home');
} else {
router.push('/sub-government-affairs-service/login');
}
}
});
const SettingStore = useSettingStore(); const SettingStore = useSettingStore();
// //
const size = computed(() => SettingStore.themeConfig.globalComSize); const size = computed(() => SettingStore.themeConfig.globalComSize);

View File

@ -65,7 +65,7 @@
</div> </div>
</template> </template>
<script setup> <script setup>
import { reactive } from 'vue'; import { onMounted, reactive } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { useApp } from '@/hooks'; import { useApp } from '@/hooks';
import { sleep } from '@/utils'; import { sleep } from '@/utils';
@ -346,6 +346,10 @@ const loadData = async () => {
// }); // });
}; };
onMounted(() => {
console.log('二次文件');
});
loadData(); loadData();
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -4,7 +4,7 @@ VITE_APP_MIAN = 'daimp-front-main'
VITE_APP_MIAN_URL = 'http://localhost:9000' VITE_APP_MIAN_URL = 'http://localhost:9000'
VITE_APP_NAME = 'sub-operation-service' VITE_APP_NAME = 'sub-operation-service'
VITE_APP_BASE_API = '/apis' VITE_APP_BASE_API = '/apis'
# VITE_APP_BASE_URL = 'http://192.168.18.99:88' VITE_APP_BASE_URL = 'http://192.168.18.74:8080'
VITE_APP_BASE_URL = 'http://192.168.18.99:8080' # VITE_APP_BASE_URL = 'http://192.168.18.99:8080'
VITE_APP_UPLOAD_API = '/uploadApis' VITE_APP_UPLOAD_API = '/uploadApis'
VITE_APP_UPLOAD_URL = 'http://192.168.18.99:9300' VITE_APP_UPLOAD_URL = 'http://192.168.18.99:9300'

View File

@ -12,11 +12,23 @@
</template> </template>
<script setup name="app"> <script setup name="app">
import { computed } from 'vue'; import { computed, onMounted } from 'vue';
import { useSettingStore } from '@/store/modules/setting'; import { useSettingStore } from '@/store/modules/setting';
// element // element
import zhCn from 'element-plus/es/locale/lang/zh-cn'; import zhCn from 'element-plus/es/locale/lang/zh-cn';
import { useRouter } from 'vue-router';
const router = useRouter();
onMounted(() => {
if (localStorage.getItem('source')) {
router.push('/sub-operation-service/dashboard/home');
} else {
if (JSON.parse(localStorage.getItem('daimp-front-main_userStore')).token) {
router.push('/sub-operation-service/dashboard/home');
} else {
router.push('/sub-operation-service/login');
}
}
});
const SettingStore = useSettingStore(); const SettingStore = useSettingStore();
// //
const size = computed(() => SettingStore.themeConfig.globalComSize); const size = computed(() => SettingStore.themeConfig.globalComSize);

View 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,
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 MiB

View File

@ -0,0 +1,268 @@
<template>
<div class="login">
<el-form ref="loginForm" :model="loginForms" :rules="loginRules" class="login-form">
<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>
</template>
<script setup>
// import { encrypt, decrypt } from '@/utils';
import { useUserStore } from '@/store/modules/user';
const UserStore = useUserStore();
// 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();
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-operation-service/dashboard/home');
history.pushState(null, null, location.href);
window.onpopstate = function () {
history.go(1);
};
}
// router.push('/sub-operation-service/dashboard/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>
<style lang="scss" scoped>
.login {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
background-image: url('@/assets/images/bg.png');
background-size: cover;
}
.title {
margin: 0px auto 30px auto;
text-align: center;
font-size: 30px;
color: $color-333;
}
.login-form {
border-radius: 6px;
background: #ffffff;
width: 400px;
padding: 25px 25px 5px 25px;
.el-input {
height: 38px;
input {
height: 38px;
}
}
.input-icon {
height: 39px;
width: 14px;
margin-left: 2px;
}
}
.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>

View File

@ -14,6 +14,10 @@
</div> </div>
</div> </div>
<div class="layout-header-top-right"> <div class="layout-header-top-right">
<span class="block-icon" @click="toHome">
<div class="iconfont icon-home" style="font-size: 12px"></div>
<span>返回首页</span>
</span>
<el-badge :hidden="goodNum < 1" :value="goodNum" :max="99" class="item" :offset="[-3, 10]"> <el-badge :hidden="goodNum < 1" :value="goodNum" :max="99" class="item" :offset="[-3, 10]">
<div style="display: flex" @click="toCart"> <div style="display: flex" @click="toCart">
<div class="iconfont icon-shopcar" style="font-size: 14px; margin: 0 5px; color: #25bf82; font-weight: bold"></div> <div class="iconfont icon-shopcar" style="font-size: 14px; margin: 0 5px; color: #25bf82; font-weight: bold"></div>
@ -24,10 +28,7 @@
<span>商家中心</span> <span>商家中心</span>
</el-badge> </el-badge>
<span @click="toUserCenter">个人中心</span> <span @click="toUserCenter">个人中心</span>
<span class="block-icon" @click="toHome"> <span @click="loginOut()">退出登录</span>
<div class="iconfont icon-home" style="font-size: 12px"></div>
<span>返回首页</span>
</span>
</div> </div>
</div> </div>
<div class="layout-header-bottom"> <div class="layout-header-bottom">
@ -74,6 +75,8 @@ import { useRouter } from 'vue-router';
import { getAssetsFile } from '@/utils'; import { getAssetsFile } from '@/utils';
import { getGoodNum } from '@/apis/agricultural.js'; import { getGoodNum } from '@/apis/agricultural.js';
import { useMethodsStore } from '@/store/modules/methods'; import { useMethodsStore } from '@/store/modules/methods';
import { ElMessage, ElMessageBox } from 'element-plus';
import { Logout } from '../../../apis/login';
const router = useRouter(); const router = useRouter();
@ -134,6 +137,41 @@ onBeforeUnmount(() => {
methodsStore.registerOuterMethod(null); 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() { function Search() {
console.log(keyword.value, 'search'); console.log(keyword.value, 'search');
} }
@ -338,6 +376,7 @@ const toCart = () => {
margin-top: 0; margin-top: 0;
} }
.layout-header-top-right { .layout-header-top-right {
align-items: center;
display: flex; display: flex;
.item { .item {
margin-left: 25px; margin-left: 25px;

View File

@ -12,6 +12,12 @@ import Views from '@/layouts/Views.vue';
import userCentre from '@/layouts/userCentre.vue'; import userCentre from '@/layouts/userCentre.vue';
export const constantRoutes = [ export const constantRoutes = [
{
path: '/sub-operation-service/login',
name: 'login',
component: () => import('@/layouts/Logo/index.vue'),
hidden: true,
},
{ {
path: '/sub-operation-service/404', path: '/sub-operation-service/404',
name: '404', name: '404',

View File

@ -44,6 +44,12 @@ const errorHandler = async (error) => {
*/ */
publicAxios.interceptors.request.use(async (config) => { publicAxios.interceptors.request.use(async (config) => {
const UserStore = useUserStore(); const UserStore = useUserStore();
if (localStorage.getItem('source')) {
config.headers['source'] = 'main';
} else {
config.headers['source'] = 'indus-pc';
}
switch (config.apisType) { switch (config.apisType) {
case 'upload': { case 'upload': {
config.baseURL = VITE_APP_UPLOAD_API; config.baseURL = VITE_APP_UPLOAD_API;

View File

@ -26,33 +26,58 @@ router.beforeEach(async (to, from, next) => {
console.log('sub-operation-service************hasToken', hasToken); console.log('sub-operation-service************hasToken', hasToken);
if (hasToken) { if (hasToken) {
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 {
if (whiteList.indexOf(to.path) !== -1) { NProgress.done();
if (to.path == '/sub-operation-service/login') {
next(); next();
} else { } 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(() => { router.afterEach(() => {