|
|
|
@ -0,0 +1,189 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div class="profile">
|
|
|
|
|
<h2>个人主页</h2>
|
|
|
|
|
|
|
|
|
|
<div v-if="showNicknameInput">
|
|
|
|
|
<label for="nickname">昵称:</label>
|
|
|
|
|
<input type="nickname" id="nickname" v-model="nickname" class="input-field">
|
|
|
|
|
<button @click="updateNickname">保存</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
|
|
|
|
<p>昵称:{{ user.nickname }}</p>
|
|
|
|
|
<button @click="toggleNicknameInput">更换</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<h1>{{ user.name }}</h1>
|
|
|
|
|
|
|
|
|
|
<p>身份证号:{{user.IDCard}}</p>
|
|
|
|
|
|
|
|
|
|
<div v-if="showEmailInput">
|
|
|
|
|
<label for="email">邮箱:</label>
|
|
|
|
|
<input type="email" id="email" v-model="email" class="input-field">
|
|
|
|
|
<button @click="updateEmail">保存</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
|
|
|
|
<p>邮箱:{{ user.email }}</p>
|
|
|
|
|
<button @click="toggleEmailInput">编辑</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-if="showPhoneInput">
|
|
|
|
|
<label for="PhoneNumber">手机号:</label>
|
|
|
|
|
<input type="phone" id="phone" v-model="phone" class="input-field">
|
|
|
|
|
<button @click="updatePhone">保存</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
|
|
|
|
<p>手机号:{{ user.phone }}</p>
|
|
|
|
|
<button @click="togglePhoneInput">更换</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="footer-nav">
|
|
|
|
|
<button @click="gotohome()">首页</button>
|
|
|
|
|
<button @click="gotomessage()">消息</button>
|
|
|
|
|
<button>我的</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
/* 在这里添加样式 */
|
|
|
|
|
.profile {
|
|
|
|
|
max-width: 400px;
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.input-field {
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
button {
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.home-container {
|
|
|
|
|
/* 添加你的样式 */
|
|
|
|
|
text-align: center;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
/* 可能需要为内容添加一些底部空间以容纳底部导航 */
|
|
|
|
|
padding-bottom: 50px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.footer-nav {
|
|
|
|
|
/* 定义底部导航的样式 */
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-around;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
background-color: #f5f5f5; /* 示例背景色 */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.footer-nav button {
|
|
|
|
|
/* 定义按钮的样式 */
|
|
|
|
|
flex: 1;
|
|
|
|
|
border: none;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
background-color: #ccc;
|
|
|
|
|
color: #333;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.footer-nav button:hover {
|
|
|
|
|
/* 按钮点击时的样式 */
|
|
|
|
|
background-color: #bbb;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
props: ['phone'],
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
user: {},
|
|
|
|
|
nickname:'',
|
|
|
|
|
showNicknameInput: false,
|
|
|
|
|
email: '',
|
|
|
|
|
showEmailInput: false,
|
|
|
|
|
phone: '',
|
|
|
|
|
showPhoneInput: false,
|
|
|
|
|
IDCard: '',
|
|
|
|
|
createtime: '',
|
|
|
|
|
status: 0,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
// 在组件创建时根据账号获取用户信息
|
|
|
|
|
this.fetchUser(this.phone);
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
fetchUser(phone) {
|
|
|
|
|
// 从后端 API 请求
|
|
|
|
|
axios.get(`http://192.168.254.35:8080/users/getByPhone?phone=15616168609`)
|
|
|
|
|
.then(response => {
|
|
|
|
|
alert(response.data);
|
|
|
|
|
this.user = response.data;
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error fetching user:', error);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
toggleNicknameInput(){
|
|
|
|
|
this.showNicknameInput = !this.showNicknameInput;
|
|
|
|
|
this.nickname = this.user.nickname;
|
|
|
|
|
},
|
|
|
|
|
updateNickname(){
|
|
|
|
|
axios.get(`http://192.168.254.35:8080/users/getByPhone?phone=15616168609`, { nickname: this.nickname })
|
|
|
|
|
.then(response => {
|
|
|
|
|
this.user.nickname = this.nickname;
|
|
|
|
|
this.toggleNicknameInput(); // 切换回展示模式
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error updating nickname:', error);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
toggleEmailInput() {
|
|
|
|
|
this.showEmailInput = !this.showEmailInput;
|
|
|
|
|
this.email = this.user.email;// 在切换到编辑模式时显示当前邮箱地址
|
|
|
|
|
},
|
|
|
|
|
updateEmail() {
|
|
|
|
|
// 这里发送请求更新用户邮箱
|
|
|
|
|
axios.get(`http://192.168.254.35:8080/users/getByPhone?phone=15616168609`, { email: this.email })
|
|
|
|
|
.then(response => {
|
|
|
|
|
this.user.email = this.email;
|
|
|
|
|
this.toggleEmailInput(); // 切换回展示模式
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error updating email:', error);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
togglePhoneInput(){
|
|
|
|
|
this.showPhoneInput = !this.showPhoneInput;
|
|
|
|
|
this.phone = this.user.phone;
|
|
|
|
|
},
|
|
|
|
|
updatePhone(){
|
|
|
|
|
axios.get(`http://192.168.254.35:8080/users/getByPhone?phone=15616168609`, { phone: this.phone })
|
|
|
|
|
.then(response => {
|
|
|
|
|
alert(this.phone);
|
|
|
|
|
this.user.phone = this.phone;
|
|
|
|
|
this.togglePhoneInput(); // 切换回展示模式
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error updating phone:', error);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
gotohome() {
|
|
|
|
|
this.$router.push('/home');
|
|
|
|
|
},
|
|
|
|
|
gotomessage() {
|
|
|
|
|
this.$router.push('/message');
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|