Navbar.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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" v-if="!topNav"/> -->
  5. <!-- <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav"/> -->
  6. <!-- <div class="sign_box">
  7. <div class="sign_item" :class="{active: activeMenu.includes((item.path||item.redirect))}" v-for="(item,index) in this.sidebarRouters.filter(res => {
  8. return res.hidden == false || res.redirect == 'index'
  9. })" :key="index"
  10. @click="tabBtn(item)">
  11. <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
  12. <item v-if="!item.meta" :icon="item.meta && item.meta.icon" :title="'首页'" />
  13. </div>
  14. </div> -->
  15. <div class="right-menu" style="display: flex;align-items: center;">
  16. <!-- <el-select
  17. v-model="companyName"
  18. clearable
  19. filterable
  20. reserve-keyword
  21. placeholder="选择小区"
  22. v-if="userId === 1 && tenantEnabled"
  23. @change="dynamicTenantEvent"
  24. @clear="dynamicClearEvent"
  25. >
  26. <el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"> </el-option>
  27. <template ><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>
  28. </el-select>
  29. <el-select
  30. v-model="companyName"
  31. clearable
  32. filterable
  33. reserve-keyword
  34. placeholder="选择小区"
  35. v-if="userId != 1 && (tenantListtw.length !=0 && tenantListtw.length !=1)"
  36. @change="dynamicTenantEventg"
  37. @clear="dynamicClearEvent"
  38. >
  39. <el-option v-for="item in tenantListtw" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"> </el-option>
  40. <template ><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>
  41. </el-select> -->
  42. <!-- <template v-if="device!=='mobile'">
  43. <search id="header-search" class="right-menu-item" />
  44. <el-tooltip content="源码地址" effect="dark" placement="bottom">
  45. <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
  46. </el-tooltip>
  47. <el-tooltip content="文档地址" effect="dark" placement="bottom">
  48. <ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />
  49. </el-tooltip>
  50. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  51. <el-tooltip content="布局大小" effect="dark" placement="bottom">
  52. <size-select id="size-select" class="right-menu-item hover-effect" />
  53. </el-tooltip>
  54. </template> -->
  55. <el-dropdown class="avatar-container right-menu-item hover-effect nhdes" trigger="hover" >
  56. <!-- <img src="../../assets/images/pic_htgl_grxx_bg.png" class="imgse" > -->
  57. <div class="nhse ">
  58. <div class="avatar-wrapper el-dropdown-link">
  59. <img :src="avatar" class="user-avatar">
  60. </div>
  61. <div class="acnes ">
  62. <p>
  63. <!-- <img src="../../assets/images/icon_htgl_hzh.png" > -->
  64. <span >
  65. {{name}}
  66. </span>
  67. </p>
  68. </div>
  69. <i style="color: #333; opacity: 0.7;display: flex;align-items: center;" class="el-icon-caret-bottom " />
  70. <!-- <i class="el-icon-caret-bottom" /> -->
  71. </div>
  72. <el-dropdown-menu slot="dropdown">
  73. <router-link to="/user/profile">
  74. <el-dropdown-item>个人中心</el-dropdown-item>
  75. </router-link>
  76. <el-dropdown-item @click.native="setting = true">
  77. <span>布局设置</span>
  78. </el-dropdown-item>
  79. <el-dropdown-item divided @click.native="logout">
  80. <span>退出登录</span>
  81. </el-dropdown-item>
  82. </el-dropdown-menu>
  83. </el-dropdown>
  84. <template>
  85. <p style="display: flex;align-items: center;width:80px; cursor:pointer; " @click="logouth">
  86. <!-- <img src="../../assets/images/icon_htdh_tc.png" class="user-avatar" style="width:13px;height:16px;margin-right: 10px;"> -->
  87. <span style="font-weight: bold;font-size: 16px;color: #343434;">退出</span>
  88. </p>
  89. </template>
  90. </div>
  91. </div>
  92. </template>
  93. <script>
  94. import { mapGetters } from 'vuex'
  95. import Breadcrumb from '@/components/Breadcrumb'
  96. import TopNav from '@/components/TopNav'
  97. import Hamburger from '@/components/Hamburger'
  98. import Screenfull from '@/components/Screenfull'
  99. import SizeSelect from '@/components/SizeSelect'
  100. import Search from '@/components/HeaderSearch'
  101. import RuoYiGit from '@/components/RuoYi/Git'
  102. import RuoYiDoc from '@/components/RuoYi/Doc'
  103. import { getCodeImg,register,getTenantList,getInfo } from "@/api/login";
  104. // import { dynamicClear, dynamicTenant,userNamet,dynamicTenantgw } from "@/api/zhihuixy/tenant";
  105. import { getToken, setToken, removeToken } from '@/utils/auth'
  106. export default {
  107. components: {
  108. Breadcrumb,
  109. TopNav,
  110. Hamburger,
  111. Screenfull,
  112. SizeSelect,
  113. Search,
  114. RuoYiGit,
  115. RuoYiDoc
  116. },
  117. computed: {
  118. ...mapGetters([
  119. 'sidebar',
  120. 'avatar',
  121. 'device',
  122. 'name',
  123. 'userId',
  124. 'dept',
  125. 'rolesName',
  126. "sidebarRouters", "sidebar", "tabIndex"
  127. ]),
  128. activeMenu() {
  129. return this.tabIndex;
  130. },
  131. setting: {
  132. get() {
  133. return this.$store.state.settings.showSettings
  134. },
  135. set(val) {
  136. this.$store.dispatch('settings/changeSetting', {
  137. key: 'showSettings',
  138. value: val
  139. })
  140. }
  141. },
  142. topNav: {
  143. get() {
  144. return this.$store.state.settings.topNav
  145. }
  146. }
  147. },
  148. data() {
  149. return {
  150. tenantEnabled:true,
  151. tenantList:[],
  152. companyName:null,
  153. tenantListtw:[],
  154. usename:'',
  155. timer:null,
  156. };
  157. },
  158. created() {
  159. console.log(this.$store.state.user)
  160. this.usename = this.$store.state.user.name
  161. // this.avatar = this.$store.state.user.avatar
  162. // if(this.$store.getters.authenticationUser =='4' || this.$store.getters.authenticationUser =='3'){
  163. // if(this.usename =='admin'){
  164. // console.log(5)
  165. // this.getnhgw()
  166. // }else{
  167. // if(sessionStorage.getItem('companyName') != null ){
  168. // if(sessionStorage.getItem('companyName') != undefined ){
  169. // this.companyName = sessionStorage.getItem('companyName')
  170. // }
  171. // }
  172. // console.log(3)
  173. // this.getnhgwon()
  174. // }
  175. // }
  176. },
  177. mouted(){
  178. // this.$nextTick(()=>{
  179. let router_path = this.$route.path
  180. console.log(router_path) // 输出当前页面的路由,如:/home
  181. // })
  182. },
  183. methods: {
  184. getnhgw(){
  185. // this.loading = true;
  186. getTenantList().then(response => {
  187. // this.tenantEnabled = response.data.tenantEnabled
  188. this.tenantList = response.data.voList;
  189. // this.loading = false;
  190. });
  191. },
  192. getnhgwon(){
  193. // this.loading = true;
  194. let ngse={'userName': this.usename}
  195. userNamet(ngse).then(response => {
  196. // this.tenantEnabled = response.data.tenantEnabled
  197. this.tenantListtw = response.data;
  198. if(response.data.length !=0 || response.data.length !=1){
  199. this.tenantEnabled = false
  200. }
  201. // this.loading = false;
  202. });
  203. },
  204. dynamicTenantEvent(){
  205. if (this.companyName != null && this.companyName !== '') {
  206. dynamicTenant(this.companyName).then(response => {
  207. this.dynamic = true;
  208. this.$tab.closeAllPage();
  209. this.$router.push('/');
  210. });
  211. }
  212. },
  213. dynamicTenantEventg(){
  214. if (this.companyName != null && this.companyName !== '') {
  215. sessionStorage.setItem('companyName', this.companyName)
  216. let ngpw={'tenantId':this.companyName,'clientId':'e5cd7e4891bf95d1d19206ce24a7b32e','grantType':'password'}
  217. // dynamicTenantgw ngpw
  218. dynamicTenantgw(ngpw).then(response => {
  219. this.dynamic = true;
  220. setToken(response.msg)
  221. let ngse={'userName': this.usename}
  222. getInfo().then(response => {
  223. // this.loading = false;
  224. this.$router.push('/');
  225. this.$tab.closeAllPage();
  226. setTimeout(() => {
  227. location.reload(true)
  228.                 }, 1000)
  229. //
  230. // location.reload(true)
  231. this.companyName = response.data.user.tenantId
  232. });
  233. // this.$tab.closeAllPage();
  234. // this.$router.push('/');
  235. });
  236. }
  237. },
  238. dynamicClearEvent(){
  239. dynamicClear().then(response => {
  240. this.dynamic = false;
  241. this.$tab.closeAllPage();
  242. this.$router.push('/');
  243. });
  244. },
  245. toggleSideBar() {
  246. this.$store.dispatch('app/toggleSideBar')
  247. },
  248. tabBtn(item) {
  249. console.log(item)
  250. if(this.activeMenu.includes((item.path||item.redirect))){
  251. return
  252. }
  253. this.$store.dispatch('app/toggleSideBartwo')
  254. if (item.redirect == 'index') {
  255. if(this.$route.path!=='/index'){
  256. this.$router.push({
  257. path: '/index'
  258. })
  259. }
  260. this.$store.dispatch('TabFn', item.redirect)
  261. return
  262. }
  263. this.$store.dispatch('TabFn', item.path)
  264. this.showde = true
  265. },
  266. init() {
  267. const route = this.$route;
  268. const {
  269. meta,
  270. path
  271. } = route;
  272. // if set path, the sidebar will highlight the path you set
  273. console.log(route,13)
  274. if (meta.activeMenu) {
  275. this.$store.dispatch('TabFn', meta.activeMenu)
  276. }
  277. this.$store.dispatch('TabFn', path)
  278. },
  279. async logout() {
  280. this.$confirm('确定注销并退出系统吗?', '提示', {
  281. confirmButtonText: '确定',
  282. cancelButtonText: '取消',
  283. type: 'warning'
  284. }).then(() => {
  285. sessionStorage.removeItem('companyName')
  286. this.$store.dispatch('LogOut').then(() => {
  287. location.href = '/index';
  288. })
  289. }).catch(() => {});
  290. },
  291. async logouth() {
  292. this.$confirm('确定注销并退出系统吗?', '提示', {
  293. confirmButtonText: '确定',
  294. cancelButtonText: '取消',
  295. type: 'warning'
  296. }).then(() => {
  297. sessionStorage.removeItem('companyName')
  298. this.$store.dispatch('LogOut').then(() => {
  299. location.href = '/index';
  300. })
  301. }).catch(() => {});
  302. }
  303. }
  304. }
  305. </script>
  306. <style lang="scss">
  307. .nhdes{
  308. position: relative;
  309. z-index: 99;
  310. .el-button-group>.el-button{
  311. border: none;
  312. padding: 0;
  313. }
  314. .el-button-group>.el-button:hover{
  315. background-color: #fff;
  316. }
  317. }
  318. </style>
  319. <style lang="scss" scoped>
  320. .navbar .right-menu .avatar-container{
  321. margin-right: 20px;
  322. }
  323. .right-menu{
  324. .el-select{
  325. // top:-17px;
  326. margin-right: 60px;
  327. }
  328. }
  329. .navbar {
  330. height: 50px;
  331. overflow: hidden;
  332. position: relative;
  333. background: #fff;
  334. // background-color: #E7F5F1;
  335. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  336. .hamburger-container {
  337. line-height: 46px;
  338. height: 100%;
  339. float: left;
  340. cursor: pointer;
  341. transition: background .3s;
  342. -webkit-tap-highlight-color:transparent;
  343. &:hover {
  344. background: rgba(0, 0, 0, .025)
  345. }
  346. }
  347. .breadcrumb-container {
  348. float: left;
  349. }
  350. .topmenu-container {
  351. position: absolute;
  352. left: 50px;
  353. }
  354. .errLog-container {
  355. display: inline-block;
  356. vertical-align: top;
  357. }
  358. .right-menu {
  359. float: right;
  360. height: 100%;
  361. line-height: 50px;
  362. &:focus {
  363. outline: none;
  364. }
  365. .right-menu-item {
  366. display: inline-block;
  367. padding: 0 8px;
  368. height: 100%;
  369. font-size: 18px;
  370. color: #5a5e66;
  371. vertical-align: text-bottom;
  372. &.hover-effect {
  373. cursor: pointer;
  374. transition: background .3s;
  375. &:hover {
  376. background: rgba(0, 0, 0, .025)
  377. }
  378. }
  379. }
  380. .avatar-container {
  381. // margin-right: 30px;
  382. position: relative;
  383. .avatar-wrapper {
  384. margin-top: 5px;
  385. position: relative;
  386. z-index: 33;
  387. .user-avatar {
  388. cursor: pointer;
  389. width: 40px;
  390. height: 40px;
  391. border-radius: 50%;
  392. }
  393. .el-icon-caret-bottom {
  394. cursor: pointer;
  395. position: absolute;
  396. right: -20px;
  397. top: 25px;
  398. font-size: 12px;
  399. z-index: 33;
  400. }
  401. }
  402. }
  403. }
  404. }
  405. .nhse{
  406. display: flex;
  407. height: 50px !important;
  408. // background-image: url("../../assets/images/pic_htgl_grxx_bg.png") !important;
  409. // background-size: 100% 70px;
  410. .acnes{
  411. display: flex;
  412. height: 100%;
  413. position: relative;
  414. z-index: 2;
  415. align-items: center;
  416. p{
  417. font-size: 13px;
  418. font-family: PingFang SC;
  419. font-weight: bold;
  420. color: #333;
  421. margin-right: 10px;
  422. opacity: 0.7;
  423. margin-left: 10px;
  424. }
  425. img{
  426. width: 16px;
  427. height: 16px;
  428. margin-right: 6px;
  429. }
  430. }
  431. }
  432. .imgse{
  433. position: absolute;
  434. right: -30px;
  435. top: 0;
  436. // filter: drop-shadow(0 0.5px 0.5px black);
  437. // height: 50px;
  438. }
  439. </style>