123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>设置管理员角色</title>
- <style>
- body {
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
- display: flex;
- justify-content: center;
- align-items: center;
- min-height: 100vh;
- margin: 0;
- background-color: #f5f5f5;
- }
- .container {
- background: white;
- padding: 40px;
- border-radius: 8px;
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
- text-align: center;
- }
- h1 {
- color: #333;
- margin-bottom: 20px;
- }
- p {
- color: #666;
- margin-bottom: 30px;
- }
- button {
- background-color: #165DFF;
- color: white;
- border: none;
- padding: 12px 24px;
- border-radius: 4px;
- font-size: 16px;
- cursor: pointer;
- transition: background-color 0.3s;
- }
- button:hover {
- background-color: #0E4BD9;
- }
- .message {
- margin-top: 20px;
- padding: 10px;
- border-radius: 4px;
- display: none;
- }
- .success {
- background-color: #E8F5E9;
- color: #2E7D32;
- display: block;
- }
- .admin-link {
- display: block;
- margin-top: 20px;
- color: #165DFF;
- text-decoration: none;
- font-weight: 500;
- }
- .admin-link:hover {
- text-decoration: underline;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>设置管理员角色</h1>
- <p>点击下方按钮,将您的用户角色设置为管理员,以便访问管理员页面。</p>
- <button onclick="setAdminRole()">设置为管理员</button>
- <div id="message" class="message"></div>
- <a href="/admin/dashboard" class="admin-link" style="display: none;">前往管理员页面</a>
- </div>
- <script>
- function setAdminRole() {
- // 创建管理员用户对象
- const adminUser = {
- id: '1',
- name: '超级管理员',
- avatar: '<div style=\'width: 40px; height: 40px; background-color: #CCFFCC; color: #555555; display: flex; align-items: center; justify-content: center; font-size: 13.333333333333334px; font-weight: bold;\'>ADMIN</div>',
- roles: ['admin', 'user'],
- permissions: ['view-all', 'edit-all', 'delete-all'],
- lastLogin: new Date().toISOString()
- };
- // 存储到本地存储
- localStorage.setItem('currentUser', JSON.stringify(adminUser));
- // 显示成功消息
- const message = document.getElementById('message');
- message.textContent = '管理员角色设置成功!';
- message.classList.add('success');
- // 显示前往管理员页面的链接
- document.querySelector('.admin-link').style.display = 'block';
- }
- // 检查是否已经是管理员
- window.onload = function() {
- const currentUser = localStorage.getItem('currentUser');
- if (currentUser) {
- try {
- const user = JSON.parse(currentUser);
- if (user.roles && user.roles.includes('admin')) {
- document.querySelector('.admin-link').style.display = 'block';
- document.querySelector('button').textContent = '已是管理员';
- document.querySelector('button').disabled = true;
- }
- } catch (e) {
- // JSON解析错误,忽略
- }
- }
- };
- </script>
- </body>
- </html>
|