Przeglądaj źródła

feat: 新增地址分享模块

wenxingxing 12 godzin temu
rodzic
commit
d88a94e6b8

+ 57 - 1
pages/user/addEditAddress.vue

@@ -45,7 +45,11 @@
 			</view>
 		</view>
 		<view class="btn-box">
-			<view class="sub-btn" @click="submit()">保存地址</view>
+			<view class="sub-btn flex-1" @click="submit()">保存地址</view>
+			<view v-if="type=='add'" class="icon-btn" style="width: 15%;" @click="openShare">
+				<image src="/static/images/icon_wx.png" mode="aspectFill"></image>
+				<text>分享</text>
+			</view>
 		</view>
 	</view>
 </template>
@@ -91,6 +95,42 @@
 			this.getCitys()
 		},
 		methods: {
+			openShare() {
+			//#ifdef H5
+				uni.showToast({
+					title: '请使用APP操作',
+					icon: 'none'
+				});				
+			//#endif
+			
+			//#ifdef APP-PLUS
+			uni.share({
+				provider: "weixin",
+				scene: 'WXSceneSession',
+				type: 5,
+				imageUrl: 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/app/app-address.jpg', //分享封面图片
+				title: '乐享韶华-邀请你填写地址,下单更方便', // 分享标题
+				miniProgram: {
+					id: getApp().globalData.miniprogamId,
+					path: '/pages_user/user/addAddress?type=add',
+					type: 0, //0-正式版; 1-测试版; 2-体验版。 默认值为0。
+					webUrl: "http://uniapp.dcloud.io"
+				},
+				success: function(res) {
+					uni.showToast({
+						title: "分享成功",
+						icon: 'none'
+					});
+				},
+				fail: function(err) {
+					// 此处是调起微信分享失败的回调
+				},
+				complete: (e) => {
+					console.log("WXSceneSession", e)
+				}
+			});
+			//#endif
+			},
 			parseAddress(){
 				if(this.content==null||this.content==""){
 					uni.showToast({
@@ -401,4 +441,20 @@
 			}
 		}
 	}
+	.icon-btn {
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+		justify-content: center;
+	
+		image {
+			width: 55rpx;
+			height: 55rpx;
+		}
+	
+		text {
+			font-size: 26rpx;
+			color: #222222;
+		}
+	}
 </style>

+ 80 - 6
pages/user/address.vue

@@ -24,8 +24,11 @@
 			
 		</view>
 		<view class="btn-box">
-			
-			<view class="sub-btn" @click="addAddress()">新建收货地址</view>
+			<view class="sub-btn flex-1" @click="addAddress()">新建收货地址</view>
+			<view class="icon-btn" style="width: 15%;" @click="openShare">
+				<image src="/static/images/icon_wx.png" mode="aspectFill"></image>
+				<text>分享</text>
+			</view>
 		</view>
 	</view>
 </template>
@@ -49,10 +52,25 @@
 		},
 		methods: {
 			selectAddress(item){
-				uni.$emit('updateAddress',item);
-				uni.navigateBack({
-			  		delta: 1
-				})
+				// 获取当前所有页面栈
+				const pages = getCurrentPages();
+				if (pages.length >= 2) {
+					const prevPage = pages[pages.length - 2];
+					if (prevPage.route === 'pages_mall/index' || prevPage.route === 'pages/user/index') {
+						uni.navigateTo({
+							url: './addEditAddress?type=edit&addressId='+item.addressId
+						})
+					}else{
+						uni.$emit('updateAddress',item);
+						uni.navigateBack({
+							delta: 1
+						})
+					}
+				}else{
+					uni.navigateTo({
+						url: './addEditAddress?type=edit&addressId='+item.addressId
+					})
+				}
 			},
 			editAddress(item){
 				uni.navigateTo({
@@ -114,6 +132,42 @@
 				uni.navigateTo({
 					url: './addEditAddress?type=add'
 				})
+			},
+			openShare() {
+				//#ifdef H5
+					uni.showToast({
+						title: '请使用APP操作',
+						icon: 'none'
+					});				
+				//#endif
+				
+				//#ifdef APP-PLUS
+				uni.share({
+					provider: "weixin",
+					scene: 'WXSceneSession',
+					type: 5,
+					imageUrl: 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/app/app-address.jpg', //分享封面图片
+					title: '乐享韶华-邀请你填写地址,下单更方便', // 分享标题
+					miniProgram: {
+						id: getApp().globalData.miniprogamId,
+						path: '/pages_user/user/address',
+						type: 0, //0-正式版; 1-测试版; 2-体验版。 默认值为0。
+						webUrl: "http://uniapp.dcloud.io"
+					},
+					success: function(res) {
+						uni.showToast({
+							title: "分享成功",
+							icon: 'none'
+						});
+					},
+					fail: function(err) {
+						// 此处是调起微信分享失败的回调
+					},
+					complete: (e) => {
+						console.log("WXSceneSession", e)
+					}
+				});
+				//#endif
 			}
 		}
 	}
@@ -214,6 +268,9 @@
  			left: 0;
  			box-sizing: border-box;
  			background: #FFFFFF;
+			display: flex;
+			align-items: center;
+			justify-content: space-between;
  			 
  			.sub-btn{
  				 
@@ -229,5 +286,22 @@
  			}
  		}
  	}
+	
+	.icon-btn {
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+		justify-content: center;
+	
+		image {
+			width: 55rpx;
+			height: 55rpx;
+		}
+	
+		text {
+			font-size: 26rpx;
+			color: #222222;
+		}
+	}
  </style>
  

+ 56 - 0
pages_user/user/addAddress.vue

@@ -41,6 +41,10 @@
 		</view>
 		<view class="btn-box">
 			<view class="sub-btn" @click="submit()">保存地址</view>
+			<view v-if="type=='add'" class="icon-btn" style="width: 15%;" @click="openShare">
+				<image src="/static/images/icon_wx.png" mode="aspectFill"></image>
+				<text>分享</text>
+			</view>
 		</view>
 	</view>
 </template>
@@ -87,6 +91,42 @@
 			this.getCitys()
 		},
 		methods: {
+			openShare() {
+			//#ifdef H5
+				uni.showToast({
+					title: '请使用APP操作',
+					icon: 'none'
+				});				
+			//#endif
+			
+			//#ifdef APP-PLUS
+			uni.share({
+				provider: "weixin",
+				scene: 'WXSceneSession',
+				type: 5,
+				imageUrl: 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/app/app-address.jpg', //分享封面图片
+				title: '乐享韶华-邀请你填写地址,下单更方便', // 分享标题
+				miniProgram: {
+					id: getApp().globalData.miniprogamId,
+					path: '/pages_user/user/addAddress?type=add',
+					type: 0, //0-正式版; 1-测试版; 2-体验版。 默认值为0。
+					webUrl: "http://uniapp.dcloud.io"
+				},
+				success: function(res) {
+					uni.showToast({
+						title: "分享成功",
+						icon: 'none'
+					});
+				},
+				fail: function(err) {
+					// 此处是调起微信分享失败的回调
+				},
+				complete: (e) => {
+					console.log("WXSceneSession", e)
+				}
+			});
+			//#endif
+			},
 			parseAddress(){
 				if(this.content==null||this.content==""){
 					uni.showToast({	icon:'none',title: '请输入地址信息'});
@@ -402,4 +442,20 @@
 			}
 		}
 	}
+	.icon-btn {
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+		justify-content: center;
+	
+		image {
+			width: 55rpx;
+			height: 55rpx;
+		}
+	
+		text {
+			font-size: 26rpx;
+			color: #222222;
+		}
+	}
 </style>

+ 60 - 2
pages_user/user/address.vue

@@ -27,8 +27,11 @@
 			
 		</view>
 		<view class="btn-box">
-			
-			<view class="sub-btn" @click="addAdress">新建收货地址</view>
+			<view class="sub-btn flex-1" @click="addAdress">新建收货地址</view>
+			<view class="icon-btn" style="width: 15%;" @click="openShare">
+				<image src="/static/images/icon_wx.png" mode="aspectFill"></image>
+				<text>分享</text>
+			</view>
 		</view>
 	</view>
 </template>
@@ -153,6 +156,42 @@
 				uni.navigateTo({
 					url: './addAddress?type=add'
 				})
+			},
+			openShare() {
+			//#ifdef H5
+				uni.showToast({
+					title: '请使用APP操作',
+					icon: 'none'
+				});				
+			//#endif
+			
+			//#ifdef APP-PLUS
+			uni.share({
+				provider: "weixin",
+				scene: 'WXSceneSession',
+				type: 5,
+				imageUrl: 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/app/app-address.jpg', //分享封面图片
+				title: '乐享韶华-邀请你填写地址,下单更方便', // 分享标题
+				miniProgram: {
+					id: getApp().globalData.miniprogamId,
+					path: '/pages_user/user/address',
+					type: 0, //0-正式版; 1-测试版; 2-体验版。 默认值为0。
+					webUrl: "http://uniapp.dcloud.io"
+				},
+				success: function(res) {
+					uni.showToast({
+						title: "分享成功",
+						icon: 'none'
+					});
+				},
+				fail: function(err) {
+					// 此处是调起微信分享失败的回调
+				},
+				complete: (e) => {
+					console.log("WXSceneSession", e)
+				}
+			});
+			//#endif
 			}
 		}
 	}
@@ -251,6 +290,9 @@
 			left: 0;
 			box-sizing: border-box;
 			background: #FFFFFF;
+			display: flex;
+			align-items: center;
+			justify-content: space-between;
 			 
 			.sub-btn{
 				 
@@ -266,4 +308,20 @@
 			}
 		}
 	}
+	.icon-btn {
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+		justify-content: center;
+	
+		image {
+			width: 55rpx;
+			height: 55rpx;
+		}
+	
+		text {
+			font-size: 26rpx;
+			color: #222222;
+		}
+	}
 </style>