GTong 8 сар өмнө
parent
commit
cccc071891

+ 4 - 3
internal/services/OALicenseInfo_services.go

@@ -181,11 +181,12 @@ func DistributeLicenseToEmailServices(OperatorUniqueID string, OaRequestId int64
 	var buffer bytes.Buffer
 	zipWriter := zip.NewWriter(&buffer)
 	for i, lic := range *LicInfos {
+		ii := i + 1
 		num := 1
-		filetestName := fmt.Sprintf("%d_%s_license_jdCount%d_%d", i, lic.LicInfo.OAGLXMName, lic.LicInfo.OANodeCount.Int64, num)
+		filetestName := fmt.Sprintf("%d_%s_license_jdCount%d_%d", ii, lic.LicInfo.OAGLXMName.String, lic.LicInfo.OANodeCount.Int64, num)
 		num++
 		// 将数据添加到 ZIP 中
-		file1, err := zipWriter.Create(filetestName)
+		file1, err := zipWriter.Create(fmt.Sprintf(filetestName+"_%s", lic.LicInfo.OAMainMAC.String))
 		if err != nil {
 			global.Logger.Errorln(err)
 		}
@@ -195,7 +196,7 @@ func DistributeLicenseToEmailServices(OperatorUniqueID string, OaRequestId int64
 				global.Logger.Errorln(err)
 			}
 		}
-		file2, err := zipWriter.Create(filetestName)
+		file2, err := zipWriter.Create(fmt.Sprintf(filetestName+"_%s", lic.LicInfo.OASecondMAC.String))
 		if lic.GenrateInfo.Lic2.Valid {
 			if err != nil {
 				global.Logger.Errorln(err)

+ 12 - 15
static/license_info/license_info_distribution.js

@@ -51,9 +51,9 @@ function showDistributeModal(item) {
 }
 
 
-function handleEmailSection(item,usersInfo) {
+function handleEmailSection(item, usersInfo) {
     console.log('调用邮箱处理');
-    console.log('handleEmailSection 用户信息:', usersInfo); // 打印用户信息
+    console.log('handleEmailSection 用户信息:', usersInfo);
     const emailInputs = document.getElementById('DistributeModal-email-inputs');
     emailInputs.innerHTML = ''; // 清空之前添加的邮箱输入框
 
@@ -74,10 +74,10 @@ function handleEmailSection(item,usersInfo) {
 
     // 防止重复绑定事件,先移除任何现有的点击事件监听器
     const addEmailBtn = document.getElementById('DistributeModal-add-email-btn');
-    addEmailBtn.replaceWith(addEmailBtn.cloneNode(true)); // 通过克隆移除所有之前绑定的事件
+    addEmailBtn.replaceWith(addEmailBtn.cloneNode(true));
     const newAddEmailBtn = document.getElementById('DistributeModal-add-email-btn');
 
-    // 绑定一次点击事件,动态添加邮箱输入框
+    // 绑定点击事件,动态添加邮箱输入框
     newAddEmailBtn.addEventListener('click', () => {
         const emailWrapper = document.createElement('div');
         emailWrapper.className = 'DistributeModal-email-input-wrapper';
@@ -90,9 +90,9 @@ function handleEmailSection(item,usersInfo) {
         // 创建删除按钮
         const removeEmailBtn = document.createElement('button');
         removeEmailBtn.className = 'DistributeModal-remove-email-btn';
-        removeEmailBtn.innerHTML = '×'; // × 符号
+        removeEmailBtn.innerHTML = '×';
         removeEmailBtn.addEventListener('click', () => {
-            emailWrapper.remove(); // 删除邮箱输入框
+            emailWrapper.remove();
         });
 
         // 将输入框和删除按钮加入到 emailWrapper 中
@@ -119,37 +119,34 @@ function handleEmailSection(item,usersInfo) {
         return duplicates;
     }
 
-    // 点击上半部分的确认按钮
+    // 点击确认按钮
     const emailConfirmBtn = document.getElementById('DistributeModal-email-confirm-btn');
     emailConfirmBtn.addEventListener('click', () => {
         // 收集邮箱信息
         let emails = Array.from(document.querySelectorAll('.DistributeModal-email-input'))
-                            .map(input => input.value.trim());
+                            .map(input => input.value.trim())
+                            .filter(email => email); // 过滤掉空邮箱
 
         // 检查是否勾选销售邮箱或运维邮箱
         const isSalesEmailChecked = document.getElementById('salesEmailCheckbox').checked;
         const isSupportEmailChecked = document.getElementById('supportEmailCheckbox').checked;
 
         if (isSalesEmailChecked) {
-            emails.push(item.SalesEmail); // 如果勾选了销售邮箱,添加到邮箱列表
+            emails.push(item.SalesEmail);
         }
 
         if (isSupportEmailChecked) {
-            emails.push(item.SupportEmail); // 如果勾选了运维邮箱,添加到邮箱列表
+            emails.push(item.SupportEmail);
         }
 
         // 检查是否存在重复的邮箱
         const duplicateEmails = findDuplicates(emails);
 
         if (duplicateEmails.length > 0) {
-            // 如果有重复的邮箱,弹出提示
             alert(`以下邮箱重复:\n${duplicateEmails.join('\n')}`);
         } else {
-            // 没有重复的邮箱,弹出确认发送提示
             if (confirm("确认发送这些邮件吗?")) {
-                // 执行邮箱分发逻辑
-               // distributeLicense(item, emails, []);
-               distributeEmails(item, emails, usersInfo);
+                distributeEmails(item, [...new Set(emails)], usersInfo); // 使用 Set 去重
                 closeDistributeModal(); // 关闭模态框
             }
         }

+ 162 - 69
static/role/role.css

@@ -3,65 +3,93 @@
     flex-wrap: wrap;
     gap: 16px;
     justify-content: flex-start;
+    padding: 20px;
 }
 
 .role-item {
-    background-color: #f9f9f9;
-    border-radius: 8px;
-    padding: 16px;
-    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
-    width: 300px;
-    transition: transform 0.2s ease-in-out;
+    background-color: #ffffff;
+    border-radius: 16px;
+    padding: 20px;
+    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
+    width: 280px;
+    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
     position: relative;
 }
 
 .role-item:hover {
-    transform: scale(1.05);
+    transform: translateY(-4px);
+    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
 }
 
 .role-info-create-role-button {
-    background-color: #007aff;
+    background-color: #0a84ff;
     color: white;
     border: none;
-    padding: 10px 20px;
-    border-radius: 10px;
+    padding: 12px 24px;
+    border-radius: 22px;
     cursor: pointer;
-    font-size: 16px;
-    font-weight: 500;
-    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
-    transition: background-color 0.3s;
-    margin-left: 20px;
+    font-size: 17px;
+    font-weight: 600;
+    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
+    transition: background-color 0.3s, transform 0.2s;
+    margin: 20px;
 }
 
 .role-info-create-role-button:hover {
-    background-color: #005bb5;
+    background-color: #0051a8;
+    transform: translateY(-2px);
 }
 
 /* 弹出菜单样式 */
 #role-action-menu {
     position: absolute;
-    background-color: #fff;
-    border: 1px solid #ccc;
-    border-radius: 5px;
-    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
-    padding: 10px;
+    background-color: #ffffff;
+    border: 1px solid #d1d1d6;
+    border-radius: 12px;
+    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
+    padding: 12px;
     z-index: 1000;
+    width: 150px;
+}
+
+#role-action-menu button {
+    width: 100%;
+    padding: 10px;
+    background-color: #0a84ff;
+    color: white;
+    border: none;
+    border-radius: 10px;
+    cursor: pointer;
+    font-size: 15px;
+    margin-bottom: 8px;
+    transition: background-color 0.3s;
+}
+
+#role-action-menu button:last-child {
+    margin-bottom: 0;
+}
+
+#role-action-menu button:hover {
+    background-color: #0051a8;
 }
 
 /* 模态框内按钮 */
 .role-info-button {
-    padding: 10px 20px;
-    background-color: #4CAF50;
+    padding: 12px 24px;
+    background-color: #34c759;
     color: white;
     border: none;
-    border-radius: 4px;
+    border-radius: 12px;
     cursor: pointer;
-    transition: background-color 0.3s;
-    margin-bottom: 10px;
+    transition: background-color 0.3s, transform 0.2s;
+    margin-bottom: 12px;
+    font-size: 16px;
+    font-weight: 500;
 }
 
 .role-info-button:hover {
-    background-color: #45a049;
+    background-color: #28a745;
+    transform: translateY(-2px);
 }
 
 .role-info-button-delete {
@@ -72,67 +100,132 @@
     background-color: #c23321;
 }
 
-
-/*创建角色模态框*/
-.role-info-modal {
-    display: none; /* 初始隐藏模态框 */
+/* 创建角色模态框 */
+.CreateRoleModal-modal {
+    display: none; /* 隐藏模态框 */
     position: fixed;
-    top: 0;
+    z-index: 2000; /* 在最上层 */
     left: 0;
-    right: 0;
-    bottom: 0;
-    background: rgba(0, 0, 0, 0.5);
-    justify-content: center;
-    align-items: center;
-    z-index: 1000; /* 确保模态框在最上层 */
+    top: 0;
+    width: 100%; /* 100% 宽 */
+    height: 100%; /* 100% 高 */
+    overflow: auto; /* 如果需要滚动条 */
+    background-color: rgba(0, 0, 0, 0.4); /* 半透明背景 */
+    backdrop-filter: blur(5px); /* 背景模糊 */
+}
+
+.CreateRoleModal-modal-content {
+    background-color: #ffffff;
+    margin: 10% auto; /* 居中 */
+    padding: 30px;
+    border-radius: 20px;
+    width: 90%;
+    max-width: 500px;
+    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
+    position: relative;
 }
 
-.role-info-modal.show {
-    display: flex; /* 添加一个类以显示模态框 */
+.CreateRoleModal-close {
+    color: #8e8e93;
+    position: absolute;
+    top: 20px;
+    right: 20px;
+    font-size: 24px;
+    font-weight: bold;
+    cursor: pointer;
+    transition: color 0.3s;
 }
 
-.createRoleModal-content {
-    background: white;
-    border-radius: 10px;
-    width: 400px;
-    padding: 20px;
-    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
+.CreateRoleModal-close:hover,
+.CreateRoleModal-close:focus {
+    color: #ff3b30;
 }
 
-.createRoleModal-content h3 {
-    margin: 0 0 15px 0;
+/* 表单元素 */
+form label {
+    display: block;
+    margin-bottom: 8px;
+    font-weight: 500;
+    color: #3c3c43;
 }
 
-.createRoleModal-content input[type="text"] {
+form input[type="text"] {
     width: 100%;
-    padding: 10px;
-    margin-bottom: 15px;
-    border: 1px solid #ccc;
-    border-radius: 5px;
+    padding: 10px 14px;
+    margin-bottom: 16px;
+    border: 1px solid #d1d1d6;
+    border-radius: 12px;
+    font-size: 16px;
+    background-color: #f2f2f7;
+    color: #1c1c1e;
 }
 
-.createRole-buttons {
-    display: flex;
-    justify-content: flex-end;
+form input[type="submit"],
+form button {
+    background-color: #0a84ff;
+    color: white;
+    border: none;
+    padding: 12px 24px;
+    border-radius: 22px;
+    cursor: pointer;
+    font-size: 17px;
+    font-weight: 600;
+    transition: background-color 0.3s, transform 0.2s;
+}
+
+form input[type="submit"]:hover,
+form button:hover {
+    background-color: #0051a8;
+    transform: translateY(-2px);
 }
 
-.createRole-button {
-    background-color: #007aff; /* iOS蓝色 */
+/* 权限复选框容器 */
+#permissionsContainer div {
+    margin-bottom: 12px;
+}
+
+#permissionsContainer label {
+    margin-left: 8px;
+    font-weight: 400;
+    color: #3c3c43;
+}
+
+/* 子权限复选框容器 */
+.role-sub-permissions {
+    margin-left: 20px;
+    margin-top: 8px;
+}
+
+/* 禁用按钮样式 */
+.role-info-button-disabled {
+    padding: 12px 24px;
+    background-color: #c7c7cc;
     color: white;
     border: none;
-    padding: 10px 15px;
-    border-radius: 5px;
-    cursor: pointer;
+    border-radius: 12px;
+    cursor: not-allowed;
+    font-size: 16px;
+    text-align: center;
 }
 
-.createRole-button:hover {
-    background-color: #005bb5; /* 深蓝色 */
+/* 置顶角色样式 */
+.top-role {
+    border: 2px solid #0a84ff;
 }
 
-.close-button {
-    position: absolute;
-    top: 10px;
-    right: 10px;
-    cursor: pointer;
-    font-size: 20px;
+/* 响应式调整 */
+@media (max-width: 600px) {
+    .role-info-cards-container {
+        flex-direction: column;
+        align-items: center;
+    }
+
+    .role-item {
+        width: 90%;
+    }
+
+    .CreateRoleModal-modal-content {
+        width: 95%;
+    }
 }
+

+ 16 - 2
static/role/role.html

@@ -23,8 +23,22 @@
         <!-- 通过JavaScript动态生成菜单内容 -->
     </div>
 
-
-
+    <div id="CreateRoleModa" class="CreateRoleModal-modal">
+        <div class="CreateRoleModal-modal-content">
+            <span class="CreateRoleModal-close">&times;</span>
+            <h2>创建角色</h2>
+            <form>
+                <label for="characterName">角色名称:</label>
+                <input type="text" id="characterName" name="characterName" required>
+                <br>
+                <h3>选择权限:</h3>
+                <div id="permissionsContainer"></div>
+                <br>
+                <input type="submit" value="提交">
+            </form>
+        </div>
+    </div>
+    
     
     <script src="role.js"></script>
 

+ 121 - 60
static/role/role.js

@@ -5,7 +5,9 @@ fetchRoles()
   // 处理修改用户按钮点击
   document.getElementById("createRoleButton").onclick = () => {
       
-    ShowCreateRoleModal(); // 打开编辑用户模态框
+    // 调用函数以设置模态框
+ShowCreateRoleModal();
+
 };
 
 function fetchRoles() {
@@ -44,7 +46,7 @@ function fetchRoles() {
         // 检查用户是否有 create_role 权限
         const hasCreateRolePermission = currentUserPermissions.includes('create_role');
 
-        // 如果有权限则显示“创建角色”按钮
+        // 如果有权限则显示"创建角色"按钮
         if (hasCreateRolePermission) {
             document.getElementById('createRoleButton').style.display = 'block';
         } else {
@@ -294,72 +296,131 @@ function deleteRole(roleName) {
 }
 
 
-
+// 修改后的 ShowCreateRoleModal 方法
 function ShowCreateRoleModal() {
-    console.log('Creating role...');
-    const createRoleButton = document.getElementById('createRoleButton');
-    const roleActionMenu = document.getElementById('role-action-menu');
-
-    createRoleButton.style.display = 'block'; // 显示创建角色按钮
+    // 获取模态框
+    var modal = document.getElementById("CreateRoleModa");
+
+    // 获取按钮
+    var btn = document.getElementById("createRoleButton");
+
+    // 获取关闭按钮
+    var span = document.getElementsByClassName("CreateRoleModal-close")[0];
+
+    // 权限数据
+    const permissionMap = {
+        'license': '许可证',
+        'user': '用户',
+        'role': '角色'
+    };
+
+    const subPermissions = {
+        'license': [
+            { id: 'generate_license', label: '生成许可证' },
+            { id: 'upload_license', label: '上传许可证(废弃)' },
+            { id: 'read_license', label: '读取许可证' },
+            { id: 'read_license_record', label: '读取许可证分发记录' },
+            { id: 'update_license', label: '修改许可证(废弃)' },
+            { id: 'delete_license', label: '删除许可证(废弃)' },
+            { id: 'dispat_license', label: '分发许可证' }
+        ],
+        'user': [
+            { id: 'create_user', label: '创建用户' },
+            { id: 'read_user', label: '读取用户' },
+            { id: 'update_user', label: '更新用户' },
+            { id: 'delete_user', label: '删除用户' }
+        ],
+        'role': [
+            { id: 'create_role', label: '创建角色' },
+            { id: 'delete_role', label: '删除角色' },
+            { id: 'update_role', label: '更新角色' },
+            { id: 'get_role', label: '获取角色' }
+        ]
+    };
+
+    // 填充复选框
+    var container = document.getElementById("permissionsContainer");
+    container.innerHTML = ''; // 清空之前的内容
+
+    for (const [key, value] of Object.entries(permissionMap)) {
+        // 创建主权限复选框
+        var mainCheckbox = document.createElement("input");
+        mainCheckbox.type = "checkbox";
+        mainCheckbox.id = key;
+        mainCheckbox.value = key;
+        mainCheckbox.name = "permissions";
+        mainCheckbox.onchange = function() {
+            toggleSubPermissions(key, this);
+        };
 
-    // 点击事件处理程序
-    createRoleButton.addEventListener('click', handleCreateRoleButtonClick);
+        var mainLabel = document.createElement("label");
+        mainLabel.htmlFor = key;
+        mainLabel.textContent = value;
+
+        container.appendChild(mainCheckbox);
+        container.appendChild(mainLabel);
+        container.appendChild(document.createElement("br")); // 换行
+
+        // 创建子权限容器
+        var subContainer = document.createElement("div");
+        subContainer.id = `${key}SubPermissions`;
+        subContainer.style.marginLeft = "20px";
+        subContainer.style.display = "none"; // 默认隐藏
+
+        // 创建子权限复选框
+        subPermissions[key].forEach(sub => {
+            var subCheckbox = document.createElement("input");
+            subCheckbox.type = "checkbox";
+            subCheckbox.id = sub.id;
+            subCheckbox.value = sub.id;
+            subCheckbox.name = "permissions";
+
+            var subLabel = document.createElement("label");
+            subLabel.htmlFor = sub.id;
+            subLabel.textContent = sub.label;
+
+            subContainer.appendChild(subCheckbox);
+            subContainer.appendChild(subLabel);
+            subContainer.appendChild(document.createElement("br")); // 换行
+        });
 
-    function handleCreateRoleButtonClick() {
-        openCreateRoleModal();
+        container.appendChild(subContainer);
     }
 
-    function openCreateRoleModal() {
-        roleActionMenu.classList.add('show'); // 显示模态框
-        roleActionMenu.innerHTML = `
-            <div class="createRoleModal-content">
-                <span class="close-button">&times;</span>
-                <h3>创建角色</h3>
-                <label for="roleName">角色名:</label>
-                <input type="text" id="roleName" required>
-                <h4>权限选择:</h4>
-                ${generateCheckboxes()}
-                <div class="createRole-buttons">
-                    <button id="submitRoleButton">提交</button>
-                </div>
-            </div>
-        `;
-
-        // 关闭模态框
-        roleActionMenu.querySelector('.close-button').onclick = function() {
-            roleActionMenu.classList.remove('show');
-        };
+    // 当用户点击按钮时,打开模态框
+    btn.onclick = function() {
+        modal.style.display = "block";
+    }
 
-        document.getElementById('submitRoleButton').onclick = function() {
-            // 处理角色创建逻辑
-            console.log("角色名:", document.getElementById('roleName').value);
-            roleActionMenu.classList.remove('show');
-        };
+    // 当用户点击关闭按钮时,关闭模态框
+    span.onclick = function() {
+        modal.style.display = "none";
     }
 
-    function generateCheckboxes() {
-        const permissions = {
-            'generate_license': '生成许可证',
-            'upload_license': '上传许可证(废弃)',
-            'read_license': '读取许可证',
-            'read_license_record': '读取许可证分发记录',
-            'update_license': '修改许可证(废弃)',
-            'delete_license': '删除许可证(废弃)',
-            'dispat_license': '分发许可证',
-            'create_user': '创建用户',
-            'read_user': '读取用户',
-            'update_user': '更新用户',
-            'delete_user': '删除用户',
-            'create_role': '创建角色',
-            'delete_role': '删除角色',
-            'update_role': '更新角色',
-            'get_role': '获取角色'
-        };
+    // 当用户在模态框外点击时,关闭模态框
+    window.onclick = function(event) {
+        if (event.target == modal) {
+            modal.style.display = "none";
+        }
+    }
+}
 
-        return Object.entries(permissions).map(([key, value]) => `
-            <label>
-                <input type="checkbox" name="${key}" value="${key}"> ${value}
-            </label><br>
-        `).join('');
+/**
+ * 切换子权限的显示与隐藏
+ * @param {string} key 主权限的键
+ * @param {HTMLElement} checkbox 主权限的复选框
+ */
+function toggleSubPermissions(key, checkbox) {
+    var subContainer = document.getElementById(`${key}SubPermissions`);
+    if (checkbox.checked) {
+        subContainer.style.display = "block";
+    } else {
+        subContainer.style.display = "none";
+        // 取消所有子权限的选中状态
+        var subCheckboxes = subContainer.querySelectorAll('input[type="checkbox"]');
+        subCheckboxes.forEach(sub => {
+            sub.checked = false;
+        });
     }
 }
+