审查视图

src/views/Home.vue 20.7 KB
朱兆平 authored
1
<template>
朱兆平 authored
2
    <el-row class="container darkmenu" style="margin-top: 0px;">
3 4 5 6 7 8 9 10 11 12 13
        <el-col :span="24" class="header">
            <el-col :span="10" class="logo" :class="collapsed?'logo-collapse-width':'logo-width'">
                {{collapsed?'':sysName}}
            </el-col>
            <el-col :span="10">
                <div class="tools" @click.prevent="collapse">
                    <i class="fa fa-align-justify"></i>
                </div>
            </el-col>
            <el-col :span="4" class="userinfo">
                <el-dropdown trigger="hover">
王勇 authored
14 15
                    <span class="el-dropdown-link userinfo-inner"><img
                            :src="this.sysUserAvatar"/> {{sysUserName}}</span>
16 17
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item>我的消息</el-dropdown-item>
xudada authored
18
                        <el-dropdown-item @click.native="editPass">修改密码</el-dropdown-item>
19
                        <el-dropdown-item @click.native="updateCache">更新缓存</el-dropdown-item>
20 21 22 23 24
                        <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-col>
        </el-col>
xudada authored
25
        <el-col>
王勇 authored
26
            <el-dialog title="修改密码" :visible.sync="dialogFormVisible" @close="resetFormClosed">
xudada authored
27 28 29 30 31
                <el-form :model="resetForm" status-icon :rules="resetFormRules" ref="resetForm" label-width="100px">
                    <el-form-item label="用户名" prop="name">
                        <span>{{sysUserName}}</span>
                    </el-form-item>
                    <el-form-item label="新密码" prop="newpwd">
王勇 authored
32 33
                        <el-input type="password" v-model="resetForm.newpwd" autocomplete="off" show-password
                                  placeholder="8-20位字符在数字、小写、大写字母以及特殊字符中四选三"></el-input>
xudada authored
34 35
                    </el-form-item>
                    <el-form-item label="确认密码" prop="renewpwd">
王勇 authored
36
                        <el-input type="password" v-model="resetForm.renewpwd" show-password auto-complete="off"></el-input>
xudada authored
37 38 39 40 41 42 43 44
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitEdit('resetForm')" style="float:right">提 交</el-button>
                    </el-form-item>

                </el-form>
            </el-dialog>
        </el-col>
45 46 47
        <el-col :span="24" class="main">
            <aside :class="collapsed?'menu-collapsed':'menu-expanded'">
                <!--导航菜单-->
王勇 authored
48 49 50
                <el-menu :default-active="$route.path" class="el-menu-vertical-demo" @open="handleopen"
                         @close="handleclose" @select="handleselect" unique-opened router v-show="!collapsed"
                         style="min-width: 230px">
51 52 53
                    <template v-for="(item,index) in $router.options.routes" v-if="!item.hidden">
                        <el-submenu :index="index+''" v-if="!item.leaf">
                            <template slot="title"><i :class="item.iconCls"></i>{{item.name}}</template>
王勇 authored
54 55 56
                            <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path"
                                          v-if="!child.hidden">{{child.name}}
                            </el-menu-item>
57
                        </el-submenu>
王勇 authored
58 59 60
                        <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>
61 62 63 64 65 66
                    </template>
                </el-menu>
                <!--导航菜单-折叠后-->
                <ul class="el-menu el-menu-vertical-demo collapsed" v-show="collapsed" ref="menuCollapsed">
                    <li v-for="(item,index) in $router.options.routes" v-if="!item.hidden" class="el-submenu item">
                        <template v-if="!item.leaf">
王勇 authored
67 68 69 70 71 72 73 74 75
                            <div class="el-submenu__title" style="padding-left: 20px;" @mouseover="showMenu(index,true)"
                                 @mouseout="showMenu(index,false)"><i :class="item.iconCls"></i></div>
                            <ul class="el-menu submenu" :class="'submenu-hook-'+index" @mouseover="showMenu(index,true)"
                                @mouseout="showMenu(index,false)">
                                <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>
76 77 78 79
                            </ul>
                        </template>
                        <template v-else>
                    <li class="el-submenu">
王勇 authored
80 81 82 83
                        <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>
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                    </li>
</template>
</li>
</ul>
</aside>
<section class="content-container">
    <div class="grid-content bg-purple-light">
        <el-col :span="24" class="breadcrumb-container">
            <strong class="title">{{$route.name}}</strong>
            <el-breadcrumb separator="/" class="breadcrumb-inner">
                <el-breadcrumb-item v-for="item in $route.matched" :key="item.path">
                    {{ item.name }}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </el-col>
        <el-col :span="24" class="content-wrapper">
            <transition name="fade" mode="out-in">
朱兆平 authored
101
                <router-view :key="$route.path +$route.query.t"></router-view>
102 103 104 105 106 107
            </transition>
        </el-col>
    </div>
</section>
</el-col>
</el-row>
朱兆平 authored
108 109 110
</template>

<script>
111
    import rt from '../routes'
王勇 authored
112
    import {editPass, resetToken} from '../api/user';
xudada authored
113
    import ElFormItem from "element-ui/packages/form/src/form-item";
王勇 authored
114
115
    export default {
朱兆平 authored
116 117 118 119 120 121

        provide() {
            return {
                reload: this.reload
            }
        },
xudada authored
122
        components: {ElFormItem},
123
        data() {
xudada authored
124 125 126
            var validatePass = (rule, value, callback) => {
                if (!value) {
                    callback(new Error('请输入新密码'));
王勇 authored
127 128 129
                } else {
                    var ls = 0;
                    if (value.match(/([a-z])+/)) {
xudada authored
130
                        ls++;
王勇 authored
131 132
                    }
                    if (value.match(/([0-9])+/)) {
xudada authored
133
                        ls++;
王勇 authored
134 135
                    }
                    if (value.match(/([A-Z])+/)) {
xudada authored
136
                        ls++;
王勇 authored
137 138
                    }
                    if ((/([\W])+/) && !value.match(/(![\u4E00-\u9FA5])+/)) {
xudada authored
139
                        ls++;
王勇 authored
140 141
                    }
                    if (value.toString().length < 8 || value.toString().length > 20) {
xudada authored
142
                        callback(new Error('密码长度为8 - 20个字符'));
王勇 authored
143 144 145
                        ls = 0;
                    }
                    if (value.match(/([\u4E00-\u9FA5])+/)) {
xudada authored
146
                        callback(new Error('不能包含中文字符'));
王勇 authored
147
                        ls = 0;
xudada authored
148 149
                    }
                    switch (ls) {
王勇 authored
150 151 152 153 154 155 156 157 158 159 160 161
                        case 0:
                            this.passwordPercent = 0;
                            callback(new Error('数字、小写字母、大写字母以及特殊字符中四选三'));
                            break;
                        case 1:
                            this.passwordPercent = 33;
                            callback(new Error('数字、小写字母、大写字母以及特殊字符中四选三'));
                            break;
                        case 2:
                            this.passwordPercent = 66;
                            callback(new Error('数字、小写字母 、大写字母以及特殊字符中四选三'));
                            break;
xudada authored
162
                        case 3:
王勇 authored
163 164 165 166 167 168
                        case 4:
                            this.passwordPercent = 100;
                            break;
                        default:
                            this.passwordPercent = 0;
                            break;
xudada authored
169
                    }
xudada authored
170 171
                    callback();
                }
xudada authored
172
xudada authored
173
            };
xudada authored
174
xudada authored
175 176 177 178 179 180 181 182 183
            var validatePass2 = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请再次输入密码'));
                } else if (value !== this.resetForm.newpwd) {
                    callback(new Error('两次输入密码不一致!'));
                } else {
                    callback();
                }
            };
184
            return {
王勇 authored
185 186
                sysName: '消息控制中心',
                collapsed: false,
187
                sysUserName: '',
王勇 authored
188
                sysUserId: '',
189
                sysUserAvatar: '',
朱兆平 authored
190
                isRouterAlive: true,
191 192 193 194 195 196 197 198 199
                form: {
                    name: '',
                    region: '',
                    date1: '',
                    date2: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: ''
xudada authored
200
                },
王勇 authored
201
                dialogFormVisible: false,
xudada authored
202 203 204 205 206 207
                resetForm: {
                    newpwd: '',
                    renewpwd: '',
                },
                resetFormRules: {
                    newpwd: [
王勇 authored
208
                        {required: true, validator: validatePass, trigger: 'blur'}
xudada authored
209 210
                    ],
                    renewpwd: [
王勇 authored
211
                        {required: true, validator: validatePass2, trigger: 'blur'}
xudada authored
212 213 214 215 216 217
                    ]
                },
                editForm: {
                    userId: '',
                    password: '',
                },
218 219 220
            }
        },
        methods: {
朱兆平 authored
221 222
            reload() {
                this.$nextTick(function () {
王勇 authored
223 224 225 226 227 228
                    this.$router.push({
                        path: this.$router.path,
                        query: {
                            t: new Date().getTime()
                        }
                    })
朱兆平 authored
229 230
                })
            },
王勇 authored
231 232
            editPass: function () {
                this.dialogFormVisible = true;
xudada authored
233
            },
王勇 authored
234 235 236 237
            updateCache: function () {
                resetToken().then(res => {
                    let response = res.data;
                    if (response.code === '200') {
238 239 240 241 242
                        this.$notify({
                            title: '成功',
                            message: '缓存更新成功',
                            type: 'success'
                        });
王勇 authored
243
                    } else {
244 245 246 247 248 249 250
                        this.$notify.error({
                            title: '失败',
                            message: '缓存更新失败'
                        });
                    }
                })
            },
王勇 authored
251 252 253 254 255 256 257 258 259 260

            /**
             * 修改密码对话框时,重置表格
             */
            resetFormClosed() {
                // 重置对话框
                this.$refs.resetForm.resetFields();
            },

            submitEdit(formName) {
xudada authored
261 262
                this.$refs[formName].validate((valid) => {
                    if (valid) {
王勇 authored
263 264 265 266 267 268 269 270 271 272 273 274 275
                        // const userInfo = {
                        //     username: this.sysUserName,
                        //     password: this.resetForm.renewpwd
                        // }
                        // // 修改MQ用户的密码
                        // updatePassword(userInfo).then((response) => {
                        //     let res = response.data;
                        //     if (res.code !== '200') {
                        //         return this.$message.error(res.msg);
                        //     }
                        // }).catch(error => {
                        //     this.$message.error(error.toString());
                        // });
王勇 authored
276 277 278 279 280 281 282

                        this.editForm.userId = this.sysUserId;
                        this.editForm.password = this.resetForm.renewpwd;
                        // 修改cloud用户的密码
                        editPass(this.editForm).then(res => {
                            let response = res.data;
                            if (response.code == '200') {
xudada authored
283 284 285 286 287
                                this.$notify({
                                    title: '密码修改成功',
                                    message: '密码修改成功,退出请重新登录',
                                    type: 'success'
                                });
王勇 authored
288 289
                                this.dialogFormVisible = false;
                            } else {
xudada authored
290 291 292 293 294 295 296 297 298 299 300 301
                                this.$notify.error({
                                    title: '密码修改失败',
                                    message: '密码修改失败!!!'
                                });
                            }
                        });
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
302 303 304 305 306 307 308 309 310 311
            onSubmit() {
                console.log('submit!');
            },
            handleopen() {
                console.log('handleopen');
            },
            handleclose() {
                console.log('handleclose');
            },
            handleselect: function (a, b) {
朱兆平 authored
312
                this.reload()
313 314 315 316 317 318 319 320
            },
            //退出登录
            logout: function () {
                var _this = this;
                this.$confirm('确认退出吗?', '提示', {
                    //type: 'warning'
                }).then(() => {
                    sessionStorage.removeItem('user');
321 322
                    sessionStorage.removeItem('menu');
                    //退出后初始化原来的路由
王勇 authored
323
                    let sysRoutes = JSON.parse(sessionStorage.getItem('sysMenu'));
324
                    console.log(sysRoutes);
325
                    _this.$router.options.routes = sysRoutes;
326
327 328
                    _this.$router.push('/login');
                }).catch(() => {
朱兆平 authored
329
330
                });
朱兆平 authored
331 332

333 334
            },
            //折叠导航栏
王勇 authored
335 336
            collapse: function () {
                this.collapsed = !this.collapsed;
337
            },
王勇 authored
338 339
            showMenu(i, status) {
                this.$refs.menuCollapsed.getElementsByClassName('submenu-hook-' + i)[0].style.display = status ? 'block' : 'none';
340 341 342
            }
        },
        mounted() {
343
            var _this = this;
344 345 346 347
            var user = sessionStorage.getItem('user');
            if (user) {
                user = JSON.parse(user);
                this.sysUserName = user.username || '';
王勇 authored
348
                this.sysUserId = user.userId || '';
349 350 351 352 353
                this.sysUserAvatar = user.userface || '/static/images/faceDefault.jpg';
            }
            //操作路由,判断本地存储的用户栏目列表是否存在,如果存在则加载路由
            var userRouters = sessionStorage.getItem('menu');
            if (userRouters) {
354
                userRouters = JSON.parse(userRouters);
355
                _this.$router.options.routes = userRouters;
356 357
                console.log("home:");
                console.log(_this.$router.options.routes);
358 359 360
            }
        }
    }
朱兆平 authored
361 362 363 364

</script>

<style scoped lang="scss">
365
    @import '~scss_vars';
王勇 authored
366
367 368 369 370 371
    .container {
        position: absolute;
        top: 0px;
        bottom: 0px;
        width: 100%;
王勇 authored
372
373 374 375
        .header {
            height: 60px;
            line-height: 60px;
朱兆平 authored
376
            background: $color-primary url("/static/images/air-banner.png");
王勇 authored
377 378
            color: #fff;
379 380 381 382
            .userinfo {
                text-align: right;
                padding-right: 35px;
                float: right;
王勇 authored
383
384 385
                .userinfo-inner {
                    cursor: pointer;
王勇 authored
386 387
                    color: #fff;
388 389 390 391 392 393 394 395 396
                    img {
                        width: 40px;
                        height: 40px;
                        border-radius: 20px;
                        margin: 10px 0px 10px 10px;
                        float: right;
                    }
                }
            }
王勇 authored
397
398 399
            .logo {
                //width:230px;
王勇 authored
400
                height: 60px;
401
                font-size: 22px;
王勇 authored
402 403 404
                padding-left: 20px;
                padding-right: 20px;
                border-color: rgba(238, 241, 146, 0.3);
405 406
                border-right-width: 1px;
                border-right-style: solid;
王勇 authored
407
408 409 410 411 412
                img {
                    width: 40px;
                    float: left;
                    margin: 10px 10px 10px 18px;
                }
王勇 authored
413
414
                .txt {
王勇 authored
415
                    color: #fff;
416 417
                }
            }
王勇 authored
418 419 420

            .logo-width {
                width: 230px;
421
            }
王勇 authored
422 423 424

            .logo-collapse-width {
                width: 60px
425
            }
王勇 authored
426 427

            .tools {
428
                padding: 0px 23px;
王勇 authored
429
                width: 14px;
430 431 432 433 434
                height: 60px;
                line-height: 60px;
                cursor: pointer;
            }
        }
王勇 authored
435
436 437 438 439 440 441 442
        .main {
            display: flex;
            // background: #324057;
            position: absolute;
            top: 60px;
            bottom: 0px;
            overflow: hidden;
王勇 authored
443
444
            aside {
王勇 authored
445
                flex: 0 0 230px;
446
                width: 230px;
447
                /*overflow-y: scroll;*/
448
                background: #606060;
449 450 451
                // position: absolute;
                // top: 0px;
                // bottom: 0px;
王勇 authored
452 453 454 455
                .collapsed {
                    width: 60px;

                    .item {
456 457
                        position: relative;
                    }
王勇 authored
458 459 460 461 462 463 464 465

                    .submenu {
                        position: absolute;
                        top: 0px;
                        left: 60px;
                        z-index: 99999;
                        height: auto;
                        display: none;
466 467 468 469
                    }

                }
            }
王勇 authored
470 471 472

            .menu-collapsed {
                flex: 0 0 60px;
473 474
                width: 60px;
            }
王勇 authored
475 476 477

            .menu-expanded {
                flex: 0 0 230px;
478 479
                width: 230px;
            }
王勇 authored
480 481

            .menu-expanded ul {
482 483
                width: 230px;
            }
王勇 authored
484
485 486
            .content-container {
                // background: #f1f2f7;
王勇 authored
487
                flex: 1;
488 489 490 491 492 493
                // position: absolute;
                // right: 0px;
                // top: 0px;
                // bottom: 0px;
                // left: 230px;
                overflow-y: scroll;
朱兆平 authored
494
                padding: 10px;
王勇 authored
495
496 497 498 499 500 501
                .breadcrumb-container {
                    //margin-bottom: 15px;
                    .title {
                        width: 200px;
                        float: left;
                        color: #475669;
朱兆平 authored
502
                        margin-left: 10px;
503
                    }
王勇 authored
504
505 506
                    .breadcrumb-inner {
                        float: right;
王勇 authored
507
                        margin-right: 10px;
朱兆平 authored
508
                    }
王勇 authored
509 510 511

                    .el-breadcrumb {
                        line-height: 36px;
512 513
                    }
                }
王勇 authored
514
515 516 517 518 519 520 521
                .content-wrapper {
                    background-color: #fff;
                    box-sizing: border-box;
                }
            }
        }
    }
朱兆平 authored
522 523
</style>
<style lang="scss">
王勇 authored
524
    .darkmenu {
朱兆平 authored
525 526
        .main {
            aside {
王勇 authored
527
                .el-menu {
朱兆平 authored
528 529
                    height: 100%;
                    background: #606060;
王勇 authored
530
朱兆平 authored
531
                    .el-menu-item {
王勇 authored
532
                        i {
朱兆平 authored
533 534
                            color: white;
                        }
王勇 authored
535
朱兆平 authored
536 537
                        color: white;
                    }
王勇 authored
538 539 540

                    .el-menu-item.is-active {
                        color: #e6a23c;
朱兆平 authored
541
                    }
王勇 authored
542 543

                    .el-menu-item:hover, .el-menu-item:focus {
朱兆平 authored
544 545
                        background-color: #1a4496;
                    }
王勇 authored
546
朱兆平 authored
547
                    .el-submenu {
王勇 authored
548
                        ul.el-menu.el-menu--inline {
朱兆平 authored
549 550
                            background: #303030;
                        }
王勇 authored
551
朱兆平 authored
552 553
                        .el-submenu__title {
                            color: white;
王勇 authored
554 555

                            i {
朱兆平 authored
556 557 558
                                color: white;
                            }
                        }
王勇 authored
559
朱兆平 authored
560 561 562 563 564 565 566 567
                        .el-submenu__title:hover {
                            background-color: #1a4496;
                        }
                    }
                }
            }
        }
    }
568
</style>