<script src="js/pace.min.js"></script>
<script src="js/require.js" data-main="js/main" defer async="true"></script>
/*--------------------------------------------------------------------------------------------------*/
var htmlEl = document.getElementsByTagName('html')[0];
var fitPage = function() {
/* The calculate of with from zepto */
var w = htmlEl.getBoundingClientRect().width;
w = Math.round(w);
w = w > 750 ? 750 : w;
var newW = w / 750 * 100;
htmlEl.style.fontSize = newW + 'px';
};
fitPage();
var t;
var func = function() {
clearTimeout(t);
t = setTimeout(fitPage, 25);
};
window.addEventListener('resize', func);
/*--------------------------------------------------------------------------------------------------*/
// 有时候你想避开"baseUrl + paths"的解析过程,而是直接指定加载某一个目录下的脚本。此时可以这样做:如果一个module ID符合下述规则之一,其ID解析会避开常规的"baseUrl + paths"配置,而是直接将其加载为一个相对于当前HTML文档的脚本:
// 以 ".js" 结束.
// 以 "/" 开始.
// 包含 URL 协议, 如 "http:" or "https:".
require.config({
baseUrl: "js",
paths: {
jquery: 'jquery-1.8.2.min',
touch: 'touch',
wx: 'https://res.wx.qq.com/open/js/jweixin-1.3.2'
}
});
require(['jquery', 'touch', 'wx'],
function($, touch, wx) {
var a = {};
//设备匹配查询
a.parseUA = function() {
var b = navigator.userAgent;
var c = navigator.userAgent.toLowerCase();
return {
mobile: !!b.match(/(iPhone|iPod|Android|ios|Mobile)/i),
pc: !b.match(/(iPhone|iPod|Android|ios|Mobile)/i),
ios: !!b.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
android: b.indexOf("Android") > -1,
weixin: c.match(/MicroMessenger/i) == "micromessenger"
}
};
//PC检查
a.pc_code = function() {
var c = a.parseUA().pc;
if (c) {
var d = document.createElement("div");
d.style.cssText = "width:100%;height:100%;position:fixed;left:0;top:0;z-index:9999999;background:#1BE394;";
var e = document.createElement("img");
e.style.cssText = "width:300px;height:300px;position:fixed;top:50%;left:50%;margin-left:-150px;margin-top:-220px;";
e.setAttribute("src", "images/codeImg.png");
d.appendChild(e);
var b = document.createElement("p");
b.style.cssText = "width:300px;height:300px;position:fixed;top:50%;left:50%;margin-left:-150px;margin-top:80px;text-align:center;font-size:18px;font-weight:bold;color:#fff;";
b.innerHTML = "为了更好的体验,请使用移动端访问~";
d.appendChild(b);
d.setAttribute("id", "pcCheck");
document.body.appendChild(d)
}
};
//竖屏检查
a.landscape = function() {
var b = document.createElement("div");
//请使用竖屏浏览
b.style.cssText = "width:100%;height:100%;position:fixed;left:0;top:0;z-index:999999999;background:#fc4a73 url(images/tip.png) no-repeat center center;display:none;";
setTimeout(function() {
document.body.appendChild(b)
}, 200);
function c() {
// var flag = document.getElementById('pcCheck')
// if (flag != undefined) {
// return false
// }
//console.log(document.body)
//console.log(window)
if (window.orientation === 180 || window.orientation === 0) {
setTimeout(function() {
b.style.display = "none"
}, 250)
}
if (window.orientation === 90 || window.orientation === -90) {
setTimeout(function() {
b.style.display = "block"
}, 250)
}
}
c();
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", c, false) //冒泡执行全局c()函数
};
//微信分享配置
a.wxshare = function() {
$.ajax({
url: '获取签名信息的接口',
type: "GET",
data: url,
success: function(res) {
wx.config({
debug: false,
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: res.data.appId, // 必填,企业号的唯一标识
timestamp: res.data.timestamp, // 必填,生成签名的时间戳
nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
signature: res.data.signature, // 必填,签名
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareQZone', 'onMenuShareWeibo']
//必填,需要使用的JS接口列表
});
wx.ready(function() {
share();
});
},
error: function(res) {}
});
function share() {
var config = {
title: '分享标题',
desc: '分享描述',
imgUrl: '分享图标',
link: '分享链接,该链接域名必须与当前企业的可信域名一致',
type: '分享类型,music、video或link,不填默认为link',
dataUrl: '如果type是music或video,则要提供数据链接,默认为空',
successFn: function() {
// 用户确认分享后执行的回调函数
},
cancelFn: function() {
// 用户取消分享后执行的回调函数
}
};
wx.onMenuShareAppMessage(config); //分享给朋友
wx.onMenuShareQQ(config); //分享到QQ
wx.onMenuShareQZone(config); //分享到QQ空间
wx.onMenuShareTimeline(config); //分享到朋友圈
wx.onMenuShareWeibo(config); //分享到腾讯微博
}
};
a.init = function() {
a.pc_code(); //PC检查
a.landscape(); //竖屏检查
a.wxshare(); //微信分享配置
};
a.init() //执行
});
参考链接H5微信分享配置 https://www.cnblogs.com/zhuweipeng/p/8583840.html