登录功能完成

This commit is contained in:
2024-08-07 15:10:28 +08:00
parent 3dcb2d0a4f
commit d433cc75f6
4 changed files with 63 additions and 114 deletions

View File

@ -1,5 +1,5 @@
<template>
<header v-loading="loading">
<header>
<div id="topnavbar">
<div class="logo logo2 cursor">
<img src="../../../static/images/logo.png" alt="">
@ -7,8 +7,7 @@
<div id="topnanv" v-show="!collapse || navShow">
<nav>
<ul class="content clearfix">
<template v-if="userName">
<li class="dropdown" v-for="(item,index) in adminMenu" :key="index">
<li class="dropdown" v-for="(item,index) in menu" :key="index">
<a href="javascript:void(0);" @click="routerTurn(item.path)">{{item.name}}<img v-show="item.children.length" src="../../../static/images/arrow-down.png" alt=""></a>
<ul class="sub-menu" v-show="item.children.length">
<li v-for="(item1,index1) in item.children" :key="index1">
@ -16,7 +15,15 @@
</li>
</ul>
</li>
<li class="dropdown">
<li v-show="isLogin" class="dropdown" v-for="(item,index) in adminMenu" :key="index">
<a href="javascript:void(0);" @click="routerTurn(item.path)">{{item.name}}<img v-show="item.children.length" src="../../../static/images/arrow-down.png" alt=""></a>
<ul class="sub-menu" v-show="item.children.length">
<li v-for="(item1,index1) in item.children" :key="index1">
<a href="javascript:void(0);" @click="routerTurn(item1.path)">{{item1.name}}</a>
</li>
</ul>
</li>
<li class="dropdown" v-if="isLogin">
<el-dropdown>
<span class="el-dropdown-link userClass">
<a href="javascript:void(0);">admin<img src="../../../static/images/arrow-down.png" alt=""></a>
@ -31,24 +38,13 @@
</el-dropdown-menu>
</el-dropdown>
</li>
</template>
<template v-else>
<li class="dropdown" v-for="(item,index) in menu" :key="index">
<a href="javascript:void(0);" @click="routerTurn(item.path)">{{item.name}}<img v-show="item.children.length" src="../../../static/images/arrow-down.png" alt=""></a>
<ul class="sub-menu" v-show="item.children.length">
<li v-for="(item1,index1) in item.children" :key="index1">
<a href="javascript:void(0);" @click="routerTurn(item1.path)">{{item1.name}}</a>
</li>
</ul>
</li>
<li class="dropdown">
<li class="dropdown" v-else>
<el-dropdown trigger="click">
<span class="el-dropdown-link userClass">
<a href="javascript:void(0);" @click="routerTurn('login')">登录</a>
</span>
</el-dropdown>
</li>
</template>
</ul>
</nav>
</div>
@ -61,6 +57,7 @@
<script>
import { initInfo, loginOut } from '@/api/login'
import Cookies from 'js-cookie'
export default {
name: 'headers',
@ -71,6 +68,7 @@ export default {
return {
loading: false,
collapse:true,
menuList: [],
menu:[
{
name:"首页",
@ -126,53 +124,6 @@ export default {
}
],
adminMenu: [
{
name:"首页",
path:"home",
children:[]
},
{
name:"数据检索",
path:"",
children:[
{
name:"数据检索",
path:"dataSearch",
children:[]
},
{
name:"航次详情",
path:"voyagedetail",
children:[]
}
]
},
{
name:"统计分析",
path:"analyse",
children:[]
},
{
name:"数据资源",
path:"",
children:[
{
name:"海洋地球物理与物理海洋信息库",
path:"physicalIndex",
children:[]
},
{
name:"海洋生物样品信息库",
path:"biologyIndex",
children:[]
},
{
name:"深海海洋视频音像信息库",
path:"phoneVideoIndex",
children:[]
}
]
},
{
name:"数据汇交",
children:[
@ -185,7 +136,7 @@ export default {
name:"样品数据集汇交",
path:"SampleDataset",
children:[]
}
},
]
},
{
@ -238,23 +189,13 @@ export default {
}
]
},
{
name:"关于我们",
path:"",
children:[]
}
],
nowPathName: '',
navShow:false
}
},
computed: {
userName() {
return sessionStorage.getItem('userName') || this.$store.state.user.name
navShow:false,
isLogin: false
}
},
created() {
console.log(this.userName)
this.getLoginInfo()
},
mounted(){
@ -298,20 +239,20 @@ export default {
},
// 退
onLogout() {
this.loading = true
loginOut().then(res => {
this.$store.commit('SET_NAME', '')
sessionStorage.setItem('userName', '')
this.$router.push({
path: 'login'
})
location.reload()
location.href = '/login#/container/login'
})
},
//
getLoginInfo() {
initInfo().then(res => {
console.log(res)
Cookies.set('JSESSIONID', res.map.FrameSessionId);
this.isLogin = res.login
if (this.isLogin) {
this.menuList = this.adminMenu
} else {
this.menuList = this.menu
}
})
}
}

View File

@ -10,6 +10,7 @@ const service = axios.create({
// baseURL: process.env.VUE_APP_BASE_API,
baseURL: process.env.VUE_APP_BASE_API,
withCredentials: true, // send cookies when cross-domain requests
crossDomain: true,
timeout: 900000 // request timeout
})
service.defaults.headers = {
@ -49,10 +50,10 @@ service.interceptors.response.use(
const res = response.data
if (res.errorCode === 10301) {
// 当前未登录或已经过期
Message({
message: res.errorMsg,
type: 'warning'
})
// Message({
// message: res.errorMsg,
// type: 'warning'
// })
sessionStorage.setItem('userName', '')
} else if (res.errorCode === 0) {
return res

View File

@ -359,7 +359,7 @@ export default {
//
//es6
var addHtml = `
<h4 style="">科考船只索一号</h4>
<h4 style="">科考船只索一号</h4>
<p>经度°${todo.launchLongtitude}</p>
<p>纬度°${todo.launchLatitude}</p>
<p>航迹向56°</p>

View File

@ -44,7 +44,8 @@
</template>
<script>
import { login } from '@/api/login'
import { initInfo, login } from '@/api/login'
import Cookies from 'js-cookie'
export default {
name: 'Login',
@ -68,9 +69,15 @@ export default {
loginCode: this.loginCode
}).then(res => {
if (res.success) {
this.$router.back()
this.$store.commit('SET_NAME', this.loginName)
sessionStorage.setItem('userName', this.loginName)
// this.$router.back()
// this.$store.commit('SET_NAME', this.loginName)
// sessionStorage.setItem('userName', this.loginName)
Cookies.set('JSESSIONID', res.entity);
initInfo().then(res => {
Cookies.set('JSESSIONID', res.map.FrameSessionId);
this.isLogin = res.login
location.href = '/'
})
} else {
this.$message.error(res.errorMsg)
}