Navbar.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="navbar">
  3. <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
  4. <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
  5. <div class="right-menu">
  6. <template v-if="device!=='mobile'">
  7. <span class="date" >{{date}}</span>
  8. <search id="header-search" class="right-menu-item" />
  9. </template>
  10. <div class="avatar-container right-menu-item hover-effect">
  11. <div class="avatar-wrapper">
  12. {{$store.state.user.nickName}}
  13. </div>
  14. <div class="logout" @click="logout">
  15. <span>安全退出</span>
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import { mapGetters } from 'vuex'
  23. import Breadcrumb from '@/components/Breadcrumb'
  24. import Hamburger from '@/components/Hamburger'
  25. import Screenfull from '@/components/Screenfull'
  26. import SizeSelect from '@/components/SizeSelect'
  27. import Search from '@/components/HeaderSearch'
  28. import RuoYiGit from '@/components/RuoYi/Git'
  29. import RuoYiDoc from '@/components/RuoYi/Doc'
  30. export default {
  31. components: {
  32. Breadcrumb,
  33. Hamburger,
  34. Screenfull,
  35. SizeSelect,
  36. Search,
  37. RuoYiGit,
  38. RuoYiDoc
  39. },
  40. data(){
  41. return{
  42. date: new Date(),
  43. }
  44. },
  45. computed: {
  46. ...mapGetters([
  47. 'sidebar',
  48. 'avatar',
  49. 'device'
  50. ]),
  51. setting: {
  52. get() {
  53. return this.$store.state.settings.showSettings
  54. },
  55. set(val) {
  56. this.$store.dispatch('settings/changeSetting', {
  57. key: 'showSettings',
  58. value: val
  59. })
  60. }
  61. }
  62. },
  63. mounted(){
  64. let that= this;
  65. this.timer = setInterval(function() {
  66. let myDate = new Date()
  67. let year = myDate.getFullYear() + '年'
  68. let month = myDate.getMonth() + 1 +'月'
  69. let day = myDate.getDate() +'日'
  70. let hours = myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours();
  71. let minutes = myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes();
  72. let seconds = myDate.getSeconds() < 10 ? "0" + myDate.getSeconds() : myDate.getSeconds();
  73. let sfb = hours + ':' + minutes + ':' + seconds
  74. that.date = year + month + day + ' ' + sfb
  75. });
  76. },
  77. methods: {
  78. toggleSideBar() {
  79. this.$store.dispatch('app/toggleSideBar')
  80. },
  81. async logout() {
  82. this.$confirm('确定注销并退出系统吗?', '提示', {
  83. confirmButtonText: '确定',
  84. cancelButtonText: '取消',
  85. type: 'warning'
  86. }).then(() => {
  87. this.$store.dispatch('LogOut').then(() => {
  88. location.href = '/center/';
  89. })
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .navbar {
  97. height: 50px;
  98. overflow: hidden;
  99. position: relative;
  100. background: #fff;
  101. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  102. .hamburger-container {
  103. line-height: 46px;
  104. height: 100%;
  105. float: left;
  106. cursor: pointer;
  107. transition: background .3s;
  108. -webkit-tap-highlight-color:transparent;
  109. &:hover {
  110. background: rgba(0, 0, 0, .025)
  111. }
  112. }
  113. .breadcrumb-container {
  114. float: left;
  115. }
  116. .errLog-container {
  117. display: inline-block;
  118. vertical-align: top;
  119. }
  120. .right-menu {
  121. float: right;
  122. height: 100%;
  123. line-height: 50px;
  124. &:focus {
  125. outline: none;
  126. }
  127. .right-menu-item {
  128. display: inline-block;
  129. padding: 0 8px;
  130. height: 100%;
  131. font-size: 18px;
  132. color: #5a5e66;
  133. vertical-align: text-bottom;
  134. &.hover-effect {
  135. cursor: pointer;
  136. transition: background .3s;
  137. &:hover {
  138. background: rgba(0, 0, 0, .025)
  139. }
  140. }
  141. }
  142. .avatar-container {
  143. margin-right: 10px;
  144. font-size: 14px;
  145. .avatar-wrapper {
  146. margin-top: 0px;
  147. position: relative;
  148. display: inline-block;
  149. cursor: default;
  150. .user-avatar {
  151. cursor: pointer;
  152. width: 40px;
  153. height: 40px;
  154. border-radius: 10px;
  155. }
  156. .el-icon-caret-bottom {
  157. position: absolute;
  158. right: -20px;
  159. top: 25px;
  160. font-size: 12px;
  161. }
  162. }
  163. .logout{
  164. margin: 0px 0 0 20px;
  165. position: relative;
  166. display: inline-block;
  167. z-index: 1;
  168. }
  169. }
  170. }
  171. }
  172. .date{
  173. width:250px;
  174. margin-right: 20px;
  175. vertical-align: top;
  176. }
  177. </style>