mt-yd-ui/src/views/main-navbar.vue

150 lines
4.9 KiB
Vue
Raw Normal View History

2022-08-02 08:48:23 +08:00
<template>
2022-10-09 10:36:18 +08:00
<nav class="aui-navbar" :class="`aui-navbar--${$store.state.navbarLayoutType}`">
2022-08-04 16:25:49 +08:00
<div class="aui-navbar__header">
<h1 class="aui-navbar__brand" @click="$router.push({ name: 'home' })">
2022-10-09 10:36:18 +08:00
<a class="aui-navbar__brand-lg" href="javascript:;">{{ $t('brand.lg') }}</a>
<a class="aui-navbar__brand-mini" href="javascript:;">{{ $t('brand.mini') }}</a>
2022-08-04 16:25:49 +08:00
</h1>
</div>
<div class="aui-navbar__body">
<el-menu class="aui-navbar__menu mr-auto" mode="horizontal">
2022-10-09 10:36:18 +08:00
<el-menu-item index="1" @click="$store.state.sidebarFold = !$store.state.sidebarFold">
<svg class="icon-svg aui-navbar__icon-menu aui-navbar__icon-menu--switch" aria-hidden="true">
2022-08-31 10:22:44 +08:00
<use xlink:href="#icon-outdent"></use>
</svg>
2022-08-04 16:25:49 +08:00
</el-menu-item>
<el-menu-item index="2" @click="refresh()">
2022-10-09 10:36:18 +08:00
<svg class="icon-svg aui-navbar__icon-menu aui-navbar__icon-menu--refresh" aria-hidden="true">
2022-08-31 10:22:44 +08:00
<use xlink:href="#icon-sync"></use>
</svg>
2022-08-04 16:25:49 +08:00
</el-menu-item>
</el-menu>
<el-menu class="aui-navbar__menu" mode="horizontal">
2022-08-26 11:07:57 +08:00
<!-- <el-menu-item index="2">
2022-08-04 16:25:49 +08:00
<a href="https://www.renren.io/" target="_blank">
<svg class="icon-svg aui-navbar__icon-menu" aria-hidden="true"><use xlink:href="#icon-earth"></use></svg>
</a>
</el-menu-item>
<el-menu-item index="2">
<a href="https://gitee.com/renrenio/renren-security" target="_blank">
<svg class="icon-svg aui-navbar__icon-menu" aria-hidden="true"><use xlink:href="#gitee"></use></svg>
</a>
2022-08-26 11:07:57 +08:00
</el-menu-item> -->
2022-08-31 10:22:44 +08:00
<el-menu-item index="3">
2022-10-09 10:36:18 +08:00
<el-dropdown placement="bottom" :show-timeout="0" @command="handleCommand">
2022-08-31 10:22:44 +08:00
<span class="el-dropdown-link">
<svg class="icon-svg aui-navbar__icon-menu" aria-hidden="true">
<use xlink:href="#icon-earth"></use>
</svg>
<!-- <i class="el-icon-arrow-down el-icon--right"></i> -->
</span>
<el-dropdown-menu slot="dropdown">
2022-10-09 10:36:18 +08:00
<el-dropdown-item :disabled="getLang() === 'zh-CN'" command="toCN">中文</el-dropdown-item>
<el-dropdown-item :disabled="getLang() === 'en'" command="toEN">En</el-dropdown-item>
2022-08-31 10:22:44 +08:00
</el-dropdown-menu>
</el-dropdown>
</el-menu-item>
2022-08-04 16:25:49 +08:00
<el-menu-item index="4" @click="fullscreenHandle()">
2022-08-31 10:22:44 +08:00
<svg class="icon-svg aui-navbar__icon-menu" aria-hidden="true">
<use xlink:href="#icon-fullscreen"></use>
</svg>
2022-08-04 16:25:49 +08:00
</el-menu-item>
<el-menu-item index="5" class="aui-navbar__avatar">
<el-dropdown placement="bottom" :show-timeout="0">
<span class="el-dropdown-link">
<img src="~@/assets/img/avatar.png" />
<span>{{ $store.state.user.name }}</span>
<i class="el-icon-arrow-down"></i>
</span>
<el-dropdown-menu slot="dropdown">
2022-10-09 10:36:18 +08:00
<el-dropdown-item @click.native="updatePasswordHandle()">{{ $t('updatePassword.title') }}</el-dropdown-item>
<el-dropdown-item @click.native="logoutHandle()">{{ $t('logout') }}</el-dropdown-item>
2022-08-04 16:25:49 +08:00
</el-dropdown-menu>
</el-dropdown>
</el-menu-item>
</el-menu>
</div>
<!-- 弹窗, 修改密码 -->
2022-10-09 10:36:18 +08:00
<update-password v-if="updatePasswordVisible" ref="updatePassword"></update-password>
2022-08-04 16:25:49 +08:00
</nav>
2022-08-02 08:48:23 +08:00
</template>
<script>
2022-08-31 10:22:44 +08:00
import Cookies from 'js-cookie'
2022-08-02 08:48:23 +08:00
import screenfull from 'screenfull'
import UpdatePassword from './main-navbar-update-password'
import { clearLoginInfo } from '@/utils'
export default {
2022-08-04 16:25:49 +08:00
inject: ['refresh'],
data() {
return {
updatePasswordVisible: false,
messageTip: false
}
},
components: {
UpdatePassword
},
methods: {
2022-08-31 10:22:44 +08:00
// 获取当前语言环境
getLang() {
return Cookies.get('language')
},
// 切换语言环境
handleCommand(command) {
// 切换语言选项时,可能需要手动刷新页面
switch (command) {
case 'toCN':
this.$root.$i18n.locale = 'zh-CN'
2022-09-02 14:09:41 +08:00
window.navigator.language = 'zh-cn'
2022-08-31 10:22:44 +08:00
break
2022-10-09 10:36:18 +08:00
case 'toEN':
console.log('root', this.$root.$i18n.locale)
this.$root.$i18n.locale = 'en'
location.reload()
window.navigator.language = 'en-US'
2022-08-31 10:22:44 +08:00
break
}
},
2022-08-04 16:25:49 +08:00
// 全屏
fullscreenHandle() {
if (!screenfull.enabled) {
return this.$message({
message: this.$t('fullscreen.prompt'),
type: 'warning',
duration: 500
})
}
screenfull.toggle()
},
// 修改密码
updatePasswordHandle() {
this.updatePasswordVisible = true
this.$nextTick(() => {
this.$refs.updatePassword.init()
})
},
// 退出
logoutHandle() {
2022-10-09 10:36:18 +08:00
this.$confirm(this.$t('prompt.info', { handle: this.$t('logout') }), this.$t('prompt.title'), {
confirmButtonText: this.$t('confirm'),
cancelButtonText: this.$t('cancel'),
type: 'warning'
})
2022-08-04 16:25:49 +08:00
.then(() => {
this.$http
2022-08-09 16:16:34 +08:00
.post(this.$http.adornUrl('/logout'))
2022-08-04 16:25:49 +08:00
.then(({ data: res }) => {
2022-08-09 16:16:34 +08:00
if (res.code !== 0) {
2022-08-04 16:25:49 +08:00
return this.$message.error(res.msg)
}
clearLoginInfo()
this.$router.push({ name: 'Login' })
})
.catch(() => {})
})
.catch(() => {})
}
}
2022-08-02 08:48:23 +08:00
}
</script>