Blame view

ant-design-vue-jeecg/src/views/user/LoginAccount.vue 4.67 KB
肖超群 authored
1
<template>
肖超群 authored
2
3
4
  <div>
    <a-form-model ref="form" :model="model" :rules="validatorRules">
      <a-form-model-item required prop="username">
5
        <a-input v-model="model.username" size="large" placeholder="请输入帐户名 / admin" @blur="getWarehouse">
肖超群 authored
6
7
8
9
10
11
12
13
14
          <a-icon slot="prefix" type="user" :style="{ color: 'rgba(0,0,0,.25)' }"/>
        </a-input>
      </a-form-model-item>
      <a-form-model-item required prop="password">
        <a-input v-model="model.password" size="large" type="password" autocomplete="false"
                 placeholder="请输入密码 / 123456">
          <a-icon slot="prefix" type="lock" :style="{ color: 'rgba(0,0,0,.25)' }"/>
        </a-input>
      </a-form-model-item>
肖超群 authored
15
肖超群 authored
16
17
18
      <a-form-model-item prop="warehouseCode">
        <a-select
          show-search
19
20
          placeholder="请选择仓库!"
          option-filter-prop="label"
肖超群 authored
21
22
23
24
25
26
27
          v-model="model.warehouseCode">
          <a-select-option v-for="item in warehouseList" :key="item.name" :value="item.code">{{
              item.name
            }}
          </a-select-option>
        </a-select>
      </a-form-model-item>
28
肖超群 authored
29
30
    </a-form-model>
  </div>
肖超群 authored
31
32
33
</template>

<script>
肖超群 authored
34
35
36
37
import {getAction} from '@/api/manage'
import Vue from 'vue'
import {mapActions} from 'vuex'
import {getWarehouseByUserCode} from '@/api/api'
肖超群 authored
38
肖超群 authored
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
export default {
  name: 'LoginAccount',
  data() {
    return {
      requestCodeSuccess: false,
      randCodeImage: '',
      currdatetime: '',
      loginType: 0,
      warehouseList: {},
      querySource: {},
      model: {
        username: '',
        password: '',
        // warehouseCode: '',
        // inputCode: ''
肖超群 authored
54
      },
肖超群 authored
55
56
57
58
59
60
61
62
      validatorRules: {
        username: [
          {required: true, message: '请输入用户名!'},
          {validator: this.handleUsernameOrEmail}
        ],
        password: [{
          required: true, message: '请输入密码!', validator: 'click'
        }],
63
        warehouseCode: [{
64
          required: true, message: '请选择仓库!', trigger: "change" ,validator: 'click'
65
        }],
肖超群 authored
66
67
68
69
70
71
72
      }
    }
  },
  created() {
    this.handleChangeCheckCode();
    this.getWarehouse();
  },
73
肖超群 authored
74
75
76
77
78
79
80
81
82
83
  methods: {
    ...mapActions(['Login']),
    /**刷新验证码*/
    handleChangeCheckCode() {
      this.currdatetime = new Date().getTime();
      // this.model.inputCode = ''
      getAction(`/sys/randomImage/${this.currdatetime}`).then(res => {
        if (res.success) {
          this.randCodeImage = res.result
          this.requestCodeSuccess = true
肖超群 authored
84
        } else {
肖超群 authored
85
86
          this.$message.error(res.message)
          this.requestCodeSuccess = false
肖超群 authored
87
        }
肖超群 authored
88
89
90
91
92
93
94
95
96
97
98
99
      }).catch(() => {
        this.requestCodeSuccess = false
      })
    },


    getWarehouse() {
      const that = this;
      this.querySource.username = that.model.username;
      let obj = getWarehouseByUserCode(that.querySource);
      obj.then((res) => {
        that.warehouseList = res.result;
100
101
102
        if (this.warehouseList != null) {
          this.model.warehouseCode = this.warehouseList[0].code;
        }
肖超群 authored
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
      })
    },

    // 判断登录类型
    handleUsernameOrEmail(rule, value, callback) {
      const regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
      if (regex.test(value)) {
        this.loginType = 0
      } else {
        this.loginType = 1
      }
      callback()
    },
    /**
     * 验证字段
     * @param arr
     * @param callback
     */
    validateFields(arr, callback) {
      let promiseArray = []
      for (let item of arr) {
        let p = new Promise((resolve, reject) => {
          this.$refs['form'].validateField(item, (err) => {
            if (!err) {
              resolve();
            } else {
              reject(err);
            }
          })
        });
        promiseArray.push(p)
      }
      Promise.all(promiseArray).then(() => {
肖超群 authored
136
        callback()
肖超群 authored
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
      }).catch(err => {
        callback(err)
      })
    },
    acceptUsername(username) {
      this.model['username'] = username
    },
    //账号密码登录
    handleLogin(rememberMe) {
      this.validateFields(['username', 'password'], (err) => {
        if (!err) {
          let loginParams = {
            username: this.model.username,
            password: this.model.password,
            warehouseCode: this.model.warehouseCode,
            checkKey: this.currdatetime,
            remember_me: rememberMe,
          }
          console.log("登录参数", loginParams)
          this.Login(loginParams).then((res) => {
            this.$emit('success', res.result)
          }).catch((err) => {
            this.$emit('fail', err)
肖超群 authored
160
          });
肖超群 authored
161
162
        } else {
          this.$emit('validateFail')
肖超群 authored
163
        }
肖超群 authored
164
      })
肖超群 authored
165
166
    }
肖超群 authored
167
肖超群 authored
168
  }
肖超群 authored
169
170

}
肖超群 authored
171
172
173
174
175
</script>

<style scoped>

</style>