Browse Source

用户头像

master
chenlong 1 year ago
parent
commit
26e509e413
  1. 2
      api/other.js
  2. 2
      config/host.js
  3. 4
      pages/UserDetail/components/index.scss
  4. 43
      pages/UserDetail/index.vue

2
api/other.js

@ -8,7 +8,7 @@ import {host} from "@/config/host";
export function getSTS(data) { export function getSTS(data) {
return request({ return request({
url: `${host}/other/get-aliyun-sts`, url: `/get-aliyun-sts`,
method: "get", method: "get",
data data
}); });

2
config/host.js

@ -4,6 +4,6 @@ const host='http://47.109.60.201:9501/api'
// const host='http://192.168.2.92:9503/api' // const host='http://192.168.2.92:9503/api'
const imghost='http://live.admin.jinghkb.com' const imghost='http://live.admin.jinghkb.com'
const title = '汪汪行天下' const title = '汪汪行天下'
const oss = 'https://fanyi-guanjia-1.'+'oss-cn-chengdu.aliyuncs.com' const oss = 'https://pet-feed.'+'oss-cn-chengdu.aliyuncs.com'
// const codehost='http://code.baomingle.cn' // const codehost='http://code.baomingle.cn'
export {host,imghost,title,oss} export {host,imghost,title,oss}

4
pages/UserDetail/components/index.scss

@ -111,4 +111,8 @@
} }
} }
} }
}
.avatarBtn::after{
border:none;
} }

43
pages/UserDetail/index.vue

@ -9,8 +9,9 @@
<view class="detail-content-item"> <view class="detail-content-item">
<view class="detail-item-title">头像</view> <view class="detail-item-title">头像</view>
<view class="detail-item-content"> <view class="detail-item-content">
<view class="detail-item-background"></view> <button open-type="chooseAvatar" class="avatarBtn" @chooseavatar="chooseAvatar">
<image class="img" mode="aspectFill" :src="user.avatar"/> <image class="img" mode="aspectFill" :src="user.avatar"/>
</button>
</view> </view>
</view> </view>
<view class="detail-content-item"> <view class="detail-content-item">
@ -105,14 +106,28 @@
id:88685, id:88685,
birthday:'2002-05-11', birthday:'2002-05-11',
}, },
writeWaitTime:1000,
writeHandler:null,
}, },
onLoad() { onLoad() {
this.setSexTitle(); this.setSexTitle();
this.getUserDetail(); this.getUserDetail();
}, },
watch:{
user:{
handler(value) {
this.writeHandler && clearTimeout(this.writeHandler);
this.writeHandler = setTimeout(() => {
this.submit();
}, this.writeWaitTime)
},
deep: true,
}
},
methods: { methods: {
getUserDetail(){ getUserDetail() {
userDetail().then(({ data }) => { userDetail().then(({data}) => {
this.user = data; this.user = data;
this.birthday = this.user.birthday ? this.user.birthday : '2000-01-01' this.birthday = this.user.birthday ? this.user.birthday : '2000-01-01'
this.user.birthday = this.birthday this.user.birthday = this.birthday
@ -120,30 +135,32 @@
this.setSexTitle(this.user.sex); this.setSexTitle(this.user.sex);
}) })
}, },
sexConfirm(v){ sexConfirm(v) {
log(v); log(v);
this.user.sex = v.value[0].value; this.user.sex = v.value[0].value;
this.setSexTitle(v.value[0].value); this.setSexTitle(v.value[0].value);
}, },
birthdayConfirm(v){ birthdayConfirm(v) {
this.birthday = uni.$u.timeFormat(v.value, 'yyyy-mm-dd'); this.birthday = uni.$u.timeFormat(v.value, 'yyyy-mm-dd');
}, },
submit(){ submit() {
if(this.user.birthday ){ if (this.user.birthday) {
this.user.birthday = uni.$u.timeFormat(this.user.birthday, 'yyyy-mm-dd') this.user.birthday = uni.$u.timeFormat(this.user.birthday, 'yyyy-mm-dd')
} }
updateUserDetail(this.user).then((data) =>{ updateUserDetail(this.user).then((data) => {
uni.setStorageSync('user', data.data); uni.setStorageSync('user', data.data);
functions.success("修改成功").then(() =>{
uni.navigateBack();
})
}); });
}, },
setSexTitle(v){ setSexTitle(v) {
log(v); log(v);
this.sexTitle = [0, '男', '女'][v ? v : this.user.sex]; this.sexTitle = [0, '男', '女'][v ? v : this.user.sex];
log(this.sexTitle); log(this.sexTitle);
} },
chooseAvatar(v) {
api.uploadOssFile(v.detail.avatarUrl).then(res => {
this.user.avatar = res.show_path;
})
},
}, },
onPageScroll(res) { onPageScroll(res) {

Loading…
Cancel
Save