|
|
@@ -12,7 +12,31 @@
|
|
|
</el-input>
|
|
|
<ul class="nav__list nav__list-right" v-if="isLogin">
|
|
|
<li class="nav__item"><router-link to="/person/info">个人中心</router-link></li>
|
|
|
- <li class="nav__item"><img class="nav__photo" src="/image/default-photo.jpg"/></li>
|
|
|
+ <li class="nav__item">
|
|
|
+ <el-popover
|
|
|
+ placement="bottom-start"
|
|
|
+ width="120"
|
|
|
+ trigger="hover"
|
|
|
+ popper-class="drop-container">
|
|
|
+ <div class="drop-info">
|
|
|
+ <div class="drop-info__item drop-info__name">{{userName}}</div>
|
|
|
+ <div class="drop-info__item">({{userPhone}})</div>
|
|
|
+ </div>
|
|
|
+ <el-menu
|
|
|
+ class="el-menu-vertical-demo drop-list">
|
|
|
+ <el-menu-item index="1" v-if="isAdmin">
|
|
|
+ 平台管理
|
|
|
+ </el-menu-item>
|
|
|
+ <el-menu-item index="2" v-if="isAdmin">
|
|
|
+ 教师界面
|
|
|
+ </el-menu-item>
|
|
|
+ <el-menu-item index="3" @click="logout">
|
|
|
+ 退出登录
|
|
|
+ </el-menu-item>
|
|
|
+ </el-menu>
|
|
|
+ <img slot="reference" class="nav__photo" src="/image/default-photo.jpg"/>
|
|
|
+ </el-popover>
|
|
|
+ </li>
|
|
|
</ul>
|
|
|
<ul class="nav__list nav__list-right" v-else>
|
|
|
<li class="nav__item"><router-link to="/login">登录</router-link></li>
|
|
|
@@ -23,12 +47,70 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import { mapState } from 'vuex'
|
|
|
+ import { mapMutations } from 'vuex'
|
|
|
export default {
|
|
|
name: "Navi",
|
|
|
data(){
|
|
|
return{
|
|
|
- isLogin: !!this.$store.state.token
|
|
|
+ isLogin: !!this.$store.state.token,
|
|
|
+ isTeacher: this.$store.state.user.role === "TEACHER",
|
|
|
+ isAdmin: this.$store.state.user.role === "ADMIN",
|
|
|
+ userName: this.$store.state.user.name,
|
|
|
+ userPhone: this.$store.state.user.phone
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted(){
|
|
|
+ if(this.$store.state.token){
|
|
|
+ localStorage.setItem('token', this.$store.state.token);
|
|
|
+ }else{
|
|
|
+ if(localStorage.getItem("token")){
|
|
|
+ this.$store.commit('saveToken', localStorage.getItem('token'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(this.$store.state.user && this.$store.state.user.name){
|
|
|
+ localStorage.setItem('user', JSON.stringify(this.$store.state.user));
|
|
|
+ }else{
|
|
|
+ if(localStorage.getItem("user")){
|
|
|
+ this.$store.commit('saveUser', JSON.parse(localStorage.getItem('user')));
|
|
|
+ console.log(JSON.parse(localStorage.getItem('user')));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.refresh();
|
|
|
+ },
|
|
|
+ // refreshed(){
|
|
|
+ // if(this.$store.state.token){
|
|
|
+ // localStorage.setItem('token', token);
|
|
|
+ // }else{
|
|
|
+ // if(localStorage.getItem("token")){
|
|
|
+ // this.$store.commit('saveToken', localStorage.getItem('token'));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if(this.$store.state.user){
|
|
|
+ // localStorage.setItem('user', JSON.stringify(this.$store.state.user));
|
|
|
+ // }else{
|
|
|
+ // if(localStorage.getItem("user")){
|
|
|
+ // this.$store.commit('saveUser', JSON.parse(localStorage.getItem('user')));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // },
|
|
|
+ methods:{
|
|
|
+ logout(){
|
|
|
+ this.$store.commit("saveToken", null);
|
|
|
+ this.$store.commit("saveUser", {});
|
|
|
+ localStorage.removeItem('token');
|
|
|
+ localStorage.removeItem('user');
|
|
|
+ this.refresh();
|
|
|
+ },
|
|
|
+ refresh(){
|
|
|
+ this.isLogin = !!this.$store.state.token;
|
|
|
+ this.isTeacher = this.$store.state.user.role === "TEACHER";
|
|
|
+ this.isAdmin = this.$store.state.user.role === "ADMIN";
|
|
|
+ this.userName = this.$store.state.user.name;
|
|
|
+ this.userPhone = this.$store.state.user.phone;
|
|
|
}
|
|
|
}
|
|
|
};
|