layout.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <el-container>
  3. <el-aside :class="menuClass" width="">
  4. <el-menu :default-active="menuActiveIndex" :router="true" :collapse="isCollapse" :unique-opened="true">
  5. <div class="site-title">
  6. <h1>Settlement system background<!-- 结算系统后台 --></h1>
  7. </div>
  8. <div class="user-profile">
  9. <img src="../../static/img/avatar/1.png" alt="" class="profile-avatar img-circle">
  10. <el-dropdown>
  11. <span class="el-dropdown-link">
  12. {{adminName}} <i class="el-icon-caret-bottom el-icon--right"></i>
  13. </span>
  14. <el-dropdown-menu slot="dropdown">
  15. <el-dropdown-item icon="el-icon-sort" @click.native="onChangePassword">Reset password<!-- 重置密码 --></el-dropdown-item>
  16. <el-dropdown-item icon="el-icon-switch-button" @click.native="onLogout">Log out<!-- 退出登录 --></el-dropdown-item>
  17. </el-dropdown-menu>
  18. </el-dropdown>
  19. </div>
  20. <template v-for="parent in menu">
  21. <el-submenu :index="'/'+parent.routePath" v-if="parent.child.length">
  22. <template slot="title">
  23. <i :class="parent.icon"></i>
  24. <span>{{parent.name}}</span>
  25. </template>
  26. <el-menu-item-group title="">
  27. <el-menu-item :index="'/'+child.routePath" v-for="child in parent.child" :key="'/'+child.routePath">
  28. <a class="left-menu-a" :href="'#/'+child.routePath">{{child.name}}</a>
  29. </el-menu-item>
  30. </el-menu-item-group>
  31. </el-submenu>
  32. <el-menu-item :index="'/'+parent.routePath" v-else>
  33. <i :class="parent.icon"></i>
  34. <span>{{parent.name}}</span>
  35. </el-menu-item>
  36. </template>
  37. </el-menu>
  38. </el-aside>
  39. <el-container>
  40. <el-header>
  41. <ul class="al-left layout-menu-left">
  42. <li class="mobile-menu">
  43. <el-button type="text" @click="onMobileMenu"><i class="el-icon-s-fold"></i></el-button>
  44. </li>
  45. <li class="scale-menu">
  46. <el-button type="text" @click="onMenu"><i class="el-icon-s-fold"></i></el-button>
  47. </li>
  48. <li class="top-message button" v-show="false">
  49. <el-button type="text" @click="onMessage"><i class="el-icon-message"></i></el-button>
  50. <transition name="custom-classes-transition" enter-active-class="animated bounceInDown">
  51. <div class="top-message-card" v-if="messageShow">
  52. </div>
  53. </transition>
  54. </li>
  55. <li>
  56. <h4>{{contentTitle}}</h4><!-- 控制台 -->
  57. </li>
  58. </ul>
  59. <div style="text-align: right;font-size: 14px;">
  60. Current System Time<!-- 当前系统时间 -->:{{nowDateTime}}&nbsp;&nbsp;&nbsp;&nbsp;
  61. Current Period<!-- 当期期数 -->:<b class="text-danger">{{periodNum}}</b>
  62. <el-breadcrumb separator="/">
  63. <el-breadcrumb-item v-for="(item, index) in breadcrumb" :to="{ path: item.path }" :key="index">
  64. {{item.title}}<!-- 顶部面包屑 -->
  65. </el-breadcrumb-item>
  66. </el-breadcrumb>
  67. </div>
  68. </el-header>
  69. <div :class="'breadcrumb-box '+menuClass" v-show="false">
  70. <div class="breadcrumb-content">
  71. </div>
  72. </div>
  73. <el-main>
  74. <router-view></router-view>
  75. </el-main>
  76. </el-container>
  77. <div style="position: fixed;right:4px;bottom: 10px;z-index: 999">
  78. <p class="mar-btm" v-if="showBackToUp">
  79. <el-tooltip class="item" effect="dark" content="Top" placement="top-start"><!-- 回到顶部 -->
  80. <el-button type="primary" @click="backTop" circle plain><i class="fa fa-arrow-up"></i></el-button>
  81. </el-tooltip>
  82. </p>
  83. <p>
  84. <el-tooltip class="item" effect="dark" content="previous page" placement="top-start"><!-- 返回上一页 -->
  85. <el-button type="primary" @click="$router.go(-1)" circle plain><i class="fa fa-arrow-left"></i></el-button>
  86. </el-tooltip>
  87. </p>
  88. </div>
  89. </el-container>
  90. </template>
  91. <script>
  92. import {WEBSOCKET_HOST} from '@/utils/config'
  93. import userInfo from '@/utils/userInfo'
  94. import network from '@/utils/network'
  95. import tool from '@/utils/tool'
  96. import Waves from '@/static/plugins/waves/waves.js'
  97. import store from '@/utils/vuexStore'
  98. import baseInfo from '@/utils/baseInfo'
  99. import initRegion from '@/utils/region'
  100. import '@/static/plugins/css/font-awesome.min.css'
  101. export default {
  102. name: 'layout',
  103. beforeCreate() {
  104. let vueObj = this
  105. // 检测用户是否已经登录,如果已经登录则直接跳转到控制台页
  106. if (!userInfo.hasLogin()) {
  107. this.$router.push('/login')
  108. return
  109. }
  110. // websocket连接
  111. let wsServer = WEBSOCKET_HOST
  112. let webSocket = new WebSocket(wsServer)
  113. store.state.socket.socketObj = webSocket
  114. webSocket.onopen = function (evt) {
  115. let userId = userInfo.userId()
  116. let sendData = {app: 'admin', userId: userId}
  117. webSocket.send(JSON.stringify(sendData))
  118. }
  119. webSocket.onmessage = function (env) {
  120. let data = JSON.parse(env.data)
  121. if (data.handle === 'adminAsync') {
  122. vueObj.$message({
  123. message: data.message,
  124. type: data.success ? 'success' : 'error',
  125. showClose: !data.success,
  126. duration: data.success ? 3000 : 0,
  127. })
  128. if (store.state.socket.onMessageCallback !== null) {
  129. store.state.socket.onMessageCallback()
  130. }
  131. }
  132. else if (data.handle === 'adminAsyncPercent') {
  133. if (store.state.socket.onMessageCallback !== null) {
  134. store.state.socket.onMessageCallback(data)
  135. }
  136. }
  137. }
  138. // 获取系统相关信息
  139. // network.getData(`site/base-info`).then(response => {
  140. // store.state.baseInfo.decLevels = response.decLevels;
  141. // store.state.baseInfo.empLevels = response.empLevels;
  142. // store.state.baseInfo.adminRoles = response.adminRoles;
  143. // store.state.baseInfo.menu = response.menu;
  144. // });
  145. // 获取地区信息
  146. initRegion(this)
  147. },
  148. mounted() {
  149. Waves.init()
  150. this.calcTime()
  151. Waves.attach('.waves-btn')
  152. this.activeNav();
  153. this.$nextTick(function () {
  154. window.addEventListener('scroll', this.scrollToTop, true);
  155. });
  156. // 取消菜单a标签的默认动作
  157. let allLeftMenuA = document.getElementsByClassName('left-menu-a')
  158. for(let i in allLeftMenuA){
  159. if(allLeftMenuA[i].onclick){
  160. allLeftMenuA[i].onclick = function(e){
  161. e.preventDefault()
  162. }
  163. }
  164. }
  165. },
  166. destroyed () {
  167. window.removeEventListener('scroll', this.scrollToTop);
  168. },
  169. data() {
  170. return {
  171. isCollapse: false,
  172. menuActiveIndex: this.$route.meta.highLight || this.$route.path,
  173. mainTitle: this.$route.meta.title,
  174. messageShow: false,
  175. profileShow: false,
  176. adminNameShow: true,
  177. menuClass: '',
  178. adminName: userInfo.adminName(),
  179. nowTime: tool.getTimestamp(),
  180. periodNum: baseInfo.nowPeriodNum(),
  181. showBackToUp:false,
  182. }
  183. },
  184. computed: {
  185. nowDateTime: function () {
  186. return tool.formatDate(this.nowTime)
  187. },
  188. menu: function () {
  189. return baseInfo.menu()
  190. },
  191. contentTitle: function () {
  192. return this.$route.meta.title
  193. },
  194. breadcrumb: function () {
  195. let breadcrumbArr = []
  196. for (let i in this.$route.meta.breadcrumb) {
  197. breadcrumbArr.push(this.$route.meta.breadcrumb[i])
  198. }
  199. breadcrumbArr.push({title: this.$route.meta.title, path: ''})
  200. return breadcrumbArr
  201. },
  202. },
  203. methods: {
  204. calcTime() {
  205. let obj = this
  206. setInterval(function () {
  207. obj.nowTime += 1
  208. }, 1000)
  209. },
  210. onMenu() {
  211. if (this.isCollapse) {
  212. this.isCollapse = false
  213. document.getElementsByTagName('body')[0].className = ''
  214. } else {
  215. this.isCollapse = true
  216. document.getElementsByTagName('body')[0].className = 'content-wrapper'
  217. }
  218. },
  219. onMobileMenu() {
  220. if (this.menuClass === 'show-menu') {
  221. this.menuClass = ''
  222. } else {
  223. this.menuClass = 'show-menu'
  224. }
  225. },
  226. onMessage() {
  227. this.messageShow = !this.messageShow
  228. },
  229. onProfile() {
  230. this.profileShow = !this.profileShow
  231. },
  232. onLogout() {
  233. userInfo.clear()
  234. this.$router.push('/login')
  235. },
  236. onChangePassword() {
  237. this.$router.push('/admin/change-password')
  238. },
  239. onCloseProfile() {
  240. this.profileShow = false
  241. },
  242. // 点击图片回到顶部方法,加计时器是为了过渡顺滑
  243. backTop () {
  244. let that = this;
  245. let timer = setInterval(() => {
  246. let _speed = Math.floor(-that.scrollTop / 5);
  247. document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + _speed;
  248. if (that.scrollTop === 0) {
  249. clearInterval(timer);
  250. }
  251. }, 16);
  252. },
  253. // 为了计算距离顶部的高度,当高度大于60显示回顶部图标,小于60则隐藏
  254. scrollToTop () {
  255. let that = this,
  256. _scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  257. that.scrollTop = _scrollTop;
  258. if (that.scrollTop > 60) {
  259. that.showBackToUp = true;
  260. } else {
  261. that.showBackToUp = false;
  262. }
  263. },
  264. activeNav(){
  265. let currentRouteMeta = this.$route.meta;
  266. if(typeof currentRouteMeta['activeRoute'] !== 'undefined'){
  267. this.menuActiveIndex = currentRouteMeta['activeRoute'];
  268. }else{
  269. this.fixedMenuActive();
  270. }
  271. },
  272. fixedMenuActive(){
  273. let module = this.$route.matched[1].path;
  274. //fixed shop nav
  275. // if(module === '/shop') module = '/shop/goods';
  276. this.menuActiveIndex = module + '/index';
  277. },
  278. }
  279. }
  280. </script>
  281. <style>
  282. @import '../../static/css/animate.css';
  283. @import '../../static/plugins/waves/waves.css';
  284. @import '../../static/css/style.css';
  285. .el-menu-item-group__title {
  286. display: none;
  287. }
  288. .el-menu-item .left-menu-a {
  289. color: #3e4d6c;
  290. }
  291. .el-breadcrumb{padding-left: 20px;}
  292. </style>