Files
app-govern/pages/user/head.vue

80 lines
2.4 KiB
Vue
Raw Normal View History

2023-02-10 16:32:41 +08:00
<template>
2023-08-11 11:03:31 +08:00
<Cn-page :loading="loading">
<view slot="body">
<view class="head">
<image class="head-img" :src="userInfo.avatar" v-if="userInfo.avatar"></image>
<image class="head-img" src="/static/head.png" v-else></image>
2023-02-10 16:32:41 +08:00
<view class="head-setup">
<view class="head-setup-item" @click="take('album')">从相册选一张</view>
<view class="head-setup-item" @click="take('camera')">拍一张照片</view>
</view>
</view>
</view>
</Cn-page>
</template>
<script>
2023-08-11 11:03:31 +08:00
import { uploadImage, getImageUrl } from '@/common/api/basic'
import { apiUpdateUser } from '@/common/api/user'
2023-02-10 16:32:41 +08:00
export default {
2023-08-11 11:03:31 +08:00
data() {
2023-02-10 16:32:41 +08:00
return {
2023-08-11 11:03:31 +08:00
loading: false,
userInfo: {},
2023-02-10 16:32:41 +08:00
}
},
methods: {
2023-08-11 11:03:31 +08:00
take(type) {
2023-02-10 16:32:41 +08:00
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: [type],
success: (res) => {
console.log(res)
2023-08-11 11:03:31 +08:00
uploadImage(res.tempFilePaths[0]).then((res) => {
console.log(res)
let result = JSON.parse(res[1].data)
apiUpdateUser({
headSculpture: result.data.minFileUrl,
}).then((res) => {
console.log(res)
2023-08-30 18:52:58 +08:00
this.userInfo.headSculpture = result.data.minFileUrl
this.userInfo.avatar = this.$config.static + result.data.minFileUrl
uni.setStorageSync(this.$cacheKey.userInfo, this.userInfo)
this.$forceUpdate()
2023-08-11 11:03:31 +08:00
})
})
},
2023-02-10 16:32:41 +08:00
})
2023-08-11 11:03:31 +08:00
},
},
onLoad(options) {
this.userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
},
2023-02-10 16:32:41 +08:00
}
</script>
2023-08-11 11:03:31 +08:00
<style lang="scss">
2023-02-10 16:32:41 +08:00
.head {
.head-img {
height: 750rpx;
width: 750rpx;
}
.head-setup {
position: fixed;
bottom: 0;
left: 0;
width: 750rpx;
padding-bottom: 60rpx;
background-color: #fff;
2023-08-11 11:03:31 +08:00
.head-setup-item {
2023-02-10 16:32:41 +08:00
height: 100rpx;
line-height: 100rpx;
text-align: center;
border-top: 1rpx solid #e8e8e8;
}
}
}
2023-08-11 11:03:31 +08:00
</style>