reset-pwd.vue 4.32 KB
<template>
	<view class="list">
		<view class="my-info">
			<view class="item">
				<view class="u-f content u-f-aic">
					<view class="u-f1">
						当前密码
					</view>
					<view class="u-f3 common">
						<input type="text" :password="!showCurrPass" v-model="form.oldPassword" />
					</view>
					<view class="eye">
						<uni-icons type="eye-filled" size="24" :color="curr" @tap="showCurr(curr)"></uni-icons>
					</view>
				</view>
			</view>
			<view class="item">
				<view class="u-f content u-f-aic">
					<view class="u-f1">
						新密码
					</view>
					<view class="u-f3 common">
						<input type="text" :password="!showNewPass" v-model="form.newPassword" />
					</view>
					<view class="eye">
						<uni-icons type="eye-filled" size="24" :color="newPass" @tap="showNew(newPass)"></uni-icons>
					</view>
				</view>
			</view>
			<view class="item last">
				<view class="u-f content u-f-aic">
					<view class="u-f1">
						确认密码
					</view>
					<view class="u-f3 common">
						<input type="text" :password="!showConPass" v-model="confirmPassword" />
					</view>
					<view class="eye">
						<uni-icons type="eye-filled" size="24" :color="confirm" @tap="showConfirm(confirm)"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="line"></view>
		<view class="footer">
			<button class="btn" type="primary" @tap="save">确定</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					oldPassword: '',
					newPassword: '',
				},
				confirmPassword: '',
				curr: 'gray',
				newPass: 'gray',
				confirm: 'gray',
				showCurrPass: false,
				showNewPass: false,
				showConPass: false,

			}
		},
		methods: {
			showCurr(curr) {
				this.showCurrPass = !this.showCurrPass;
				if (curr == 'gray') {
					this.curr = 'rgb(0, 122, 255)'
				} else {
					this.curr = 'gray'
				}

			},
			showNew(newPass) {
				this.showNewPass = !this.showNewPass;
				if (newPass == 'gray') {
					this.newPass = 'rgb(0, 122, 255)'
				} else {
					this.newPass = 'gray'
				}

			},
			showConfirm(confirm) {
				this.showConPass = !this.showConPass;
				if (confirm == 'gray') {
					this.confirm = 'rgb(0, 122, 255)'
				} else {
					this.confirm = 'gray'
				}

			},
			save() {
				if (!this.form.oldPassword.trim()) {
					uni.showModal({
						title: '提示',
						content: '请输入当前密码!',
						showCancel: false
					});
					return
				}
				if (!this.form.newPassword.trim()) {
					uni.showModal({
						title: '提示',
						content: '请输入新密码!',
						showCancel: false
					});
					return
				}
				if (!this.confirmPassword.trim()) {
					uni.showModal({
						title: '提示',
						content: '请输入确认密码!',
						showCancel: false
					});
					return
				}
				if (this.form.newPassword.trim() !== this.confirmPassword.trim()) {
					uni.showModal({
						title: '提示',
						content: '新密码和确认密码不一致,请确认!',
						showCancel: false
					});
					return
				}

				this.$api.user.updatePassword(this.form.oldPassword, this.form.newPassword).then(res => {

					if (res.data.code == 200) {
						uni.showModal({
							title: '提示',
							content: '密码修改成功,为了安全,需要重新登录!',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '../login/login'
									})
								}
							}
						})
					} else {
						uni.showModal({
							title: '提示',
							content: res.data.msg
						})
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.list {
		position: fixed;
		width: 100%;

		.my-info {
			margin-top: $uni-spacing-col-base;
			padding-left: $uni-spacing-row-base;
			background-color: $uni-bg-color;
			font-size: $uni-font-size-lg;

			.item {
				height: 90rpx;
				line-height: 90rpx;
				border-bottom: 2rpx solid $uni-border-color;

				.content {
					padding: 0 $uni-spacing-row-base;

					.common {
						text-align: right;
					}

					.eye {
						margin-left: $uni-spacing-row-base;
					}
				}
			}

			.last {
				border-bottom: none;
			}

		}

		.line {
			border-top: 2rpx solid $uni-border-color;
		}

		.footer {
			margin-top: 50rpx;
			padding: 0 50rpx;

			.btn {
				height: 80rpx;
				line-height: 80rpx;
				border-radius: 50rpx;
				font-size: 36rpx;

			}
		}
	}
</style>