app.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. $('#confirm').click(function (event) {
  14. event.preventDefault()
  15. $(this).prop("disabled", true);
  16. setTimeout(function () {
  17. $("#confirm").prop("disabled", false);
  18. }, 1000);
  19. var wifiName = $('#WiFiName').val();
  20. if (wifiName.trim().length === 0) {
  21. layer.msg('必须输入Wi-Fi账号✅');
  22. return
  23. }
  24. var wifiPwd = $('#WiFiPwd').val();
  25. if (wifiPwd.trim().length < 8) {
  26. layer.msg('必须输入正确的Wi-Fi密码✅');
  27. return
  28. }
  29. var uuId = $('#UUId').val();
  30. if (uuId.trim().length === 0) {
  31. layer.msg('必须传UUId✅');
  32. return
  33. }
  34. $.ajax({
  35. url: 'http://ptt.radio1964.com/v1/device/set-wifi', // 替换为后台接口的实际URL
  36. method: 'POST', // 替换为后台接口的实际请求方法
  37. data: {
  38. wifiName: wifiName,
  39. wifiPwd: wifiPwd,
  40. UUId: uuId,
  41. },
  42. success: function (response) {
  43. layer.msg('✅ 设置成功', {
  44. icon: 1
  45. }, function () {
  46. var ua = navigator.userAgent.toLowerCase();
  47. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  48. WeixinJSBridge.call('closeWindow');
  49. } else if (ua.indexOf("alipay") != -1) {
  50. AlipayJSBridge.call('closeWebview');
  51. } else if (ua.indexOf("baidu") != -1) {
  52. BLightApp.closeWindow();
  53. }
  54. window.location.reload();
  55. });
  56. },
  57. error: function (error) {
  58. layer.msg('💤 请稍后再试');
  59. }
  60. });
  61. });
  62. });