Home.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <el-row class="container">
  3. <el-col :span="24" class="header">
  4. <el-col :span="10" class="logo" :class="collapsed?'logo-collapse-width':'logo-width'">
  5. {{collapsed?'':sysName}}
  6. </el-col>
  7. <el-col :span="10">
  8. <div class="tools" @click.prevent="collapse">
  9. <i class="el-icon-menu"></i>
  10. </div>
  11. </el-col>
  12. <el-col :span="8">
  13. <div style="color:red;font-size:30px;">
  14. 模拟----(Demo)
  15. </div>
  16. </el-col>
  17. <el-col :span="4" class="userinfo">
  18. <el-dropdown trigger="hover">
  19. <span class="el-dropdown-link userinfo-inner"> {{sysUserName}}&nbsp;&nbsp;<span v-if="is_reg==1" style="color:red">登录中</span></span>
  20. <el-dropdown-menu slot="dropdown">
  21. <el-dropdown-item>我的消息</el-dropdown-item>
  22. <el-dropdown-item>设置</el-dropdown-item>
  23. <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
  24. </el-dropdown-menu>
  25. </el-dropdown>
  26. </el-col>
  27. </el-col>
  28. <el-col :span="24" class="main">
  29. <aside :class="collapsed?'menu-collapsed':'menu-expanded'">
  30. <!--导航菜单-->
  31. <el-menu :default-active="$route.path" class="el-menu-vertical-demo" @open="handleopen" @close="handleclose" @select="handleselect"
  32. unique-opened router v-show="!collapsed">
  33. <template v-for="(item,index) in $router.options.routes" v-if="!item.hidden">
  34. <el-submenu :index="index+''" v-if="!item.leaf">
  35. <template slot="title"><i :class="item.iconCls"></i>{{item.name}}</template>
  36. <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path" v-if="!child.hidden">{{child.name}}</el-menu-item>
  37. </el-submenu>
  38. <el-menu-item v-if="item.leaf&&item.children.length>0" :index="item.children[0].path"><i :class="item.iconCls"></i>{{item.children[0].name}}</el-menu-item>
  39. </template>
  40. </el-menu>
  41. <!--导航菜单-折叠后-->
  42. <ul class="el-menu el-menu-vertical-demo collapsed" v-show="collapsed" ref="menuCollapsed">
  43. <li v-for="(item,index) in $router.options.routes" v-if="!item.hidden" class="el-submenu item">
  44. <template v-if="!item.leaf">
  45. <div class="el-submenu__title" style="padding-left: 20px;" @mouseover="showMenu(index,true)" @mouseout="showMenu(index,false)"><i :class="item.iconCls"></i></div>
  46. <ul class="el-menu submenu" :class="'submenu-hook-'+index" @mouseover="showMenu(index,true)" @mouseout="showMenu(index,false)">
  47. <li v-for="child in item.children" v-if="!child.hidden" :key="child.path" class="el-menu-item" style="padding-left: 40px;" :class="$route.path==child.path?'is-active':''" @click="$router.push(child.path)">{{child.name}}</li>
  48. </ul>
  49. </template>
  50. <template v-else>
  51. <li class="el-submenu">
  52. <div class="el-submenu__title el-menu-item" style="padding-left: 20px;height: 56px;line-height: 56px;padding: 0 20px;" :class="$route.path==item.children[0].path?'is-active':''" @click="$router.push(item.children[0].path)"><i :class="item.iconCls"></i></div>
  53. </li>
  54. </template>
  55. </li>
  56. </ul>
  57. </aside>
  58. <section class="content-container">
  59. <div class="grid-content bg-purple-light">
  60. <el-col :span="24" class="breadcrumb-container">
  61. <!-- 路由的名字 -->
  62. <strong class="title">{{$route.name}}</strong>
  63. <el-breadcrumb separator="/" class="breadcrumb-inner">
  64. <el-breadcrumb-item v-for="item in $route.matched" :key="item.path">
  65. {{ item.name }}
  66. </el-breadcrumb-item>
  67. </el-breadcrumb>
  68. </el-col>
  69. <el-col :span="24" class="content-wrapper">
  70. <transition name="fade" mode="out-in">
  71. <router-view></router-view>
  72. </transition>
  73. </el-col>
  74. </div>
  75. </section>
  76. </el-col>
  77. </el-row>
  78. </template>
  79. <script>
  80. export default {
  81. data() {
  82. return {
  83. sysName:'MT5跟单',
  84. collapsed:false, //是否折叠
  85. sysUserName: '', //用户名
  86. sysUserAvatar: '', //用户头像
  87. is_reg:null,
  88. form: {
  89. name: '',
  90. region: '',
  91. date1: '',
  92. date2: '',
  93. delivery: false,
  94. type: [],
  95. resource: '',
  96. desc: ''
  97. }
  98. }
  99. },
  100. mounted() {
  101. var user = sessionStorage.getItem('user'); //获取用户的信息
  102. var is_reg = sessionStorage.getItem('is_reg'); //获取登录状态
  103. if (user) {
  104. user = JSON.parse(user);
  105. this.sysUserName = user || ''; //获取用户的姓名
  106. this.is_reg = is_reg;
  107. // this.sysUserAvatar = user.avatar || '';
  108. }
  109. },
  110. methods: {
  111. onSubmit() {
  112. console.log('submit!');
  113. },
  114. handleopen() {
  115. //console.log('handleopen');
  116. },
  117. handleclose() {
  118. //console.log('handleclose');
  119. },
  120. handleselect: function (a, b) {
  121. },
  122. //退出登录
  123. logout: function () {
  124. var _this = this;
  125. this.$confirm('确认退出吗?', '提示', {
  126. //type: 'warning'
  127. }).then(() => {
  128. var loginParams = { is_reg: 0 }; //登录状态为未登录
  129. _this.$api.post('/api/index/base/logout',loginParams, response => {
  130. if (response.status == 200 && response.status < 300) {
  131. if(response.data){
  132. sessionStorage.removeItem('user'); //移除user的存储
  133. sessionStorage.removeItem('is_reg'); //移除is_reg的存储
  134. sessionStorage.removeItem('authKey');
  135. _this.$router.push('/login'); //从新跳转到login页面
  136. }
  137. } else {
  138. console.log(response.data);
  139. }
  140. });
  141. }).catch(() => {
  142. });
  143. },
  144. //折叠导航栏
  145. collapse:function(){
  146. this.collapsed=!this.collapsed;
  147. },
  148. showMenu(i,status){
  149. this.$refs.menuCollapsed.getElementsByClassName('submenu-hook-'+i)[0].style.display=status?'block':'none';
  150. },
  151. },
  152. }
  153. </script>
  154. <style>
  155. .el-message-box__header > .el-message-box__headerbtn{
  156. display: none !important;
  157. }
  158. </style>
  159. <style scoped lang="scss">
  160. @import '~scss_vars';
  161. .container {
  162. position: absolute;
  163. top: 0px;
  164. bottom: 0px;
  165. width: 100%;
  166. .header {
  167. height: 60px;
  168. line-height: 60px;
  169. background: $color-primary;
  170. color:#fff;
  171. .userinfo {
  172. text-align: right;
  173. padding-right: 35px;
  174. float: right;
  175. .userinfo-inner {
  176. cursor: pointer;
  177. color:#fff;
  178. img {
  179. width: 40px;
  180. height: 40px;
  181. border-radius: 20px;
  182. margin: 10px 0px 10px 10px;
  183. float: right;
  184. }
  185. }
  186. }
  187. .logo {
  188. //width:230px;
  189. height:60px;
  190. text-align: center;
  191. font-size: 22px;
  192. padding-left:20px;
  193. padding-right:20px;
  194. border-color: rgba(238,241,146,0.3);
  195. border-right-width: 1px;
  196. border-right-style: solid;
  197. img {
  198. width: 40px;
  199. float: left;
  200. margin: 10px 10px 10px 18px;
  201. }
  202. .txt {
  203. color:#fff;
  204. }
  205. }
  206. .logo-width{
  207. width:140px;
  208. }
  209. .logo-collapse-width{
  210. width:60px
  211. }
  212. .tools{
  213. padding: 0px 23px;
  214. width:14px;
  215. height: 60px;
  216. line-height: 60px;
  217. cursor: pointer;
  218. }
  219. }
  220. .main {
  221. display: flex;
  222. // background: #324057;
  223. position: absolute;
  224. top: 60px;
  225. bottom: 0px;
  226. overflow: hidden;
  227. aside {
  228. flex:0 0 230px;
  229. width: 230px;
  230. // position: absolute;
  231. // top: 0px;
  232. // bottom: 0px;
  233. .el-menu{
  234. height: 100%;
  235. }
  236. .collapsed{
  237. width:60px;
  238. .item{
  239. position: relative;
  240. }
  241. .submenu{
  242. position:absolute;
  243. top:0px;
  244. left:60px;
  245. z-index:99999;
  246. height:auto;
  247. display:none;
  248. }
  249. }
  250. }
  251. .menu-collapsed{
  252. flex:0 0 60px;
  253. width: 60px;
  254. }
  255. .menu-expanded{
  256. flex:0 0 140px;
  257. width: 60px;
  258. }
  259. // 恢复折叠菜单的样式
  260. .menu-expanded .el-menu-vertical-demo{
  261. width: 140px !important;
  262. }
  263. .content-container {
  264. // background: #f1f2f7;
  265. flex:1;
  266. // position: absolute;
  267. // right: 0px;
  268. // top: 0px;
  269. // bottom: 0px;
  270. // left: 230px;
  271. overflow-y: scroll;
  272. padding: 20px;
  273. .breadcrumb-container {
  274. //margin-bottom: 15px;
  275. .title {
  276. width: 200px;
  277. float: left;
  278. color: #475669;
  279. }
  280. .breadcrumb-inner {
  281. float: right;
  282. }
  283. }
  284. .content-wrapper {
  285. background-color: #fff;
  286. box-sizing: border-box;
  287. }
  288. }
  289. }
  290. }
  291. </style>