<style lang="scss"> .container{ background:#f6f6f6; min-height:100%; .card{ padding-bottom:100rpx; input{ background:#F7F7F7; height:80rpx; border-radius: 24rpx; font-size:25rpx; padding:0 28rpx; &+input{ margin-top:28rpx; } } } } </style> <template> <view class="container"> <d-navbar text="修改密码" isBack style="--bg:#10C176;--c:#fff;"> <button slot="right" class="cu-btn round" @click="submit">保存</button> </d-navbar> <view class="card"> <input placeholder="请输入旧密码" type="password" v-model="formData.oldpassword"/> <input placeholder="请输入新密码(6-20位字母和数字的组合)" type="password" v-model="formData.password"/> <input placeholder="再次输入新密码" type="password" v-model="formData.confirmpassword"/> </view> </view> </template> <script> import request from '@/common/request' export default{ data(){ return{ formData:{ confirmpassword: "", password: "", oldpassword:"", username: this.$store.getters['userInfo'].username, } } }, methods:{ check(){ if(!this.formData.oldpassword){ uni.showToast({title:"请输入旧密码!",icon:"none"}) return false }else if(!this.formData.password){ uni.showToast({title:"请输入密码!",icon:"none"}) return false }else if(!/^(?=.*\d)(?=.*[a-zA-Z])(?=.*[^\da-zA-Z\s]).+$/.test(this.formData.password)){ uni.showToast({title:"密码格式为6-20位字母和数字的组合!",icon:"none"}) return false }else if(this.formData.confirmpassword!=this.formData.password){ uni.showToast({title:"输入密码不一致!",icon:"none"}) return false } return true }, async submit(){ if(this.check()){ var res=await request("/sys/user/updatePassword",{ method:"put", body: this.formData }) if(res.statu){ uni.navigateBack() }else{ uni.showModal({ title:"提示", content:res.msg||"修改失败!", showCancel:false, }) } } }, } } </script>