| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 | import base from '@/config/baseUrl';import store from '@/store';import $http from '@/config/requestConfig'import {	getLocation,	setShare} from '@/plugins/wxJsSDK';/** * APP内嵌网页 -- 安卓IOS交互 */export const appMutual = (name, query = null, errCallback) => {	if (/android/i.test(navigator.userAgent)) {		if (window.shangChengView) {			if (typeof(query) == "object") {				query = JSON.stringify(query);			}			window.shangChengView[name](query);		} else {			errCallback && errCallback();		}	} else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {		if (window.webkit) {			window.webkit.messageHandlers[name].postMessage(query)		} else {			errCallback && errCallback();		}	}};/** * 获取url中的参数 */export const getUrlData = () => {	var strs;	var url = window.location.href; //获取url中"?"符后的字串	var theRequest = new Object();	if (url.indexOf("?") != -1) {		url = url.substr(url.indexOf("?"));		var str = url.substr(1);		strs = str.split("&");		for (var i = 0; i < strs.length; i++) {			var index = strs[i].indexOf("=");			theRequest[strs[i].slice(0, index)] = unescape(strs[i].slice(index + 1, strs[i].length));		}	}	return theRequest;}//公众号微信支付export const wxPublicPay = (payInfo, callback) => {	$http.get("api/pay/v1/pay_public_wx", {		orderNo: payInfo.orderNo	}).then(data => {		let wxConfigObj = {			appId: data.appId,			timeStamp: data.timeStamp,			nonceStr: data.nonceStr,			package: data.package,			signType: data.signType,			paySign: data.sign		};		function onBridgeReady() {			window.WeixinJSBridge.invoke("getBrandWCPayRequest", wxConfigObj, function(				res			) {				if (res.err_msg == "get_brand_wcpay_request:ok") {					callback && callback(res);				} else // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回    ok,但并不保证它绝对可靠。					if (res.err_msg == "get_brand_wcpay_request:cancel") {						// common.loadWarn('支付遇到问题,您取消了支付');					} else				if (res.err_msg == "get_brand_wcpay_request:fail") {					// common.myConfirm('支付遇到问题,您可能需要重新登录', '', function () {					//   obj.wxLoginOAuth();					// });				}			});		}		if (typeof window.WeixinJSBridge == "undefined") {			if (document.addEventListener) {				document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);			} else if (document.attachEvent) {				document.attachEvent("WeixinJSBridgeReady", onBridgeReady);				document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);			}		} else {			onBridgeReady();		}	});};// 浏览器判断// export const getBrowser = () => {// 	let ua = navigator.userAgent.toLowerCase();// 	if (ua.match(/MicroMessenger/i) == "micromessenger") {// 		return "微信";// 	}// 	return "其他";// };// 获取地址信息(公众号获取 或 内嵌APP获取)export const getLatLonH5 = function(successCallback, errCallback) {	if (getBrowser() == '微信') {		getLocation().then(res => {			successCallback(res);		}, err => {			console.log("位置信息错误", err);			errCallback("位置信息获取失败");		});	} else {		let clearTime = setTimeout(() => {			errCallback("获取经纬度超时");		}, 5000);		window.getAppLatLon = function(res) {			clearTimeout(clearTime);			successCallback(res);		}		appMutual("getAppLatLon", true);	}};// 公众号分享export const publicShareFun = function(info = {}, callback) {	if (getBrowser() == "微信") {		let shareInfo = {			title: info.shareTitle || info.title || base.share.title,			desc: info.desc || info.shareContent || base.share.desc,			imgUrl: info.imgUrl || info.shareImg || base.share.imgUrl,			link: info.link || info.shareUrl || base.share.link,		};		setShare(shareInfo, callback);	}}// export const h5Login = function(type = "judge", callback) {// 	// var getRequest = getUrlData();// 	if (getBrowser() == "微信") {// 		uni.reLaunch({// 			url: "/pages/login/login"// 		});// 	} else {// 		appMutual("jumpLogin", null, function() {// 			if (type == "force") {// 				uni.reLaunch({// 					url: "/pages/login/login"// 				});// 			}else{// 				uni.showModal({// 					title:"提示",// 					content:"您还未登录,请先登录~",// 					confirmText: "去登录",// 					cancelText: "再逛会",// 					success: (res) => {// 						if(res.confirm){// 							uni.reLaunch({// 								url: "/pages/login/login"// 							});// 						}// 					}// 				});// 			}// 		});// 	}// }
 |