添加公司名称并添加下拉列表展示

This commit is contained in:
熊丽君
2021-09-15 11:17:56 +08:00
parent 561091693b
commit c30f24b3f3
5 changed files with 87 additions and 15 deletions

View File

@ -6,6 +6,7 @@ const getters = {
cachedViews: state => state.tagsView.cachedViews, cachedViews: state => state.tagsView.cachedViews,
token: state => state.user.token, token: state => state.user.token,
avatar: state => state.user.avatar, avatar: state => state.user.avatar,
companyName: state => state.user.companyName,
badge: state => state.user.badge, badge: state => state.user.badge,
name: state => state.user.name, name: state => state.user.name,
introduction: state => state.user.introduction, introduction: state => state.user.introduction,

View File

@ -1,4 +1,5 @@
import { login, register, logout, getInfo } from '@/api/login'; import { login, register, logout, getInfo } from '@/api/login';
import { userInfo } from '@/api/home/info';
import { getMsgCount } from '@/api/home/news'; import { getMsgCount } from '@/api/home/news';
import { getToken, setToken, removeToken } from '@/utils/auth'; import { getToken, setToken, removeToken } from '@/utils/auth';
@ -9,6 +10,7 @@ const user = {
name: '', name: '',
userId: '', userId: '',
avatar: '', avatar: '',
companyName: '',
roles: [], roles: [],
permissions: [] permissions: []
}, },
@ -23,6 +25,9 @@ const user = {
SET_NAME: (state, name) => { SET_NAME: (state, name) => {
state.name = name; state.name = name;
}, },
SET_COMNAME: (state, companyName) => {
state.companyName = companyName;
},
SET_USER_ID: (state, userId) => { SET_USER_ID: (state, userId) => {
state.userId = userId; state.userId = userId;
localStorage.setItem('web-userId', userId); localStorage.setItem('web-userId', userId);
@ -92,7 +97,14 @@ const user = {
GetInfo({ commit, state }) { GetInfo({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getInfo(state.token) getInfo(state.token)
.then(res => { .then(async res => {
const { data } = await userInfo();
if (data) {
// 公司名
commit('SET_COMNAME', data.companyName);
} else {
commit('SET_COMNAME', data);
}
const user = res.data; const user = res.data;
const avatar = !res.data.icon const avatar = !res.data.icon
? require('@/assets/image/profile.jpg') ? require('@/assets/image/profile.jpg')

View File

@ -9,17 +9,25 @@
<i class="mark">|</i> <i class="mark">|</i>
<el-button type="text" @click="handlePage(false)">注册</el-button> <el-button type="text" @click="handlePage(false)">注册</el-button>
</div> </div>
<div <div class="login_btn avatar-wrapper" v-else>
class="login_btn avatar-wrapper" <span style="margin-right:20px">{{
v-else companyName == '' || !companyName ? '请先完善个人信息' : companyName
@click="handlePath('/mine')" }}</span>
> <el-popover placement="bottom" trigger="hover">
<!-- <span> <div class="pop">
<i>20</i> <div @click="handlePath('/mine/info')">基本信息</div>
</span> --> <div @click="handlePath('/mine/account')">账户安全</div>
<el-badge :value="badge" :max="10" class="item"> <div @click="handlePath('/mine/ollection')">我的收藏</div>
<div @click="handlePath('/mine/news')">
消息通知
<span></span>
</div>
<div @click="logout">退出登录</div>
</div>
<el-badge :value="badge" :max="10" class="item" slot="reference">
<img :src="avatar" class="user-avatar" /> <img :src="avatar" class="user-avatar" />
</el-badge> </el-badge>
</el-popover>
</div> </div>
<div class="img2_box"> <div class="img2_box">
<img src="@/assets/image/02.png" alt="" /> <img src="@/assets/image/02.png" alt="" />
@ -47,7 +55,7 @@
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
export default { export default {
computed: { computed: {
...mapGetters(['avatar', 'badge']) ...mapGetters(['avatar', 'companyName', 'badge'])
}, },
data() { data() {
return { return {
@ -55,6 +63,17 @@ export default {
}; };
}, },
methods: { methods: {
async logout() {
this.$confirm('确定退出账号吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$store.dispatch('LogOut').then(() => {
location.href = '/';
});
});
},
handlePage(flag) { handlePage(flag) {
this.$router.push({ path: '/login', query: { status: flag } }); this.$router.push({ path: '/login', query: { status: flag } });
}, },
@ -101,11 +120,14 @@ export default {
} }
} }
.avatar-wrapper { .avatar-wrapper {
text-align: right; // text-align: right;
display: flex;
justify-content: flex-end;
align-items: center;
.el-badge { .el-badge {
// display: block; // display: block;
// position: relative; // position: relative;
top: 10px; // top: 10px;
right: 8px; right: 8px;
border: 1px solid #ffa32c; border: 1px solid #ffa32c;
border-radius: 50%; border-radius: 50%;
@ -117,6 +139,9 @@ export default {
height: 40px; height: 40px;
border-radius: 50%; border-radius: 50%;
} }
.user-avatar:hover {
border: 1px solid #ffa32c;
}
} }
} }
.img2_box { .img2_box {
@ -148,4 +173,30 @@ export default {
} }
} }
} }
.el-popover {
.pop {
text-align: center;
font-size: 16px;
line-height: 34px;
div:nth-child(4) {
position: relative;
}
div {
span {
position: absolute;
top: 50%;
right: 15px;
transform: translateY(-50%);
width: 5px;
height: 5px;
border-radius: 50%;
background-color: red;
}
}
div:hover {
background-color: #ccc;
cursor: pointer;
}
}
}
</style> </style>

View File

@ -236,6 +236,7 @@ export default {
}); });
this.form.labelIdList = ids; this.form.labelIdList = ids;
updateCompanyUser(this.form).then(({ message }) => { updateCompanyUser(this.form).then(({ message }) => {
store.commit('SET_COMNAME', this.form.companyName);
this.msgSuccess(message); this.msgSuccess(message);
this.getUserInfo(); this.getUserInfo();
}); });

View File

@ -56,8 +56,15 @@ export default {
}, },
watch: { watch: {
$route(newVal, oldVal) { $route(newVal, oldVal) {
console.log(newVal);
if (newVal.path === '/mine/info') { if (newVal.path === '/mine/info') {
this.index = 0; this.index = 0;
} else if (newVal.path === '/mine/account') {
this.index = 1;
} else if (newVal.path === '/mine/ollection') {
this.index = 2;
} else if (newVal.path === '/mine/news') {
this.index = 3;
} }
} }
}, },