he2802 před 4 roky
rodič
revize
a1b702e992
4 změnil soubory, kde provedl 103 přidání a 10 odebrání
  1. 1 0
      components/my.vue
  2. 99 6
      pages2/wd/avatar.vue
  3. 1 1
      pages2/wd/info.vue
  4. 2 3
      store/index.js

+ 1 - 0
components/my.vue

@@ -268,6 +268,7 @@
 	.avatar{
 		width: 140rpx;
 		height: 140rpx;
+		border-radius: 50%;
 	}
 	
 	

+ 99 - 6
pages2/wd/avatar.vue

@@ -2,7 +2,7 @@
 	<view>
 		<u-cell-group>
 				<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  title="昵称" :value="userInfo.nickname" @click="editNickName"></u-cell-item>
 			</u-cell-group>
@@ -12,7 +12,7 @@
 				</view>
 			</u-modal>
 			<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>
 			</view>
@@ -25,18 +25,93 @@
 		data() {
 			return {
 				show: false,
+				avatarUrl:''
 			}
 		},
 		onLoad(option) {
 			
 		},
 		onShow(){
+			this.avatarUrl = this.userInfo.avatar
 		},
 		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 => {
 					if (res.data.code === 200) {
 						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(){
 				this.$method.exit()
 			},
@@ -89,6 +181,7 @@
 	.avatar{
 		height: 70rpx;
 		width: 70rpx;
+		border-radius: 50%;
 		
 	}
 page {

+ 1 - 1
pages2/wd/info.vue

@@ -301,7 +301,7 @@ export default {
 						filePath: options,
 						fileType: 'image',
 						header: {
-							AuthorizationToken: 'WX ' + self.$store.state.token
+							AuthorizationToken: 'WX ' + uni.getStorageSync('token')
 						},
 						formData: {
 							key: ossToken.dir,

+ 2 - 3
store/index.js

@@ -21,15 +21,14 @@ const store = new Vuex.Store({
 						
 					});
 				}
-			}else{
-				return state.userInfo
+				
 			}
+			return state.userInfo
 		}
 	},
     mutations: {  
         updateUserInfo(state, provider) {  
             state.userInfo = provider.userInfo;  
-			console.log(state.userInfo,999)
         },  
         
     }