app.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. $(document).ready(function () {
  2. $('#toggleEye').click(function () {
  3. var pwdInput = $('#WiFiPwd');
  4. var pwdType = pwdInput.attr('type');
  5. if (pwdType === 'password' && $(this).hasClass('am-icon-eye-slash')) {
  6. pwdInput.attr('type', 'text');
  7. $(this).removeClass('am-icon-eye-slash').addClass('am-icon-eye');
  8. } else {
  9. pwdInput.attr('type', 'password');
  10. $(this).removeClass('am-icon-eye').addClass('am-icon-eye-slash');
  11. }
  12. });
  13. window.onload = function () {
  14. // 从URL中获取UUID参数
  15. const uuidFromUrl = getQueryParam('uuid');
  16. // 获取 HTML 元素
  17. var uuidElement = document.getElementById('UUID');
  18. // 使用 JavaScript 替换占位符
  19. uuidElement.textContent = "UUID: " + uuidFromUrl;
  20. // uuidElement.textContent = uuidElement.textContent.replace('{{.uuid}}', uuidFromUrl);
  21. };
  22. // 函数:从URL中获取查询参数的值
  23. function getQueryParam(param) {
  24. const urlParams = new URLSearchParams(window.location.search);
  25. return urlParams.get(param);
  26. }
  27. // 确定
  28. $('#confirm').click(function (event) {
  29. event.preventDefault()
  30. $(this).prop("disabled", true);
  31. setTimeout(function () {
  32. $("#confirm").prop("disabled", false);
  33. }, 1000);
  34. var wifiName = $('#WiFiName').val();
  35. if (wifiName.trim().length === 0) {
  36. layer.msg('必须输入Wi-Fi账号✅');
  37. return
  38. }
  39. var wifiPwd = $('#WiFiPwd').val();
  40. if (wifiPwd.trim().length < 8) {
  41. layer.msg('必须输入正确的Wi-Fi密码✅');
  42. return
  43. }
  44. var uuId = $('#UUId').val();
  45. if (uuId.trim().length === 0) {
  46. layer.msg('必须传UUId✅');
  47. return
  48. }
  49. console.log("gadsfadsfafda===00==" + uuId);
  50. console.log("gadsfadsfafda===11==" + wifiName);
  51. console.log("gadsfadsfafda===22==" + wifiPwd);
  52. // 网络请求
  53. $.ajax({
  54. url: 'http://ptt.radio1964.com/v1/device/set-wifi', // 替换为后台接口的实际URL
  55. method: 'POST', // 替换为后台接口的实际请求方法
  56. data: {
  57. wifiName: wifiName,
  58. wifiPwd: wifiPwd,
  59. UUId: uuId,
  60. },
  61. success: function (response) {
  62. layer.msg('✅ 设置成功', {
  63. icon: 1
  64. }, function () {
  65. var ua = navigator.userAgent.toLowerCase();
  66. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  67. WeixinJSBridge.call('closeWindow');
  68. } else if (ua.indexOf("alipay") != -1) {
  69. AlipayJSBridge.call('closeWebview');
  70. } else if (ua.indexOf("baidu") != -1) {
  71. BLightApp.closeWindow();
  72. }
  73. window.location.reload();
  74. });
  75. },
  76. error: function (error) {
  77. layer.msg('💤 请稍后再试');
  78. }
  79. });
  80. });
  81. });