|
@@ -2,7 +2,7 @@
|
|
|
<view>
|
|
<view>
|
|
|
<u-cell-group>
|
|
<u-cell-group>
|
|
|
<u-cell-item title="头像" @click="editAvatar">
|
|
<u-cell-item title="头像" @click="editAvatar">
|
|
|
- <image :src="userInfo!=null?$method.splitImgHost(userInfo.avatar):''" class="avatar"></image>
|
|
|
|
|
|
|
+ <image :src="userInfo!=null?$method.splitImgHost(avatarUrl):''" class="avatar"></image>
|
|
|
</u-cell-item>
|
|
</u-cell-item>
|
|
|
<u-cell-item title="昵称" :value="userInfo.nickname" @click="editNickName"></u-cell-item>
|
|
<u-cell-item title="昵称" :value="userInfo.nickname" @click="editNickName"></u-cell-item>
|
|
|
</u-cell-group>
|
|
</u-cell-group>
|
|
@@ -12,7 +12,7 @@
|
|
|
</view>
|
|
</view>
|
|
|
</u-modal>
|
|
</u-modal>
|
|
|
<view style="position: fixed;bottom: 50rpx;width: 100%;padding: 20rpx;">
|
|
<view style="position: fixed;bottom: 50rpx;width: 100%;padding: 20rpx;">
|
|
|
- <button @click="submit" class="submit_btn">保存</button>
|
|
|
|
|
|
|
+ <button @click="submitForm" class="submit_btn">保存</button>
|
|
|
|
|
|
|
|
<button @click="exit" class="exit_btn">退出登录</button>
|
|
<button @click="exit" class="exit_btn">退出登录</button>
|
|
|
</view>
|
|
</view>
|
|
@@ -25,18 +25,93 @@
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
show: false,
|
|
show: false,
|
|
|
|
|
+ avatarUrl:''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
onLoad(option) {
|
|
onLoad(option) {
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
onShow(){
|
|
onShow(){
|
|
|
|
|
+ this.avatarUrl = this.userInfo.avatar
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
- submit(){
|
|
|
|
|
- if(this.userInfo.nickname==''){
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ imageInfos(){
|
|
|
|
|
+ var self = this
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ uni.getImageInfo({
|
|
|
|
|
+ src: self.avatarUrl,
|
|
|
|
|
+ success: async res => {
|
|
|
|
|
+ let canvasWidth = res.width; //图片原始长宽
|
|
|
|
|
+ let canvasHeight = res.height;
|
|
|
|
|
+ if (canvasWidth > 1000 || canvasHeight > 1000) {
|
|
|
|
|
+ uni.compressImage({
|
|
|
|
|
+ src: self.avatarUrl,
|
|
|
|
|
+ quality: 75,
|
|
|
|
|
+ width: '50%',
|
|
|
|
|
+ height: '50%',
|
|
|
|
|
+ success: async rest => {
|
|
|
|
|
+ const waitUpload = await self.uploadFile(rest.tempFilePath, 0);
|
|
|
|
|
+ resolve()
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('无需压缩');
|
|
|
|
|
+ const waitUpload = await self.uploadFile(self.avatarUrl, 0);
|
|
|
|
|
+ resolve()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ uploadFile(options, int) {
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ var self = this;
|
|
|
|
|
+ var data = {
|
|
|
|
|
+ imageStatus: int
|
|
|
|
|
+ };
|
|
|
|
|
+ this.$api.aliyunpolicy(data).then(res => {
|
|
|
|
|
+ var ossToken = res.data.data.resultContent;
|
|
|
|
|
+ uni.uploadFile({
|
|
|
|
|
+ url: ossToken.host,
|
|
|
|
|
+ name: 'file',
|
|
|
|
|
+ filePath: options,
|
|
|
|
|
+ fileType: 'image',
|
|
|
|
|
+ header: {
|
|
|
|
|
+ AuthorizationToken: 'WX ' + uni.getStorageSync('token')
|
|
|
|
|
+ },
|
|
|
|
|
+ formData: {
|
|
|
|
|
+ key: ossToken.dir,
|
|
|
|
|
+ OSSAccessKeyId: ossToken.accessid,
|
|
|
|
|
+ policy: ossToken.policy,
|
|
|
|
|
+ Signature: ossToken.signature,
|
|
|
|
|
+ callback: ossToken.callback,
|
|
|
|
|
+ success_action_status: 200
|
|
|
|
|
+ },
|
|
|
|
|
+ success: result => {
|
|
|
|
|
+ if (result.statusCode === 200) {
|
|
|
|
|
+ self.userInfo.avatar = ossToken.dir;
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '上传失败',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: error => {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '上传接口报错',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ updateInfo(){
|
|
|
|
|
+ let self = this
|
|
|
this.$api.appuserInfo(this.userInfo).then(res => {
|
|
this.$api.appuserInfo(this.userInfo).then(res => {
|
|
|
if (res.data.code === 200) {
|
|
if (res.data.code === 200) {
|
|
|
uni.showToast({
|
|
uni.showToast({
|
|
@@ -47,6 +122,23 @@
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
|
|
+ submitForm(){
|
|
|
|
|
+ if(this.userInfo.nickname==''){
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: "提示",
|
|
|
|
|
+ content: '昵称不能为空',
|
|
|
|
|
+ showCancel: false
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.submit()
|
|
|
|
|
+ },
|
|
|
|
|
+ async submit(){
|
|
|
|
|
+ if(this.avatarUrl!=this.userInfo.avatar){
|
|
|
|
|
+ const waitYS = await this.imageInfos();
|
|
|
|
|
+ }
|
|
|
|
|
+ this.updateInfo()
|
|
|
|
|
+ },
|
|
|
exit(){
|
|
exit(){
|
|
|
this.$method.exit()
|
|
this.$method.exit()
|
|
|
},
|
|
},
|
|
@@ -89,6 +181,7 @@
|
|
|
.avatar{
|
|
.avatar{
|
|
|
height: 70rpx;
|
|
height: 70rpx;
|
|
|
width: 70rpx;
|
|
width: 70rpx;
|
|
|
|
|
+ border-radius: 50%;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
page {
|
|
page {
|