export default {
		data() {
			return {
				sweixin: null
			}
		},
		methods: {
			getPlus() {
				//获取当前显示的webview
				var pages = getCurrentPages()
				var page = pages[pages.length - 1]
				var currentWebview = page.$getAppWebview()
				//调用H5+APP的扩展API
				var shares=null;
				let that = this
				var pusher = plus.share.getServices(function(s){
					shares={};
					for(var i in s){
						var t=s[i];
						shares[t.id]=t;
					}
					that.sweixin=shares['weixin'];
				}, function(e){
					console.log("获取分享服务列表失败:"+e.message);
				});
				//放入当前的webview
				currentWebview.append(pusher);
			},
			// 跳转到微信的小程序
			async openWxProgram(url, appId){
				
				// app跳转到小程序
				plus.share.getServices(
					res => {
						let sweixin = null;
						for (let i in res) {
							if (res[i].id == 'weixin') {
								sweixin = res[i];
							}
						}
						//唤醒微信小程序
						if (sweixin) {
							uni.hideLoading()
							sweixin.launchMiniProgram({
								id: appId, //需要跳转到的小程序的原始id,这是特别要注意的,
								type: 0, // //0 release ,1 test, 2 preview
								//跳转指定小程序的页面
								// path: 'pages/union/proxy/proxy?spreadUrl=' + encodeURIComponent(url)
								path: url
							});
						}
					}
				)
			},
			// 跳转到APP
			async openApp(app_url, h5_url){
				if (typeof plus !== 'undefined'){
					console.log(app_url);
					if(plus.runtime.isApplicationExist({ pname: 'com.jingdong.app.mall'},{action:'openApp.jdMobile://'})){
						await plus.runtime.openURL(app_url, (error) => {
							uni.hideLoading()
							if (error) {
								   uni.showModal({
									  title: '提示',
									  content: '是否打开网页版京东?',
									  confirmText: '打开网页版',
									  cancelText: '取消',
									  success: (res) => {
										  if (res.confirm) {
											  if (app_url.startsWith('//')) {
											      app_url = 'https:' + app_url;
											  }
											 plus.runtime.openURL(app_url)
										  }
									  }
								  });
							}
						});
					}
				}
			},
			async openInTaobao(item){
				console.log(item);
				// let url = 'https://u.jd.com/AOmpGGc';
				// let appId = 'gh_45b306365c3d';
				// console.log("wx", wx.miniapp);
				uni.showToast({
					title: '跳转中......' ,
					icon: 'none'
				});
				setTimeout(()=>{
					uni.hideLoading()
				},6000)
				
				const res = await request.get('appV2/tbk/link/jd', {
					link_url:item.link_url
				},{login: true}).then(res => {
					setTimeout(()=>{
						uni.hideLoading()
					},20)
					// 京东: com.jingdong.app.mall --- openApp.jdMobile://
					if(typeof plus !== 'undefined' && plus.runtime.isApplicationExist({ pname: 'com.jingdong.app.mall'},{action:'openApp.jdMobile://'})){
						console.log("京东APP");
						this.openApp(res.data.app_url, res.data.h5_url);
						// this.openWxProgram(res.data.wxminiapp.page, res.data.wxminiapp.id);
					}else if(typeof plus !== 'undefined' && plus.runtime.isApplicationExist({ pname: 'com.tencent.mm'})){
						// 微信:com.tencent.mm --- weixin://
						console.log("微信APP");
						this.openWxProgram(res.data.wxminiapp.page, res.data.wxminiapp.id);
					}else{
						console.log("都没有");
						let url = res.data.h5_url;
						uni.showModal({
							title: '提示',
							content: '是否打开网页版京东?',
							confirmText: '打开网页版',
							cancelText: '取消',
							success: (res) => {
							  if (res.confirm) {
									if (url.startsWith('//')) {
									  url = 'https:' + url;
									}
									plus.runtime.openURL(res.data.h5_url)
							  }
							}
						});
					}
				})
			},
		}
}
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐