xytSk-App/pages/personInfo/personInfo.vue

258 lines
6.0 KiB
Vue
Raw Normal View History

2024-06-05 17:26:16 +08:00
<template>
<view class="container">
<div class="userinfo">
<div class="icon" @click="goBack">
<uni-icons type="back" size="25" color="white"></uni-icons>
</div>
<div class="Header">
<span>个人信息</span>
</div>
</div>
<uni-list class="info">
<uni-list-item
title="头像"
show-arrow="true"
clickable
class="listContainer"
2024-06-06 17:41:41 +08:00
@click="showActionSheet(default_src)"
2024-06-05 17:26:16 +08:00
>
<template v-slot:footer >
2024-06-06 17:41:41 +08:00
<image class="slot-image" :src="default_src" mode="aspectFill"></image>
2024-06-05 17:26:16 +08:00
</template>
</uni-list-item>
<uni-list-item
v-for="(item, index) in userListShow"
:key="index"
clickable
:title="item.name"
class="listContainer"
2024-06-06 17:41:41 +08:00
@click="modifyValue(item)"
2024-06-05 17:26:16 +08:00
>
<template v-slot:footer >
2024-06-06 17:41:41 +08:00
<div class="item" @click.stop="changeItemInfo(item,index)">
2024-06-05 17:26:16 +08:00
<text >{{item.info}}</text>
</div>
</template>
</uni-list-item>
</uni-list>
2024-06-06 17:41:41 +08:00
<button type="primary" class="button" @click="save"></button>
2024-06-05 17:26:16 +08:00
</view>
2024-06-06 17:41:41 +08:00
2024-06-05 17:26:16 +08:00
</template>
<script>
let modify = false
//访问数据
const userList = uni.getStorageSync('value')
2024-06-06 17:41:41 +08:00
let userListShow = [
2024-06-05 17:26:16 +08:00
{name: '手机号码', info: userList.phone},
]
export default {
data() {
return {
userList: userList,
userListShow:userListShow,
2024-06-06 17:41:41 +08:00
modify: modify,
default_src: uni.getStorageSync('avatar'),
fileId: '',
phone: userList.phone,
reset: false,
2024-06-05 17:26:16 +08:00
}
},
2024-06-06 17:41:41 +08:00
mounted() { //挂载时重新获取一次Storage数据
this.userList = uni.getStorageSync('value')
this.userListShow[0].info = this.userList.phone
},
2024-06-05 17:26:16 +08:00
methods: {
goBack(){
uni.navigateBack()
},
2024-06-06 17:41:41 +08:00
showActionSheet(default_src){ //修改头像
2024-06-05 17:26:16 +08:00
uni.showActionSheet({
itemList: ['拍照/上传照片', '恢复默认头像'],
success: (res) => {
console.log('选择了第' + (res.tapIndex + 1) + '个选项');
if (res.tapIndex === 0) { //拍照上传照片
2024-06-06 17:41:41 +08:00
uni.chooseImage({
count: 1,
sizeType: ['origin','compressed'],
sourceType: ['camera', 'album'],
success: (res) => {
const tempFilePaths = res.tempFilePaths;
console.log('--------拍照上传照片--------',res);
this.default_src = tempFilePaths[0]
uni.uploadFile({
url: uni.$http.baseUrl+'/gunshiApp/xfflood/my/info/file/upload/singleSimple',
fileType: 'image',
filePath: tempFilePaths[0],
name: 'file',
success: (res) => {
this.fileId = JSON.parse(res.data).data.fileId
},
})
}
})
2024-06-05 17:26:16 +08:00
} else if(res.tapIndex === 1) { //恢复默认头像
2024-06-06 17:41:41 +08:00
console.log('click');
this.reset = true
this.default_src = '../../static/tabs/头像_icon@2x.png'
2024-06-05 17:26:16 +08:00
}
},
fail: (err) => {
console.log('弹窗取消');
}
});
},
modifyValue(item){
console.log(item);
2024-06-05 17:43:38 +08:00
2024-06-06 17:41:41 +08:00
},
changeItemInfo(item,index){ //修改电话
uni.showModal({
title:"修改"+item.name,
editable:true,
placeholderText:item.info,
confirmText:"确认",
cancelText:"取消",
success: (res) => {
const phoneReg = /^[1][3-9]\d{9}$/;
if (res.confirm){
if (phoneReg.test(res.content) ){
this.userListShow[index].info = res.content
this.phone = res.content
uni.showToast({
title:"修改成功,请保存",
icon: "none",
duration: 1000,
})
} else {
uni.showToast({
title:"请输入正确手机号码",
icon: "none",
duration: 1000,
})
}
}
},
fail: (err) => {
console.log('取消');
}
})
},
save(){
if (this.fileId == ''){ //图片无修改或重置时
if (this.reset) { //重置头像
//调接口清空返回图片路径的data
uni.$http.get('/gunshiApp/xfflood/my/info/recover').then(res=>{
uni.setStorageSync('avatar','../../static/tabs/头像_icon@2x.png')
})
console.log('重置头像');
}
let params = {
"phone": this.phone,
}
uni.$http.post('/gunshiApp/xfflood/my/info/update',params).then(res=>{
console.log('-----修改图片1-----',res);
let new_userList = uni.getStorageSync('value')
new_userList.phone = this.phone
uni.setStorageSync('value', new_userList)
uni.reLaunch({
url:'/pages/mypage/mypage'
})
},err=>{
console.log('----err----',err);
})
} else { //修改图片后
let params = {
"phone": this.phone,
"attach": {
"fileId": this.fileId,
},
}
uni.$http.post('/gunshiApp/xfflood/my/info/update',params).then(res=>{
console.log('-----修改图片2-----',res);
if (res.data.code == 200){
console.log('---修改图片3---',res);
let url = '/gunshiApp/xfflood/bzProjectManipulationRecord/file/get/'+this.fileId
uni.$http.get(url).then(res=>{
uni.setStorageSync('avatar','http://223.75.53.141:9102/test.by-lyf.tmp'+res.data.data.filePath)
console.log('-----modifiedAvatar------',uni.getStorageSync('avatar'));
})
uni.reLaunch({
url:'/pages/mypage/mypage'
})
}
})
}
2024-06-05 17:26:16 +08:00
}
}
}
</script>
<style>
.userinfo{
border-radius: 5px;
display: flex;
flex-direction: row;
margin-top: 5vh;
margin-left: 2vw;
margin-bottom: 2vh;
align-items: center;
width: 95%;
height: 6vh;
background-color: #007afd;
}
.icon{
width: 6vw;
height: 6vh;
align-items: center;
line-height: 6vh;
}
.Header{
display: flex;
flex-direction: row;
flex: 0.95;
justify-content: center;
color: white;
font-size: 20px;
}
.info{
margin: 1vh;
}
.listContainer{
height: 6vh;
line-height: 8vh;
}
.button{
margin-top: 60vh;
border-radius: 10px;
display: flex;
flex-direction: column-reverse;
width: 92%;
height: 6vh;
font-size: 20px;
color: white;
background-color: #007afd;
}
.slot-image{
2024-06-06 17:41:41 +08:00
margin-top: 12px;
width: 40px;
height: 40px;
border-radius: 50%;
2024-06-05 17:26:16 +08:00
}
</style>