HeadBar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <div class="headbar" :style="{ 'background': '#fff' }"
  3. :class="$store.state.app.collapse ? 'position-collapse-left' : 'position-left'">
  4. <!-- 导航收缩 -->
  5. <div class="navigation">
  6. <span class="hamburg">
  7. <el-menu class="el-menu-demo" text-color="#333333 " :active-text-color="themeColor"
  8. mode="horizontal">
  9. <el-menu-item index="1" @click="onCollapse">
  10. <hamburger :isActive="collapse"></hamburger>
  11. </el-menu-item>
  12. </el-menu>
  13. </span>
  14. <!-- 导航菜单 -->
  15. <span class="navbar" style="text-align: justify;">
  16. <el-menu :default-active="menuIndex" class="el-menu-demo" style="overflow-x: hidden;border: none;font-weight: 400; display: flex;"
  17. text-color="rgb(51,51,51,60%)" :active-text-color="themeColor" mode="horizontal"
  18. @select="selectNavBar">
  19. <el-menu-item style="font-size: 15px;" :index="item.id" v-for="item in leftNavItems" :key="item.id">{{ item.name }}</el-menu-item>
  20. </el-menu>
  21. </span>
  22. <!-- 收缩栏 -->
  23. <el-menu :default-active="menuIndex" class="el-menu-demo" mode="horizontal" @select="selectNavBar"
  24. active-text-color="#ffd04b" text-color="#fff">
  25. <el-submenu style="float:right;" class="right-item" v-if="Object.keys(rightNavItems).length === 0 ? false : true"
  26. index="10">
  27. <template slot="title">
  28. <i class="el-icon-s-fold" style="font-size:28px;color:#fff;"></i>
  29. </template>
  30. <el-menu-item :key="key" v-for="(item, key) in rightNavItems" :index="item.id" style="margin: 4px 0;">{{
  31. item.name }}</el-menu-item>
  32. </el-submenu>
  33. </el-menu>
  34. </div>
  35. <!-- 工具栏 -->
  36. <span class="toolbar" :class="{'active':toolbarActive}" v-popover:popover-personal>
  37. <el-popover
  38. placement="bottom"
  39. ref="reference"
  40. width="300px"
  41. trigger="click" @show="show" @hide="hide">
  42. <personal-panel :user="userData"></personal-panel>
  43. <img slot="reference" :src="userData.headSculpture?userData.headSculpture:avatar" />
  44. </el-popover>
  45. <el-badge :is-dot="isDot">
  46. <div class="personalStyle">
  47. <span >{{ userData.roleName }} - {{ userData.name }}</span>
  48. <span style="color:rgba(51, 51, 51, 0.80) ">{{ userData.id }}</span>
  49. </div>
  50. </el-badge>
  51. </span>
  52. </div>
  53. </template>
  54. <script>
  55. import { mapState } from 'vuex'
  56. import Hamburger from "@/components/Hamburger"
  57. import ThemePicker from "@/components/ThemePicker"
  58. import LangSelector from "@/components/LangSelector"
  59. import Action from "@/components/Toolbar/Action"
  60. import NoticePanel from "@/views/Core/NoticePanel"
  61. import MessagePanel from "@/views/Core/MessagePanel"
  62. import PersonalPanel from "@/views/Core/PersonalPanel"
  63. export default {
  64. components: {
  65. Hamburger,
  66. ThemePicker,
  67. LangSelector,
  68. Action,
  69. NoticePanel,
  70. MessagePanel,
  71. PersonalPanel
  72. },
  73. computed: {
  74. ...mapState({
  75. appName: state => state.app.appName,
  76. themeColor: state => state.app.themeColor,
  77. collapse: state => state.app.collapse,
  78. navTree: state => state.menu.navTree,
  79. leftTree: state => state.menu.leftTree,
  80. }),
  81. leftNavItems: function () {
  82. if (this.screenWidth<=1650 && this.sum > 0) {
  83. return this.navTree.slice(0, '-' + this.sum);
  84. } else {
  85. return this.navTree;
  86. }
  87. },
  88. rightNavItems: function () {
  89. if (this.screenWidth<=1650 && this.sum > 0) {
  90. return this.navTree.slice('-' + this.sum);
  91. } else {
  92. return {}
  93. }
  94. },
  95. },
  96. data() {
  97. return {
  98. isDot: false,
  99. toolbarActive:false,
  100. sum: null,
  101. datawidth: 1920,
  102. screenWidth: document.body.clientWidth,
  103. userData: {},
  104. activeIndex: '86',
  105. langVisible: false,
  106. avatar: "./../../assets/user1.png",
  107. menuIndex: localStorage.getItem("routerId"),
  108. }
  109. },
  110. created() {
  111. if(localStorage.getItem("routerId")){
  112. this.$store.commit('changeLeftTree', localStorage.getItem("routerId"));
  113. }
  114. if(!JSON.parse(localStorage.getItem('user_data'))){
  115. this.$api.user.getLoginUser().then((response) => {
  116. response.data.headSculpture = response.data.headSculpture?process.env.BASE_URL +response.data.headSculpture:response.data.headSculpture
  117. this.userData=response.data
  118. })
  119. }else{
  120. this.userData=JSON.parse(localStorage.getItem('user_data'))
  121. }
  122. if(this.screenWidth<=1260){
  123. this.sum = Math.ceil((this.datawidth - this.screenWidth) / 100)
  124. }
  125. else{
  126. this.sum = Math.ceil((this.datawidth - this.screenWidth) / 140)
  127. }
  128. if (!this.timer) {
  129. // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
  130. // this.screenWidth = newValue;
  131. this.timer = true;
  132. setTimeout(() => {
  133. this.timer = false;
  134. }, 400);
  135. }
  136. // if (this.leftNavItems.length > 8) {
  137. // if (this.screenWidth < this.datawidth) {
  138. // // if(this.screenWidth<=1260){
  139. // // this.sum = Math.ceil((this.datawidth - this.screenWidth) / 100)
  140. // // }
  141. // // else{
  142. // // this.sum = Math.ceil((this.datawidth - this.screenWidth) / 140)
  143. // // }
  144. // // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
  145. // if (!this.timer) {
  146. // // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
  147. // // this.screenWidth = newValue;
  148. // this.timer = true;
  149. // setTimeout(() => {
  150. // this.timer = false;
  151. // }, 400);
  152. // }
  153. // }
  154. // }
  155. },
  156. watch: {
  157. navTree(newValue){
  158. if(localStorage.getItem("routerId") && newValue.length>0){
  159. this.$store.commit('changeLeftTree', localStorage.getItem("routerId"));
  160. }
  161. },
  162. screenWidth(newValue) {
  163. if(newValue<=1260){
  164. this.sum = Math.ceil((this.datawidth - newValue) / 100)
  165. }
  166. else{
  167. this.sum = Math.ceil((this.datawidth - newValue) / 140)
  168. }
  169. // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
  170. if (!this.timer) {
  171. // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
  172. // this.screenWidth = newValue;
  173. this.timer = true;
  174. setTimeout(() => {
  175. this.timer = false;
  176. }, 400);
  177. }
  178. }
  179. },
  180. mounted() {
  181. window.onresize = () => {
  182. this.screenWidth = document.body.clientWidth
  183. }
  184. this.sysName = "Zgdd Platform";
  185. this.$store.commit('SET_TIMER', setInterval(() => {
  186. this.getMessage()
  187. }, 3000))
  188. // var user = sessionStorage.getItem("user")
  189. // if (user) {
  190. // this.user.id = user;
  191. // this.$api.user.findById(user).then((personRes) => {
  192. // this.user.name = personRes.data.sysUser.name;
  193. // this.user.avatar = require("@/assets/user.png")
  194. // Cookies.set('name', personRes.data.sysUser.name) // 放置token到Cookie
  195. // if (user != 'admin') {
  196. // this.user.registeInfo = "入司时间:" + this.transformTime(personRes.data.esmUserInternal.intime);
  197. // this.user.deptId = personRes.data.sysUser.deptId;
  198. // this.user.jobCode = personRes.data.sysUser.jobCode;
  199. // this.$api.dept.getDeptById(this.user.deptId).then(deptRes => {
  200. // this.user.deptName = deptRes.data.name;
  201. // });
  202. // this.$api.dict.findByLableName("jobcode").then((response) => {
  203. // var jobList = response.data; // 把获取到的数据赋给this.data
  204. // for (let i = 0; i < jobList.length; i++) {
  205. // if (jobList[i].value == this.user.jobCode) {
  206. // this.user.jobName = jobList[i].label;
  207. // }
  208. // }
  209. // })
  210. // }
  211. // })
  212. // }
  213. },
  214. methods: {
  215. getMessage() {
  216. let that = this
  217. that.$api.letter.getMessage({
  218. pageNum: 1,
  219. pageSize: 10
  220. }).then(res => {
  221. if(res.code === 200) {
  222. if(res.data.list&&res.data.list.length>0) {
  223. let list = res.data.list.filter(item => item.state === '0')
  224. if(list.length>0) {
  225. that.isDot = true
  226. } else {
  227. that.isDot = false
  228. }
  229. } else {
  230. that.isDot = false
  231. }
  232. }
  233. })
  234. },
  235. show(e){
  236. this.toolbarActive=true;
  237. },
  238. hide(){
  239. this.toolbarActive=false;
  240. },
  241. openWindow(url) {
  242. window.open(url)
  243. },
  244. selectNavBar(key, keyPath) {
  245. //切换左侧菜单
  246. this.$store.commit('changeLeftTree', key);
  247. localStorage.setItem('routerId', key) // 保存用户到本地会话
  248. },
  249. // 折叠导航栏
  250. onCollapse: function () {
  251. this.$store.commit('onCollapse')
  252. },
  253. // 切换主题
  254. onThemeChange: function (themeColor) {
  255. this.$store.commit('setThemeColor', themeColor)
  256. },
  257. // 语言切换
  258. changeLanguage(lang) {
  259. lang === '' ? 'zh_cn' : lang
  260. this.$i18n.locale = lang
  261. this.langVisible = false
  262. },
  263. transformTime(date) {
  264. var d = new Date(date);
  265. var strYear = d.getFullYear();
  266. var strMonth = d.getMonth() + 1;
  267. var strDay = d.getDate();
  268. var hh = d.getHours();
  269. if (hh < 10) {
  270. hh = "0" + hh;
  271. }
  272. if (strMonth < 10) {
  273. strMonth = "0" + strMonth;
  274. }
  275. if (strDay < 10) {
  276. strDay = "0" + strDay;
  277. }
  278. var datetime =
  279. strYear + "-" + strMonth + "-" + strDay + " " + hh + ":00:00";
  280. return datetime;
  281. },
  282. },
  283. }
  284. </script>
  285. <style scoped lang="scss">
  286. .personalStyle{
  287. font-size: 14px;
  288. margin: 5px;
  289. display: flex;
  290. flex-direction: column;
  291. span{
  292. display: inline-block;
  293. line-height: 20px;
  294. }
  295. }
  296. .headbar {
  297. position: fixed;
  298. top: 0;
  299. right: 0;
  300. z-index: 1030;
  301. height: 60px;
  302. line-height: 60px;
  303. border-color: rgba(180, 190, 190, 0.8);
  304. border-left-width: 0;
  305. border-left-style: solid;
  306. display: flex;
  307. justify-content: space-between;
  308. width: auto;
  309. box-shadow: 0 1px 4px #ccc;
  310. }
  311. .navigation {
  312. display: flex;
  313. }
  314. .hamburg,
  315. .navbar {
  316. text-align: left;
  317. }
  318. .toolbar {
  319. float: right;
  320. display: flex;
  321. align-items: center;
  322. border-radius: 24px 24px 24px 24px;
  323. margin: 7px;
  324. img {
  325. width: 40px;
  326. height: 40px;
  327. border-radius: 50%;
  328. margin: 0 5px;
  329. float: right;
  330. }
  331. }
  332. .active {
  333. background: rgba(180, 180, 180, 0.12);
  334. border: 1px solid rgba(180, 180, 180, 0.12);
  335. }
  336. .el-menu-item {
  337. // padding: 0 15px!important;
  338. padding: 0 14px !important;
  339. }
  340. .lang-item {
  341. font-size: 16px;
  342. padding-left: 8px;
  343. padding-top: 8px;
  344. padding-bottom: 8px;
  345. cursor: pointer;
  346. }
  347. .lang-item:hover {
  348. font-size: 18px;
  349. background: #b0d6ce4d;
  350. }
  351. .user-info {
  352. font-size: 20px;
  353. color: #fff;
  354. cursor: pointer;
  355. img {
  356. width: 40px;
  357. height: 40px;
  358. border-radius: 50%;
  359. margin: 10px 0px 10px 10px;
  360. float: right;
  361. }
  362. }
  363. .badge {
  364. line-height: 18px;
  365. }
  366. .position-left {
  367. left: 220px;
  368. }
  369. .position-collapse-left {
  370. left: 65px;
  371. }
  372. /deep/ {
  373. .el-submenu__icon-arrow {
  374. color: #fff;
  375. }
  376. }
  377. </style>