setPassword.vue 2.89 KB
<template>
	<v-layout id="Password" column justify-center align-center>
    <v-flex>
			<Stepper :step="stepper" />
			<div class="PasswordInputBlock">
				<input class="PasswordInput" id="PasswordInput-0" ref="0" maxlength="1" type="password" v-model="inputValue[0]" @input="passwordInput">
				<input class="PasswordInput" id="PasswordInput-1" ref="1" maxlength="1" type="password" v-model="inputValue[1]" @input="passwordInput">
				<input class="PasswordInput" id="PasswordInput-2" ref="2" maxlength="1" type="password" v-model="inputValue[2]" @input="passwordInput">
				<input class="PasswordInput" id="PasswordInput-3" ref="3" maxlength="1" type="password" v-model="inputValue[3]" @input="passwordInput">
				<input class="PasswordInput" id="PasswordInput-4" ref="4" maxlength="1" type="password" v-model="inputValue[4]" @input="passwordInput">
			</div>
			<div class="ConfirmButtonBlock" v-if="stepper === 2">
				<v-btn depressed id="ConfirmButton">确  认</v-btn>
			</div>
    </v-flex>
	</v-layout>
</template>

<script>
	import Stepper from '@/components/Stepper'
	export default {
		layout: 'lightColor',
		data: () => ({
			stepper: 1,
			password: '',
			passwordConfirm: '',
			inputValue: {
				0: '',
				1: '',
				2: '',
				3: '',
				4: '',
			}
		}),
		components: {
			Stepper
		},
		methods: {
			passwordInput(e) {
				let id = e.target.id
				let index = parseInt(id.split('-')[1])
				if (index < 4) {
					index++
					let next = this.$refs[index.toString()]
					next.focus()
				} else {
					if (this.stepper === 1) {
						this.password = this.passwordConnect()
						if (this.password !== false) {
							this.stepper++
							this.inputValue = {
								0: '',
								1: '',
								2: '',
								3: '',
								4: '',
							}
							this.$refs['0'].focus()
						}
					} else {
						this.passwordConfirm = this.passwordConnect()
					}
				}
			},
			passwordConnect() {
				let result = ''
				for (let i = 0; i < 5; i++) {
					let code = this.inputValue[i]
					if (code) {
						result += code
					} else {
						return false
					}
				}
				console.log(result)
				return result
			}
		}
	}
</script>

<style lang="scss" scoped>
	#Password {
		
		.PasswordInputBlock {
			margin-top: 2.9rem;
			text-align: center;

			.PasswordInput {
				width: 2.5rem;
				height: 2.5rem;
				line-height: 2.5rem;
				background-color: #fff;
				border: 1px solid $gold;
				outline: none;
				text-align: center;
				font-size: 1.5rem;
				margin: 0 0.75rem;
			}
		}

		.ConfirmButtonBlock {
      width: 100%;
			margin-top: 3.5rem;
			text-align: center;

      #ConfirmButton {
        color: #484646;
        background-image: linear-gradient(-213deg, #DAB269 0%, #E7C78C 92%);
        border-radius: 2px;
        width: 18.5rem;
        height: 2.8rem;
        margin: auto;
      }
    }
	}
</style>