优化代码

This commit is contained in:
pengxiaolong
2025-08-06 20:48:39 +08:00
parent 40c3282515
commit 0a721e99f8
54 changed files with 1252 additions and 205 deletions

View File

@@ -62,9 +62,7 @@
<view class="Nickname" @click="modifyPassword">
<view class="avatarmodify-item">密码</view>
<view class="NicknameInput">
<view class="NicknameInput-name">{{
havaPassword ? "" : "未设置"
}}</view>
<view class="NicknameInput-name">{{ havaPassword == true ? "" : "未设置" }}</view>
<image
class="more"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/More.png"
@@ -108,34 +106,52 @@ export default {
};
},
onLoad(option) {
uni.getStorage({
key: "userinfo",
success: (res) => {
this.id = res.data.id;
this.name = res.data.nickName;
this.userinfo = this.useravatar = res.data.headerIcon;
this.email = res.data.email;
this.havaPassword = res.data.havaPassword;
},
});
this.id = option.id;
this.getUserInfo();
},
onShow() {
uni.getStorage({
key: "userinfo",
success: (res) => {
this.id = res.data.id;
this.name = res.data.nickName;
this.userinfo = this.useravatar = res.data.headerIcon;
this.email = res.data.email;
this.havaPassword = res.data.havaPassword;
},
});
this.getUserInfo();
},
methods: {
//获取个人信息
getUserInfo() {
request({
url: "user/getUserInfo",
method: "POST",
data: {
id: this.id,
},
userInfo: true,
}).then((res) => {
if (res.code == 200) {
this.userinfo = res.data;
uni.setStorageSync("userinfo", res.data);
setTimeout(() => {
uni.getStorage({
key: "userinfo",
success: (res) => {
this.id = res.data.id;
this.name = res.data.nickName;
this.userinfo = this.useravatar = res.data.headerIcon;
this.email = res.data.email;
this.havaPassword = res.data.havaPassword;
},
});
}, 300);
} else {
console.log(res.msg);
}
});
},
//修改密码
modifyPassword() {
uni.navigateTo({
url: "/pages/Setting/settingmod/changePassword?id=" + this.id,
url:
"/pages/Setting/settingmod/changePassword?id=" +
this.id +
"&havaPassword=" +
this.havaPassword,
});
},
// 修改邮箱
@@ -166,24 +182,25 @@ export default {
userId: this.id,
},
userInfo: true,
}).then((res) => {
if (res.code === 200) {
uni.showToast({
title: "登录成功",
icon: "success",
});
}else{
uni.showToast({
title: res,
icon: "none",
});
}
})
.then((res) => {
if (res.code === 200) {
uni.showToast({
title: "登录成功",
icon: "success",
});
} else {
uni.showToast({
title: res,
icon: "none",
});
}
})
.catch((err) => {
uni.showToast({
title: "登录失败",
icon: "none",
})
icon: "none",
});
});
}
// 其他类型暂不处理

View File

@@ -18,8 +18,28 @@
<view class="contentbox">
<view class="content">
<!-- -->
<input
type="email"
class="weui-input"
placeholder="请输入邮箱号"
v-model="email"
/>
<text class="error" v-if="turnsoutemail == ''">第一次填写邮箱时请确保填写正确的邮箱地址填写错误请联系客服</text>
<text class="error" v-if="error">请输入正确的邮箱地址</text>
<view v-if="turnsoutemail != ''" class="Verificationcodebox">
<input
type="text"
class="weui-input"
placeholder="验证码"
v-model="Verificationcode"
/>
<view class="Verificationcodebtn" @click="sendVerificationCode">获取验证码</view>
</view>
<text v-if="VerificationcodeSent && turnsoutemail != ''" class="VerificationcodeSent">验证码已发送至{{turnsoutemail}}邮箱请注意查收</text>
<!-- -->
<view class="btn" @click="onSubmit">确认</view>
<text class="forget" @click="onCustomerService">忘记邮箱请联系客服</text>
<!-- -->
</view>
</view>
@@ -27,17 +47,171 @@
</template>
<script>
import request from "../../../components/request.js";
import { goEasylogin, goEasylogout } from "../../../components/goEasyTool/tool.js";
export default {
data() {
return {
title: "Hello",
email: "",//邮箱
Verificationcode: "",//验证码
id: "",//用户id
error: false,//邮箱错误
VerificationcodeSent: false,//验证码是否已发送
turnsoutemail:'',//修改前的邮箱
};
},
onLoad() {
// 页面加载时执行
onLoad(options) {
this.turnsoutemail = this.email = options.email == "null" ? "" : options.email;
this.id = options.id;
},
methods: {
// 返回上一页
//提交验证
onSubmit() {
if (this.turnsoutemail == "") {
this.setEmail()
}else{
this.hasEmail()
}
},
//有邮箱修改
hasEmail() {
if (!this.validateEmail(this.email)) {
this.error = true;
return;
}
uni.showLoading({
title: "修改中...",
mask: true,
});
request({
url: "user/updateUserMail",
method: "POST",
data: {
code: this.Verificationcode,
mailAddress: this.email,
},
userInfo: true,
})
.then((ress) => {
console.log("修改调用返回", ress);
if (ress.code === 200) {
uni.hideLoading();
uni.showToast({
title: "修改成功,请到您的邮箱进行验证激活",
duration: 5000,
icon: "none",
});
//```````````````````````````````````````````````````````````````````````登录成功后跳转回原页面 或 首页
setTimeout(() => {
uni.navigateBack({
delta: 1,
});
}, 5000);
//````````````````````````````````````````````````````````````````````
} else {
uni.hideLoading();
uni.showToast({
title: ress.msg,
icon: "none",
});
}
})
.catch((err) => {
console.log("修改调用失败", err);
uni.hideLoading();
uni.showToast({
title: "修改失败",
icon: "none",
});
});
},
//发送验证码
sendVerificationCode() {
request({
url: "user/sendUpdateMailConfirmMail",
method: "POST",
data: {
mailAddress: this.email,
},
userInfo: true,
}).then((ress) => {
this.VerificationcodeSent = true;
});
},
//第一次提交
setEmail() {
if (!this.validateEmail(this.email)) {
this.error = true;
return;
}
uni.showLoading({
title: "修改中...",
mask: true,
});
goEasylogout(this.$goeasy);
request({
url: "user/updateUserInfo",
method: "POST",
data: {
id: this.id,
email: this.email,
},
userInfo: true,
})
.then((ress) => {
console.log("修改调用返回", ress);
if (ress.code === 200) {
uni.hideLoading();
uni.showToast({
title: "修改成功,请到您的邮箱进行验证激活",
duration: 5000,
icon: "none",
});
uni.setStorageSync("userinfo", ress.data);
goEasylogin(
this.$goeasy,
String(ress.data.id),
ress.data.headerIcon,
ress.data.nickName
);
//```````````````````````````````````````````````````````````````````````登录成功后跳转回原页面 或 首页
setTimeout(() => {
uni.navigateBack({
delta: 1,
});
}, 5000);
//````````````````````````````````````````````````````````````````````
} else {
uni.hideLoading();
uni.showToast({
title: ress.msg,
icon: "none",
});
}
})
.catch((err) => {
console.log("修改调用失败", err);
uni.hideLoading();
uni.showToast({
title: "修改失败",
icon: "none",
});
});
},
//邮箱验证
validateEmail(email) {
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return regex.test(email);
},
//联系客服
onCustomerService() {
uni.navigateTo({
url: "/pages/Mine/minecomponents/contact",
})
},
//返回上一页
onBack() {
wx.navigateBack({
delta: 1,
@@ -97,4 +271,56 @@ export default {
flex-direction: column;
align-items: center;
}
.weui-input {
width: 90%;
height: 80rpx;
margin-top: 40rpx;
border-bottom: 1px solid #ccc;
}
.Verificationcodebox {
width: 90%;
height: 80rpx;
margin-top: 40rpx;
display: flex;
align-items: center;
}
.Verificationcodebtn {
width: 30%;
height: 100%;
margin-bottom: -40rpx;
background-color: #e6e6e6;
color: #ffffff;
font-size: 24rpx;
line-height: 40rpx;
background-color: #00afb2;
text-align: center;
line-height: 80rpx;
}
.VerificationcodeSent{
color: #00afb2;
font-size: 24rpx;
margin-top: 40rpx;
}
.btn {
width: 80%;
height: 80rpx;
margin-top: 150rpx;
background: linear-gradient(135deg, #00afb2, #4fcacd);
color: #fff;
text-align: center;
line-height: 80rpx;
border-radius: 40rpx;
font-size: 30rpx;
border: none;
cursor: pointer;
}
.error {
color: red;
font-size: 20rpx;
}
.forget{
font-size: 24rpx;
color: #00afb2;
margin-top: 50rpx;
}
</style>

View File

@@ -174,7 +174,7 @@ export default {
width: 80%;
height: 80rpx;
margin-top: 50rpx;
background-color: #00b4ff;
background: linear-gradient(135deg, #00afb2, #4fcacd);
color: #fff;
text-align: center;
line-height: 80rpx;

View File

@@ -17,25 +17,308 @@
<view class="title">修改密码</view>
<view class="contentbox">
<view class="content">
<!-- -->
<!-- 旧密码输入框 -->
<view class="uni-input-wrapper" v-if="havaPassword">
<input
class="uni-input"
v-model="oldPassword"
placeholder="请输入旧密码"
:password="showoldPassword"
/>
<view>
<img
class="passwordImg"
@click="changeoldPassword"
:src="
showoldPassword
? 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Displaypassword.png'
: 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/notdisplaypassword.png'
"
alt=""
/>
</view>
</view>
<text v-if="havaPassword" class="error">您的密码必须包含大小字母和数字长度在6-16位之间</text>
<text v-if="oldPasswordError == true && havaPassword == true" class="error-text">请输入正确的旧密码</text>
<!-- 新密码输入框 -->
<view class="uni-input-wrapper">
<input
class="uni-input"
v-model="newPassword"
placeholder="请输入新密码"
:password="shownewPassword"
/>
<view>
<img
class="passwordImg"
@click="changenewPassword"
:src="
shownewPassword
? 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Displaypassword.png'
: 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/notdisplaypassword.png'
"
alt=""
/>
</view>
</view>
<text class="error">您的密码必须包含大小字母和数字长度在6-16位之间</text>
<text v-if="newPasswordErrorone" class="error-text">请输入合法的密码</text>
<text v-if="newPasswordErrortwo" class="error-text">新密码和旧密码不能相同</text>
<!-- 新密码输入框 -->
<view class="uni-input-wrapper">
<input
class="uni-input"
v-model="confirmPassword"
placeholder="请重复输入新密码"
:password="showconfirmPassword"
/>
<view>
<img
class="passwordImg"
@click="changeconfirmPassword"
:src="
showconfirmPassword
? 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Displaypassword.png'
: 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/notdisplaypassword.png'
"
alt=""
/>
</view>
</view>
<text v-if="confirmPasswordError" class="error-text"
>请确认两次输入的密码是否一致</text
>
<!-- 确认按钮 -->
<view class="confirmBtn" @click="onConfirm"> 确认修改 </view>
<!-- -->
<!-- 忘记密码 -->
<view class="forgetPassword">
<text class="forgetPasswordText" @click="onforgetPassword">忘记密码</text>
</view>
</view>
</view>
</view>
</template>
<script>
import { goEasylogin, goEasylogout } from "../../../components/goEasyTool/tool.js";
import request from "../../../components/request.js";
export default {
data() {
return {
title: "Hello",
oldPassword: "", //旧密码
newPassword: "", //新密码
confirmPassword: "", //确认密码
showoldPassword: true, //旧密码是否显示
shownewPassword: true, //新密码是否显示
showconfirmPassword: true, //确认密码是否显示
oldPasswordError: false, //旧密码错误
newPasswordErrorone: false, //新密码错误
newPasswordErrortwo: false, //新密码错误
confirmPasswordError: false, //确认密码错误
id: "", //用户id
havaPassword: null, //是否有密码/false无密码/true有密码
email: "", //邮箱
};
},
onLoad() {
// 页面加载时执行
uni.getStorage({
key: "userinfo",
success: (res) => {
this.id = res.data.id;
this.havaPassword = res.data.havaPassword;
console.log(this.id, this.havaPassword);
this.email = res.data.email;
},
});
},
onShow() {
uni.getStorage({
key: "userinfo",
success: (res) => {
this.id = res.data.id;
this.havaPassword = res.data.havaPassword;
console.log(this.id, this.havaPassword);
this.email = res.data.email;
},
});
},
methods: {
// 忘记密码
onforgetPassword() {
if (this.email === ""||this.email === null) {
uni.showToast({
title: "请先绑定邮箱再进行操作",
icon: "none",
duration: 2000,
});
return;
}
request({
url: "user/forgetMail",
method: "POST",
data: {
mailAddress: this.email,
},
userInfo: true,
}).then((ress) => {
if (ress.code === 200) {
uni.showToast({
title: "已向您的"+this.email+"邮箱发送密码重置邮件,请在邮箱中进行密码重置",
icon: "success",
duration: 5000,
});
}else{
uni.showToast({
title: ress.data,
icon: "none",
duration: 2000,
});
}
}).catch(() => {
uni.showToast({
title: '网络错误',
icon: "none",
duration: 2000,
});
});
},
// 验证密码合法性
validatePassword(password) {
const regex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)[A-Za-z\d]{6,16}$/;
return regex.test(password);
},
// 确认修改
onConfirm() {
this.oldPasswordError = false;
this.newPasswordErrorone = false;
this.newPasswordErrortwo = false;
this.confirmPasswordError = false;
if (this.email === ""||this.email === null) {
uni.showToast({
title: "请先绑定邮箱再进行操作",
icon: "none",
duration: 2000,
});
return;
}
if (this.oldPassword === "" && this.havaPassword == true) {
this.oldPasswordError = true;
return;
}
if (this.validatePassword(this.oldPassword) === false && this.havaPassword == true) {
this.oldPasswordError = true;
return;
}
if (this.validatePassword(this.newPassword) === false) {
this.newPasswordErrorone = true;
return;
}
if (this.newPassword === "") {
this.newPasswordErrorone = true;
return;
}
if (this.newPassword === this.oldPassword) {
this.newPasswordErrortwo = true;
return;
}
if (this.confirmPassword !== this.newPassword) {
this.confirmPasswordError = true;
return;
}
if (this.havaPassword) {
uni.showLoading({
title: "修改中...",
mask: true,
});
goEasylogout(this.$goeasy);
request({
url: "user/updateUserInfo",
method: "POST",
data: {
id: this.id,
newPassword: this.newPassword,
confirmPassword: this.confirmPassword,
oldPassword: this.oldPassword,
},
userInfo: true,
}).then((ress) => {
console.log("修改调用返回", ress);
if (ress.code === 200) {
uni.showToast({
title: "修改成功",
icon: "success",
});
uni.setStorageSync("userinfo", ress.data);
goEasylogin(
this.$goeasy,
String(ress.data.id),
ress.data.headerIcon,
ress.data.nickName
);
uni.hideLoading();
//```````````````````````````````````````````````````````````````````````登录成功后跳转回原页面 或 首页
uni.navigateBack({
delta: 1,
});
//````````````````````````````````````````````````````````````````````
} else {
uni.hideLoading();
uni.showToast({
title: ress.data,
icon: "none",
});
}
});
} else {
uni.showLoading({
title: "修改中...",
mask: true,
});
request({
url: "user/setPassword",
method: "POST",
data: {
id: this.id,
password: this.newPassword,
confirmPassword: this.confirmPassword,
},
userInfo: true,
}).then((ress) => {
console.log("修改调用返回", ress);
if (ress.code === 200) {
uni.showToast({
title: "修改成功",
icon: "success",
});
uni.hideLoading();
//```````````````````````````````````````````````````````````````````````登录成功后跳转回原页面 或 首页
uni.navigateBack({
delta: 1,
});
//````````````````````````````````````````````````````````````````````
} else {
uni.hideLoading();
uni.showToast({
title: ress.data,
icon: "none",
});
}
});
}
},
//新密码显示/隐藏
changenewPassword() {
this.shownewPassword = !this.shownewPassword;
},
// 确认密码显示/隐藏
changeconfirmPassword() {
this.showconfirmPassword = !this.showconfirmPassword;
},
// 旧密码显示/隐藏
changeoldPassword() {
this.showoldPassword = !this.showoldPassword;
},
// 返回上一页
onBack() {
console.log(1);
@@ -97,4 +380,53 @@ export default {
flex-direction: column;
align-items: center;
}
.uni-input-wrapper {
width: 70%;
display: flex;
align-items: center;
padding: 8rpx 13rpx;
flex-direction: row;
flex-wrap: nowrap;
border-bottom: 1px solid #e5e5e5;
margin-top: 60rpx;
}
.uni-input {
height: 50rpx;
padding: 15rpx 25rpx;
line-height: 50rpx;
font-size: 28rpx;
flex: 1;
}
.passwordImg {
width: 40rpx;
height: 40rpx;
}
.error-text {
color: red;
font-size: 20rpx;
}
.error {
color: #999;
font-size: 24rpx;
}
.confirmBtn {
width: 90%;
height: 90rpx;
background: linear-gradient(135deg, #00afb2, #4fcacd);
color: #fff;
text-align: center;
line-height: 90rpx;
font-size: 36rpx;
border-radius: 50rpx;
margin-top: 70rpx;
}
.forgetPassword {
width: 90%;
display: flex;
justify-content: flex-end;
margin-top: 40rpx;
}
.forgetPasswordText {
color: #00afb2;
}
</style>