zhaowei
2025-06-06 82066b669b0056e95d3d51d192708988f9693f61
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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
269
<template>
  <div class="login-bg">
    <div class="login-container">
      <a-card class="login-card">
        <h2 class="title">登录</h2>
 
        <a-form-model :model="model" ref="form" :rules="validateRules" @keyup.enter.native="handleLogin">
          <!-- 刷卡登录输入框 -->
          <a-form-model-item prop="workNo" :has-feedback="feedbackConfig.workNoFeedback">
            <a-input v-model="model.workNo" placeholder="请刷卡或输入卡号" size="large" autocomplete="off"
                     @change="clearAnotherLoginInfo('workNo')">
              <a-icon slot="prefix" type="credit-card"/>
            </a-input>
          </a-form-model-item>
 
          <div class="divider">
            <span class="line"></span>
            <span class="text">或</span>
            <span class="line"></span>
          </div>
 
          <!-- 常规登录表单 -->
          <a-form-model-item prop="username" :has-feedback="feedbackConfig.usernameFeedback">
            <a-input
              v-model="model.username"
              placeholder="用户名"
              size="large"
              @change="clearAnotherLoginInfo('username')"
              autocomplete="off"
            >
              <a-icon slot="prefix" type="user"/>
            </a-input>
          </a-form-model-item>
 
          <a-form-model-item prop="password" :has-feedback="feedbackConfig.passwordFeedback">
            <a-input-password
              v-model="model.password"
              placeholder="密码"
              size="large"
              @change="clearAnotherLoginInfo('password')"
              autocomplete="off"
            >
              <a-icon slot="prefix" type="lock"/>
            </a-input-password>
          </a-form-model-item>
 
          <a-button type="primary" size="large" block :loading="loading" @click="handleLogin">登录</a-button>
        </a-form-model>
        <!--<div class="footer">-->
        <!--<a @click="handleRegister">注册账号</a>-->
        <!--<a @click="handleForget">忘记密码</a>-->
        <!--</div>-->
      </a-card>
    </div>
  </div>
</template>
 
<script>
  import { mapActions } from 'vuex'
  import { timeFix } from '@/utils/util'
 
  export default {
    name: 'OperatorLogin',
    data() {
      return {
        model: {
          isOperator: true // 判断是哪个登录页登录
        },
        feedbackConfig: {
          workNoFeedback: true,
          usernameFeedback: true,
          passwordFeedback: true
        },
        loading: false,
        validateRules: {
          workNo: [
            { validator: this.checkWorkNo, trigger: 'blur' }
          ],
          username: [
            { validator: this.checkUsername, trigger: 'blur' }
          ],
          password: [
            { validator: this.checkPassword, trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      ...mapActions(['Login']),
 
      handleLogin() {
        this.$refs.form.validate(valid => {
          if (valid) {
            this.loading = true
 
            if (this.model.workNo) this.$refs.form.clearValidate(['username', 'password'])
            else this.$refs.form.clearValidate('workNo')
 
            console.log('登录信息:', this.model)
            this.model.loginType = 'terminal'
 
            this.Login(this.model)
              .then((res) => {
                this.loginSuccess(res.result)
              })
              .catch((err) => {
                this.loginFailed(err, this.model.username)
              })
          } else {
            return false
          }
        })
      },
 
      loginSuccess() {
        this.$router.push({ path: '/terminal/index' }).catch(() => {
        })
 
        this.$notification.success({
          message: '欢迎',
          description: `${timeFix()},欢迎回来`
        })
        this.loading = false
      },
 
      //登录后台失败
      loginFailed(err, username) {
        let description = ((err.response || {}).data || {}).message || err.message || '请求出现错误,请稍后再试'
 
        this.$notification.error({
          message: '登录失败',
          description: description
        })
        this.loading = false
      },
 
      /**
       * 输入框值改变时触发
       * @param inputProp 输入框对应属性
       */
      clearAnotherLoginInfo(inputProp) {
        this.feedbackConfig[inputProp + 'Feedback'] = true
 
        if (inputProp === 'workNo') {
          delete this.model.username
          delete this.model.password
          this.$refs.form.clearValidate(['username', 'password'])
        } else {
          delete this.model.workNo
          this.$refs.form.clearValidate('workNo')
        }
      },
 
      checkWorkNo(rule, value, callback) {
        if (!this.model.username && !this.model.password) {
          if (!value) {
            callback(new Error('请刷卡或输入卡号!'))
            this.feedbackConfig.usernameFeedback = this.feedbackConfig.passwordFeedback = true
          } else {
            callback()
          }
        } else {
          this.feedbackConfig.workNoFeedback = false
          callback()
        }
      },
 
      checkUsername(rule, value, callback) {
        if (!this.model.workNo) {
          if (!value) {
            callback(new Error('请输入用户名!'))
            if (!this.model.password) this.feedbackConfig.workNoFeedback = true
          } else {
            callback()
          }
        } else {
          this.feedbackConfig.usernameFeedback = false
          callback()
        }
      },
 
      checkPassword(rule, value, callback) {
        if (!this.model.workNo) {
          if (!value) {
            callback(new Error('请输入密码!'))
            if (!this.model.username) this.feedbackConfig.workNoFeedback = true
          } else {
            callback()
          }
        } else {
          this.feedbackConfig.passwordFeedback = false
          callback()
        }
      }
 
      // handleRegister() {
      //   this.$router.push('/register')
      // },
      // handleForget() {
      //   this.$message.info('请联系管理员重置密码')
      // }
    }
  }
</script>
 
<style lang="less" scoped>
  .login-bg {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
    url('../../../assets/operator-login-bg.png') no-repeat center;
    background-size: cover;
 
    .login-container {
      width: 100%;
      max-width: 420px;
      padding: 0 20px;
 
      .login-card {
        border-radius: 8px;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
        background: rgba(255, 255, 255, 0.95);
 
        .title {
          margin-bottom: 24px;
          text-align: center;
          color: #1890ff;
          font-size: 24px;
          font-weight: 500;
        }
 
        .divider {
          display: flex;
          align-items: center;
          margin: 20px 0;
 
          .line {
            flex: 1;
            height: 1px;
            background: rgba(0, 0, 0, 0.15);
          }
 
          .text {
            padding: 0 16px;
            color: rgba(0, 0, 0, 0.45);
          }
        }
 
        .footer {
          display: flex;
          justify-content: space-between;
          margin-top: 16px;
 
          a {
            color: #1890ff;
            cursor: pointer;
 
            &:hover {
              text-decoration: underline;
            }
          }
        }
      }
    }
 
  }
</style>