YM
2024-05-27 0edf94722a0dcc338567fec7df76b2e0acd39b92
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
270
271
272
273
274
275
276
277
278
<template>
    <view>
        <el-card :style="{width: width + 'px'}">
            <view  style="display: flex; justify-content: space-between;">
                <h2 style="color: #244a7b;padding-bottom: 20rpx;">{{title}}</h2>
                <view  v-if="BackLoginTrue" style="cursor: pointer;font-size: 20rpx;color: #244a7b;">
                    {{BackLogin}}
                </view>
            </view>
            <el-form :hide-required-asterisk="true" ref="loginForm" :label-position="BackLoginTrue ? 'left' : 'top'"
                label-width="80px" :rules="getDynamicRules" :model="formData">
                <el-form-item class="ssss" v-for="(item,index) in internalData.formData" :key="item.id"
                    :prop="item.id" :label="item.lable">
                    <el-input   type="password" class="aaa" :data-index="index" autocomplete="off"
                        v-if="item.type == 'pass'||item.type == 'affirmPass'" v-model="item.val"></el-input>
                    <el-input class="aaa" v-else v-model="item.val"></el-input>
                </el-form-item>
                <el-form-item class="btn">
                    <el-button class="font-family"
                        style="margin-top: 30rpx; font-weight:900;font-size: 30rpx; width: 100%;background-color: #244a7b;color: #fff;padding: 30rpx;"
                        size="medium" @click="Login">登录</el-button>
                </el-form-item>
                <view 
                    style="font-size: 18rpx;color: #9E9E9E;text-align: center;line-height: 1;margin-bottom: 20rpx;">
                    用户注册即代表同意《服务条款》和《用户隐私保护和个人信息条款》</view>
                <!-- 登录时 忘记密码/快速注册   -->
                <view  v-if="loginTrue" style="display: flex;font-size: 20rpx;" :style="{color:color}">
                    <view  style="display: inline-block;cursor: pointer;" @click="forgetPass">忘记密码</view>
                    <view  style="display: inline-block;margin: 0 20rpx;"> | </view>
                    <view  style="display: inline-block;cursor: pointer;" @click="quickRegister">快速注册</view>
                </view>
            </el-form>
        </el-card>
    </view>
</template>
 
<script>
    export default {
        props: {
            title: {
                type: String,
                default () {
                    return "用户注册"
                }
            },
            BackLogin: {
                type: String,
                default () {
                    return " 已有账号?返回登录"
                }
            },
            // 上下排列
            BackLoginTrue: {
                type: Boolean,
                default () {
                    return true
                }
            },
            color: {
                type: String,
                default () {
                    return "#244a7b"
                }
            },
            // 用户登录时
            loginTrue: {
                type: Boolean,
                default () {
                    return false
                }
            },
            // 用户注册时
            Register: {
                type: Boolean,
                default () {
                    return false
                }
            },
            width: {
                type: Number,
                default () {
                    return 400;
                },
            },
            // data数据
            formData: {
                type: Object,
                default () {
                    return {
                        formData: [{
                                lable: '登录',
                                id: 1,
                                val: '',
                                type: '',
                            },
                            {
                                lable: '登录1',
                                id: 2,
                                val: 'sdwwwf',
                                type: 'pass',
                            },
                        ],
                    };
                },
            },
        },
        watch: {
            formData: {
                deep: true,
                handler(a, b) {
                    if (this.dataIndex != null) {
                        this.InputElem(this.dataIndex)
                    }
                },
            },
        },
        computed: {
            getDynamicRules() {
                const dynamicRules = {};
                this.formData.formData.forEach((item) => {
                    item.id = String(item.id);
                    dynamicRules[item.id] = [];
                    // 是密码 F
                    if (item.type == 'pass' || item.type == "affirmPass") {
                        dynamicRules[item.id].push({
                            required: true,
                            message: '请输入' + item.lable,
                            trigger: ['blur', 'change']
                        });
                        dynamicRules[item.id].push({
                            min: 3,
                            max: 5,
                            message: '长度在 3 到 5 个字符',
                            trigger: ['blur', 'change']
                        });
                        // 手机号或邮箱
                    } else if (item.type == 'cellphoneORmailbox') {
                        dynamicRules[item.id].push({
                            required: true,
                            message: '请输入' + item.lable,
                            trigger: ['blur', 'change']
                        }, )
                        // 所有不是的走
                    } else {
                        dynamicRules[item.id].push({
                            required: true,
                            message: '请输入' + item.lable,
                            trigger: ['blur', 'change']
                        });
                    }
                });
                return dynamicRules;
            },
        },
        methods: {
            // 登录跳转
            Login() {
                // 将数据修改成一个对象返回出去
                const result = this.formData.formData.reduce((obj, item) => {
                    obj[item.name] = item.val
                    return obj
                }, {})
                this.$emit('Login', result)
            },
            // 忘记密码
            forgetPass() {
 
            },
            // 快速注册
            quickRegister() {
 
            },
            handleInputChange(event, index) {
                this.dataIndex = index
            },
            handleBlur(index) {
                // this.InputElem(index)
            },
            InputElem(index) {
                // 找到输入框元素
                var inputElement = document.querySelectorAll('.aaa input')[index];
 
                if (inputElement.value.trim() === '') {
                    // 如果值为空,将边框颜色设为黑色
                    inputElement.style.borderColor = 'red';
                    setTimeout(() => {
                        this.$nextTick(() => {
                            inputElement.parentNode.nextElementSibling.style.display = "block"
                        })
                    }, 0)
                } else {
                    // 如果有值,保持原本的样式(这里可以根据需求设置其他样式)
                    inputElement.style.borderColor = '#2d476a';
                    setTimeout(() => {
                        this.$nextTick(() => {
                            inputElement.parentNode.nextElementSibling.style.display = "none"
                        })
                    }, 0)
                }
                // 监听输入框的 blur 事件
                inputElement.addEventListener('blur', function() {
                    // 描述问题
                    // var inputerror = document.querySelectorAll('.ssss .el-form-item__error')[index];
 
                    // // 可以根据需要继续添加其他需要重置的样式
                    if (inputElement.value.trim() === '') {
                        // 如果值为空,将边框颜色设为黑色
                        inputElement.style.borderColor = 'red';
                        // inputerror.style.display = 'block';
                        setTimeout(() => {
                            inputElement.parentNode.nextElementSibling.style.display = "block"
                        }, 0)
                    } else {
                        // 如果有值,保持原本的样式(这里可以根据需求设置其他样式)
                        inputElement.style.borderColor = '#2d476a';
                        setTimeout(() => {
                            inputElement.parentNode.nextElementSibling.style.display = "none"
                        }, 0)
                    }
                });
                // 监听输入框的 focus 事件
                inputElement.addEventListener('focus', function() {
                    inputElement.style.borderColor = '#2d476a';
                });
 
            }
 
        },
        data() {
 
            return {
                dataIndex: null,
                internalData: this.formData,
                formValueData: {}
            };
        }
    };
</script>
 
<style scoped>
    * {
        box-sizing: border-box;
    }
 
    .btn>>>.el-form-item__content {
        margin-left: 0 !important;
    }
 
    ::v-deep .el-input__inner {
        border: none;
        border-bottom: 1px solid #2d476a;
        border-radius: 0;
    }
 
    ::v-deep .el-form-item__error {
        /* display: none; */
    }
 
    ::v-deep .input.invalid:focus {
        border-color: #2d476a !important;
    }
 
    ::v-deep .el-input__inner:invalid {
        border-color: #2d476a !important;
    }
 
    ::v-deep .el-form-item__label {
        padding: 0;
    }
 
    ::v-deep .el-form-item__label {
        color: #2d476a;
    }
 
    ::v-deep .el-form-item {
        margin-bottom: 32rpx;
    }
</style>