1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- document.addEventListener('DOMContentLoaded', function () {
- document.getElementById('toggleEye').addEventListener('click', function () {
- var pwdInput = document.getElementById('WiFiPwd');
- var pwdType = pwdInput.type;
- if (pwdType === 'password' && this.classList.contains('am-icon-eye-slash')) {
- pwdInput.type = 'text';
- this.classList.remove('am-icon-eye-slash');
- this.classList.add('am-icon-eye');
- } else {
- pwdInput.type = 'password';
- this.classList.remove('am-icon-eye');
- this.classList.add('am-icon-eye-slash');
- }
- });
- document.getElementById('confirm').addEventListener('click', function () {
- this.disabled = true;
- setTimeout(() => {
- this.disabled = false;
- }, 1000);
- var wifiName = document.getElementById('WiFiName').value.trim();
- if (wifiName.length === 0) {
- alert('必须输入Wi-Fi账号✅');
- return;
- }
- var wifiPwd = document.getElementById('WiFiPwd').value.trim();
- if (wifiPwd.length < 8) {
- alert('必须输入正确的Wi-Fi密码✅');
- return;
- }
- var uuId = document.getElementById('UUId').value.trim();
- if (uuId.length === 0) {
- alert('必须传UUId✅');
- return;
- }
- fetch('http://ptt.radio1964.com/v1/device/set-wifi', { // 替换为后台接口的实际URL
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- wifiName: wifiName,
- wifiPwd: wifiPwd,
- UUId: uuId,
- })
- }).then(response => response.json())
- .then(data => {
- alert('✅ 设置成功')
- var ua = navigator.userAgent.toLowerCase();
- if (ua.match(/micromessenger/i)) {
- WeixinJSBridge.call('closeWindow');
- } else if (ua.indexOf("alipay") !== -1) {
- AlipayJSBridge.call('closeWebview');
- } else if (ua.indexOf("baidu") !== -1) {
- BLightApp.closeWindow();
- }
- window.location.reload();
- })
- .catch(error => {
- alert('💤 请稍后再试');
- });
- });
- });
|