zuozhengqing
2024-02-05 7be007bd93ae0ec6eee9b0931f8a1de98123889d
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
<template>
  <div class="box_wrap">
    <el-card class="box-card">
      <div class="card-top">
        <img src="@/assets/images/logo.png" />
      </div>
      <p>智能报工系统</p>
      <div class="card_bottom">
        <el-form ref="ruleFormRef" :model="ruleForm" status-icon :rules="rules" label-width="25%" class="demo-ruleForm">
          <el-form-item label="" prop="accountNumber">
            <el-input v-model.number="ruleForm.accountNumber" style="width: 70%" placeholder="用户名" />
          </el-form-item>
          <el-form-item label="" prop="pass">
            <el-input
              v-model="ruleForm.pass"
              style="width: 70%"
              placeholder="密码"
              type="password"
              autocomplete="off"
            />
          </el-form-item>
          <!-- <el-form-item label="确认密码" prop="checkPass">
            <el-input v-model="ruleForm.checkPass" type="password" autocomplete="off" />
          </el-form-item> -->
          <el-form-item>
            <el-button type="primary" @click="submitForm(ruleFormRef)">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>
 
<script setup lang="ts">
import { ref, reactive } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
 
const ruleFormRef = ref<FormInstance>()
 
const checkAge = (rule: any, value: any, callback: any) => {
  if (!value) {
    return callback(new Error('请输入用户名'))
  } else {
    callback()
  }
}
 
const validatePass = (rule: any, value: any, callback: any) => {
  if (value === '') {
    callback(new Error('请输入密码'))
  } else {
    callback()
  }
}
// const validatePass2 = (rule: any, value: any, callback: any) => {
//   if (value === '') {
//     callback(new Error('Please input the password again'))
//   } else if (value !== ruleForm.pass) {
//     callback(new Error("Two inputs don't match!"))
//   } else {
//     callback()
//   }
// }
 
const ruleForm = reactive({
  pass: '',
  // checkPass: '',
  accountNumber: ''
})
 
const rules = reactive<FormRules<typeof ruleForm>>({
  pass: [{ validator: validatePass, trigger: 'blur' }],
  // checkPass: [{ validator: validatePass2, trigger: 'blur' }],
  accountNumber: [{ validator: checkAge, trigger: 'blur' }]
})
 
const submitForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.validate((valid) => {
    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!')
      return false
    }
  })
}
</script>
<style scoped lang="less">
// ::v-deep body {
//   background: #fff;
// }
 
.box_wrap {
  width: 100%;
  min-height: 100vh;
  background-image: url('@/assets/images/loginBackground.png');
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
 
  .box-card {
    width: 30%;
    margin: 0 auto;
    height: 500px;
    border-radius: 15px;
 
    .card-top {
      text-align: center;
 
      img {
        width: 160px;
        height: 120px;
      }
    }
 
    p {
      text-align: center;
      color: #315bac;
      font-size: 24px;
      margin-bottom: 20px;
    }
 
    .card_bottom {
      .el-form {
        .el-form-item {
          .el-form-item__error {
            margin-left: 260px;
          }
 
          .el-input {
            .el-input__wrapper {
              padding-left: 50px;
            }
          }
 
          .el-button {
            width: 70%;
          }
        }
      }
    }
  }
}
 
::v-deep .el-form-item__content {
  display: flex;
  align-items: center;
  // justify-content: center;
}
</style>