From cbe649348d0bc5429a92d6c6f0e43e41f3aa88f0 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Thu, 17 Jun 2021 10:14:05 +0800
Subject: [PATCH] 子页面返回父页面通过onShow 调用实现数据刷新

---
 pages/myself/childen/xinxi.vue |    6 +
 pages/myself/myself.vue        |  145 +++++++++++++++++++++++++++---------------------
 2 files changed, 86 insertions(+), 65 deletions(-)

diff --git a/pages/myself/childen/xinxi.vue b/pages/myself/childen/xinxi.vue
index 42d5ef8..ecf1277 100644
--- a/pages/myself/childen/xinxi.vue
+++ b/pages/myself/childen/xinxi.vue
@@ -73,7 +73,11 @@
 			return this.$store.state.puserIphone
 		},
 	},
-	mounted(){
+	//子页面返回时刷新数据
+	onShow(){
+		this.getUserInfo();
+	},
+	onLoad() {
 		//页面进入后查询用户账户信息
 		this.getUserInfo();
 	},
diff --git a/pages/myself/myself.vue b/pages/myself/myself.vue
index 4dc7b3c..a88da08 100644
--- a/pages/myself/myself.vue
+++ b/pages/myself/myself.vue
@@ -108,6 +108,10 @@
 				this.useimg = this.$store.state.avatar;
 			}
 		},
+		//子页面返回时执行
+		onShow() {
+			
+		},
 		methods: {
 			openThere(fn) {
 				this[fn]();
@@ -166,73 +170,86 @@
 					that.showTextmsg = false;
 				}
 			},
-			//图片上传
+			//头像查看,上传
 			ChooseImage() {
 				var that = this;
-					uni.chooseImage({
-						count: 1, //可选择数量,默认9
-						sizeType: ['compressed','original'], //上传压缩图,原图
-						sourceType: ['album','camera'], //从相册选择或从使用相机
-						success: async (res) => {
-							for (var i = 0; i < res.tempFiles.length; i++) {
-								if(res.tempFiles[i].size > 10 * 1024 * 1000){  //上传图片大小限制
-									uni.showToast({
-										title: "照片大小不能10MB", 
-										icon: "none"
-									})
-									return
-								}
-							}
-							var tempFilePath = res.tempFilePaths;
-							try{
-								uni.showLoading({
-									title:"上传中...",
-									mask:true
-								})
-								var that = this;
-								// 文件上传
-								uni.uploadFile({
-									// url: 'https://web.byisf.com/api/blade-jfpts/depl/put-depl', //仅为示例,非真实的接口地址
-									url: 'http://web.byisf.com:82/blade-jfpts/depl/put-depl',
-									filePath: tempFilePath[0],
-									name: 'file',
-									formData: {
-										'user': 'test'  // 上传附带参数
-									},
-									success: (data) => {
-										that.useimg = JSON.parse(data.data).data;
-										//修改用户头像信息
-										uni.request({
-											url:"http://s16s652780.51mypc.cn/api/blade-user/updateUserInfo",
-											method:"POST",
-											data:{
-												id: this.$store.state.puserID,
-												avatar:that.useimg
-											},
-											success:(res)=> {
-												if(res.data.code==200){
-													uni.showToast({
-													    title: '上传成功!',
-													    duration: 2000
-													});
-												}
-											}
-										})
-									}
-								});
-							}catch(e){
-								console.log(e);
-							}finally{
-								uni.hideLoading();
-							}
+				uni.showActionSheet({
+					// itemList按钮的文字接受的是数组
+					itemList: ["查看头像","更换头像"],
+					success(e){
+						var index = e.tapIndex;
+						if(index === 0){
+							// 用户点击了预览当前图片
+							// 可以自己实现当前头像链接的读取
+						    let url  = that.useimg;
+						    let arr=[]
+						    arr.push(url)
+						    uni.previewImage({
+								// 预览功能图片也必须是数组的
+								urls: arr
+						    })
 						}
-					}); 
-				}
-			// geton() {
-			// 	wx.navigateTo({
-			// 		url: '../poput/workbench/policeDetails/policeDetails?id=111'
-			// 	})
-			// }
+					    if(index === 1){
+							// 用户点击了从图库上传
+							uni.chooseImage({
+								count: 1, //可选择数量,默认9
+								sizeType: ['compressed','original'], //上传压缩图,原图
+								sourceType: ['album','camera'], //从相册选择或从使用相机
+								success: async (res) => {
+									if(res.tempFiles[0].size > 10 * 1024 * 1000){  //上传图片大小限制
+										uni.showToast({
+											title: "照片大小不能10MB", 
+											icon: "none"
+										})
+										return
+									}
+									var tempFilePath = res.tempFilePaths;
+									try{
+										uni.showLoading({
+											title:"上传中...",
+											mask:true
+										})
+										// 文件上传
+										uni.uploadFile({
+											// url: 'https://web.byisf.com/api/blade-jfpts/depl/put-depl', //仅为示例,非真实的接口地址
+											url: 'http://web.byisf.com:82/blade-jfpts/depl/put-depl',
+											filePath: tempFilePath[0],
+											name: 'file',
+											formData: {
+												'user': 'test'  // 上传附带参数
+											},
+											success: (data) => {
+												that.useimg = JSON.parse(data.data).data;
+												//修改用户头像信息
+												uni.request({
+													url:"http://s16s652780.51mypc.cn/api/blade-user/updateUserInfo",
+													method:"POST",
+													data:{
+														id: that.$store.state.puserID,
+														avatar:that.useimg
+													},
+													success:(res)=> {
+														if(res.data.code==200){
+															uni.showToast({
+															    title: '上传成功!',
+															    duration: 2000
+															});
+														}
+													}
+												})
+											}
+										});
+									}catch(e){
+										console.log(e);
+									}finally{
+										uni.hideLoading();
+									}
+								}
+							})
+						}
+					}
+				});
+			}
 		},
 	}
 </script>

--
Gitblit v1.9.3