manage.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  2. var Manage = function(){
  3. this.weixinURL = "http://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  4. this.time = "?"+new Date().getTime();
  5. this.weixin();
  6. }
  7. //动态加载js文件
  8. Manage.prototype.LoadJs = function(_files, succes){
  9. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  10. var classcodes = [];
  11. var FileArray = [];
  12. if (typeof _files === "object") {
  13. FileArray = _files;
  14. } else {
  15. /*如果文件列表是字符串,则用,切分成数组*/
  16. if (typeof _files === "string") {
  17. FileArray = _files.split(",");
  18. }
  19. }
  20. if (FileArray != null && FileArray.length > 0) {
  21. var LoadedCount = 0;
  22. for (var i = 0; i < FileArray.length; i++) {
  23. loadFile(FileArray[i], function() {
  24. LoadedCount++;
  25. if (LoadedCount == FileArray.length) {
  26. try {
  27. succes();
  28. }
  29. catch(err) {
  30. console.log("err: 您未定义回调");
  31. }
  32. }
  33. })
  34. }
  35. }
  36. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  37. function loadFile(url, success) {
  38. if (!FileIsExt(classcodes, url)) {
  39. var _ThisType = GetFileType(url);
  40. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  41. var fileObj = null;
  42. if (ThisType == ".js") {
  43. fileObj = document.createElement('script');
  44. fileObj.src = url;
  45. } else if (ThisType == ".css") {
  46. fileObj = document.createElement('link');
  47. fileObj.href = url;
  48. fileObj.type = "text/css";
  49. fileObj.rel = "stylesheet";
  50. } else if (ThisType == ".less") {
  51. fileObj = document.createElement('link');
  52. fileObj.href = url;
  53. fileObj.type = "text/css";
  54. fileObj.rel = "stylesheet/less";
  55. }
  56. success = success || function() {};
  57. fileObj.onload = fileObj.onreadystatechange = function() {
  58. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  59. success();
  60. classcodes.push(url)
  61. }
  62. }
  63. document.getElementsByTagName('head')[0].appendChild(fileObj);
  64. } else {
  65. success();
  66. }
  67. }
  68. /*获取文件类型,后缀名,小写*/
  69. function GetFileType(url) {
  70. if (url != null && url.length > 0) {
  71. return url.substr(url.lastIndexOf(".")).toLowerCase();
  72. }
  73. return "";
  74. }
  75. /*文件是否已加载*/
  76. function FileIsExt(FileArray, _url) {
  77. if (FileArray != null && FileArray.length > 0) {
  78. var len = FileArray.length;
  79. for (var i = 0; i < len; i++) {
  80. if (FileArray[i] == _url) {
  81. return true;
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87. };
  88. //获取页面url后面的参数
  89. Manage.prototype.number = function(variable) {
  90. var query = window.location.search.substring(1);
  91. var vars = query.split("&");
  92. for (var i=0;i<vars.length;i++) {
  93. var pair = vars[i].split("=");
  94. if(pair[0] == variable){return pair[1];}
  95. }
  96. return(false);
  97. };
  98. Manage.prototype.weixin = function() {
  99. var that = this;
  100. g_weixinObj = {
  101. "lineLink" : window.location.href,
  102. "imgUrl" : "http://www.4dageweb.com/SuperPanoramic/images/weixintitle.jpg",
  103. "desc" : "四维时代提供技术支持",
  104. }
  105. this.LoadJs(that.weixinURL+that.time,function(){
  106. weixinShare();
  107. });
  108. function weixinShare(){
  109. $.ajax({
  110. url:'http://www.4dage.com/Weixin3/wechatconfig/jssdk',
  111. type: "post",
  112. data : {
  113. 'url' : location.href.split('#')[0]
  114. },
  115. dataType:"jsonp",
  116. jsonpCallback:"success_jsonp",
  117. success:function(data,textStatus){
  118. wx.config({
  119. // debug : true,
  120. appId : data.appId,
  121. timestamp : data.timestamp,
  122. nonceStr : data.nonceStr,
  123. signature : data.signature,
  124. jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
  125. 'onMenuShareAppMessage', 'onMenuShareQQ',
  126. 'onMenuShareWeibo', 'hideMenuItems',
  127. 'showMenuItems', 'hideAllNonBaseMenuItem',
  128. 'showAllNonBaseMenuItem', 'translateVoice',
  129. 'startRecord', 'stopRecord', 'onRecordEnd',
  130. 'playVoice', 'pauseVoice', 'stopVoice',
  131. 'uploadVoice', 'downloadVoice', 'chooseImage',
  132. 'previewImage', 'uploadImage', 'downloadImage',
  133. 'getNetworkType', 'openLocation', 'getLocation',
  134. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  135. 'scanQRCode', 'chooseWXPay',
  136. 'openProductSpecificView', 'addCard', 'chooseCard',
  137. 'openCard' ]
  138. });
  139. },
  140. error:function(XMLHttpRequest,textStatus,errorThrown){
  141. console.log("jsonp.error:"+textStatus);
  142. }
  143. });
  144. var success_jsonp = function(json){
  145. console.log(json);
  146. };
  147. wx.ready(function(){
  148. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  149. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  150. //分享到朋友圈
  151. wx.onMenuShareTimeline({
  152. title: document.querySelector("head title").innerHTML, // 分享标题
  153. link: g_weixinObj.lineLink, // 分享链接
  154. imgUrl: g_weixinObj.imgUrl, // 分享图标
  155. desc: g_weixinObj.desc
  156. });
  157. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  158. wx.onMenuShareAppMessage({
  159. title: document.querySelector("head title").innerHTML, // 分享标题
  160. desc: g_weixinObj.desc, // 分享描述
  161. link: g_weixinObj.lineLink, // 分享链接
  162. imgUrl: g_weixinObj.imgUrl, // 分享图标
  163. type: '', // 分享类型,music、video或link,不填默认为link
  164. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  165. });
  166. });
  167. wx.onMenuShareWeibo({
  168. title: document.querySelector("head title").innerHTML, // 分享标题
  169. desc: g_weixinObj.desc, // 分享描述
  170. link: g_weixinObj.lineLink, // 分享链接
  171. imgUrl: g_weixinObj.imgUrl, // 分享图标
  172. success: function () {
  173. // 用户确认分享后执行的回调函数
  174. },
  175. cancel: function () {
  176. // 用户取消分享后执行的回调函数
  177. }
  178. });
  179. wx.onMenuShareQZone({
  180. title: document.querySelector("head title").innerHTML, // 分享标题
  181. desc: g_weixinObj.desc, // 分享描述
  182. link: g_weixinObj.lineLink, // 分享链接
  183. imgUrl: g_weixinObj.imgUrl, // 分享图标
  184. success: function () {
  185. // 用户确认分享后执行的回调函数
  186. },
  187. cancel: function () {
  188. // 用户取消分享后执行的回调函数
  189. }
  190. });
  191. wx.onMenuShareQQ({
  192. title: document.querySelector("head title").innerHTML, // 分享标题
  193. desc: g_weixinObj.desc, // 分享描述
  194. link: g_weixinObj.lineLink, // 分享链接
  195. imgUrl: g_weixinObj.imgUrl, // 分享图标
  196. success: function () {
  197. // 用户确认分享后执行的回调函数
  198. },
  199. cancel: function () {
  200. // 用户取消分享后执行的回调函数
  201. }
  202. });
  203. wx.error(function(res){
  204. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  205. });
  206. }
  207. }
  208. var manage = new Manage();