登录功能完成

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> <template>
<header v-loading="loading"> <header>
<div id="topnavbar"> <div id="topnavbar">
<div class="logo logo2 cursor"> <div class="logo logo2 cursor">
<img src="../../../static/images/logo.png" alt=""> <img src="../../../static/images/logo.png" alt="">
@ -7,48 +7,44 @@
<div id="topnanv" v-show="!collapse || navShow"> <div id="topnanv" v-show="!collapse || navShow">
<nav> <nav>
<ul class="content clearfix"> <ul class="content clearfix">
<template v-if="userName"> <li class="dropdown" v-for="(item,index) in menu" :key="index">
<li 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>
<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">
<ul class="sub-menu" v-show="item.children.length"> <li v-for="(item1,index1) in item.children" :key="index1">
<li v-for="(item1,index1) in item.children" :key="index1"> <a href="javascript:void(0);" @click="routerTurn(item1.path)">{{item1.name}}</a>
<a href="javascript:void(0);" @click="routerTurn(item1.path)">{{item1.name}}</a> </li>
</li> </ul>
</ul> </li>
</li> <li v-show="isLogin" class="dropdown" v-for="(item,index) in adminMenu" :key="index">
<li class="dropdown"> <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>
<el-dropdown> <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"> <span class="el-dropdown-link userClass">
<a href="javascript:void(0);">admin<img src="../../../static/images/arrow-down.png" alt=""></a> <a href="javascript:void(0);">admin<img src="../../../static/images/arrow-down.png" alt=""></a>
</span> </span>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item> <el-dropdown-item>
<a href="javascript:void(0);" @click="routerTurn('personalCenter')">个人中心</a> <a href="javascript:void(0);" @click="routerTurn('personalCenter')">个人中心</a>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item> <el-dropdown-item>
<a href="javascript:void(0);" @click="onLogout">退出登录</a> <a href="javascript:void(0);" @click="onLogout">退出登录</a>
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
</li> </li>
</template> <li class="dropdown" v-else>
<template v-else> <el-dropdown trigger="click">
<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">
<el-dropdown trigger="click">
<span class="el-dropdown-link userClass"> <span class="el-dropdown-link userClass">
<a href="javascript:void(0);" @click="routerTurn('login')">登录</a> <a href="javascript:void(0);" @click="routerTurn('login')">登录</a>
</span> </span>
</el-dropdown> </el-dropdown>
</li> </li>
</template>
</ul> </ul>
</nav> </nav>
</div> </div>
@ -61,6 +57,7 @@
<script> <script>
import { initInfo, loginOut } from '@/api/login' import { initInfo, loginOut } from '@/api/login'
import Cookies from 'js-cookie'
export default { export default {
name: 'headers', name: 'headers',
@ -71,6 +68,7 @@ export default {
return { return {
loading: false, loading: false,
collapse:true, collapse:true,
menuList: [],
menu:[ menu:[
{ {
name:"首页", name:"首页",
@ -126,53 +124,6 @@ export default {
} }
], ],
adminMenu: [ 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:"数据汇交", name:"数据汇交",
children:[ children:[
@ -185,7 +136,7 @@ export default {
name:"样品数据集汇交", name:"样品数据集汇交",
path:"SampleDataset", path:"SampleDataset",
children:[] children:[]
} },
] ]
}, },
{ {
@ -238,23 +189,13 @@ export default {
} }
] ]
}, },
{
name:"关于我们",
path:"",
children:[]
}
], ],
nowPathName: '', nowPathName: '',
navShow:false navShow:false,
isLogin: false
} }
}, },
computed: {
userName() {
return sessionStorage.getItem('userName') || this.$store.state.user.name
}
},
created() { created() {
console.log(this.userName)
this.getLoginInfo() this.getLoginInfo()
}, },
mounted(){ mounted(){
@ -298,20 +239,20 @@ export default {
}, },
// 退 // 退
onLogout() { onLogout() {
this.loading = true
loginOut().then(res => { loginOut().then(res => {
this.$store.commit('SET_NAME', '') location.href = '/login#/container/login'
sessionStorage.setItem('userName', '')
this.$router.push({
path: 'login'
})
location.reload()
}) })
}, },
// //
getLoginInfo() { getLoginInfo() {
initInfo().then(res => { 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,
baseURL: process.env.VUE_APP_BASE_API, baseURL: process.env.VUE_APP_BASE_API,
withCredentials: true, // send cookies when cross-domain requests withCredentials: true, // send cookies when cross-domain requests
crossDomain: true,
timeout: 900000 // request timeout timeout: 900000 // request timeout
}) })
service.defaults.headers = { service.defaults.headers = {
@ -49,10 +50,10 @@ service.interceptors.response.use(
const res = response.data const res = response.data
if (res.errorCode === 10301) { if (res.errorCode === 10301) {
// 当前未登录或已经过期 // 当前未登录或已经过期
Message({ // Message({
message: res.errorMsg, // message: res.errorMsg,
type: 'warning' // type: 'warning'
}) // })
sessionStorage.setItem('userName', '') sessionStorage.setItem('userName', '')
} else if (res.errorCode === 0) { } else if (res.errorCode === 0) {
return res return res

View File

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

View File

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