审查视图

src/views/HomeNew.vue 15.1 KB
朱兆平 authored
1
<template>
小范 authored
2 3
    <el-container style="height: 100%">
        <el-aside style="width:250px;background-color: rgb(38, 56, 76)" id="l-menu">
朱兆平 authored
4 5 6 7 8 9 10 11 12
            <NavMenu :collapsed="collapsed"></NavMenu>
        </el-aside>

        <el-container>
            <el-header style="text-align: right; font-size: 12px">
                <div class="tools" @click.prevent="collapse"  style="width: 15px;z-index:9999;position:absolute;">
                    <!--                    ;margin-top: 80px;z-index:9999;margin-left: 170px-->
                            <i  style="color:#a6b6c6;vertical-align: middle;line-height: 60px;" :class="[collapsed?'el-icon-s-unfold':'el-icon-s-fold']"></i>
                </div>
13 14
                <i class="el-icon-question" style="vertical-align: middle;"></i>
                <i class="el-icon-message-solid" style="vertical-align: middle;"></i>
朱兆平 authored
15 16 17 18
                <el-dropdown trigger="hover" style="margin-top:10px">
                    <span class="el-dropdown-link userinfo-inner">
                        <img width="40" height="40" style="border-radius:50%;" src="~img/faceDefault.jpg"/></span>
                    <el-dropdown-menu slot="dropdown">
朱兆平 authored
19
                        <el-dropdown-item>用户:{{sysUserName}}</el-dropdown-item>
朱兆平 authored
20
                        <el-dropdown-item>我的消息</el-dropdown-item>
21
                        <el-dropdown-item @click.native="changePass">修改密码</el-dropdown-item>
朱兆平 authored
22 23 24 25 26 27
                        <el-dropdown-item @click.native="updateCache">更新缓存</el-dropdown-item>
                        <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-header>
28
            <el-main>
朱兆平 authored
29 30 31
                <TabMenu></TabMenu>
            </el-main>
        </el-container>
朱兆平 authored
32
        <el-dialog title="修改密码" :visible.sync="dialogFormVisible" width="70%">
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
            <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-row :gutter="1">
                    <el-col :span="11">
                        <el-form-item label=" " prop="newpwd">
                            <el-input type="password" v-model="resetForm.newpwd" autocomplete="off" show-password placeholder="8-20位字符在数字、小写、大写字母以及特殊字符中四选三">
                                <template slot="prepend">新密码</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label=" " prop="renewpwd">
                            <el-input type="password" v-model="resetForm.renewpwd" show-password auto-complete="off" placeholder="8-20位字符在数字、小写、大写字母以及特殊字符中四选三">
                                <template slot="prepend">确认密码</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-form-item>
                    <el-button type="primary" @click="submitEdit('resetForm')" style="float:right">提 交</el-button>
                </el-form-item>

            </el-form>
        </el-dialog>
朱兆平 authored
60 61 62 63 64
    </el-container>
</template>

<script>
    import rt from '../routes'
朱兆平 authored
65
    import { editPass,resetToken,loginedUserInfo,heartBeat} from '../api/user';
朱兆平 authored
66 67 68
    import ElFormItem from "element-ui/packages/form/src/form-item";
    import TabMenu from "@/components/TabMenu"
    import NavMenu from "@/components/NavMenu"
69 70
    import loginuserInfo from "@/api/base";
    import axios from "axios";
71 72
    import {mapActions, mapGetters} from 'vuex'
    import jsutil from "@/common/js/util";
朱兆平 authored
73 74 75 76 77 78 79 80 81 82

    export default {

        provide() {
            return {
                reload: this.reload
            }
        },
        components: {ElFormItem,TabMenu,NavMenu},
        data() {
83 84 85 86 87 88 89 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 116 117 118 119 120 121 122 123 124
            var validatePass = (rule, value, callback) => {
                if (!value) {
                    callback(new Error('请输入新密码'));
                }else {
                    var ls=0;
                 if(value.match(/([a-z])+/)){
                        ls++;
                    } if(value.match(/([0-9])+/)){
                        ls++;
                    } if(value.match(/([A-Z])+/)){
                        ls++;
                    } if((/([\W])+/) && !value.match(/(![\u4E00-\u9FA5])+/)){
                        ls++;
                    }  if (value.toString().length < 8 || value.toString().length > 20) {
                        callback(new Error('密码长度为8 - 20个字符'));
                        ls=0;
                    } if(value.match(/([\u4E00-\u9FA5])+/)){
                        callback(new Error('不能包含中文字符'));
                        ls=0;
                    }
                    switch (ls) {
                        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;
                        case 3:
                        case 4: this.passwordPercent = 100;break;
                        default: this.passwordPercent = 0;break;
                    }
                    callback();
                }

            };

            var validatePass2 = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请再次输入密码'));
                } else if (value !== this.resetForm.newpwd) {
                    callback(new Error('两次输入密码不一致!'));
                } else {
                    callback();
                }
            };
朱兆平 authored
125 126 127 128
            return {
                rotate:false,
                sysName:'',
                collapsed:false,
129
                sysUserName: '',
朱兆平 authored
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
                sysUserId:'',
                // sysUserAvatar: '',
                isRouterAlive: true,
                form: {
                    name: '',
                    region: '',
                    date1: '',
                    date2: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: ''
                },
                editForm: {
                    userId: '',
                    password: '',
                },
147 148 149 150 151 152 153 154 155 156 157 158 159
                dialogFormVisible:false,
                resetForm: {
                    newpwd: '',
                    renewpwd: '',
                },
                resetFormRules: {
                    newpwd: [
                        { required: true, validator: validatePass, trigger: 'blur' }
                    ],
                    renewpwd: [
                        { required: true, validator: validatePass2, trigger: 'blur' }
                    ]
                },
朱兆平 authored
160 161 162
            }
        },
        methods: {
163 164 165 166
            ...mapActions( // 语法糖
                ['setUserInfoStore','setUserMenuStore'] // 相当于this.$store.dispatch('modifyName'),提交这个方法
            ),
            initUserInfo:function() {
167 168 169 170
                this.setUserInfoStore(loginedUserInfo());
                this.sysUserName = this.getUserInfoStore.username || '';
                this.sysUserId=this.getUserInfoStore.userId||'';
                this.sysUserAvatar = this.getUserInfoStore.userface || '~img/faceDefault.jpg';
171
            },
朱兆平 authored
172 173
            reload() {
                this.$nextTick(function () {
174 175 176 177 178 179
                    this.$router.push({
                        path: this.$router.path,
                        query:{
                            t: new Date().getTime()
                        }
                    })
朱兆平 authored
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
                })
            },
            onSubmit() {
                console.log('submit!');
            },
            handleopen() {
                console.log('handleopen');
            },
            handleclose() {
                console.log('handleclose');
            },
            handleselect: function (a, b) {
                this.reload()
            },
            // 退出登录
            logout: function () {
                var _this = this;
                this.$confirm('确认退出吗?', '提示', {
                    //type: 'warning'
                }).then(() => {
200
                    this.$axios.defaults.headers.common['Authorization'] = undefined;
朱兆平 authored
201 202
                    sessionStorage.removeItem('user');
                    sessionStorage.removeItem('menu');
203 204 205 206 207 208 209 210 211 212
                    //清空菜单
                    this.setUserMenuStore([]);
                    this.setUserInfoStore({
                        userId: 0,
                        username: '',
                        companyId: 0,
                        companyName: '',
                        realname: '',
                        userface: ''
                    });
朱兆平 authored
213 214 215 216 217 218 219 220 221 222 223 224 225 226
                    //退出后初始化原来的路由
                    let sysRoutes =  JSON.parse(sessionStorage.getItem('sysMenu'));
                    _this.$router.options.routes = sysRoutes;

                    _this.$router.push('/login');
                }).catch(() => {

                });


            },
            //折叠导航栏
            collapse:function(){
                this.collapsed=!this.collapsed;
227
            },
228
            checkUpdate() {
朱兆平 authored
229
                axios.get('/static/nmmsVer.json?ver='+Date.now()).then(function(response) {
230
                    // 判断版本号是否与本地一致
朱兆平 authored
231
                    if (response && response.data.nmmsVer != localStorage.getItem('nmmsVer')) {
232 233 234 235 236 237 238
                        localStorage.setItem('nmmsVer', response.data.nmmsVer)
                        location.reload()
                    } else {
                    }
                }).catch(function(error) {
                })
            },
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
            submitEdit(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.editForm.userId=this.sysUserId;
                        this.editForm.password=this.resetForm.renewpwd;
                        editPass(this.editForm).then(res=>{
                            let response=res.data;
                            if(response.code=='200'){
                                this.$notify({
                                    title: '密码修改成功',
                                    message: '密码修改成功,退出请重新登录',
                                    type: 'success'
                                });
                                this.dialogFormVisible=false;
                            }else{
                                this.$notify.error({
                                    title: '密码修改失败',
                                    message: '密码修改失败!!!'
                                });
                            }
                        });
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            changePass:function(){
                this.dialogFormVisible=true;
            },
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
            updateCache:function(){
                resetToken().then( res =>{
                    let response  = res.data;
                    if (response.code === '200'){
                        this.$notify({
                            title: '成功',
                            message: '缓存更新成功',
                            type: 'success'
                        });
                    }else{
                        this.$notify.error({
                            title: '失败',
                            message: '缓存更新失败'
                        });
                    }
                })
            },
朱兆平 authored
286 287 288
            heartBeatAPI:function () {
                heartBeat().then(response => {
朱兆平 authored
289 290 291 292 293
                }).catch(e=>{
                    this.$notify.error({
                        title: '心跳',
                        message: '心跳失败'
                    });
朱兆平 authored
294 295
                });
            }
朱兆平 authored
296
        },
297
298 299 300
        computed: {
            ...mapGetters(['getUserInfoStore','getUserMenuStore']) // 动态计算属性,相当于this.$store.getters.resturantName
        },
301
朱兆平 authored
302
        mounted() {
303 304 305

            this.checkUpdate();
            var _this = this;
朱兆平 authored
306 307 308 309 310 311
            //操作路由,判断本地存储的用户栏目列表是否存在,如果存在则加载路由
            var userRouters = sessionStorage.getItem('menu');
            if (userRouters) {
                userRouters = JSON.parse(userRouters);
                _this.$router.options.routes = userRouters;
            }
312 313 314 315 316

            // 定时获取版本号
            setInterval(() => {
                this.checkUpdate();
            }, 30000);
朱兆平 authored
317
            setInterval(() => {
朱兆平 authored
318 319 320 321
                if (this.sysUserName){
                    this.heartBeatAPI();
                }
            }, 90000);
322 323
            this.$nextTick(function(){
                this.initUserInfo();
小范 authored
324 325
                // this.rowDrop();   //行拖拽效果
326
            })
朱兆平 authored
327 328 329 330 331 332 333
        },
        watch: {
            collapsed(value) {
                let menuDom = document.getElementById("l-menu");
                //折叠
                if (value){
                    this.$nextTick(function () {
朱兆平 authored
334
                        menuDom.setAttribute("style","width:90px;background-color: rgb(38, 56, 76);");
朱兆平 authored
335 336 337 338
                    })
                }else {
                    //不折叠
                    this.$nextTick(function () {
朱兆平 authored
339
                        menuDom.setAttribute("style","width:250px;background-color: rgb(38, 56, 76);");
朱兆平 authored
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
                    })

                }
            }
        }
    }

</script>
<style>
</style>
<style scoped lang="scss">
    @import '~scss_vars';

</style>
<style lang="scss">
    header{
        line-height: 60px;
        box-shadow: 0px 10px 10px #eaeff3;
        z-index: 2;
        i{
            font-size: 24px;
            margin-right: 20px;
            text-align: center;
            vertical-align: middle;
            height: 60px;
            margin-top: 0px;
            color: rgb(166, 182, 198);
            width: 30px;
        }
    }
370 371 372
    main.el-main{
        background-color:#f5f7fd;
        padding:0 10px 10px 10px;
朱兆平 authored
373
    }
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
    .el-dialog__header {
        padding: 20px 20px 10px;
        padding-top: 10px;
        /*border-left: 5px solid rgb(111, 130, 148);*/
        border-radius: 0px 5px 0 0;
        /*font-weight: 700;*/
        font-size: 12px;
        /*border-bottom: 1px solid rgb(111, 130, 148);*/
        background: #f5f7fd;
        color: #778ca2;
    }
    .el-dialog__title {
        line-height: 24px;
        font-size: 14px;
        color: #778ca2;
    }
    .el-dialog__body {
        padding: 5px 20px;
    }

朱兆平 authored
395 396

</style>