优化代码

This commit is contained in:
pengxiaolong
2025-08-05 22:05:56 +08:00
parent 3eddd94922
commit 40c3282515
86 changed files with 1700 additions and 399 deletions

View File

@@ -1,17 +1,90 @@
<template>
<view class="container">
<button class="login-btn" open-type="chooseAvatar" @chooseavatar="Userinfo">
<image class="avatar" :src="userinfo"></image>
</button>
<input
type="nickname"
class="weui-input"
placeholder="请输入昵称"
@blur="inputName"
v-model="name"
/>
<button class="weui-btn" @click="wxLogin">修改</button>
<button class="weui-btn" @click="cancel">取消</button>
<view class="bg">
<image
class="bgImg"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/HomeBackground.png"
mode="scaleToFill"
/>
</view>
<view class="Return" @click="onBack">
<image
class="ReturnImg"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Return.png"
mode="scaleToFill"
/>
</view>
<view class="title">设置</view>
<view class="contentbox">
<view class="content">
<!-- 修改头像 -->
<button class="login-btn" open-type="chooseAvatar" @chooseavatar="Userinfo">
<view class="avatarmodify">
<view class="avatarmodify-item">头像</view>
<view class="avatarmodify-img">
<image class="avatar" :src="userinfo"></image>
<image
class="more"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/More.png"
mode="scaleToFill"
/>
</view>
</view>
</button>
<!-- 修改昵称 -->
<view class="Nickname" @click="inputNickname">
<view class="avatarmodify-item">昵称</view>
<view class="NicknameInput">
<view class="NicknameInput-name">{{ name }}</view>
<image
class="more"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/More.png"
mode="scaleToFill"
/>
</view>
</view>
<!-- 修改邮箱 -->
<view class="Nickname" @click="modifyEmailAddress">
<view class="avatarmodify-item">邮箱</view>
<view class="NicknameInput">
<view class="NicknameInput-name">{{
email == "" || email == null ? "未绑定" : email
}}</view>
<image
class="more"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/More.png"
mode="scaleToFill"
/>
</view>
</view>
<!-- 修改密码 -->
<view class="Nickname" @click="modifyPassword">
<view class="avatarmodify-item">密码</view>
<view class="NicknameInput">
<view class="NicknameInput-name">{{
havaPassword ? "" : "未设置"
}}</view>
<image
class="more"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/More.png"
mode="scaleToFill"
/>
</view>
</view>
<!-- 扫码登录web端 -->
<view class="Nickname" @click="scanCode">
<view class="avatarmodify-item">扫码</view>
<view class="NicknameInput">
<image
class="more"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/More.png"
mode="scaleToFill"
/>
</view>
</view>
</view>
</view>
</view>
</template>
@@ -19,7 +92,7 @@
import request from "../../components/request.js";
import postFile from "../../components/postFile.js";
import generateFileName from "../../components/generateFileName.js";
import { goEasylogin,goEasylogout } from "../../components/goEasyTool/tool.js";
import { goEasylogin, goEasylogout } from "../../components/goEasyTool/tool.js";
export default {
inject: ["$global"],
@@ -30,6 +103,8 @@ export default {
id: "",
info: {},
useravatar: "",
email: null,
havaPassword: false,
};
},
onLoad(option) {
@@ -39,61 +114,100 @@ export default {
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;
},
});
},
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;
},
});
},
methods: {
cancel() {
//修改密码
modifyPassword() {
uni.navigateTo({
url: "/pages/Setting/settingmod/changePassword?id=" + this.id,
});
},
// 修改邮箱
modifyEmailAddress() {
uni.navigateTo({
url:
"/pages/Setting/settingmod/changeEmail?email=" + this.email + "&id=" + this.id,
});
},
// 修改昵称
inputNickname() {
uni.navigateTo({
url:
"/pages/Setting/settingmod/changeNickname?name=" + this.name + "&id=" + this.id,
});
},
// 扫码登录web端
scanCode() {
uni.scanCode({
success: (res) => {
const data = JSON.parse(res.result);
if (data.type === "qrcdoe") {
request({
url: "user/scan",
method: "POST",
data: {
uuid: data.uuid,
userId: this.id,
},
userInfo: true,
}).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",
})
});
}
// 其他类型暂不处理
},
});
},
onBack() {
uni.navigateBack({
delta: 1,
});
},
// 输入昵称
inputName(e) {
this.name = e.detail.value;
},
// 选择头像
async Userinfo(e) {
const { avatarUrl } = e.detail;
this.userinfo = avatarUrl;
this.changeHeaderIcon();
},
// 微信登录
wxLogin(e) {
// 修改头像
changeHeaderIcon() {
goEasylogout(this.$goeasy);
uni.showLoading({
title: "修改中...",
mask: true,
});
if (this.useravatar == this.userinfo) {
request({
url: "user/updateUserInfo",
method: "POST",
data: {
id: this.id,
headerIcon: this.userinfo.split("/").pop(),
nickName: this.name,
},
userInfo: true,
}).then((ress) => {
if (ress.code === 200) {
uni.showToast({
title: "修改成功",
icon: "success",
});
uni.setStorageSync("userinfo", ress.data.info);
goEasylogin(this.$goeasy,String(ress.data.info.id),ress.data.info.headerIcon,ress.data.info.nickName);
uni.hideLoading();
uni.navigateBack({
delta: 1,
});
} else {
uni.showToast({
title: "修改失败",
icon: "none",
});
}
});
}else{
postFile({
path: this.userinfo,
name: generateFileName(),
@@ -109,14 +223,19 @@ export default {
},
userInfo: true,
}).then((ress) => {
console.log("修改调用返回",ress);
console.log("修改调用返回", ress);
if (ress.code === 200) {
uni.showToast({
title: "修改成功",
icon: "success",
});
uni.setStorageSync("userinfo", ress.data.info);
goEasylogin(this.$goeasy,String(ress.data.info.id),ress.data.info.headerIcon,ress.data.info.nickName);
goEasylogin(
this.$goeasy,
String(ress.data.info.id),
ress.data.info.headerIcon,
ress.data.info.nickName
);
uni.hideLoading();
//```````````````````````````````````````````````````````````````````````登录成功后跳转回原页面 或 首页
uni.navigateBack({
@@ -124,53 +243,139 @@ export default {
});
//````````````````````````````````````````````````````````````````````
} else {
uni.hideLoading();
uni.showToast({
title: "修改失败",
title: ress.msg,
icon: "none",
});
}
});
})
.catch((err) => {
console.log('上传失败', err);
uni.hideLoading();
uni.showToast({
title: "上传失败",
icon: "none",
});
});
}
},
},
};
</script>
<style scoped>
.container {
.bg {
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
z-index: -1;
}
.bgImg {
width: 100%;
height: 100%;
}
.Return {
position: fixed;
left: 35rpx;
top: 120rpx;
width: 46rpx;
height: 46rpx;
z-index: 2;
}
.title {
position: fixed;
top: 120rpx;
left: 0;
right: 0;
text-align: center;
font-size: 34rpx;
color: #100e0f;
font-weight: bold;
z-index: 1;
}
.ReturnImg {
width: 100%;
height: 100%;
}
.contentbox {
position: absolute;
top: 200rpx;
left: 0rpx;
right: 0rpx;
bottom: 0rpx;
}
.content {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: linear-gradient(to bottom, #11cb2a6e, #2574fc6d);
}
.avatarmodify {
width: 94%;
height: 100rpx;
background-color: #fff;
padding-left: 3%;
padding-right: 3%;
display: flex;
justify-content: space-between;
align-items: center;
}
.avatarmodify-item {
font-size: 24rpx;
color: #100e0f;
line-height: 100rpx;
font-weight: bold;
}
.avatarmodify-img {
display: flex;
align-items: center;
}
.login-btn {
width: 200rpx;
height: 200rpx;
border-radius: 50%;
padding: 0px;
margin-bottom: 60rpx;
width: 100%;
height: 100rpx;
padding: 0;
margin: 0;
border: none;
background-color: #fff;
border-radius: 0rpx;
display: flex;
}
.login-btn::after {
border: none;
border-radius: 0rpx;
}
.avatar {
width: 100%;
height: 100%;
border-radius: 50%;
width: 80rpx;
height: 80rpx;
border-radius: 10rpx;
}
.weui-input {
width: 80%;
text-align: center;
margin-bottom: 40rpx;
.more {
width: 15rpx;
height: 30rpx;
margin-left: 30rpx;
}
.weui-btn {
width: 40%;
margin-top: 20rpx;
background-color: #11cb2a00;
color: #fff;
.Nickname {
width: 94%;
height: 100rpx;
display: flex;
justify-content: space-between;
align-items: center;
padding-left: 3%;
padding-right: 3%;
background-color: #fff;
border-top: 1rpx solid #f0f0f0;
}
.NicknameInput {
display: flex;
align-items: center;
}
.NicknameInput-name {
font-size: 24rpx;
color: #bdbdbd;
line-height: 100rpx;
font-weight: bold;
}
</style>

View File

@@ -0,0 +1,100 @@
<template>
<view class="changeEmail">
<view class="bg">
<image
class="bgImg"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/HomeBackground.png"
mode="scaleToFill"
/>
</view>
<view class="Return" @click="onBack">
<image
class="ReturnImg"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Return.png"
mode="scaleToFill"
/>
</view>
<view class="title">邮箱</view>
<view class="contentbox">
<view class="content">
<!-- -->
<!-- -->
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: "Hello",
};
},
onLoad() {
// 页面加载时执行
},
methods: {
// 返回上一页
onBack() {
wx.navigateBack({
delta: 1,
});
},
},
};
</script>
<style scoped>
.bg {
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
z-index: -1;
}
.bgImg {
width: 100%;
height: 100%;
}
.Return {
position: fixed;
left: 35rpx;
top: 120rpx;
width: 46rpx;
height: 46rpx;
z-index: 2;
}
.title {
position: fixed;
top: 120rpx;
left: 0;
right: 0;
text-align: center;
font-size: 34rpx;
color: #100e0f;
font-weight: bold;
z-index: 1;
}
.ReturnImg {
width: 100%;
height: 100%;
}
.contentbox {
position: absolute;
top: 200rpx;
left: 0rpx;
right: 0rpx;
bottom: 0rpx;
}
.content {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
</style>

View File

@@ -0,0 +1,186 @@
<template>
<view class="changeNickname">
<view class="bg">
<image
class="bgImg"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/HomeBackground.png"
mode="scaleToFill"
/>
</view>
<view class="Return" @click="onBack">
<image
class="ReturnImg"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Return.png"
mode="scaleToFill"
/>
</view>
<view class="title">修改昵称</view>
<view class="contentbox">
<view class="content">
<!-- -->
<input
type="nickname"
class="weui-input"
placeholder="请输入昵称"
@blur="inputName"
v-model="name"
/>
<!-- -->
<view class="btn" @click="onSubmit">确认修改</view>
</view>
</view>
</view>
</template>
<script>
import { goEasylogin, goEasylogout } from "../../../components/goEasyTool/tool.js";
import request from "../../../components/request.js";
export default {
data() {
return {
name: "",
id: "",
};
},
onLoad(options) {
// 页面加载时执行
this.name = options.name;
this.id = options.id;
},
methods: {
// 提交修改
onSubmit() {
if (this.name.trim() === "") {
wx.showToast({
title: "昵称不能为空",
icon: "none",
duration: 1000,
});
return;
}
uni.showLoading({
title: "修改中...",
mask: true,
});
goEasylogout(this.$goeasy);
request({
url: "user/updateUserInfo",
method: "POST",
data: {
id: this.id,
nickName: this.name,
},
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.msg,
icon: "none",
});
}
});
},
// 输入昵称
inputName(e) {
this.name = e.detail.value;
},
// 返回上一页
onBack() {
wx.navigateBack({
delta: 1,
});
},
},
};
</script>
<style scoped>
.bg {
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
z-index: -1;
}
.bgImg {
width: 100%;
height: 100%;
}
.Return {
position: fixed;
left: 35rpx;
top: 120rpx;
width: 46rpx;
height: 46rpx;
z-index: 2;
}
.title {
position: fixed;
top: 120rpx;
left: 0;
right: 0;
text-align: center;
font-size: 34rpx;
color: #100e0f;
font-weight: bold;
z-index: 1;
}
.ReturnImg {
width: 100%;
height: 100%;
}
.contentbox {
position: absolute;
top: 200rpx;
left: 0rpx;
right: 0rpx;
bottom: 0rpx;
}
.content {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.weui-input {
width: 80%;
height: 80rpx;
margin-top: 40rpx;
border-bottom: 1px solid #ccc;
}
.btn {
width: 80%;
height: 80rpx;
margin-top: 50rpx;
background-color: #00b4ff;
color: #fff;
text-align: center;
line-height: 80rpx;
border-radius: 40rpx;
font-size: 30rpx;
border: none;
cursor: pointer;
}
</style>

View File

@@ -0,0 +1,100 @@
<template>
<view class="change-password">
<view class="bg">
<image
class="bgImg"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/HomeBackground.png"
mode="scaleToFill"
/>
</view>
<view class="Return" @click="onBack">
<image
class="ReturnImg"
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Return.png"
mode="scaleToFill"
/>
</view>
<view class="title">修改密码</view>
<view class="contentbox">
<view class="content">
<!-- -->
<!-- -->
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: "Hello",
};
},
onLoad() {
// 页面加载时执行
},
methods: {
// 返回上一页
onBack() {
console.log(1);
wx.navigateBack({
delta: 1,
});
},
},
};
</script>
<style scoped>
.bg {
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
z-index: -1;
}
.bgImg {
width: 100%;
height: 100%;
}
.Return {
position: fixed;
left: 35rpx;
top: 120rpx;
width: 46rpx;
height: 46rpx;
z-index: 2;
}
.title {
position: fixed;
top: 120rpx;
left: 0;
right: 0;
text-align: center;
font-size: 34rpx;
color: #100e0f;
font-weight: bold;
z-index: 1;
}
.ReturnImg {
width: 100%;
height: 100%;
}
.contentbox {
position: absolute;
top: 200rpx;
left: 0rpx;
right: 0rpx;
bottom: 0rpx;
}
.content {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
</style>