wave.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. function isMobile() {
  2. return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
  3. }
  4. (function () {
  5. var language = (/^zh/.test(navigator.language) ? "zh" : "en");
  6. var template_data = {};
  7. var module = $('input[name=module]').val();
  8. var ssid = $('input[name=ssid]').val();
  9. var link = $('input[name=url]').val();
  10. var authcode = $('input[name=authcode]').val();
  11. $(function () {
  12. window.DAFU = {
  13. brand: "Xuanfeng",
  14. locale: 'zh',
  15. params: {},
  16. platform: {},
  17. config: {
  18. server: "/index/ajax/jsonFormat?lang=" + language + "&link=" + link + (ssid ? "&ssid=" + ssid : '') + (module == 's' ? '&s=' + module : '')
  19. },
  20. data: {},
  21. APP: {},
  22. module,
  23. ssid,
  24. signPackage: {},
  25. AD: {},
  26. init: function () {
  27. },
  28. query: function () {
  29. var self = this;
  30. $.getJSON(this.config.server, this.getQueryParams(), function (ret) {
  31. if (ret.code != '200') {
  32. alert(ret.msg);
  33. return false;
  34. }
  35. self.data = ret.data;
  36. self.signPackage = ret.data.signPackage;
  37. template_data = ret.data.template_data;
  38. if (ret.data.template_language) {
  39. language = ret.data.template_language;
  40. }
  41. $.extend(Mark.includes, template_data);
  42. if (!self.data.template) {
  43. self.successVip();
  44. } else if (['tmp1', 'tmp2', 'tmp3', 'tmp4', 'tmp5', 'tmp6', 'tmp7'].indexOf(self.data.template) > -1) {
  45. self.successVip();
  46. } else if (['error'].indexOf(self.data.template) > -1) {
  47. self.error(ret.data.msg);
  48. }
  49. });
  50. },
  51. getQuerySetting: function () {
  52. var url = $('input[name="url"]').val();
  53. if (url) return url;
  54. var pathname = window.location.pathname.substring(1);
  55. pathname = pathname.split("?")[0];
  56. return pathname.replace(/show\//, "");
  57. },
  58. getQueryParams: function GetRequest() {
  59. var url = location.search;
  60. var theRequest = new Object();
  61. if (url.indexOf("?") != -1) {
  62. var str = url.substr(1);
  63. var strs = str.split("&");
  64. for (var i = 0; i < strs.length; i++) {
  65. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  66. }
  67. }
  68. return theRequest;
  69. },
  70. //当前使用渲染
  71. successVip: function () {
  72. var tmp = Mark.up($('#title').html(), this.data);
  73. $('head').append(tmp);
  74. var tmp = Mark.up($('#meta').html(), this.data);
  75. $('head').append(tmp);
  76. this.data.support_ios = (this.data.support & 1) ? true : false;
  77. this.data.support_android = (this.data.support & 2) ? true : false;
  78. $('body').append(Mark.up($('#content').html(), this.data));
  79. var clipboard = new ClipboardJS('#copy_button');
  80. clipboard.on('success', function (e) {
  81. var msg = e.trigger.getAttribute('aria-label');
  82. alert(msg);
  83. e.clearSelection();
  84. });
  85. if (this.data.use_auth_code == 1) {
  86. $('.template-pwd label').text(template_data.REQUIRE_ACODE);
  87. }
  88. if (!ssid && !this.data.in_super && this.data.show_guide && this.data.ext == 'iOS') {//信任引导
  89. $('<div style="text-align:center;padding:15px;">' +
  90. '<a target="_blank" href="/index/guide?lang=' + language+' " style="color:#157df1;">' +
  91. '<span class="glyphicon glyphicon-hand-right"></span>' +
  92. '&nbsp;&nbsp;' + template_data.UNTRUSTED_ENTERPRISE_DEVELOPER + '</a></div>'
  93. ).insertBefore('.down_load');
  94. $('.down_load').before().css('margin-top', 0);
  95. } else if (ssid || this.data.in_super) {//安装教程
  96. $('<div style="text-align:center;padding:15px;" onclick="showmodal(1)">' +
  97. '<a href="javascript:;" style="color:#157df1;">' +
  98. '<span class="glyphicon glyphicon-hand-right"></span>' +
  99. '&nbsp;&nbsp;' + template_data.SUPER_INSTALLATION_TUTORIAL + '</a></div>'
  100. ).insertBefore('.down_load');
  101. $('.down_load').before().css('margin-top', 0);
  102. }
  103. $('body').append(Mark.up($('#copyright').html(), this.data));
  104. this.showAd();
  105. this.showPopup();
  106. //this.weixin();
  107. if (this.data.is_publish == 0) {
  108. Modal.templateModal({
  109. imgName: "modal-bg-2.jpg",
  110. title1: template_data.REALNAME_LAYER_HINT,
  111. title2: template_data.REALNAME_LAYER_TITLE,
  112. p: template_data.REALNAME_LAYER_CONTENT,
  113. align: 'left', // 居左 left, 居中 center, 居右 right
  114. btnText: template_data.REALNAME_LAYER_BUTTON_TEXT,
  115. btnClass: "modal-btn1"
  116. });
  117. }
  118. if (this.data.super_sign && !this.data.plist_path) {
  119. startWorker();
  120. }
  121. if (this.data.plist_path) {
  122. $('a.down_load').attr('href', this.data.plist_path);
  123. $('.resign').show();
  124. }
  125. $('.resign').click(function () {
  126. return location.href = "/index/super_sign/resign?ssid=" + ssid;
  127. //old
  128. $.get('/index/super_sign/resign', {ssid}, function (ret) {
  129. if (ret.msg) {
  130. $('.msg-text').show().text(ret.msg);
  131. }
  132. if (ret.data) {
  133. $('.resign').hide();
  134. startWorker()
  135. }
  136. }, 'json');
  137. });
  138. },
  139. error: function (msg) {
  140. $('body').append(Mark.up($('#error-content').html(), this.data));
  141. $(".error-msg").html(template_data[msg]);
  142. },
  143. success: function () {
  144. var tmp = Mark.up($('#title').html(), this.data);
  145. $('head').append(tmp);
  146. var tmp = Mark.up($('#meta').html(), this.data);
  147. $('head').append(tmp);
  148. var top_title = Mark.up($('#top_title').html(), this.data);
  149. $('body').append(top_title);
  150. var button = Mark.up($('#button').html(), this.data);
  151. $('body').append(button);
  152. $('body').append(Mark.up($('#intro').html(), this.data));
  153. $('body').append(Mark.up($('#qrcode').html(), this.data));
  154. var clipboard = new ClipboardJS('#copy_button');
  155. clipboard.on('success', function (e) {
  156. var msg = e.trigger.getAttribute('aria-label');
  157. alert(msg);
  158. e.clearSelection();
  159. });
  160. this.data.show_guide = this.data.show_guide;
  161. $('body').append(Mark.up($('#copyright').html(), this.data));
  162. //this.weixin();
  163. this.showAd();
  164. this.showPopup();
  165. },
  166. showAd: function () {
  167. if (parseInt(this.data.show_ad) == 0) {
  168. return;
  169. }
  170. $.ajax({
  171. type: "POST",
  172. url: "/index/ajax/adsense?template=" + this.data.template,
  173. data: {'template': this.data.template},
  174. dataType: 'html',
  175. beforeSend: function (xhr) {
  176. },
  177. success: function (result, textStatus, jqXHR) {
  178. if (result) {
  179. $('body').append(result);
  180. $('.template-footer').css("margin-bottom", "60px");
  181. }
  182. },
  183. error: function (jqXHR, textStatus, errorThrown) {
  184. }
  185. });
  186. },
  187. reportApp: function () {
  188. $("#reportModal").modal("show");
  189. // 举报 单选
  190. $(document).on('click', '.report ul li', function () {
  191. $("#reportModal .report ul li").find(".icon").removeClass("icon-radio-checked").siblings("input[type=radio]").prop("checked", false);
  192. $(this).find(".icon").addClass("icon-radio-checked").siblings("input[type=radio]").prop("checked", true);
  193. // console.log($("#reportModal :checked").val());
  194. });
  195. // 举报保存
  196. $(document).on('click', (".report .save"), function () {
  197. $(this).attr('disabled', true);
  198. var checkedRadio = $("#reportModal .report ul");
  199. var textarea = $("#reportModal .report textarea");
  200. var email = $("#reportModal .report input[name=email]");
  201. var emailValidation = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/;
  202. if (checkedRadio.find(":checked").length > 0) {
  203. checkedRadio.parents(".form-group").removeClass("form-error");
  204. } else {
  205. checkedRadio.parents(".form-group").addClass("form-error");
  206. }
  207. if (textarea.val().length > 0) {
  208. textarea.parents(".form-group").removeClass("form-error");
  209. } else {
  210. textarea.parents(".form-group").addClass("form-error");
  211. }
  212. if (emailValidation.test(email.val())) {
  213. email.parents(".form-group").removeClass("form-error");
  214. } else {
  215. email.parents(".form-group").addClass("form-error");
  216. }
  217. var errorLength = $("#reportModal .report .form-error").length;
  218. if (errorLength > 0) {
  219. $("#reportModal").modal("show");
  220. } else {
  221. var app_id = DAFU.data.id;
  222. var app_name = DAFU.data.app_name;
  223. $.post('/index/ajax/report', {
  224. email: email.val(),
  225. type: $.trim(checkedRadio.find(":checked").parent().text()),
  226. message: textarea.val(),
  227. app_id: app_id,
  228. app_name: app_name
  229. }, function (data) {
  230. $('#report-sending').hide();
  231. if (data.code == 200) {
  232. $("#reportModal").modal("hide");
  233. Modal.generalModal({
  234. backdrop: true, // 点击阴影是否关闭弹窗, // true 开启; false 关闭
  235. iconClass: "", // success: icon-modal-success1, error: icon-modal-error2
  236. title: template_data.REPORT_THANKS, // 弹窗标题
  237. p: template_data.REPORT_MESSAGE, // 弹窗内容
  238. align: 'left', // 弹窗内容排列顺序 left center right
  239. cancelBtnText: "", // 取消按钮文字
  240. successBtnText: template_data.BUTTON_OK, // 确定按钮文字
  241. successBtnModal: true, // 点击确定按钮是否关闭弹窗 true 关闭 false 不关闭
  242. cancelBtnModal: true, // 点击取消按钮是否关闭弹窗 true 关闭 false 不关闭
  243. successCallback: function () {
  244. },
  245. cancelCallback: function () {
  246. }
  247. });
  248. } else {
  249. alert(data.msg);
  250. }
  251. }, 'json');
  252. }
  253. });
  254. },
  255. clickReport: function () {
  256. $('.dialog-close .icon-close').click(function () {
  257. $('#reportDialog').hide();
  258. });
  259. $('#reportDialog').show();
  260. $('.custom-checkbox').click(function () {
  261. $('.custom-checkbox').removeClass('active');
  262. $(this).addClass('active');
  263. });
  264. $("#submit_report").click(function () {
  265. var email = $('#report-email').val();
  266. var type = $('div .active').html();
  267. var message = $('#report-content').val();
  268. var app_id = DAFU.data.id;
  269. var app_name = DAFU.data.app_name;
  270. if (!email) {
  271. $('.email-error').show();
  272. return false;
  273. } else {
  274. $('.email-error').hide();
  275. }
  276. if (!type) {
  277. $('.type-error').show();
  278. return false;
  279. } else {
  280. $('.type-error').hide();
  281. }
  282. if (!message) {
  283. $('.message-error').show();
  284. return false;
  285. } else {
  286. $('.message-error').hide();
  287. }
  288. $('#report-sending').show();
  289. $.post('/index/ajax/report', {
  290. email: email,
  291. type: type,
  292. message: message,
  293. app_id: app_id,
  294. app_name: app_name
  295. }, function (data) {
  296. $('#report-sending').hide();
  297. if (data.code == 200) {
  298. $('#report-form').hide();
  299. $('#report-feedback').show();
  300. } else {
  301. alert(data.msg);
  302. }
  303. }, 'json');
  304. });
  305. },
  306. showPopup: function () {
  307. var browser = {
  308. versions: function () {
  309. var u = navigator.userAgent;
  310. var ua = navigator.userAgent.toLocaleLowerCase();
  311. var app = navigator.appVersion;
  312. return {
  313. trident: u.indexOf('Trident') > -1, // IE内核
  314. presto: u.indexOf('Presto') > -1, // opera内核
  315. webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
  316. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, // 火狐内核
  317. mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), // 是否为移动终端
  318. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), // IOS终端
  319. android: u.indexOf('Android') > -1, // 安卓终端
  320. iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, // 是否为iphone或QQHD浏览器
  321. iPad: u.indexOf('iPad') > -1, // 是否为iPad
  322. webApp: u.indexOf('Safari') == -1, // 是否web应用程序,没有头部与底部
  323. QQbrw: u.indexOf('MQQBrowser') > -1, // QQ浏览器
  324. weiXin: u.indexOf('MicroMessenger') > -1, // 微信
  325. QQ: ua.match(/\sQQ/i) == " qq", // QQ App内置浏览器(需要配合使用)
  326. weiBo: ua.match(/WeiBo/i) == "weibo", // 微博
  327. safari: /Safari/.test(u) && !/Chrome/.test(u) && u.indexOf('MQQBrowser') < 0 && !/CriOS/.test(u),
  328. UCbrw: u.indexOf('UCBrowser') > -1, //UC浏览器
  329. ucSpecial: u.indexOf('rv:1.2.3.4') > -1,
  330. Symbian: u.indexOf('Symbian') > -1,
  331. ucSB: u.indexOf('Firofox/1.') > -1
  332. };
  333. }(),
  334. language: (navigator.browserLanguage || navigator.language).toLowerCase()
  335. };
  336. var weixin, weibo, isQQ, isiOS, isAndroid = false;
  337. var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
  338. if (browser.versions.mobile) {//判断是否是移动设备打开
  339. if (browser.versions.weiXin) {
  340. weixin = true;
  341. }
  342. if (browser.versions.weiBo) {
  343. weibo = true;
  344. }
  345. if (browser.versions.QQ) {
  346. isQQ = true;
  347. }
  348. if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
  349. isiOS = true;
  350. }
  351. if (browser.versions.android) {
  352. isAndroid = true;
  353. }
  354. if (browser.versions.safari) {
  355. isSafari = true;
  356. } else {
  357. isSafari = false;
  358. }
  359. }
  360. var appType = (this.data.ext == 'iOS') ? 'ios' : 'android';
  361. if (weixin == true) {
  362. $('.down_load').hide();
  363. if (isiOS == true) {
  364. $("#weixin_ios").show();
  365. $("#weixin_android").hide();
  366. } else {
  367. $("#weixin_ios").hide();
  368. $("#weixin_android").show();
  369. }
  370. return false;
  371. }
  372. if (isQQ) {
  373. $('.down_load').hide();
  374. if (isiOS == true) {
  375. $("#weixin_ios").show();
  376. $("#weixin_android").hide();
  377. } else {
  378. $("#weixin_ios").hide();
  379. $("#weixin_android").show();
  380. }
  381. return false;
  382. }
  383. if (isiOS && !isSafari && (browser.versions.UCbrw || this.data.fileExt == 'mobileconfig')) {
  384. $('.down_load').hide();
  385. $("#no_safari").show();
  386. }
  387. if (appType == 'android' && isiOS) {
  388. $('.down_load').hide();
  389. } else if (appType == 'ios' && !isiOS) {
  390. $('.down_load').hide();
  391. } else {
  392. var app_source = this.data.source;
  393. $('.down_load').click(function () {
  394. $(this).hide();
  395. $("#showtext").show();
  396. var a = $.ua.browser.name;
  397. var c = a.match(/safari/gi);
  398. if (!ssid && c && "ios" == appType && app_source != 3) {
  399. setTimeout(function () {
  400. $("#showtext").hide();
  401. var a = $("<a href='/static/app/app.mobileprovision' class='ms-btn template-btn clearfix pc-pwd' style='display:block;background-color:#40acf1; border: 1px solid #40acf1;margin: 15px'>" +
  402. (DAFU.data.in_super ? template_data.INSTALL_MOBILECONFIG : template_data.TRUST_DEVELOPER)
  403. + "</a>");
  404. $("#showtext").after(a);
  405. // location.href = "/static/app/app.mobileprovision";
  406. }, 6000);
  407. }
  408. location.href = $(this).attr('href');
  409. });
  410. }
  411. },
  412. weixin: function () {
  413. wx.config({
  414. debug: false,
  415. appId: this.signPackage["appId"],
  416. timestamp: this.signPackage["timestamp"],
  417. nonceStr: this.signPackage["nonceStr"],
  418. signature: this.signPackage["signature"],
  419. jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ']
  420. });
  421. var this_app = this.data;
  422. wx.ready(function () {
  423. wx.onMenuShareAppMessage({
  424. title: this_app.app_name,
  425. desc: decodeURIComponent(encodeURIComponent('版本:' + this_app.version + '.' + this_app.version_code + ' 大小:' + this_app.app_size).replace(/\+/g, '%20')),
  426. link: www_domain + this_app.url,
  427. imgUrl: "https:" + this_app.icon_300
  428. });
  429. wx.onMenuShareTimeline({
  430. title: this_app.app_name,
  431. desc: decodeURIComponent(encodeURIComponent('版本:' + this_app.version + '.' + this_app.version_code + ' 大小:' + this_app.app_size).replace(/\+/g, '%20')),
  432. link: www_domain + this_app.url,
  433. imgUrl: "https:" + this_app.icon_300
  434. });
  435. wx.onMenuShareQQ({
  436. title: this_app.app_name,
  437. desc: decodeURIComponent(encodeURIComponent('版本:' + this_app.version + '.' + this_app.version_code + ' 大小:' + this_app.app_size).replace(/\+/g, '%20')),
  438. link: www_domain + this_app.url,
  439. imgUrl: "https:" + this_app.icon_300
  440. });
  441. });
  442. },
  443. submitPwd: function () {
  444. var url = this.getQuerySetting();
  445. var password = $("input[name='pwd']").val();
  446. var ssid = $('input[name=ssid]').val();
  447. // 验证密码是否正确
  448. $.getJSON('/index/ajax/' + (DAFU.data.use_auth_code == 1 ? 'check_authcode' : 'check_password'), {
  449. url, password, ssid
  450. }, function (ret) {
  451. if (ret.code == 200) {
  452. if (DAFU.data.use_auth_code == 1) {
  453. DAFU.authcode = password;
  454. }
  455. var href = '/' + url + (DAFU.data.use_auth_code == 1 ? '?authcode=' : '?password=') + password + (ssid ? '&ssid=' + ssid : '');
  456. window.location.href = href;
  457. } else {
  458. $("#autoHideTemplateModal").find(".modal-dialog").addClass("modal-sm").find(".auto-hide .mt5").text(template_data[DAFU.data.use_auth_code == 1 ? (ret.msg || 'AUTHCODE_WRONG') : 'PASSWORD_WRONG']);
  459. autoHideModal('#autoHideTemplateModal', 3000);
  460. }
  461. });
  462. //window.location.href = '/' + this.getQuerySetting() + '?password=' + $('#password').val();
  463. },
  464. showProvision: function () {
  465. }
  466. },
  467. DAFU.init(), DAFU.query();
  468. var message = '正在排队'
  469. var time = 0;
  470. var loading = ' <img src="/static/pack/layer/theme/default/loading-2.gif" height="20" style="margin-top: -5px"/>';
  471. function dosign() {
  472. message = template_data['SIGNING'];
  473. time = 0
  474. var appid = $('input[name=appid]').val();
  475. var ssid = $('input[name=ssid]').val();
  476. var authcode = $('input[name=authcode]').val();
  477. if (appid && ssid) {
  478. $('a.down_load').hide();
  479. $('a.grey').css('display', 'inline-block');
  480. var link = $('input[name=url]').val();
  481. $.get('/index/super_sign/dosign', {appid, ssid, authcode}, function (ret) {
  482. if (ret.msg) {
  483. clearInterval(DAFU.si);
  484. var msg = ret.msg;
  485. if (template_data[msg])
  486. msg = template_data[msg];
  487. show_grey(msg);
  488. }
  489. if (ret.data) {
  490. // hide_grey(template_data['DOWNLOAD_INSTALL'])
  491. $('a.down_load').attr('href', ret.data.plist_path);
  492. }
  493. }, 'json');
  494. }
  495. }
  496. function check_sign() {
  497. time++;
  498. show_grey(message + loading);
  499. $.get('/index/super_sign/check_sign', {ssid}, function (ret) {
  500. if (ret.code == 5) {
  501. clearInterval(DAFU.si);
  502. hide_grey(template_data[ret.msg])
  503. $('.resign').show();
  504. $('a.down_load').trigger("click");
  505. } else if (ret.code == 2) {
  506. dosign();
  507. } else if (ret.code < 0) {
  508. clearInterval(DAFU.si);
  509. show_grey(template_data[ret.msg])
  510. }
  511. }, 'json');
  512. }
  513. function startWorker() {
  514. time = 0;
  515. check_sign();
  516. DAFU.si = setInterval(function () {
  517. check_sign();
  518. }, 1000);
  519. show_grey();
  520. }
  521. function show_grey(msg) {
  522. $('a.down_load').hide();
  523. $('a.grey').css('display', 'inline-block');
  524. $('a.grey span.fl').html(msg || template_data['LOADING']);
  525. }
  526. function hide_grey(msg) {
  527. $('a.grey').hide();
  528. $('a.down_load').show();
  529. $('a.down_load span:last-child').html(msg);
  530. }
  531. });
  532. }).call(this);