登录功能完成

This commit is contained in:
2024-08-05 13:36:10 +08:00
parent 3bee267219
commit 3dcb2d0a4f
5 changed files with 199 additions and 109 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<header> <header v-loading="loading">
<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,34 +7,48 @@
<div id="topnanv" v-show="!collapse || navShow"> <div id="topnanv" v-show="!collapse || navShow">
<nav> <nav>
<ul class="content clearfix"> <ul class="content clearfix">
<li class="dropdown" v-for="(item,index) in menu" :key="index"> <template v-if="userName">
<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> <li class="dropdown" v-for="(item,index) in adminMenu" :key="index">
<ul class="sub-menu" v-show="item.children.length"> <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>
<li v-for="(item1,index1) in item.children" :key="index1"> <ul class="sub-menu" v-show="item.children.length">
<a href="javascript:void(0);" @click="routerTurn(item1.path)">{{item1.name}}</a> <li v-for="(item1,index1) in item.children" :key="index1">
</li> <a href="javascript:void(0);" @click="routerTurn(item1.path)">{{item1.name}}</a>
</ul> </li>
</li> </ul>
<li class="dropdown"> </li>
<el-dropdown> <li class="dropdown">
<span class="el-dropdown-link userClass"> <el-dropdown>
<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>
<el-dropdown trigger="click"> </li>
<span class="el-dropdown-link userClass"> </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">
<el-dropdown trigger="click">
<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>
@ -55,6 +69,7 @@ export default {
}, },
data(){ data(){
return { return {
loading: false,
collapse:true, collapse:true,
menu:[ menu:[
{ {
@ -104,93 +119,142 @@ export default {
} }
] ]
}, },
{
name:"数据汇交",
children:[
{
name:"航次数据汇交",
path:"VoyageReg",
children:[]
},
{
name:"样品数据集汇交",
path:"SampleDataset",
children:[]
}
]
},
{
name:"字典管理",
children:[
{
name:"数据样品类型",
path:"dataSampleType",
children:[]
},
{
name:"设备类型",
path:"docType",
children:[]
},
{
name:"平台类型",
path:"platformType",
children:[]
},
{
name:"参航单位",
path:"visitorUnit",
children:[]
},
{
name:"共享单位",
path:"sharedUnit",
children:[]
},
]
},
{
name:"系统管理",
children:[
{
name:"用户管理",
path:"userManage",
children:[]
},
{
name:"角色管理",
path:"roleManage",
children:[]
},
{
name:"单位管理",
path:"unitManage",
children:[]
}
]
},
{ {
name:"关于我们", name:"关于我们",
path:"", path:"",
children:[] children:[]
}, }
// {
// name:"",
// path:"personalCenter",
// children:[]
// },
// {
// name:"",
// path:"login",
// children:[]
// },
], ],
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:[
{
name:"航次数据汇交",
path:"VoyageReg",
children:[]
},
{
name:"样品数据集汇交",
path:"SampleDataset",
children:[]
}
]
},
{
name:"字典管理",
children:[
{
name:"数据样品类型",
path:"dataSampleType",
children:[]
},
{
name:"设备类型",
path:"docType",
children:[]
},
{
name:"平台类型",
path:"platformType",
children:[]
},
{
name:"参航单位",
path:"visitorUnit",
children:[]
},
{
name:"共享单位",
path:"sharedUnit",
children:[]
},
]
},
{
name:"系统管理",
children:[
{
name:"用户管理",
path:"userManage",
children:[]
},
{
name:"角色管理",
path:"roleManage",
children:[]
},
{
name:"单位管理",
path:"unitManage",
children:[]
}
]
},
{
name:"关于我们",
path:"",
children:[]
}
],
nowPathName: '', nowPathName: '',
navShow:false navShow:false
} }
}, },
computed: {
userName() {
return sessionStorage.getItem('userName') || this.$store.state.user.name
}
},
created() { created() {
console.log(this.userName)
this.getLoginInfo() this.getLoginInfo()
}, },
mounted(){ mounted(){
@ -234,11 +298,14 @@ export default {
}, },
// 退 // 退
onLogout() { onLogout() {
this.loading = true
loginOut().then(res => { loginOut().then(res => {
this.$store.commit('SET_NAME', '')
sessionStorage.setItem('userName', '')
this.$router.push({ this.$router.push({
path: 'login' path: 'login'
}) })
this.getLoginInfo() location.reload()
}) })
}, },
// //

View File

@ -4,7 +4,7 @@ import getters from './getters'
import app from './modules/app' import app from './modules/app'
import settings from './modules/settings' import settings from './modules/settings'
import sample from '@/store/modules/sample' import sample from '@/store/modules/sample'
// import user from './modules/user' import user from './modules/user'
Vue.use(Vuex) Vue.use(Vuex)
@ -12,8 +12,8 @@ const store = new Vuex.Store({
modules: { modules: {
app, app,
settings, settings,
sample sample,
// user user
}, },
getters getters
}) })

18
src/store/modules/user.js Normal file
View File

@ -0,0 +1,18 @@
const user = {
state: {
name: ''
},
mutations: {
SET_NAME: (state, name) => {
state.name = name
}
},
actions: {
}
}
export default user

View File

@ -53,11 +53,12 @@ service.interceptors.response.use(
message: res.errorMsg, message: res.errorMsg,
type: 'warning' type: 'warning'
}) })
sessionStorage.setItem('userName', '')
} else if (res.errorCode === 0) { } else if (res.errorCode === 0) {
return res return res
} else { } else {
Message({ Message({
message: '系统错误', message: res.errorMsg,
type: 'warning' type: 'warning'
}) })
} }

View File

@ -55,6 +55,8 @@ export default {
loginCode: '1234' loginCode: '1234'
} }
}, },
created() {
},
methods: { methods: {
onLogin() { onLogin() {
if (!this.loginName) return this.$message.warning('请输入用户名') if (!this.loginName) return this.$message.warning('请输入用户名')
@ -67,6 +69,8 @@ export default {
}).then(res => { }).then(res => {
if (res.success) { if (res.success) {
this.$router.back() this.$router.back()
this.$store.commit('SET_NAME', this.loginName)
sessionStorage.setItem('userName', this.loginName)
} else { } else {
this.$message.error(res.errorMsg) this.$message.error(res.errorMsg)
} }