app.js 2.0 KB

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