1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
| currentUser = { username: username, email: email, role: 'user', token: 'user-token-' + Date.now(), registerDate: new Date().toLocaleDateString('zh-CN'), dataLimit: 100, dataUsed: 0, expiryDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toLocaleDateString('zh-CN'), status: 'active' }; localStorage.setItem('v2rayUser', JSON.stringify(currentUser)); localStorage.setItem('v2rayUsers', JSON.stringify([currentUser])); updateUIAfterLogin(); registerModal.style.display = 'none'; showToast('注册成功!已自动登录。'); } function updateUIAfterLogin() { userName.textContent = currentUser.username; userRole.textContent = currentUser.role === 'admin' ? '管理员' : '普通用户'; loginBtn.style.display = 'none'; registerBtn.style.display = 'none'; logoutBtn.style.display = 'block'; if (currentUser.role === 'admin') { adminBtn.style.display = 'block'; adminTab.style.display = 'block'; isAdmin = true; } else { adminBtn.style.display = 'none'; adminTab.style.display = 'none'; isAdmin = false; } updateDashboardData(); updateSubscribeLink(); } function updateDashboardData() { if (!currentUser) return; document.getElementById('account-status').textContent = currentUser.status === 'active' ? '活跃' : '离线'; document.getElementById('account-level').textContent = currentUser.role === 'admin' ? '管理员' : '普通用户'; document.getElementById('register-date').textContent = currentUser.registerDate; document.getElementById('data-usage').textContent = `${currentUser.dataUsed.toFixed(1)}/${currentUser.dataLimit} GB`; document.getElementById('upload-usage').textContent = (currentUser.dataUsed * 0.4).toFixed(1) + ' GB'; document.getElementById('download-usage').textContent = (currentUser.dataUsed * 0.6).toFixed(1) + ' GB'; document.getElementById('expiry-date').textContent = currentUser.expiryDate; const progressBar = document.querySelector('.progress'); const usagePercent = (currentUser.dataUsed / currentUser.dataLimit) * 100; progressBar.style.width = `${Math.min(usagePercent, 100)}%`; if (usagePercent > 90) { progressBar.style.backgroundColor = 'var(--danger-color)'; } else if (usagePercent > 70) { progressBar.style.backgroundColor = 'var(--warning-color)'; } else { progressBar.style.backgroundColor = 'var(--primary-color)'; } } function updateSubscribeLink() { if (!currentUser) return; const domain = window.location.hostname || 'your-domain.com'; subscribeLink.textContent = `https://${domain}/subscribe?token=${currentUser.token}`; generateQRCode(); } function generateQRCode() { qrcodeDiv.innerHTML = ''; if (!currentUser) return; new QRCode(qrcodeDiv, { text: subscribeLink.textContent, width: 200, height: 200, colorDark: "#000000", colorLight: "#ffffff", correctLevel: QRCode.CorrectLevel.H }); } function copySubscribeLink() { if (!currentUser) { showToast('请先登录', true); return; } navigator.clipboard.writeText(subscribeLink.textContent) .then(() => { showToast('订阅链接已复制到剪贴板'); }) .catch(err => { console.error('无法复制文本: ', err); showToast('复制失败', true); }); } function resetSubscribeLink() { if (!currentUser) { showToast('请先登录', true); return; } if (!confirm('确定要重置订阅链接吗?旧链接将立即失效。')) { return; } currentUser.token = 'user-token-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9); localStorage.setItem('v2rayUser', JSON.stringify(currentUser)); updateSubscribeLink(); showToast('订阅链接已重置'); } function switchView(viewName) { viewSections.forEach(section => { section.classList.remove('active'); }); navTabs.forEach(tab => { tab.classList.remove('active'); }); document.getElementById(`${viewName}-view`).classList.add('active'); document.querySelector(`.nav-tab[data-view="${viewName}"]`).classList.add('active'); if (viewName === 'subscription') { generateQRCode(); } } function logout() { currentUser = null; isAdmin = false; localStorage.removeItem('v2rayUser'); userName.textContent = '未登录'; userRole.textContent = '请登录或注册'; loginBtn.style.display = 'block'; registerBtn.style.display = 'block'; logoutBtn.style.display = 'none'; adminBtn.style.display = 'none'; adminTab.style.display = 'none'; switchView('dashboard'); showToast('已退出登录'); } function showToast(message, isError = false) { toast.textContent = message; toast.className = 'toast' + (isError ? ' error' : ''); toast.classList.add('show'); setTimeout(() => { toast.classList.remove('show'); }, 3000); } document.addEventListener('DOMContentLoaded', initPage); </script> </body> </html>
|