succinic.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. var root = null;
  2. var user = {};
  3. var query = {};
  4. var product = {};
  5. init();
  6. function init() {
  7. window.root = getRootPath();
  8. parseQueryParms();
  9. $("#useraccount_tt").attr("value", getUrlParam("freeflow_token"));
  10. var param = {
  11. fes: getUrlParam("fes"),
  12. sou: getUrlParam("sou")
  13. };
  14. var def = $.Deferred();
  15. $.ajax({
  16. url: root + "-s1api" + "/ini/getstyle",
  17. type: "POST",
  18. contentType: "application/json",
  19. data: JSON.stringify(param),
  20. timeout: 10000
  21. }).then(
  22. function (responseText) {
  23. var response = JSON.parse(responseText);
  24. if (response.resultCode != "0000") {
  25. // window.location.href = window.root + "/404.html";
  26. // def.reject();
  27. // return def;
  28. }
  29. add();
  30. if (
  31. response.product[0].productid == "2020010201" ||
  32. response.product[0].productid == "2022071807"
  33. ) {
  34. product = response.product[0];
  35. } else {
  36. product = response.product[1];
  37. }
  38. // for (i = 0; i < response.product.length; i++) {
  39. // products[response.product[i].productid] = response.product[i]
  40. // }
  41. // $("#fog_" + product.url).attr("value", product.fog);
  42. // var smslist = product.icon.split(",");
  43. // for (var i = 0; i < smslist.length; i++) {
  44. // if (i == 0) {
  45. // $("#sendsms_order_" + product.url).attr("value", smslist[i]);
  46. // }
  47. // if (i == 1) {
  48. // $("#sendsms_cancel_" + product.url).attr("value", smslist[i]);
  49. // }
  50. // if (i == 2) {
  51. // $("#sendsms_yuyue_" + product.url).attr("value", smslist[i]);
  52. // }
  53. // }
  54. // def.resolve(response);
  55. },
  56. function (jqXHR, textStatus, errorThrown) {
  57. if (textStatus === "timeout") {
  58. // window.location.href = getRootPath() + "/hot.html?cb=" + encodeURIComponent(window.location.href);
  59. }
  60. }
  61. );
  62. return def;
  63. }
  64. function add() {
  65. var $container = $(".sms-form").find(".form-group");
  66. $container
  67. .find(".sendcode")
  68. .unbind("click")
  69. .on("click", function () {
  70. sendSms($container, "login");
  71. });
  72. $container
  73. .find(".login")
  74. .unbind("click")
  75. .on("click", function () {
  76. showLoading();
  77. checkCode($container)
  78. .done(function (response) {
  79. var url = getQueryString("redirectUrl");
  80. if (
  81. decodeURIComponent(url).indexOf("https://800.wo.cn") >= 0 ||
  82. decodeURIComponent(url).indexOf("https://operation1.bol.wo.cn/") >= 0
  83. ) {
  84. console.log(1);
  85. window.location.href =
  86. decodeURIComponent(url) +
  87. "&userid=" +
  88. response.userid +
  89. "&usermob=" +
  90. response.usermob;
  91. }
  92. })
  93. .fail(function (data) {
  94. hideLoading();
  95. });
  96. });
  97. }
  98. function getQueryString(name) {
  99. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  100. var r = window.location.search.substr(1).match(reg);
  101. if (r != null) return unescape(r[2]);
  102. return null;
  103. }
  104. function hideLoading($loading) {
  105. if ($loading) {
  106. $loading.trigger("close");
  107. return;
  108. } else if (window.$loading) {
  109. window.$loading.trigger("close");
  110. return;
  111. }
  112. }
  113. function showLoading(message) {
  114. if (window.$loading) {
  115. window.$loading.trigger("close");
  116. }
  117. $("body").css("overflow", "hidden");
  118. var msg = message || "处理中,请稍后...";
  119. var $overlay = $('<div class="overlay overlay-loading"></div>');
  120. var $loading = $(
  121. '<div class="loading">' + ' <div class="content">' + msg + "</div>" + "</div>"
  122. );
  123. $overlay.appendTo($(document.body));
  124. $loading.appendTo($(document.body));
  125. $loading.on("close", function () {
  126. $("body").css("overflow", "auto");
  127. $overlay.remove();
  128. $loading.remove();
  129. $loading = null;
  130. });
  131. window.$loading = $loading;
  132. return $loading;
  133. }
  134. function sendSms($container, smstype, currentProduct) {
  135. var def = $.Deferred();
  136. if ($container.attr("n") != null && $container.attr("n") > 0) {
  137. return;
  138. }
  139. var usermob = $container.find(".usermob").val();
  140. if (usermob == null || usermob.trim() == "") {
  141. showAlert("请输入联通手机号码");
  142. def.reject();
  143. return def;
  144. }
  145. if (!usermob.startsWith("1") || usermob.length != 11) {
  146. showAlert("手机号码格式不正确");
  147. def.reject();
  148. return def;
  149. }
  150. var param = {
  151. fes: getUrlParam("fes"),
  152. sou: getUrlParam("sou"),
  153. fog: product.fog,
  154. usermob: usermob,
  155. smstype: smstype
  156. };
  157. user.usermob = usermob;
  158. var count = 60;
  159. $container.attr("n", count);
  160. $.ajax({
  161. url: root + "-s1api" + "/sms/send",
  162. type: "POST",
  163. contentType: "application/json",
  164. data: JSON.stringify(param)
  165. }).then(function (response) {
  166. if (response.resultCode != "0000") {
  167. count = 0;
  168. $container.attr("n", count);
  169. showAlert(response.errorInfo);
  170. return;
  171. }
  172. var $sendcode = $container.find(".sendcode");
  173. var template = "{}s";
  174. if ($sendcode.is("input")) {
  175. $sendcode.val(template.replace("{}", count));
  176. } else {
  177. $sendcode.text(template.replace("{}", count));
  178. }
  179. $sendcode.addClass("sendcode-wait");
  180. var timer = setInterval(function () {
  181. count -= 1;
  182. $container.attr("n", count);
  183. if ($sendcode.is("input")) {
  184. $sendcode.val(template.replace("{}", count));
  185. } else {
  186. $sendcode.text(template.replace("{}", count));
  187. }
  188. if (count === 0) {
  189. clearInterval(timer);
  190. if ($sendcode.is("input")) {
  191. $sendcode.val("获取验证码");
  192. } else {
  193. $sendcode.text("获取验证码");
  194. }
  195. $container.attr("n", count);
  196. $sendcode.removeClass("sendcode-wait");
  197. }
  198. }, 1000);
  199. try {
  200. window.HtmlPageVisitor && window.HtmlPageVisitor.setMp(user.usermob);
  201. } catch (e) {}
  202. });
  203. }
  204. function checkCode($container, keepUserInfo) {
  205. var def = $.Deferred();
  206. var usermob = $container.find(".usermob").val();
  207. var smscode = $container.find(".smscode").val();
  208. if (keepUserInfo == null) keepUserInfo = false;
  209. if (usermob == null || usermob.trim() == "") {
  210. showAlert("请输入联通手机号码");
  211. def.reject();
  212. return def;
  213. }
  214. if (smscode == null || smscode.trim() == "") {
  215. showAlert("请输入验证码");
  216. def.reject();
  217. return def;
  218. }
  219. if (smscode.length != 6) {
  220. showAlert("短信验证码不正确");
  221. def.reject();
  222. return def;
  223. }
  224. var param = {
  225. fes: getUrlParam("fes"),
  226. sou: getUrlParam("sou"),
  227. fog: product.fog,
  228. code: smscode,
  229. usermob: usermob
  230. };
  231. $.ajax({
  232. url: root + "-s1api" + "/checkvercode",
  233. type: "POST",
  234. contentType: "application/json",
  235. data: JSON.stringify(param)
  236. })
  237. .then(function (response) {
  238. $container.find(".smscode").val("");
  239. switch (response.resultCode) {
  240. case "0000":
  241. user.userid = response.userid;
  242. user.usermob = usermob;
  243. user.usertime = new Date().getTime();
  244. if (!keepUserInfo) {
  245. $container.find(".usermob").val("");
  246. $container.find(".usermob").val("");
  247. }
  248. def.resolve(response);
  249. break;
  250. default:
  251. showAlert(response.errorInfo);
  252. def.reject(response);
  253. break;
  254. }
  255. })
  256. .fail(function (error) {
  257. def.reject("服务调用异常");
  258. });
  259. return def;
  260. }
  261. function showAlert(message, hideButton, buttonLabel, hideTitle) {
  262. var title = "";
  263. if (hideTitle == undefined || hideTitle == false) {
  264. title = "温馨提示";
  265. }
  266. var $overlay = $('<div class="overlay overlay-alert"></div>');
  267. var $dialog = $(
  268. '<div class="dialog-alert">' +
  269. "<h1>" +
  270. title +
  271. "</h1>" +
  272. '<div class="content">' +
  273. message +
  274. "</div>" +
  275. '<div class="actions">' +
  276. ' <div class="btn btnsr">' +
  277. (buttonLabel == null || buttonLabel == "" ? "关闭" : buttonLabel) +
  278. "</div>" +
  279. "</div>" +
  280. "</div>"
  281. );
  282. $("body").css("overflow", "hidden");
  283. $overlay.appendTo($(document.body));
  284. $dialog.appendTo($(document.body));
  285. if (hideButton == true) {
  286. $dialog.find(".btn").remove();
  287. }
  288. $dialog.close = function () {
  289. $("body").css("overflow", "auto");
  290. $overlay.remove();
  291. $dialog.remove();
  292. $dialog = null;
  293. };
  294. var def = $.Deferred();
  295. $dialog.find(".btn").on("click", function () {
  296. $dialog.close();
  297. def.resolve($dialog);
  298. });
  299. return def;
  300. }
  301. function getRootPath() {
  302. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  303. var curWwwPath = window.document.location.href;
  304. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  305. var pathName = window.document.location.pathname;
  306. var pos = curWwwPath.indexOf(pathName);
  307. //获取主机地址,如: http://localhost:8080
  308. var localhostPath = curWwwPath.substring(0, pos);
  309. //获取带"/"的项目名,如:/ems
  310. var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
  311. root = localhostPath + projectName;
  312. return localhostPath + projectName;
  313. }
  314. function getUrlParam(urlprm) {
  315. var reg = new RegExp("(^|&)" + urlprm + "=([^&]*)(&|$)");
  316. var r = window.location.search.substr(1).match(reg);
  317. if (r != null) {
  318. return r[2];
  319. }
  320. }
  321. function parseQueryParms() {
  322. var QUERY_SEPARATOR = "&",
  323. VALUE_SEPARATOR = "=";
  324. var queryStr = window.location.search.substring(1);
  325. var startIndex = 0,
  326. vIndex,
  327. qIndex;
  328. while (queryStr.length > 0) {
  329. vIndex = queryStr.indexOf(VALUE_SEPARATOR, startIndex);
  330. if (vIndex == -1) {
  331. break;
  332. }
  333. qIndex = queryStr.indexOf(QUERY_SEPARATOR, vIndex + 1);
  334. if (qIndex == -1) {
  335. qIndex = queryStr.length;
  336. }
  337. var key = queryStr.substring(startIndex, vIndex);
  338. var value = queryStr.substring(vIndex + 1, qIndex);
  339. query[key] = decodeURIComponent(value);
  340. startIndex = qIndex + 1;
  341. }
  342. }