index.vue 9.0 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">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
10
        <el-header class="header-cont">
11 12 13 14
          <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.奇淼( 已提交
15 16 17 18 19 20
          <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.奇淼( 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34
          <div class="fl-right right-box">
            <el-dropdown>
              <span class="el-dropdown-link">
                <img :src="userInfo.headerImg" height="30" width="30" />
                {{userInfo.nickName}}
                <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 已提交
35
                <el-dropdown-item @click.native="showPassword=true" icon="el-icon-s-custom">修改密码</el-dropdown-item>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
36 37 38 39
                <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>
L
liuyang 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
            <el-dialog
              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.奇淼( 已提交
62
          </div>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
63
      
Mr.奇淼('s avatar
Mr.奇淼( 已提交
64
        </el-header>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
65
        <!-- 当前面包屑用路由自动生成可根据需求修改 -->
66 67
        <!-- 
        :to="{ path: item.path }" 暂时注释不用-->
Mr.奇淼('s avatar
Mr.奇淼( 已提交
68
        <HistoryComponent />
Mr.奇淼('s avatar
Mr.奇淼( 已提交
69
        <transition mode="out-in" name="el-fade-in-linear">
70
          <router-view class="admin-box"></router-view>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
71 72
        </transition>
      </el-main>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
73 74
    </el-container>
  </el-container>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
75 76 77
</template>

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

81
import { mapGetters, mapActions } from 'vuex'
L
liuyang 已提交
82
import { changePassword } from '@/api/user'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
83
export default {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
84
  name: 'Layout',
85 86
  data() {
    return {
J
导航  
jinlan.du 已提交
87 88 89
      isCollapse: false,
      isSider: true,
      isMobile: false,
L
liuyang 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
      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.奇淼( 已提交
116 117
      },
      
Mr.奇淼('s avatar
Mr.奇淼( 已提交
118 119
    }
  },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
120
  components: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
121
    Aside,HistoryComponent
122
  },
L
liuyang 已提交
123 124 125 126 127 128 129 130 131
  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 已提交
132
  },
133
  methods: {
134
    ...mapActions('user', ['LoginOut']),
135
    totalCollapse() {
L
liuyang 已提交
136 137 138 139
      this.isCollapse = !this.isCollapse
      this.isSider = !this.isCollapse
      this.isShadowBg = !this.isCollapse
      this.$bus.emit('totalCollapse')
140
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
141 142
    toPerson() {
      this.$router.push({ name: 'person' })
J
导航  
jinlan.du 已提交
143
    },
L
liuyang 已提交
144
    changeShadow() {
J
导航  
jinlan.du 已提交
145 146 147
      this.isShadowBg = !this.isShadowBg
      this.isSider = !!this.isCollapse
      this.totalCollapse()
L
liuyang 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    },
    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()
172 173
    }
  },
174
  computed: {
175
    ...mapGetters('user', ['userInfo']),
Mr.奇淼('s avatar
Mr.奇淼( 已提交
176
    ...mapGetters('history', ['historys','activeValue']),
177 178
    title() {
      return this.$route.meta.title || '当前页面'
179
    },
180
    matched() {
181 182
      return this.$route.matched
    }
J
导航  
jinlan.du 已提交
183 184
  },
  mounted() {
L
liuyang 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
    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.奇淼( 已提交
206
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
207 208 209
}
</script>

Mr.奇淼('s avatar
Mr.奇淼( 已提交
210 211
<style lang="scss">
$headerHigh: 52px;
212
$mainHight: 100vh;
213
.el-dropdown-link {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
214 215 216 217 218
  cursor: pointer;
}
.dropdown-group {
  min-width: 100px;
}
219
.el-scrollbar__wrap {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
220 221
  padding-bottom: 17px;
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
222
.layout-cont {
223 224 225 226 227
  .right-box {
    text-align: center;
    vertical-align: middle;
    img {
      vertical-align: middle;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
228
      border: 1px solid #ccc;
229 230 231
      border-radius: 6px;
    }
  }
232 233 234 235 236 237 238
  .menu-contorl {
    line-height: 52px;
    font-size: 20px;
    color: #eee;
    display: table-cell;
    vertical-align: middle;
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
239 240
  .header-cont {
    height: $headerHigh !important;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
241
    background: #fff;
242
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
Mr.奇淼('s avatar
Mr.奇淼( 已提交
243
    line-height: $headerHigh;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
244 245
  }
  .main-cont {
246
    .breadcrumb {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
247 248 249
      line-height: 48px;
      display: inline-block;
      padding: 0 24px;
J
jinlan.du 已提交
250 251
      // padding: 6px;
      // border-bottom: 1px solid #eee;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
252 253 254 255 256
    }
    .router-history{
      background: #fff;
      margin-top: 1px;
      padding: 0 6px;
257
    }
258
    &.el-main {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
259
      overflow: auto;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
260
      background: #fff;
J
jinlan.du 已提交
261 262
      // padding: 0px 10px;
      // background: #fff;
263
    }
264 265 266 267
    height: $mainHight !important;
    overflow: visible;
    position: relative;
    .menu-total {
268 269 270 271 272 273 274 275 276 277 278 279 280 281
      // 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;
282 283
    }
    .aside {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
284
      overflow: auto;
J
导航  
jinlan.du 已提交
285
      // background: #fff;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
286
      &::-webkit-scrollbar {
287 288
        display: none;
      }
289
    }
290

291
    .el-menu-vertical {
292
      height: 100vh !important;
293
      visibility: auto;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
294
      &:not(.el-menu--collapse) {
295
        width: 220px;
296
      }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
297
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
298

Mr.奇淼('s avatar
Mr.奇淼( 已提交
299 300 301 302 303
    &::-webkit-scrollbar {
      display: none;
    }
    &.main-left {
      width: auto !important;
304 305
    }
    &.main-right {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
306
      .admin-title {
307 308
        float: left;
        font-size: 16px;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
309
        vertical-align: middle;
310
        margin-left: 20px;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
311 312 313
        img {
          vertical-align: middle;
        }
314
        &.collapse {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
315 316 317
          width: 53px;
        }
      }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
318 319 320
    }
  }
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
321
</style>