import wx from 'weixin-js-sdk'; // 判断当前环境 export const handleToTypes = () => { let userAgent = navigator.userAgent.toLowerCase(); let type = ''; if (userAgent.indexOf('miniprogram') > -1) { if (userAgent.indexOf('alipay') > -1) { // 支付宝小程序环境 console.log('支付宝小程序'); type = 'alipaymini'; } else if ( userAgent.indexOf('wechat') > -1 || userAgent.indexOf('wx') > -1 ) { // 微信小程序 console.log('微信小程序'); type = 'wechatmini'; } //else{ // // this.juti = '其他小程序' // } } else if ( userAgent.indexOf('android') > -1 || userAgent.indexOf('linux') > -1 || userAgent.indexOf('adr') > -1 ) { type = 'android'; console.log('android'); } else { if (userAgent.indexOf('wechat') > -1 || userAgent.indexOf('wx') > -1) { // this.juti = '微信公众号' console.log('微信内部打开未内嵌'); type = 'wechat'; } else { // 其他页面暂时未实现 type = 'other'; } } return type; }; // 判断是否为网页还是其他 export const isWeb = (str) => { const reg = /(https?:\/\/)?(([0-9a-z.]+\.[a-z]+)|(([0-9]{1,3}\.){3}[0-9]{1,3}))(:[0-9]+)?(\/[0-9a-z%/.\-_]*)?(\?[0-9a-z=&%_\-]*)?(\#[0-9a-z=&%_\-]*)?/gi; return reg.test(str); }; export const handleToZhifubao = (path) => { my.navigateTo({ url: path }); }; // 跳转微信小程序内部 export const handleTonei = (path) => { wx.miniProgram.navigateTo({ url: path, // 可选,小程序的页面路径,可以不填 extraData: { // 可选,传递给小程序的数据,如分享信息等 }, success(res) { // 打开小程序成功的回调 // console.log(res); // alert(JSON.stringify(res) + '123') }, fail(err) { // 打开小程序失败的回调 // console.error(err); // alert(JSON.stringify(err) + '456') } }); };