app.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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},function(){
  45. var ua = navigator.userAgent.toLowerCase();
  46. if(ua.match(/MicroMessenger/i)=="micromessenger") {
  47. WeixinJSBridge.call('closeWindow');
  48. } else if(ua.indexOf("alipay")!=-1){
  49. AlipayJSBridge.call('closeWebview');
  50. }else if(ua.indexOf("baidu")!=-1){
  51. BLightApp.closeWindow();
  52. }
  53. window.location.reload();
  54. });
  55. },
  56. error: function(error) {
  57. layer.msg('💤 请稍后再试');
  58. }
  59. });
  60. });
  61. });