index.vue 9.6 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
<template>
L
liuyang 已提交
2
  <el-container class="layout-cont">
J
导航  
jinlan.du 已提交
3
    <el-container :class="[isSider?'openside':'hideside',isMobile ? 'mobile': '']">
L
liuyang 已提交
4
      <el-row :class="[isShadowBg?'shadowBg':'']" @click.native="changeShadow()"></el-row>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
5
      <el-aside class="main-cont main-left">
6
        <Aside class="aside" />
Mr.奇淼('s avatar
Mr.奇淼( 已提交
7
      </el-aside>
8
      <!-- 分块滑动功能 -->
Mr.奇淼('s avatar
Mr.奇淼( 已提交
9
      <el-main class="main-cont main-right">
10 11
        <transition mode="out-in" name="el-fade-in-linear">
          <div class="topfix" :style="{width: `calc(100% - ${isCollapse?'54px':'220px'})`}">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
12
        <el-header class="header-cont">
13 14 15 16
          <div @click="totalCollapse" class="menu-total">
            <i class="el-icon-s-unfold" v-if="isCollapse"></i>
            <i class="el-icon-s-fold" v-else></i>
          </div>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
17 18 19 20 21 22
          <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
          <el-breadcrumb-item
            :key="item.path"
            v-for="item in matched.slice(1,matched.length)"
          >{{item.meta.title}}</el-breadcrumb-item>
        </el-breadcrumb>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
23 24 25 26
          <div class="fl-right right-box">
            <el-dropdown>
              <span class="el-dropdown-link">
                <img :src="userInfo.headerImg" height="30" width="30" />
27
                {{userInfo.title}}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
28 29 30 31 32 33 34 35 36
                <i class="el-icon-arrow-down"></i>
              </span>
              <el-dropdown-menu class="dropdown-group" slot="dropdown">
                <el-dropdown-item>
                  <span>
                    更多信息
                    <el-badge is-dot />
                  </span>
                </el-dropdown-item>
L
liuyang 已提交
37
                <el-dropdown-item @click.native="showPassword=true" icon="el-icon-s-custom">修改密码</el-dropdown-item>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
38 39 40 41
                <el-dropdown-item @click.native="toPerson" icon="el-icon-s-custom">个人信息</el-dropdown-item>
                <el-dropdown-item @click.native="LoginOut" icon="el-icon-table-lamp">登 出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
 
          </div>
        </el-header>
        <!-- 当前面包屑用路由自动生成可根据需求修改 -->
        <!--
        :to="{ path: item.path }" 暂时注释不用-->
        <HistoryComponent />
        </div>
        </transition>
        <transition mode="out-in" name="el-fade-in-linear">
          <keep-alive>
            <router-view v-if="$route.meta.keepAlive" class="admin-box"></router-view>
          </keep-alive>
        </transition>
        <transition mode="out-in" name="el-fade-in-linear">
            <router-view v-if="!$route.meta.keepAlive" class="admin-box"></router-view>
        </transition>
      </el-main>
    </el-container>
               <el-dialog
L
liuyang 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
              title="修改密码"
              :visible.sync="showPassword"
              @close="clearPassword"
              width="360px"
            >
              <el-form ref="modifyPwdForm" :model="pwdModify" :rules="rules" label-width="80px">
                <el-form-item prop="password" :minlength="6" label="原密码">
                  <el-input v-model="pwdModify.password" show-password></el-input>
                </el-form-item>
                <el-form-item prop="newPassword" :minlength="6" label="新密码">
                  <el-input v-model="pwdModify.newPassword" show-password></el-input>
                </el-form-item>
                <el-form-item prop="confirmPassword" :minlength="6" label="确认密码">
                  <el-input v-model="pwdModify.confirmPassword" show-password></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="showPassword=false">取 消</el-button>
                <el-button type="primary" @click="savePassword">确 定</el-button>
              </div>
            </el-dialog>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
83
  </el-container>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
84 85 86
</template>

<script>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
87
import Aside from '@/view/layout/aside'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
88 89
import HistoryComponent from '@/view/layout/aside/historyComponent/history'

90
import { mapGetters, mapActions } from 'vuex'
L
liuyang 已提交
91
import { changePassword } from '@/api/user'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
92
export default {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
93
  name: 'Layout',
94 95
  data() {
    return {
J
导航  
jinlan.du 已提交
96 97 98
      isCollapse: false,
      isSider: true,
      isMobile: false,
L
liuyang 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
      isShadowBg: false,
      showPassword: false,
      pwdModify: {},
      rules: {
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, message: '最少6个字符', trigger: 'blur' }
        ],
        newPassword: [
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 6, message: '最少6个字符', trigger: 'blur' }
        ],
        confirmPassword: [
          { required: true, message: '请输入确认密码', trigger: 'blur' },
          { min: 6, message: '最少6个字符', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              if (value !== this.pwdModify.newPassword) {
                callback(new Error('两次密码不一致'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ]
Mr.奇淼('s avatar
Mr.奇淼( 已提交
125
      },
K
klausY 已提交
126

Mr.奇淼('s avatar
Mr.奇淼( 已提交
127 128
    }
  },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
129
  components: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
130
    Aside,HistoryComponent
131
  },
L
liuyang 已提交
132 133 134 135 136 137 138 139 140
  created() {
    let screenWidth = document.body.clientWidth
    if (screenWidth < 1000) {
      this.isMobile = true
      this.isSider = false
      this.isCollapse = !this.isCollapse
    } else {
      this.isMobile = false
    }
J
导航  
jinlan.du 已提交
141
  },
142
  methods: {
143
    ...mapActions('user', ['LoginOut']),
144
    totalCollapse() {
L
liuyang 已提交
145 146 147 148
      this.isCollapse = !this.isCollapse
      this.isSider = !this.isCollapse
      this.isShadowBg = !this.isCollapse
      this.$bus.emit('totalCollapse')
149
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
150 151
    toPerson() {
      this.$router.push({ name: 'person' })
J
导航  
jinlan.du 已提交
152
    },
L
liuyang 已提交
153
    changeShadow() {
J
导航  
jinlan.du 已提交
154 155 156
      this.isShadowBg = !this.isShadowBg
      this.isSider = !!this.isCollapse
      this.totalCollapse()
L
liuyang 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
    },
    savePassword() {
      this.$refs.modifyPwdForm.validate(valid => {
        if (valid) {
          changePassword({
            username: this.userInfo.userName,
            password: this.pwdModify.password,
            newPassword: this.pwdModify.newPassword
          }).then(() => {
            this.$message.success('修改密码成功!')
            this.showPassword = false
          })
        } else {
          return false
        }
      })
    },
    clearPassword() {
      this.pwdModify = {
        password: '',
        newPassword: '',
        confirmPassword: ''
      }
      this.$refs.modifyPwdForm.clearValidate()
181 182
    }
  },
183
  computed: {
184
    ...mapGetters('user', ['userInfo']),
Mr.奇淼('s avatar
Mr.奇淼( 已提交
185
    ...mapGetters('history', ['historys','activeValue']),
186 187
    title() {
      return this.$route.meta.title || '当前页面'
188
    },
189
    matched() {
190 191
      return this.$route.matched
    }
J
导航  
jinlan.du 已提交
192 193
  },
  mounted() {
L
liuyang 已提交
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    window.onresize = () => {
      return (() => {
        let screenWidth = document.body.clientWidth
        if (!this.screenWidth && this.isSider) {
          if (screenWidth < 1000) {
            this.isMobile = true
            this.isSider = false
            this.isCollapse = true
            this.$bus.emit('collapse', this.isCollapse)
          }
        } else {
          if (screenWidth < 1000) {
            this.isMobile = true
            this.isSider = false
            this.isCollapse = true
          } else {
            this.isMobile = false
          }
        }
      })()
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
215
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
216 217 218
}
</script>

Mr.奇淼('s avatar
Mr.奇淼( 已提交
219 220
<style lang="scss">
$headerHigh: 52px;
221
$mainHight: 100vh;
222
.el-dropdown-link {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
223 224 225 226 227
  cursor: pointer;
}
.dropdown-group {
  min-width: 100px;
}
228 229 230 231 232 233
.topfix{
  position:fixed;
  top:0;
  box-sizing: border-box;
  z-index: 999;
}
K
klausY 已提交
234
.admin-box{
235
  background-color: rgb(255,255,255);
236
  margin-top: 100px;
K
klausY 已提交
237
}
238
.el-scrollbar__wrap {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
239 240
  padding-bottom: 17px;
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
241
.layout-cont {
242 243 244 245 246
  .right-box {
    text-align: center;
    vertical-align: middle;
    img {
      vertical-align: middle;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
247
      border: 1px solid #ccc;
248 249 250
      border-radius: 6px;
    }
  }
251 252 253 254 255 256 257
  .menu-contorl {
    line-height: 52px;
    font-size: 20px;
    color: #eee;
    display: table-cell;
    vertical-align: middle;
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
258 259
  .header-cont {
    height: $headerHigh !important;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
260
    background: #fff;
261
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
Mr.奇淼('s avatar
Mr.奇淼( 已提交
262
    line-height: $headerHigh;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
263 264
  }
  .main-cont {
265
    .breadcrumb {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
266 267 268
      line-height: 48px;
      display: inline-block;
      padding: 0 24px;
J
jinlan.du 已提交
269 270
      // padding: 6px;
      // border-bottom: 1px solid #eee;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
271 272 273 274
    }
    .router-history{
      background: #fff;
      padding: 0 6px;
275
    }
276
    &.el-main {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
277
      overflow: auto;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
278
      background: #fff;
J
jinlan.du 已提交
279 280
      // padding: 0px 10px;
      // background: #fff;
281
    }
282 283 284 285
    height: $mainHight !important;
    overflow: visible;
    position: relative;
    .menu-total {
286 287 288 289 290 291 292 293 294 295 296 297 298 299
      // z-index: 5;
      // position: absolute;
      // top: 10px;
      // right: -35px;
      margin-left: -10px;
      float: left;
      margin-top: 10px;
      width: 30px;
      height: 30px;
      line-height: 30px;
      font-size: 30px;
      // border: 0 solid #ffffff;
      // border-radius: 50%;
      // background: #fff;
300 301
    }
    .aside {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
302
      overflow: auto;
J
导航  
jinlan.du 已提交
303
      // background: #fff;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
304
      &::-webkit-scrollbar {
305 306
        display: none;
      }
307
    }
308

309
    .el-menu-vertical {
310
      height: 100vh !important;
311
      visibility: auto;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
312
      &:not(.el-menu--collapse) {
313
        width: 220px;
314
      }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
315
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
316

Mr.奇淼('s avatar
Mr.奇淼( 已提交
317 318 319 320 321
    &::-webkit-scrollbar {
      display: none;
    }
    &.main-left {
      width: auto !important;
322 323
    }
    &.main-right {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
324
      .admin-title {
325 326
        float: left;
        font-size: 16px;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
327
        vertical-align: middle;
328
        margin-left: 20px;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
329 330 331
        img {
          vertical-align: middle;
        }
332
        &.collapse {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
333 334 335
          width: 53px;
        }
      }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
336 337 338
    }
  }
}
K
klausY 已提交
339
</style>