zj
2024-06-03 89d48809779ae41f8712539584798d5900b64b78
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<template>
  <div class="login-dialog">
    <el-dialog
      :title="$t('hj248')"
      :center='true'
      :visible.sync="$store.state.loginIsShow"
      width="40%">
      <div class="login-box dialog-box">
        <!-- <h2 class="logo-img">
             <img :src="$store.state.siteInfo.siteLogoSm" alt="">
        </h2> -->
        <el-form :hide-required-asterisk='true' :model="form" ref="ruleForm" :rules="rule" class="demo-form-inline">
          <el-form-item label="" prop="phone">
            <el-input maxlength="11" max="11" type='text' v-model="form.phone" :placeholder="$t('regPhone2')">
              <i slot="prepend" class="iconfont icon-shouji"></i>
            </el-input>
          </el-form-item>
          <el-form-item label="" prop="pwd">
            <el-input type='' v-model="form.pwd" :placeholder="$t('hj30')">
              <i slot="prepend" class="iconfont icon-mima"></i>
            </el-input>
          </el-form-item>
        </el-form>
        <div>
          {{$t('hj223')}}<a @click="toRegister">{{$t('hj15')}}</a>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" :loading="islogin" @click="submit('ruleForm')">{{$t('hj24')}}</el-button>
        </div>
      </div>
 
    </el-dialog>
  </div>
</template>
 
<script>
  import * as api from '../axios/api'
  import { setLocalstorage } from '../utils/localstorage'
 
  export default {
    components: {},
    props: {},
    data () {
      let validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error(this.$t('regPhone2')))
        } else {
          // let myreg = /^[1][3,4,5,7,8][0-9]{9}$/  //手机号码验证
          let myreg = /^[0-9]{11}$/ // 手机号码验证
          if (!myreg.test(value)) {
            callback(new Error(this.$t('hj28')))
          }
          callback()
        }
      }
      // let validatePass2 = (rule, value, callback) => {
      //   if (value === '') {
      //     callback(new Error('请输入密码'))
      //   } else {
      //     let value = psd.replace('/s*/g', '')
      //     let myreg = '/^[a-zA-Z0-9!@#$%^&*.]{6,12}$/' // 手机号码验证
      //     if (!myreg.test(value)) {
      //       callback(new Error('请输入正确的手机号码'))
      //     }
      //     callback()
      //   }
      // }
      return {
        dialogVisible: false,
        islogin: false,
        form: {
          phone: '',
          pwd: ''
        },
        rule: {
          phone: [
            { required: true, validator: validatePass, message: this.$t('regPhone2'), trigger: 'blur' }
          ],
          pwd: [
            { required: true, message: this.$t('hj30'), trigger: 'blur' }
          ]
        }
      }
    },
    watch: {},
    computed: {},
    created () {},
    mounted () {},
    methods: {
      submit (formName) {
        // 提交
        this.$refs[formName].validate(async (valid) => {
          if (valid) {
            let opts = {
              phone: this.form.phone,
              userPwd: this.form.pwd
            }
            this.islogin = true
            let data = await api.login(opts)
            if (data.status === 0) {
              this.$store.state.userInfo.phone = this.phone
              // window.localStorage.setItem('phone',this.form.phone)
              setLocalstorage('phone', this.form.phone)
              this.$store.state.loginIsShow = false
              this.$store.state.haslogin = true
              this.$message.success(data.msg)
            } else {
              this.$message.error(data.msg)
            }
            this.islogin = false
          } else {
            return false
          }
        })
      },
      toRegister () {
        // 去注册
        this.$store.state.loginIsShow = false
        this.$router.push('/register')
      }
    }
  }
</script>
<style lang="less" scoped>
  .login-box {
    padding: 0px 40px;
  }
 
  .logo-img {
    text-align: center;
    margin-bottom: 20px;
 
    img {
      width: 100px;
      height: 100px;
    }
  }
 
  .dialog-footer {
    display: block;
    padding-bottom: 20px;
 
    .el-button {
      width: 100%;
      margin-top: 30px;
    }
  }
 
  .login-dialog /deep/ .el-dialog {
    .login-box {
      height: 240px;
    }
  }
</style>