index.vue 9.9 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
        <transition mode="out-in" name="el-fade-in-linear">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
          <div
            class="topfix"
            :style="{width: `calc(100% - ${isMobile?'0px':isCollapse?'54px':'220px'})`}"
          >
            <el-header class="header-cont">
              <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>
              <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>
              <div class="fl-right right-box">
                <el-dropdown>
                  <span class="el-dropdown-link">
                    <img :src="userInfo.headerImg" height="30" width="30" />
                    {{userInfo.title}}
                    <i class="el-icon-arrow-down"></i>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
32
                  </span>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
                  <el-dropdown-menu class="dropdown-group" slot="dropdown">
                    <el-dropdown-item>
                      <span>
                        更多信息
                        <el-badge is-dot />
                      </span>
                    </el-dropdown-item>
                    <el-dropdown-item @click.native="showPassword=true" icon="el-icon-s-custom">修改密码</el-dropdown-item>
                    <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>
              </div>
            </el-header>
            <!-- 当前面包屑用路由自动生成可根据需求修改 -->
            <!--
            :to="{ path: item.path }" 暂时注释不用-->
            <HistoryComponent />
51 52 53 54 55 56 57 58
          </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">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
59
          <router-view v-if="!$route.meta.keepAlive" class="admin-box"></router-view>
60 61 62
        </transition>
      </el-main>
    </el-container>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    <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.奇淼( 已提交
80
  </el-container>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
81 82 83
</template>

<script>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
84 85
import Aside from "@/view/layout/aside";
import HistoryComponent from "@/view/layout/aside/historyComponent/history";
Mr.奇淼('s avatar
Mr.奇淼( 已提交
86

Mr.奇淼('s avatar
Mr.奇淼( 已提交
87 88
import { mapGetters, mapActions } from "vuex";
import { changePassword } from "@/api/user";
Mr.奇淼('s avatar
Mr.奇淼( 已提交
89
export default {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
90
  name: "Layout",
91 92
  data() {
    return {
J
导航  
jinlan.du 已提交
93 94 95
      isCollapse: false,
      isSider: true,
      isMobile: false,
L
liuyang 已提交
96 97 98 99 100
      isShadowBg: false,
      showPassword: false,
      pwdModify: {},
      rules: {
        password: [
Mr.奇淼('s avatar
Mr.奇淼( 已提交
101 102
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, message: "最少6个字符", trigger: "blur" }
L
liuyang 已提交
103 104
        ],
        newPassword: [
Mr.奇淼('s avatar
Mr.奇淼( 已提交
105 106
          { required: true, message: "请输入新密码", trigger: "blur" },
          { min: 6, message: "最少6个字符", trigger: "blur" }
L
liuyang 已提交
107 108
        ],
        confirmPassword: [
Mr.奇淼('s avatar
Mr.奇淼( 已提交
109 110
          { required: true, message: "请输入确认密码", trigger: "blur" },
          { min: 6, message: "最少6个字符", trigger: "blur" },
L
liuyang 已提交
111 112 113
          {
            validator: (rule, value, callback) => {
              if (value !== this.pwdModify.newPassword) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
114
                callback(new Error("两次密码不一致"));
L
liuyang 已提交
115
              } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
116
                callback();
L
liuyang 已提交
117 118
              }
            },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
119
            trigger: "blur"
L
liuyang 已提交
120 121
          }
        ]
Mr.奇淼('s avatar
Mr.奇淼( 已提交
122 123
      }
    };
Mr.奇淼('s avatar
Mr.奇淼( 已提交
124
  },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
125
  components: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
126 127
    Aside,
    HistoryComponent
J
导航  
jinlan.du 已提交
128
  },
129
  methods: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
130
    ...mapActions("user", ["LoginOut"]),
131
    totalCollapse() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
132 133 134 135
      this.isCollapse = !this.isCollapse;
      this.isSider = !this.isCollapse;
      this.isShadowBg = !this.isCollapse;
      this.$bus.emit("collapse", this.isCollapse);
136
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
137
    toPerson() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
138
      this.$router.push({ name: "person" });
J
导航  
jinlan.du 已提交
139
    },
L
liuyang 已提交
140
    changeShadow() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
141 142 143
      this.isShadowBg = !this.isShadowBg;
      this.isSider = !!this.isCollapse;
      this.totalCollapse();
L
liuyang 已提交
144 145 146 147 148 149 150 151 152
    },
    savePassword() {
      this.$refs.modifyPwdForm.validate(valid => {
        if (valid) {
          changePassword({
            username: this.userInfo.userName,
            password: this.pwdModify.password,
            newPassword: this.pwdModify.newPassword
          }).then(() => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
153 154 155
            this.$message.success("修改密码成功!");
            this.showPassword = false;
          });
L
liuyang 已提交
156
        } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
157
          return false;
L
liuyang 已提交
158
        }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
159
      });
L
liuyang 已提交
160 161 162
    },
    clearPassword() {
      this.pwdModify = {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
163 164 165 166 167
        password: "",
        newPassword: "",
        confirmPassword: ""
      };
      this.$refs.modifyPwdForm.clearValidate();
168 169
    }
  },
170
  computed: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
171 172
    ...mapGetters("user", ["userInfo"]),
    ...mapGetters("history", ["historys", "activeValue"]),
173
    title() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
174
      return this.$route.meta.title || "当前页面";
175
    },
176
    matched() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
177
      return this.$route.matched;
178
    }
J
导航  
jinlan.du 已提交
179 180
  },
  mounted() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
    let screenWidth = document.body.clientWidth;
    if (screenWidth < 1000) {
      this.isMobile = true;
      this.isSider = false;
      this.isCollapse = true;
    } else if (screenWidth >= 1000 && screenWidth < 1200) {
      this.isMobile = false;
      this.isSider = false;
      this.isCollapse = true;
    } else {
      this.isMobile = false;
      this.isSider = true;
      this.isCollapse = false;
    }
    this.$bus.emit("collapse", this.isCollapse);
    this.$bus.emit("mobile", this.isMobile);
L
liuyang 已提交
197 198
    window.onresize = () => {
      return (() => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
199 200 201 202 203 204 205 206 207
        let screenWidth = document.body.clientWidth;
        if (screenWidth < 1000) {
          this.isMobile = true;
          this.isSider = false;
          this.isCollapse = true;
        } else if (screenWidth >= 1000 && screenWidth < 1200) {
          this.isMobile = false;
          this.isSider = false;
          this.isCollapse = true;
L
liuyang 已提交
208
        } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
209 210 211
          this.isMobile = false;
          this.isSider = true;
          this.isCollapse = false;
L
liuyang 已提交
212
        }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
213 214 215 216
        this.$bus.emit("collapse", this.isCollapse);
        this.$bus.emit("mobile", this.isMobile);
      })();
    };
Mr.奇淼('s avatar
Mr.奇淼( 已提交
217
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
218
};
Mr.奇淼('s avatar
Mr.奇淼( 已提交
219 220
</script>

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

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

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