app.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. document.addEventListener('DOMContentLoaded', function () {
  2. document.getElementById('toggleEye').addEventListener('click', function () {
  3. var pwdInput = document.getElementById('WiFiPwd');
  4. var pwdType = pwdInput.type;
  5. if (pwdType === 'password' && this.classList.contains('am-icon-eye-slash')) {
  6. pwdInput.type = 'text';
  7. this.classList.remove('am-icon-eye-slash');
  8. this.classList.add('am-icon-eye');
  9. } else {
  10. pwdInput.type = 'password';
  11. this.classList.remove('am-icon-eye');
  12. this.classList.add('am-icon-eye-slash');
  13. }
  14. });
  15. document.getElementById('confirm').addEventListener('click', function () {
  16. this.disabled = true;
  17. setTimeout(() => {
  18. this.disabled = false;
  19. }, 1000);
  20. var wifiName = document.getElementById('WiFiName').value.trim();
  21. if (wifiName.length === 0) {
  22. alert('必须输入Wi-Fi账号✅');
  23. return;
  24. }
  25. var wifiPwd = document.getElementById('WiFiPwd').value.trim();
  26. if (wifiPwd.length < 8) {
  27. alert('必须输入正确的Wi-Fi密码✅');
  28. return;
  29. }
  30. var uuId = document.getElementById('UUId').value.trim();
  31. if (uuId.length === 0) {
  32. alert('必须传UUId✅');
  33. return;
  34. }
  35. fetch('http://ptt.radio1964.com/v1/device/set-wifi', { // 替换为后台接口的实际URL
  36. method: 'POST',
  37. headers: {
  38. 'Content-Type': 'application/json',
  39. },
  40. body: JSON.stringify({
  41. wifiName: wifiName,
  42. wifiPwd: wifiPwd,
  43. UUId: uuId,
  44. })
  45. }).then(response => response.json())
  46. .then(data => {
  47. alert('✅ 设置成功')
  48. var ua = navigator.userAgent.toLowerCase();
  49. if (ua.match(/micromessenger/i)) {
  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. .catch(error => {
  59. alert('💤 请稍后再试');
  60. });
  61. });
  62. });