index.vue 12.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">
J
jinlan.du 已提交
6 7 8 9
           <div class="tilte">
              <img src="~@/assets/nav_logo.png" alt=""  class="logoimg">
              <h2 v-if="isSider" class="tit-text">Gin-Vue-Admin</h2>
            </div>
10
        <Aside class="aside" />
Mr.奇淼('s avatar
Mr.奇淼( 已提交
11
      </el-aside>
12
      <!-- 分块滑动功能 -->
Mr.奇淼('s avatar
Mr.奇淼( 已提交
13
      <el-main class="main-cont main-right">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
14
        <transition :duration="{ enter: 800, leave: 100 }" mode="out-in" name="el-fade-in-linear">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
          <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">
31 32 33 34 35 36 37 38 39 40 41 42 43
                <transition name="el-fade-in-linear">
                  <div v-show="show" class="transition-box" style="display: inline-block; ">
                     <el-select v-model="value" filterable placeholder="请选择" @blur="test()">
                      <el-option
                              v-for="item in options"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                      </el-option>
                    </el-select>
                  </div>
                </transition>
                <i class="el-icon-search" style="font-size: 20px; display: inline-block; " @click="show = !show"></i>
J
jinlan.du 已提交
44
                <Screenfull class="screenfull"></Screenfull>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
45 46 47 48 49
                <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.奇淼( 已提交
50
                  </span>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
                  <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 />
69 70 71 72 73 74 75 76
          </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.奇淼( 已提交
77
          <router-view v-if="!$route.meta.keepAlive" class="admin-box"></router-view>
78 79 80
        </transition>
      </el-main>
    </el-container>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    <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.奇淼( 已提交
98
  </el-container>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
99 100 101
</template>

<script>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
102 103
import Aside from "@/view/layout/aside";
import HistoryComponent from "@/view/layout/aside/historyComponent/history";
J
jinlan.du 已提交
104
import Screenfull from "@/view/layout/screenfull";
Mr.奇淼('s avatar
Mr.奇淼( 已提交
105 106
import { mapGetters, mapActions } from "vuex";
import { changePassword } from "@/api/user";
Mr.奇淼('s avatar
Mr.奇淼( 已提交
107
export default {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
108
  name: "Layout",
109 110
  data() {
    return {
111
      show:false,
J
导航  
jinlan.du 已提交
112 113 114
      isCollapse: false,
      isSider: true,
      isMobile: false,
L
liuyang 已提交
115 116 117 118 119
      isShadowBg: false,
      showPassword: false,
      pwdModify: {},
      rules: {
        password: [
Mr.奇淼('s avatar
Mr.奇淼( 已提交
120 121
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, message: "最少6个字符", trigger: "blur" }
L
liuyang 已提交
122 123
        ],
        newPassword: [
Mr.奇淼('s avatar
Mr.奇淼( 已提交
124 125
          { required: true, message: "请输入新密码", trigger: "blur" },
          { min: 6, message: "最少6个字符", trigger: "blur" }
L
liuyang 已提交
126 127
        ],
        confirmPassword: [
Mr.奇淼('s avatar
Mr.奇淼( 已提交
128 129
          { required: true, message: "请输入确认密码", trigger: "blur" },
          { min: 6, message: "最少6个字符", trigger: "blur" },
L
liuyang 已提交
130 131 132
          {
            validator: (rule, value, callback) => {
              if (value !== this.pwdModify.newPassword) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
133
                callback(new Error("两次密码不一致"));
L
liuyang 已提交
134
              } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
135
                callback();
L
liuyang 已提交
136 137
              }
            },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
138
            trigger: "blur"
L
liuyang 已提交
139 140
          }
        ]
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
      },
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      value:''
Mr.奇淼('s avatar
Mr.奇淼( 已提交
159
    };
Mr.奇淼('s avatar
Mr.奇淼( 已提交
160
  },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
161
  components: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
162
    Aside,
J
jinlan.du 已提交
163 164
    HistoryComponent,
    Screenfull
J
导航  
jinlan.du 已提交
165
  },
166
  methods: {
167 168 169
    test(){
      this.show = false
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
170
    ...mapActions("user", ["LoginOut"]),
171
    totalCollapse() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
172 173 174 175
      this.isCollapse = !this.isCollapse;
      this.isSider = !this.isCollapse;
      this.isShadowBg = !this.isCollapse;
      this.$bus.emit("collapse", this.isCollapse);
176
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
177
    toPerson() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
178
      this.$router.push({ name: "person" });
J
导航  
jinlan.du 已提交
179
    },
L
liuyang 已提交
180
    changeShadow() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
181 182 183
      this.isShadowBg = !this.isShadowBg;
      this.isSider = !!this.isCollapse;
      this.totalCollapse();
L
liuyang 已提交
184 185 186 187 188 189 190 191 192
    },
    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.奇淼( 已提交
193 194 195
            this.$message.success("修改密码成功!");
            this.showPassword = false;
          });
L
liuyang 已提交
196
        } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
197
          return false;
L
liuyang 已提交
198
        }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
199
      });
L
liuyang 已提交
200 201 202
    },
    clearPassword() {
      this.pwdModify = {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
203 204 205 206 207
        password: "",
        newPassword: "",
        confirmPassword: ""
      };
      this.$refs.modifyPwdForm.clearValidate();
208 209
    }
  },
210
  computed: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
211 212
    ...mapGetters("user", ["userInfo"]),
    ...mapGetters("history", ["historys", "activeValue"]),
213
    title() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
214
      return this.$route.meta.title || "当前页面";
215
    },
216
    matched() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
217
      return this.$route.matched;
218
    }
J
导航  
jinlan.du 已提交
219 220
  },
  mounted() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
    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 已提交
237 238
    window.onresize = () => {
      return (() => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
239 240 241 242 243 244 245 246 247
        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 已提交
248
        } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
249 250 251
          this.isMobile = false;
          this.isSider = true;
          this.isCollapse = false;
L
liuyang 已提交
252
        }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
253 254 255 256
        this.$bus.emit("collapse", this.isCollapse);
        this.$bus.emit("mobile", this.isMobile);
      })();
    };
Mr.奇淼('s avatar
Mr.奇淼( 已提交
257
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
258
};
Mr.奇淼('s avatar
Mr.奇淼( 已提交
259 260
</script>

Mr.奇淼('s avatar
Mr.奇淼( 已提交
261 262
<style lang="scss">
$headerHigh: 52px;
263
$mainHight: 100vh;
264
.el-dropdown-link {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
265 266 267 268 269
  cursor: pointer;
}
.dropdown-group {
  min-width: 100px;
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
270 271 272
.topfix {
  position: fixed;
  top: 0;
273 274 275
  box-sizing: border-box;
  z-index: 999;
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
276 277
.admin-box {
  background-color: rgb(255, 255, 255);
278
  margin-top: 100px;
K
klausY 已提交
279
}
280
.el-scrollbar__wrap {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
281 282
  padding-bottom: 17px;
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
283
.layout-cont {
284 285 286 287 288
  .right-box {
    text-align: center;
    vertical-align: middle;
    img {
      vertical-align: middle;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
289
      border: 1px solid #ccc;
290 291 292
      border-radius: 6px;
    }
  }
293 294 295 296 297 298 299
  .menu-contorl {
    line-height: 52px;
    font-size: 20px;
    color: #eee;
    display: table-cell;
    vertical-align: middle;
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
300 301
  .header-cont {
    height: $headerHigh !important;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
302
    background: #fff;
303
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
Mr.奇淼('s avatar
Mr.奇淼( 已提交
304
    line-height: $headerHigh;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
305 306
  }
  .main-cont {
307
    .breadcrumb {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
308 309 310
      line-height: 48px;
      display: inline-block;
      padding: 0 24px;
J
jinlan.du 已提交
311 312
      // padding: 6px;
      // border-bottom: 1px solid #eee;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
313
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
314
    .router-history {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
315 316
      background: #fff;
      padding: 0 6px;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
317
      border-top: 1px solid #dcdcdc;
318
    }
319
    &.el-main {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
320
      overflow: auto;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
321
      background: #fff;
J
jinlan.du 已提交
322 323
      // padding: 0px 10px;
      // background: #fff;
324
    }
325 326 327 328
    height: $mainHight !important;
    overflow: visible;
    position: relative;
    .menu-total {
329 330 331 332 333 334 335 336 337 338 339 340 341 342
      // 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;
343 344
    }
    .aside {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
345
      overflow: auto;
J
导航  
jinlan.du 已提交
346
      // background: #fff;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
347
      &::-webkit-scrollbar {
348 349
        display: none;
      }
350
    }
351

352
    .el-menu-vertical {
353
      height: 100vh !important;
354
      visibility: auto;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
355
      &:not(.el-menu--collapse) {
356
        width: 220px;
357
      }
358

Mr.奇淼('s avatar
Mr.奇淼( 已提交
359
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
360 361 362 363 364 365 366
.el-menu--collapse{
        li{
          .el-tooltip,.el-submenu__title{
            padding:0px 15px !important;
          }
        }
      }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
367 368 369 370 371
    &::-webkit-scrollbar {
      display: none;
    }
    &.main-left {
      width: auto !important;
372 373
    }
    &.main-right {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
374
      .admin-title {
375 376
        float: left;
        font-size: 16px;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
377
        vertical-align: middle;
378
        margin-left: 20px;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
379 380 381
        img {
          vertical-align: middle;
        }
382
        &.collapse {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
383 384 385
          width: 53px;
        }
      }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
386 387 388
    }
  }
}
J
jinlan.du 已提交
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
.tilte{
  background: #001529;
  min-height: 64px;
  line-height: 64px;
  background: #002140;
  text-align: center;
  .logoimg{
    width: 30px;
    height: 30px;
    vertical-align: middle;
    background: #fff;
    border-radius: 50%;
    padding: 3px;
  }
  .tit-text{
    display: inline-block;
    color: #fff;
    font-weight: 600;
    font-size: 20px;
    vertical-align: middle;
  }
}
411 412 413 414
.el-input__inner{
  border: none;
  border-bottom: 1px solid #606266;
}
J
jinlan.du 已提交
415 416
.screenfull{
  display: inline-block;
417

J
jinlan.du 已提交
418
}
K
klausY 已提交
419
</style>