user-common.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. function sendRequest(url, type, data, success) {
  2. //可能直接传递option
  3. var optionIn = {};
  4. var contentType = null;
  5. if ($.isPlainObject(url)) {
  6. optionIn = url;
  7. url = optionIn.url;
  8. type = optionIn.type;
  9. data = optionIn.data;
  10. contentType = optionIn.contentType;
  11. success = optionIn.success;
  12. }
  13. var requestUrl = url;
  14. if (url.indexOf("/") !== 0) {
  15. requestUrl = "/user/" + url;
  16. }
  17. var option = {
  18. url: requestUrl,
  19. type: type,
  20. dataType: "json",
  21. data: data,
  22. success: function (result) {
  23. if (result.result == 0) {
  24. msgPopup("温馨提示", result.description, "我知道了");
  25. return false;
  26. } else {
  27. if (success) {
  28. success(result)
  29. }
  30. }
  31. },
  32. error: function (res) {
  33. if (res.status == 401) {
  34. goScanFor401()
  35. } else {
  36. var Prompt = "温馨提示",
  37. desc = "获取数据失败,请检查网络",
  38. btnText = "我知道了";
  39. msgPopup(Prompt, desc, btnText);
  40. }
  41. },
  42. complete: function () {
  43. }
  44. };
  45. if (contentType != null) {
  46. option.contentType = contentType
  47. }
  48. myAjax(option);
  49. }
  50. var goScanFor401HasDialog = false;
  51. function goScanFor401() {
  52. if (goScanFor401HasDialog) {
  53. return true;
  54. }
  55. goScanFor401HasDialog = true;
  56. function goScan() {
  57. mui.confirm("您的登录已过期,是否要扫码设备登录?", "温馨提示", null, function (btnObj) {
  58. if (btnObj.index == 1) {
  59. scanQRCodeGoDevice();
  60. }
  61. goScanFor401HasDialog = false;
  62. });
  63. }
  64. if (window.mui) {
  65. goScan()
  66. } else {
  67. // 使用缓存获取,避免刷新后重新向服务器请求
  68. $.ajaxSetup({
  69. cache: true
  70. });
  71. $.getScript("/components/lib/mui.min.js", function () {
  72. $('<link>').appendTo('head').attr({
  73. rel: "stylesheet",
  74. type: 'text/css',
  75. href: '/components/lib/mui.min.css',
  76. });
  77. goScan()
  78. });
  79. }
  80. }
  81. //页面居中的黑色文字小提示
  82. function toast(e) {
  83. var t = ($("body").append('<div class="toast"></div>'), $(".toast")), n = '<div class="toast-msg"><div class="toast-text">' + e + "</div></div>";
  84. t.on("touchmove", function (e) {
  85. e.preventDefault()
  86. }), $("body").append(n), setTimeout(function () {
  87. t.remove(), $(".toast-msg").remove()
  88. }, 3000)
  89. }
  90. //设备离线需要获取扫码权限
  91. function offline(data) {
  92. var showDevice = getQueryString("showDevice"); //强制展示设备,无论是否离线
  93. if (!showDevice && !data.payload.online) {
  94. var errorPage = '<div class="error-page"><div class="remind-panel"><div class="remind-pic"></div><div class="text-item">设备(' + data.payload.logicalCode + ')离线</div><div class="text-sub-item">请重新选择设备扫码支付或现金支付</div></div><ul class="btn-list flexbox"><li class="flex"><a href="javascript:;" class="btn-skin scan-btn">重新扫码</a></li></ul></div>';
  95. $("body").append(errorPage);
  96. var scanBtn = $(".scan-btn");
  97. scanBtn.tap(function () {
  98. scanQRCodeGoDevice()
  99. })
  100. }
  101. }
  102. // 扫码事件-去查看设备
  103. function scanQRCodeGoDevice() {
  104. ScanResult(function (resultStr) {
  105. goPage(resultStr);
  106. })
  107. }
  108. var Server_Url = {
  109. equipmentPara: "/user/message/equipmentPara",
  110. Task_List: "/ad/taskList"
  111. };