common.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. var ac_filename = window.location.pathname;
  2. ac_filename = ac_filename.split('/').pop();
  3. ac_filename = ac_filename && ac_filename!='index' ? '_'+ac_filename : '';
  4. var ac_val = parseInt($.fn.cookie('ac_val')) || 0;
  5. $(function () {
  6. //菜单
  7. $('.pop_up_menu_box > i, .head_menu_but, .pum_tit_box a').click(function () {
  8. $('.pop_up_menu_box').toggleClass('pop_up_menu_show');
  9. });
  10. });
  11. var commont = {
  12. /**
  13. * 切割参数
  14. * @param sname string 要获取的参数
  15. * @param str string 被切割的字符
  16. * @param smark string 用于切割字符
  17. * @returns {string}
  18. */
  19. getQueryString: function (sname, str, smark) {
  20. str = str ? str : window.location.search;
  21. smark = smark ? smark : '&';
  22. if (sname) {
  23. var c_start = str.indexOf(sname + "=");
  24. if (c_start != -1) {
  25. c_start = c_start + sname.length + 1;
  26. var c_end = str.indexOf(smark, c_start);
  27. if (c_end == -1) c_end = str.length;
  28. return decodeURIComponent(str.substring(c_start, c_end));
  29. }
  30. }
  31. return "";
  32. }
  33. };
  34. //关闭APP弹窗
  35. $(document).on('click', '.popup-close', function(){
  36. if (window.cps !== undefined) {
  37. window.cps.dismissDialogWebView();
  38. }
  39. });
  40. //调用APP方法打开url
  41. $(document).on('click','.client-url',function(){
  42. try {
  43. var url = decodeURIComponent($(this).attr('href'));
  44. console.log(url);
  45. if (window.cps !== undefined) {
  46. var urlJsonStr = JSON.stringify({"uri":url});
  47. window.cps.toAppPage(urlJsonStr);
  48. return false;
  49. }
  50. } catch (e) {
  51. }
  52. return false;
  53. });
  54. //关闭窗口
  55. $(document).on('click', 'close-window', function () {
  56. if (window.cps !== undefined) {
  57. window.cps.finsh();
  58. return false;
  59. }
  60. return false;
  61. });
  62. //回退按钮
  63. $(document).on("click", ".head_return_page_but, .new_search_return", function () {
  64. if (window.cps !== undefined) {
  65. window.cps.goBack();
  66. }
  67. });
  68. /**
  69. * H5登录
  70. * @param commonHeader
  71. */
  72. function h5JsLogin(commonHeader, sign) {
  73. //window.cps.showMsg('{"msg":"h5登录"}');
  74. $.ajax({
  75. type: "POST",
  76. url: "/clientwebapi/index/getJsLoginToken",
  77. beforeSend: function (request) {
  78. request.setRequestHeader("common", commonHeader);
  79. request.setRequestHeader("sign", sign);
  80. },
  81. success: function (result) {
  82. if (result.code == 1) {
  83. $.fn.cookie('uid',result.data.uid,{expires: 365, path: '/'});
  84. $.fn.cookie('token',result.data.token,{expires: 365, path: '/'});
  85. $.fn.cookie('sign',result.data.sign,{expires: 365, path: '/'});
  86. }
  87. }
  88. });
  89. }