| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | <template>	<view class=" pwd-retrieve-container my-page">		<form>			<view class="uni-form-item uni-row">				<view class="title">旧密码</view>				<input :class="'uni-input '+oldPassword" name="oldPassword" :password="true" :value="user.oldPassword"					placeholder="请输入旧密码" @focus="inputFocus('oldPassword')" @blur="inputBlur('oldPassword')"					@input="inputOld" />			</view>			<view class="uni-form-item uni-row">				<view class="title">新密码</view>				<input :class="'uni-input '+newPassword" name="newPassword" :password="true" :value="user.newPassword"					placeholder="请输入新密码" @focus="inputFocus('newPassword')" @blur="inputBlur('newPassword')"					@input="inputNew" />			</view>			<view class="uni-form-item uni-row">				<view class="title">确认密码</view>				<input :class="'uni-input '+confirmPassword" name="confirmPassword" :password="true"					:value="user.confirmPassword" placeholder="请确认新密码" @focus="inputFocus('confirmPassword')"					@blur="inputBlur('confirmPassword')" @input="inputConfirm" />			</view>			<button type="primary" @click="submit">提交</button>		</form>	</view></template><script lang="uts">	import { updateUserPwd } from "@/api/system/user"	import { updateData, getList } from '@/api/work';	import { getCurrentUserSync, getCurrentUserNameSync } from '@/utils/auth.uts'		type User = {		oldPassword : string | null,		newPassword : string | null,		confirmPassword : string | null	}	export default {		data() {			return {				oldPassword: '',				newPassword: '',				confirmPassword: '',				user: {					oldPassword: null,					newPassword: null,					confirmPassword: null				} as User,			}		},		methods: {			inputFocus(tag : string) {				this.$data[tag] = "my-focus"			},			inputBlur(tag : string) {				this.$data[tag] = "my-blur"			},			inputOld(event : UniInputEvent) {				this.user.oldPassword = event.detail.value			},			inputNew(event : UniInputEvent) {				this.user.newPassword = event.detail.value			},			inputConfirm(event : UniInputEvent) {				this.user.confirmPassword = event.detail.value			},			submit() {				if (this.user.oldPassword == null) {					uni.showToast({						title: "旧密码不能为空",						icon: "error"					})					return				}				if (this.user.newPassword == null) {					uni.showToast({						title: "新密码不能为空",						icon: "error"					})					return				} else if (this.user.newPassword != null && (this.user.newPassword.length < 6 || this.user.newPassword.length > 20)) {					uni.showToast({						title: "长度在6到20个字符",						icon: "error"					})					return				}				if (this.user.oldPassword == this.user.newPassword) {					uni.showToast({						title: "新旧密码不能相同",						icon: "error"					})					return				}				if (this.user.confirmPassword == null) {					uni.showToast({						title: "确认密码不能为空",						icon: "error"					})					return				} else if (this.user.confirmPassword != this.user.newPassword) {					uni.showToast({						title: "两次输入的密码不一致",						icon: "error"					})					return				}				let username = '';				let oldPassword = '';				getList('app_user', 'username', getCurrentUserNameSync(), null, null, null).then((res : UTSJSONObject) => {					let userList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>();					console.log(userList);					if (userList != null && userList.length > 0) {						let user = userList[0];						username = user.getString('username') ?? '';						oldPassword = user.getString('password') ?? '';					}					// 添加逻辑判断:验证原密码是否匹配					if (oldPassword == this.user.oldPassword) {						let updatedData = "password='" + this.user.confirmPassword + "' ";						updateData('app_user', updatedData, 'username', username).then((res : UTSJSONObject) => {							let data = res?.['data'] as boolean ?? false;							if (data != null && data == true) {								uni.showToast({									title: "更新成功!",								});								setTimeout(() => {																}, 1500)								uni.reLaunch({								  url: '/pages/mine/index'								});							} else {								uni.showToast({									title: "更新失败,请稍后重试!",									icon: "error"								});							}						});					} else {						uni.showToast({							title: "更新失败,原密码不匹配!",							icon: "error"						});					}				});			}		}	}</script><style lang="scss">	.my-page {		background-color: #ffffff;		width: 100%;		height: 100%;	}	.pwd-retrieve-container {		padding-top: 36rpx;		padding: 15px;	}</style>
 |