|
|
|
|
@ -34,10 +34,11 @@
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 电话 -->
|
|
|
|
|
<view class="profile-item">
|
|
|
|
|
<view class="profile-item" @click="changePhone">
|
|
|
|
|
<view class="item-label">手机号</view>
|
|
|
|
|
<view class="item-content">
|
|
|
|
|
<text class="item-value">{{ userStore.userInfo.phone }}</text>
|
|
|
|
|
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
@ -73,12 +74,7 @@
|
|
|
|
|
|
|
|
|
|
<!-- 退出登录按钮 -->
|
|
|
|
|
<view class="logout-section">
|
|
|
|
|
<uv-button
|
|
|
|
|
type="primary"
|
|
|
|
|
size="large"
|
|
|
|
|
@click="logout"
|
|
|
|
|
:loading="logoutLoading"
|
|
|
|
|
>
|
|
|
|
|
<uv-button type="primary" size="large" @click="logout" :loading="logoutLoading">
|
|
|
|
|
退出登录
|
|
|
|
|
</uv-button>
|
|
|
|
|
</view>
|
|
|
|
|
@ -97,19 +93,13 @@
|
|
|
|
|
: ""
|
|
|
|
|
}}
|
|
|
|
|
</view>
|
|
|
|
|
<uv-input
|
|
|
|
|
v-model="editValue"
|
|
|
|
|
:placeholder="getPlaceholder()"
|
|
|
|
|
:type="
|
|
|
|
|
<uv-input v-model="editValue" :placeholder="getPlaceholder()" :type="
|
|
|
|
|
editType === 'phone'
|
|
|
|
|
? 'number'
|
|
|
|
|
: editType === 'email'
|
|
|
|
|
? 'email'
|
|
|
|
|
: 'text'
|
|
|
|
|
"
|
|
|
|
|
border="bottom"
|
|
|
|
|
clearable
|
|
|
|
|
></uv-input>
|
|
|
|
|
" border="bottom" clearable></uv-input>
|
|
|
|
|
<view class="modal-actions">
|
|
|
|
|
<uv-button type="default" @click="closeEditModal">取消</uv-button>
|
|
|
|
|
<uv-button type="primary" @click="saveEdit">保存</uv-button>
|
|
|
|
|
@ -118,12 +108,7 @@
|
|
|
|
|
</uv-popup>
|
|
|
|
|
|
|
|
|
|
<!-- 头像选择弹窗 -->
|
|
|
|
|
<uv-popup
|
|
|
|
|
ref="avatarSheet"
|
|
|
|
|
mode="bottom"
|
|
|
|
|
@close="closeAvatarSheet"
|
|
|
|
|
:round="10"
|
|
|
|
|
>
|
|
|
|
|
<uv-popup ref="avatarSheet" mode="bottom" @close="closeAvatarSheet" :round="10">
|
|
|
|
|
<view class="avatar-sheet">
|
|
|
|
|
<view class="sheet-header">
|
|
|
|
|
<view class="sheet-title">选择头像</view>
|
|
|
|
|
@ -145,13 +130,59 @@
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</uv-popup>
|
|
|
|
|
|
|
|
|
|
<uv-popup ref="popup" mode="center" :closeOnClickOverlay="false" :round="10">
|
|
|
|
|
<view class="bind-phone-modal">
|
|
|
|
|
<view class="modal-header">
|
|
|
|
|
<view class="modal-title">换绑手机号</view>
|
|
|
|
|
<view class="modal-subtitle">请输入换绑手机号信息</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="modal-form">
|
|
|
|
|
<uv-form :model="bindPhoneInfo" :rules="bindPhoneRules" ref="bindPhoneForm">
|
|
|
|
|
<uv-form-item prop="phone">
|
|
|
|
|
<uv-input v-model="bindPhoneInfo.phone" placeholder="请输入手机号" type="number" maxlength="11"
|
|
|
|
|
border="surround"></uv-input>
|
|
|
|
|
</uv-form-item>
|
|
|
|
|
<uv-form-item prop="code">
|
|
|
|
|
<uv-input v-model="bindPhoneInfo.code" placeholder="请输入验证码" border="surround">
|
|
|
|
|
<template v-slot:suffix>
|
|
|
|
|
<uv-code ref="bindCodeRef" @change="bindCodeChange" seconds="60"
|
|
|
|
|
changeText="X秒重新获取"></uv-code>
|
|
|
|
|
<text style="color: #4d82fd; font-size: 12px" @click="getBindCode">
|
|
|
|
|
{{ bindCodeTips }}
|
|
|
|
|
</text>
|
|
|
|
|
</template>
|
|
|
|
|
</uv-input>
|
|
|
|
|
</uv-form-item>
|
|
|
|
|
</uv-form>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="modal-actions">
|
|
|
|
|
<uv-button type="default" @click="closeBindPhoneModal" customStyle="margin-right: 12px;">
|
|
|
|
|
取消
|
|
|
|
|
</uv-button>
|
|
|
|
|
<uv-button type="primary" @click="confirmBindPhone" :loading="bindingPhone">
|
|
|
|
|
确认绑定
|
|
|
|
|
</uv-button>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</uv-popup>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref, onMounted } from "vue";
|
|
|
|
|
import { onShow } from "@dcloudio/uni-app";
|
|
|
|
|
import { useAuthStore, useUserStore } from "@/store";
|
|
|
|
|
import {
|
|
|
|
|
ref,
|
|
|
|
|
onMounted
|
|
|
|
|
} from "vue";
|
|
|
|
|
import {
|
|
|
|
|
onShow
|
|
|
|
|
} from "@dcloudio/uni-app";
|
|
|
|
|
import {
|
|
|
|
|
useAuthStore,
|
|
|
|
|
useUserStore
|
|
|
|
|
} from "@/store";
|
|
|
|
|
import RPC from "@/utils/request";
|
|
|
|
|
|
|
|
|
|
const authStore = useAuthStore();
|
|
|
|
|
@ -269,22 +300,34 @@ const saveEdit = async () => {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (editType.value === 'username') {
|
|
|
|
|
RPC.post('/user/update',{id:userStore.userInfo.id,username:editValue.value}).then(() => {
|
|
|
|
|
RPC.post('/user/update', {
|
|
|
|
|
id: userStore.userInfo.id,
|
|
|
|
|
username: editValue.value
|
|
|
|
|
}).then(() => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "保存成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
userStore.setUserInfo({...userStore.userInfo,username:editValue.value})
|
|
|
|
|
userStore.setUserInfo({
|
|
|
|
|
...userStore.userInfo,
|
|
|
|
|
username: editValue.value
|
|
|
|
|
})
|
|
|
|
|
closeEditModal()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (editType.value === 'email') {
|
|
|
|
|
RPC.post('/user/update',{id:userStore.userInfo.id,email:editValue.value}).then(() => {
|
|
|
|
|
RPC.post('/user/update', {
|
|
|
|
|
id: userStore.userInfo.id,
|
|
|
|
|
email: editValue.value
|
|
|
|
|
}).then(() => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "保存成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
userStore.setUserInfo({...userStore.userInfo,email:editValue.value})
|
|
|
|
|
userStore.setUserInfo({
|
|
|
|
|
...userStore.userInfo,
|
|
|
|
|
email: editValue.value
|
|
|
|
|
})
|
|
|
|
|
closeEditModal()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
@ -411,6 +454,134 @@ onShow(() => {
|
|
|
|
|
// 页面显示时刷新用户信息
|
|
|
|
|
loadUserInfo();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const popup = ref(null);
|
|
|
|
|
const bindingPhone = ref(false);
|
|
|
|
|
const bindCodeTips = ref("获取验证码");
|
|
|
|
|
const bindCodeRef = ref(null);
|
|
|
|
|
const bindPhoneForm = ref(null);
|
|
|
|
|
const bindPhoneInfo = ref({
|
|
|
|
|
phone: "",
|
|
|
|
|
code: "",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const changePhone = () => {
|
|
|
|
|
bindPhoneInfo.value = {
|
|
|
|
|
phone: "",
|
|
|
|
|
code: "",
|
|
|
|
|
}
|
|
|
|
|
popup.value.open()
|
|
|
|
|
}
|
|
|
|
|
const bindPhoneRules = ref({
|
|
|
|
|
phone: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: "请输入手机号",
|
|
|
|
|
trigger: ["blur", "change"],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
pattern: /^1[3-9]\d{9}$/,
|
|
|
|
|
message: "请输入正确的手机号",
|
|
|
|
|
trigger: ["blur", "change"],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
code: {
|
|
|
|
|
required: true,
|
|
|
|
|
message: "请输入验证码",
|
|
|
|
|
trigger: ["blur", "change"],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const bindCodeChange = (text) => {
|
|
|
|
|
bindCodeTips.value = text;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const closeBindPhoneModal = () => {
|
|
|
|
|
popup.value.close();
|
|
|
|
|
bindPhoneInfo.value = {
|
|
|
|
|
phone: "",
|
|
|
|
|
code: "",
|
|
|
|
|
};
|
|
|
|
|
bindCodeTips.value = "获取验证码";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const confirmBindPhone = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await bindPhoneForm.value.validate();
|
|
|
|
|
|
|
|
|
|
bindingPhone.value = true;
|
|
|
|
|
|
|
|
|
|
// 调用绑定手机号API
|
|
|
|
|
RPC.post('/user/bind_phone', {
|
|
|
|
|
phone: bindPhoneInfo.value.phone,
|
|
|
|
|
code: bindPhoneInfo.value.code,
|
|
|
|
|
token: authStore.accessToken
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
console.log('bind_phone', res)
|
|
|
|
|
bindingPhone.value = false;
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "换绑成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
popup.value.close()
|
|
|
|
|
RPC.post('/user/info', {
|
|
|
|
|
token: authStore.accessToken,
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
userStore.setUserInfo(res)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("换绑手机号失败:", error);
|
|
|
|
|
bindingPhone.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getBindCode = () => {
|
|
|
|
|
if (!bindPhoneInfo.value.phone) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "请输入手机号",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!/^1[3-9]\d{9}$/.test(bindPhoneInfo.value.phone)) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "请输入正确的手机号",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bindCodeRef.value.canGetCode) {
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: "正在获取验证码",
|
|
|
|
|
});
|
|
|
|
|
// 调用发送验证码API
|
|
|
|
|
RPC.post('/user/bind_phone/send_code', {
|
|
|
|
|
phone: bindPhoneInfo.value.phone,
|
|
|
|
|
token: authStore.accessToken
|
|
|
|
|
}).then(() => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '验证码已发送',
|
|
|
|
|
icon: 'success'
|
|
|
|
|
})
|
|
|
|
|
bindCodeRef.value.start()
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '发送失败,请重试',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "倒计时结束后再发送",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
@ -537,4 +708,42 @@ onShow(() => {
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.bind-phone-modal {
|
|
|
|
|
width: 320px;
|
|
|
|
|
padding: 24px;
|
|
|
|
|
|
|
|
|
|
.modal-header {
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin-bottom: 24px;
|
|
|
|
|
|
|
|
|
|
.modal-title {
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
color: #333;
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.modal-subtitle {
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: #666;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.modal-form {
|
|
|
|
|
margin-bottom: 24px;
|
|
|
|
|
|
|
|
|
|
.uv-form-item {
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.modal-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
|
|
|
|
.uv-button {
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|