zhangyanpeng
2020-03-17 ecd4be909222faa66fa174e3ea6f0855edf1fe23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<template>
  <div class="login" ref="hello_div">
    <!-- <div class="img-container">
      <img :src="loginImg" alt="">
    </div> -->
        <div class="login_" ref="logon_div">
            <el-form ref="loginForm" :model="loginForm" class="login-form" label-position="left">
                <el-form-item prop="loginName">
                    <el-input
                        v-model="loginForm.loginName"
                        placeholder="输入用户名"
                        name="loginName"
                        type="text"
                        
                    >
                        
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                        :type="passwordType"
                        v-model="loginForm.password"
                        placeholder="输入密码"
                        name="password"
                     
                        @keyup.enter.native="handleLogin"
                    >
                        <span slot="suffix" class="suffix-icon" :class="{eyeOpen: isOpen}" @click="showPwd">
                            <svg-icon :icon-class="eyeIconClass" />
                        </span>
                    </el-input>
                </el-form-item>
             
                <el-button :loading="loading" class="loginButton" type="primary" @click.native.prevent="handleLogin">登录</el-button>
            </el-form>
        </div>
  </div>
</template>
 
<script>
/**
 * 登录组件
 * @author Sky
 */
export default {
 
  data () {
    return {
   //   path: '/' + process.env.VUE_APP_FACTORY_KEY + '/user/confirm-password',
      loginImg: require('@/assets/login-left.jpg'),
      loginForm: { // 表单数据
        loginName: '',
        password: ''
      },
      passwordType: 'password', // 输入框类型
      loading: false, // 加载中
      eyeIconClass: 'eye-off', // 密码图标显示
      isOpen: false // 根据状态显示不同样式类名
    }
  },
    
    mounted() {
        this.setWH();
    },
 
  methods: {
        setWH() {
            //获取屏幕宽度
            let hello_Width = this.$refs.hello_div.offsetWidth;
        //    let hello_Height = this.$refs.hello_div.offsetHeight;
            let hello_Height = document.documentElement.clientHeight;
            //获取登录元素宽度
            let logon_Width = this.$refs.logon_div.offsetWidth;
            let logon_Height = this.$refs.logon_div.offsetHeight;
            //设置登录元素的magin-left
            if (hello_Width>logon_Width) {
                let margin_left = (hello_Width - logon_Width)/2;
                this.$refs.logon_div.style['margin-left'] = margin_left + "px";
            }
            
            if (hello_Height>logon_Height) {
                let margin_top = (hello_Height - logon_Height)/2;
                this.$refs.logon_div.style['margin-top'] = margin_top + "px";
            }
        },
    // 忘记密码回调
   
    // 清除用户名
    
    // 密码显示切换
    showPwd () {
      if (this.passwordType === 'password') {
        this.passwordType = ''
        this.eyeIconClass = 'eye'
        this.isOpen = true
      } else {
        this.passwordType = 'password'
        this.eyeIconClass = 'eye-off'
        this.isOpen = false
      }
    },
        
    // 登录
    handleLogin () {
            let url = "/api/user/login";
            let params = this.loginForm;
            this.$axios.get(url,{
                 params
               }).then(data_ => {
               if(data_.data.success) {
                   localStorage.setItem('userId',data_.data.data.id);
                   localStorage.setItem('userName',data_.data.data.name);
                   localStorage.setItem('roleId',data_.data.data.roleCode);
                   localStorage.setItem('roleName',data_.data.data.roleName);
                   localStorage.setItem('departId',data_.data.data.departCode);
                   localStorage.setItem('departName',data_.data.data.departName);
                       this.$router.push('/');
               }else {
                    this.$message({message:'登陆失败', type: 'warning'});
               }
                
               }).catch(error =>{
               })
            
        
        },
  }
}
</script>
 
<style >
    .login_ {
        max-width: 350px;
        background-color: #f9f9fb;
        padding: 20px;
    }
 
</style>