Merge branch 'main' of http://182.92.169.222:3000/dlsx/ContestPortal
commit
e385501a08
15 changed files with 425 additions and 20 deletions
@ -1,5 +1,5 @@ |
||||
# 变量必须以 VITE_ 为前缀才能暴露给外部读取 |
||||
NODE_ENV = 'development' |
||||
VITE_APP_TITLE = '教学一体化平台' |
||||
VITE_APP_BASE_API = 'http://39.106.16.162:8080' |
||||
VITE_APP_BASE_API = http://localhost:18085/jeecg-boot |
||||
# VITE_APP_BASE_API = 'http://127.0.0.1:8080' |
@ -0,0 +1,25 @@ |
||||
import request from '@/utils/requset' |
||||
|
||||
export const getCode = (time:any) => { |
||||
return request({ |
||||
url:'/sys/randomImage/' + time, |
||||
}) |
||||
} |
||||
export const loginApi = (data:any) => { |
||||
return request({ |
||||
url:'/sys/login', |
||||
method:"POST", |
||||
data |
||||
}) |
||||
} |
||||
export const getUserInfoApi = () => { |
||||
return request({ |
||||
url:'/sys/user/getUserInfo' |
||||
}) |
||||
} |
||||
|
||||
export const logOut = () => { |
||||
return request({ |
||||
url:'/sys/logout' |
||||
}) |
||||
} |
After Width: | Height: | Size: 484 KiB |
After Width: | Height: | Size: 2.1 KiB |
@ -0,0 +1,23 @@ |
||||
import router from '@/router/index' |
||||
import userStore from './store/module/user' |
||||
|
||||
router.beforeEach(async (to, form, next) => { |
||||
const useuserStore = userStore() |
||||
|
||||
if (useuserStore.token) { |
||||
if (to.path === '/login') { |
||||
next({ path: '/' }) |
||||
} else { |
||||
if (!Object.keys(useuserStore.userInfo).length) { |
||||
useuserStore.getUserInfo() |
||||
next() |
||||
|
||||
}else{ |
||||
next() |
||||
} |
||||
} |
||||
}else{ |
||||
next() |
||||
} |
||||
}) |
||||
export default router |
@ -0,0 +1,11 @@ |
||||
|
||||
const defineRouter = [ |
||||
{ |
||||
path:'/login', |
||||
component: () => import('@/views/login/index.vue'), |
||||
meta:{ |
||||
title:'登录' |
||||
} |
||||
} |
||||
] |
||||
export default defineRouter |
@ -0,0 +1,45 @@ |
||||
import { defineStore } from 'pinia' |
||||
import { loginApi,getUserInfoApi ,logOut} from '@/api/user' |
||||
import { ElNotification } from 'element-plus' |
||||
import { setToken, getToken ,removeToken} from '@/utils/token' |
||||
|
||||
const userStore = defineStore('defineStore', { |
||||
state: (): any => ({ |
||||
token: getToken() || '', |
||||
userInfo: {}, |
||||
}), |
||||
actions: { |
||||
async login(parmas: any) { |
||||
const res: any = await loginApi(parmas) |
||||
|
||||
if (res.code === 412) { |
||||
return 0 |
||||
} else if (res.code === 500) { |
||||
return 1 |
||||
} else { |
||||
console.log(res.result.userInfo) |
||||
this.token = res.result.token |
||||
setToken(this.token) |
||||
this.userInfo = res.result.userInfo |
||||
ElNotification({ |
||||
title: '登录成功', |
||||
message: '欢迎回来' + this.userInfo.username, |
||||
type: 'success', |
||||
})
|
||||
} |
||||
}, |
||||
async getUserInfo(){ |
||||
const res:any = await getUserInfoApi() |
||||
this.userInfo = res.result.userInfo |
||||
console.log(res); |
||||
|
||||
}, |
||||
async layOut(){ |
||||
await logOut() |
||||
removeToken() |
||||
this.token = '' |
||||
this.userInfo = {} |
||||
} |
||||
}, |
||||
}) |
||||
export default userStore |
@ -0,0 +1,9 @@ |
||||
export const setToken = (token: string) => { |
||||
localStorage.setItem('token', token) |
||||
} |
||||
export const removeToken = () => { |
||||
localStorage.removeItem('token') |
||||
} |
||||
export const getToken = () => { |
||||
return localStorage.getItem('token') |
||||
} |
@ -0,0 +1,146 @@ |
||||
<template> |
||||
<div class="login-content"> |
||||
<div class="login-form"> |
||||
<div class="login-title">登录</div> |
||||
<div class="form"> |
||||
<el-form :model="form" label-width="80"> |
||||
<el-form-item label="账号"> |
||||
<el-input v-model="form.account" style="height: .2344rem" /> |
||||
</el-form-item> |
||||
<el-form-item label="密码"> |
||||
<el-input v-model="form.password" style="height: .2344rem" /> |
||||
</el-form-item> |
||||
<el-form-item label="验证码"> |
||||
<div class="captcha"> |
||||
<el-input |
||||
v-model="form.captcha" |
||||
style="height: .2344rem" |
||||
maxlength="4" |
||||
/> |
||||
<div class="code" @click="getcodeinfo"> |
||||
<img :src="codeUrl" alt="" srcset="" /> |
||||
</div> |
||||
</div> |
||||
</el-form-item> |
||||
</el-form> |
||||
<div class="submit gradient" @click.enter="submit">登录</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</template> |
||||
|
||||
<script lang="ts" setup> |
||||
import { onMounted, reactive, ref, toRefs, watch } from 'vue' |
||||
import { getCode } from '@/api/user' |
||||
import userStore from '@/store/module/user' |
||||
import { ElMessage } from 'element-plus' |
||||
import { useRouter } from 'vue-router' |
||||
|
||||
const useUserStore = userStore() |
||||
const form = ref({ |
||||
account: '', |
||||
password: '', |
||||
captcha: '', |
||||
}) |
||||
const codeUrl = ref('') |
||||
const getcodeinfo = async () => { |
||||
const res: any = await getCode(1629428467008) |
||||
codeUrl.value = res.result |
||||
console.log(codeUrl.value) |
||||
} |
||||
getcodeinfo() |
||||
const Router = useRouter() |
||||
const submit = async () => { |
||||
console.log(111, useUserStore) |
||||
|
||||
let data = { |
||||
captcha: form.value.captcha, |
||||
checkKey: 1629428467008, |
||||
password: form.value.password, |
||||
username: form.value.account, |
||||
} |
||||
const res = await useUserStore.login(data) |
||||
console.log(res) |
||||
if (res === 0) { |
||||
ElMessage('验证码错误') |
||||
getcodeinfo() |
||||
} else if (res === 1) { |
||||
ElMessage('账号或密码错误') |
||||
getcodeinfo() |
||||
}else{ |
||||
Router.push('/') |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style lang="scss" scoped> |
||||
.login-content { |
||||
width: 100%; |
||||
height: 100vh; |
||||
background: url('../../assets/images/bg.png') no-repeat; |
||||
background-size: cover; |
||||
display: flex; |
||||
align-items: center; |
||||
justify-content: center; |
||||
.login-form { |
||||
width: 640px; |
||||
height: 820px; |
||||
border-radius: 15px; |
||||
background-color: #ffffff1a !important; |
||||
padding: 70px 60px; |
||||
backdrop-filter: blur(10px); |
||||
box-shadow: 0 4px 8px 1px rgba(0, 0, 0, 0.2); |
||||
.login-title { |
||||
font-size: 32px; |
||||
font-weight: 700; |
||||
} |
||||
.form { |
||||
margin-top: 35px; |
||||
padding: 0 40px; |
||||
.captcha { |
||||
width: 100%; |
||||
height: 100%; |
||||
position: relative; |
||||
.code { |
||||
width: 100%; |
||||
height: 100%; |
||||
position: absolute; |
||||
top: 0; |
||||
right: 0; |
||||
width: 105px; |
||||
height: 100%; |
||||
// background-color: pink; |
||||
display: flex; |
||||
align-items: center; |
||||
img{ |
||||
width: 100%; |
||||
height: 100%; |
||||
} |
||||
} |
||||
} |
||||
.submit { |
||||
width: 399px; |
||||
height: 50px; |
||||
text-align: center; |
||||
line-height: 50px; |
||||
font-size: 20px; |
||||
font-weight: 600; |
||||
cursor: pointer; |
||||
color: #fff; |
||||
border-radius: 10px; |
||||
margin-top: 35px; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
:deep(.el-form-item) { |
||||
display: flex; |
||||
flex-direction: column; |
||||
} |
||||
:deep(.el-input__wrapper) { |
||||
box-shadow: none; |
||||
} |
||||
:deep(.el-form-item__label) { |
||||
justify-content: start; |
||||
} |
||||
</style> |
Loading…
Reference in new issue