public.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. // 请求地址
  2. // var ajaxUrl= 'https://sgmhks.sgmlink.com/sgm_weixin_card';
  3. var projectUrl = 'https://sgmhks.sgmlink.com/sgm_txh_web/';
  4. // 测试地址
  5. // var ajaxUrl= 'http://shaopf.jiinfo.cn/';
  6. const ajaxUrl = 'https://sgmhkstest-web.sgmlink.com/hks-card/'
  7. // const ajaxUrl = 'https://txh.suggest.vip'
  8. // var projectUrl = 'https://sgmhks.sgmlink.com/sgm_weixin_card_web/';
  9. var isDev = false;
  10. // var ajaxUrl= 'https://txh.suggest.vip';
  11. //var workWxAuthUrl = 'https://auth2-shgm.qyhub.cn/auth/auth?url=https%3a%2f%2fsgmhks.sgmlink.com%2fsgm_weixin_card%2fapi%2fweixin%2fcp%2flogin%2fhome&appid=584e2fd227448&extattr=name,avatar,weixinid,extraData.business_unit,extraData.business_dept,extraData.business_role_desc';
  12. var workWxAuthUrl = 'https://auth-shgm-wx.cw.sgmlink.com/auth/auth?url=https%3a%2f%2fsgmhks.sgmlink.com%2fsgm_weixin_card%2fapi%2fweixin%2fcp%2flogin%2fhome&appid=5ee8b1317b62a&extattr=name,avatar,weixinid,extraData.business_unit,extraData.business_dept,extraData.business_role_desc';
  13. // var workWxAuthUrl = 'https%3a%2f%2fsgmhkstest-web.sgmlink.com%2fhks-card%2fapi%2fweixin%2fcp%2flogin%2fhome&appid=5836556fa9d9a&extattr=name,avatar,ldap_userid,weixinid,extraData.sex,extraData.birthdate,extraData.business_unit,extraData.business_dept,extraData.business_role_desc';
  14. const api = {
  15. //前台-推荐人-我的推荐
  16. myRecommendLog :'/api/sgm/activity/AllStaffMarketingFacade/myRecommendLog',
  17. //前台-被推荐人-查询状态
  18. recQueryStatus:'/api/sgm/activity/AllStaffMarketingFacade/recQueryStatus',
  19. //微信授权
  20. getAuthUrl:'/jiinfo/weixin/WeiXinController/getAuthUrl',
  21. //微信登录
  22. getJsapiTicket:'/jiinfo/weixin/WeiXinController/getJsapiTicket',
  23. //查找省市
  24. findProvinceAndCity:'/api/sgm/weixin/card/ReplacementFacade/findProvinceAndCity',
  25. //查找门店
  26. findPage:'/api/sgm/weixin/card/ReplacementFacade/findPage',
  27. //获取短信验证码
  28. getAuthCode :'/api/sgm/weixin/miniprogram/MpLoginFacade/login',
  29. //绑定手机号
  30. register:'/api/sgm/weixin/card/LoginFacade/register',
  31. //小程序token登录
  32. tokenLogin:'/api/sgm/weixin/card/MpLogin/tokenLogin',
  33. //前台-提交留资
  34. submit:'/api/sgm/activity/AllStaffMarketingFacade/submit',
  35. //前台-选择礼遇
  36. chooseEntity:'/api/sgm/activity/AllStaffMarketingFacade/chooseEntity',
  37. //邀请
  38. invite:'/api/sgm/activity/AllStaffMarketingFacade/invite',
  39. //获取礼品列表
  40. queryEntityList:'/api/sgm/activity/AllStaffMarketingFacade/queryEntityList',
  41. //根据条件分页查询
  42. queryCarsList:'/api/sgm/weixin/marketing/TCpwxCarReadFacade/findPage',
  43. //根据条件分页查询
  44. queryCarTypeList:'/api/sgm/weixin/marketing/TCpwxCarReadFacade/findCarTypeList',
  45. //更新点击量
  46. updateCount:'/api/sgm/weixin/marketing/TCpwxCarWriteFacade/updateCount',
  47. // tallType告知行为类型
  48. tallType:'/api/sgm/activity/AllStaffMarketingFacade/statistics',
  49. // 表示用户已读
  50. readAdvert:'/api/sgm/activity/AllStaffMarketingFacade/readAdvert',
  51. // 手机号认证
  52. getAuthPhone:'/api/weixin/getAuthPhone',
  53. // 获取验证码
  54. getCode:'/api/weixin/getCode',
  55. // 分页查询渠道奖品信息
  56. getFlag:'/api/sgm/weixin/card/PcwController/getFlag',
  57. // flag
  58. addFlag:'/api/sgm/weixin/card/PcwController/addFlag',
  59. //获取抽奖剩余次数
  60. getDrawRemainingCount:`/api/sgm/weixin/card/PcwController/getDrawRemainingCount`,
  61. //抽奖
  62. draw:`/api/sgm/weixin/card/PcwController/draw`,
  63. //根据渠道ID查询获奖信息
  64. getMyPrize:`/api/sgm/weixin/card/PcwController/getMyPrize`,
  65. //查询页面
  66. enterPage: `/api/sgm/weixin/card/PcwController/enterPage`,
  67. }
  68. //防止安卓input导致页面变形
  69. //获取url参数
  70. function GetQueryString(name){
  71. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  72. var r = window.location.search.substr(1).match(reg);
  73. //
  74. if(r!=null)return unescape(r[2].replace(/\<|\>|\(|\)|\{|\}|\;|\/|\`|\,|\"|\'|\%|\&|\$|\@|\\’|\ \”|\|/g,"")); return null;
  75. }
  76. //添加replaceAll函数
  77. String.prototype.replaceAll = function(s1,s2){
  78. return this.replace(new RegExp(s1,"gm"),s2);
  79. }
  80. //获取终端
  81. function getTerminal(){
  82. var ua = navigator.userAgent.toLowerCase();
  83. if (/iphone|ipad|ipod/.test(ua)) {
  84. return "ios"
  85. } else if (/android/.test(ua)) {
  86. return "android"
  87. }else {
  88. return "pc"
  89. }
  90. }
  91. function showLoading(text){
  92. $('body').append(`<div class="pop_loading">${text||'加载中'}</div>`);
  93. }
  94. function hideLoading(){
  95. $('.pop_loading').eq(0).remove();
  96. }
  97. function post(option) {
  98. let url = option.url;
  99. let data = option.data || {};
  100. // data = {...data,
  101. // cpUserParam:{
  102. // cpUserId:1234
  103. // }
  104. // }
  105. let success = option.success;
  106. let fail = option.fail;
  107. let complete=option.complete||function(){};
  108. let noToast = option.noToast || false;
  109. let noLoading = option.noLoading || false;
  110. if(!noLoading){
  111. showLoading()
  112. }
  113. $.ajax({
  114. url: ajaxUrl + url,
  115. data: JSON.stringify(data),
  116. // 将XHR对象的withCredentials设为true
  117. xhrFields: {
  118. withCredentials: true
  119. },
  120. crossDomain: true,
  121. type: 'post',
  122. dataType: 'JSON',
  123. contentType: 'application/json; charset=UTF-8',
  124. beforeSend: function (request) {
  125. if(GetQueryString('token')){
  126. request.setRequestHeader("token", GetQueryString('token'));
  127. }
  128. },
  129. success: function(res) {
  130. console.log(res)
  131. if(!noLoading){
  132. hideLoading()
  133. }
  134. // debugger;
  135. <<<<<<< HEAD
  136. // if(res.code=="99990004" || res.code=="99990005"){
  137. // //window.location.href=res.data;
  138. // if(GetQueryString('token')){
  139. // mpLogin();
  140. // return;
  141. // }
  142. // var ua= window.navigator.userAgent.toLowerCase()
  143. // if(url.endsWith("myRecommendLog")){
  144. // //alert('进入企业微信')
  145. // window.location.href = workWxAuthUrl;
  146. // }else{
  147. // getAuthUrl();
  148. // }
  149. // return;
  150. // }
  151. =======
  152. if(res.code=="99990004" || res.code=="99990005"){
  153. //window.location.href=res.data;
  154. // if(GetQueryString('token')){
  155. // mpLogin();
  156. // return;
  157. // }
  158. var ua= window.navigator.userAgent.toLowerCase()
  159. if(url.endsWith("myRecommendLog")){
  160. //alert('进入企业微信')
  161. window.location.href = workWxAuthUrl;
  162. }else{
  163. getAuthUrl();
  164. }
  165. return;
  166. }
  167. >>>>>>> da8383baab1517166755c7051e43d21e5abd90dd
  168. if(res.code=='99990000'){
  169. success&&success(res)
  170. }else{
  171. if(!noToast){
  172. showToast('01',res.message)
  173. }
  174. if(fail){
  175. fail(res)
  176. }
  177. }
  178. }, complete:function(xhr, ts){
  179. complete(xhr,ts)
  180. },
  181. error:function (xhr,status,error){
  182. if(xhr.status==500){
  183. hideLoading();
  184. showToast('01','服务器错误')
  185. }
  186. }
  187. })
  188. }
  189. let isGetAuthUrl = false
  190. //微信登录
  191. function getAuthUrl(){
  192. if(isGetAuthUrl){return false}
  193. isGetAuthUrl = true
  194. post({
  195. url:api.getAuthUrl,
  196. data:{
  197. url:window.location.href
  198. },
  199. noToast:true,
  200. noLoading:true,
  201. success:function(res){
  202. window.location.href=res.data;
  203. }
  204. })
  205. }
  206. //微信小程序登录
  207. function mpLogin(data,callback){
  208. post({
  209. url:api.tokenLogin,
  210. data:{
  211. token:data
  212. },
  213. noToast:true,
  214. noLoading:false,
  215. success:function(res){
  216. callback&&callback(res)
  217. //showToast(res.code,res.message);
  218. }
  219. })
  220. }
  221. //提示框
  222. function showToast(code,message){
  223. if(code=='00'){
  224. var c='success';
  225. }else{
  226. var c='danger';
  227. }
  228. $('body').append('<div class="alert alert-'+c+'" role="alert">\
  229. <font style="vertical-align: inherit;">\
  230. <font style="vertical-align: inherit;">'+message+'</font>\
  231. </font>\
  232. </div>')
  233. setTimeout(function(){
  234. $('.alert').remove();
  235. },3000);
  236. }
  237. $(function(){
  238. let token = GetQueryString("token");
  239. console.log("token"+token);
  240. if(token&&window.location.href.indexOf('html/recommended.html')==-1){
  241. console.log("token"+token);
  242. mpLogin(token);
  243. }
  244. })
  245. function showShare(){
  246. let newClass = '';
  247. if(GetQueryString('token')){
  248. newClass = 'share_pop2'
  249. }
  250. $('body').append(`
  251. <div class="share_pop ${newClass}">
  252. <img src="https://sgmhks.sgmlink.com/hks_miniprogram/static/tjg/share_btn.png" class="share_btn" onclick="$('.share_pop').eq(0).remove()">
  253. </div>
  254. `)
  255. //自定义转发到微信
  256. // try{
  257. // wx.invoke(
  258. // "shareWechatMessage", {
  259. // title: shareConfig.title, // 分享标题
  260. // desc: '', // 分享描述
  261. // link: shareConfig.link, // 分享链接
  262. // imgUrl: shareConfig.imgUrl // 分享封面
  263. // }, function(res) {
  264. // alert(res);
  265. // if (res.err_msg == "shareWechatMessage:ok") {
  266. // }
  267. // }
  268. // );
  269. // }catch(err){
  270. // alert(err)
  271. // }
  272. // alert(111);
  273. }