123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
- var Manage = function(){
- this.weixinURL = "http://res.wx.qq.com/open/js/jweixin-1.2.0.js",
- this.time = "?"+new Date().getTime();
- this.weixin();
- }
- //动态加载js文件
- Manage.prototype.LoadJs = function(_files, succes){
- /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
- var classcodes = [];
- var FileArray = [];
- if (typeof _files === "object") {
- FileArray = _files;
- } else {
- /*如果文件列表是字符串,则用,切分成数组*/
- if (typeof _files === "string") {
- FileArray = _files.split(",");
- }
- }
- if (FileArray != null && FileArray.length > 0) {
- var LoadedCount = 0;
- for (var i = 0; i < FileArray.length; i++) {
- loadFile(FileArray[i], function() {
- LoadedCount++;
- if (LoadedCount == FileArray.length) {
- try {
- succes();
- }
- catch(err) {
- console.log("err: 您未定义回调");
- }
- }
- })
- }
- }
- /*加载JS文件,url:文件路径,success:加载成功回调函数*/
- function loadFile(url, success) {
- if (!FileIsExt(classcodes, url)) {
- var _ThisType = GetFileType(url);
- var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
- var fileObj = null;
- if (ThisType == ".js") {
- fileObj = document.createElement('script');
- fileObj.src = url;
- } else if (ThisType == ".css") {
- fileObj = document.createElement('link');
- fileObj.href = url;
- fileObj.type = "text/css";
- fileObj.rel = "stylesheet";
- } else if (ThisType == ".less") {
- fileObj = document.createElement('link');
- fileObj.href = url;
- fileObj.type = "text/css";
- fileObj.rel = "stylesheet/less";
- }
- success = success || function() {};
- fileObj.onload = fileObj.onreadystatechange = function() {
- if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
- success();
- classcodes.push(url)
- }
- }
- document.getElementsByTagName('head')[0].appendChild(fileObj);
- } else {
- success();
- }
- }
- /*获取文件类型,后缀名,小写*/
- function GetFileType(url) {
- if (url != null && url.length > 0) {
- return url.substr(url.lastIndexOf(".")).toLowerCase();
- }
- return "";
- }
- /*文件是否已加载*/
- function FileIsExt(FileArray, _url) {
- if (FileArray != null && FileArray.length > 0) {
- var len = FileArray.length;
- for (var i = 0; i < len; i++) {
- if (FileArray[i] == _url) {
- return true;
- }
- }
- }
- return false;
- }
-
- };
- //获取页面url后面的参数
- Manage.prototype.number = function(variable) {
- var query = window.location.search.substring(1);
- var vars = query.split("&");
- for (var i=0;i<vars.length;i++) {
- var pair = vars[i].split("=");
- if(pair[0] == variable){return pair[1];}
- }
- return(false);
- };
- Manage.prototype.weixin = function() {
- var that = this;
- g_weixinObj = {
- "lineLink" : window.location.href,
- "imgUrl" : "http://www.4dageweb.com/SuperPanoramic/images/weixintitle.jpg",
- "desc" : "四维时代提供技术支持",
- }
- this.LoadJs(that.weixinURL+that.time,function(){
- weixinShare();
- });
- function weixinShare(){
- $.ajax({
- url:'http://www.4dage.com/Weixin3/wechatconfig/jssdk',
- type: "post",
- data : {
- 'url' : location.href.split('#')[0]
- },
- dataType:"jsonp",
- jsonpCallback:"success_jsonp",
- success:function(data,textStatus){
- wx.config({
- // debug : true,
- appId : data.appId,
- timestamp : data.timestamp,
- nonceStr : data.nonceStr,
- signature : data.signature,
- jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
- 'onMenuShareAppMessage', 'onMenuShareQQ',
- 'onMenuShareWeibo', 'hideMenuItems',
- 'showMenuItems', 'hideAllNonBaseMenuItem',
- 'showAllNonBaseMenuItem', 'translateVoice',
- 'startRecord', 'stopRecord', 'onRecordEnd',
- 'playVoice', 'pauseVoice', 'stopVoice',
- 'uploadVoice', 'downloadVoice', 'chooseImage',
- 'previewImage', 'uploadImage', 'downloadImage',
- 'getNetworkType', 'openLocation', 'getLocation',
- 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
- 'scanQRCode', 'chooseWXPay',
- 'openProductSpecificView', 'addCard', 'chooseCard',
- 'openCard' ]
- });
- },
- error:function(XMLHttpRequest,textStatus,errorThrown){
- console.log("jsonp.error:"+textStatus);
- }
- });
-
- var success_jsonp = function(json){
- console.log(json);
- };
- wx.ready(function(){
- // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
- //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
- //分享到朋友圈
- wx.onMenuShareTimeline({
- title: document.querySelector("head title").innerHTML, // 分享标题
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- desc: g_weixinObj.desc
- });
- //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
- wx.onMenuShareAppMessage({
- title: document.querySelector("head title").innerHTML, // 分享标题
- desc: g_weixinObj.desc, // 分享描述
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- type: '', // 分享类型,music、video或link,不填默认为link
- dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
- });
- });
- wx.onMenuShareWeibo({
- title: document.querySelector("head title").innerHTML, // 分享标题
- desc: g_weixinObj.desc, // 分享描述
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- success: function () {
- // 用户确认分享后执行的回调函数
- },
- cancel: function () {
- // 用户取消分享后执行的回调函数
- }
- });
- wx.onMenuShareQZone({
- title: document.querySelector("head title").innerHTML, // 分享标题
- desc: g_weixinObj.desc, // 分享描述
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- success: function () {
- // 用户确认分享后执行的回调函数
- },
- cancel: function () {
- // 用户取消分享后执行的回调函数
- }
- });
- wx.onMenuShareQQ({
- title: document.querySelector("head title").innerHTML, // 分享标题
- desc: g_weixinObj.desc, // 分享描述
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- success: function () {
- // 用户确认分享后执行的回调函数
- },
- cancel: function () {
- // 用户取消分享后执行的回调函数
- }
- });
- wx.error(function(res){
- // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
- });
- }
- }
- var manage = new Manage();
|