diff --git a/apps/admin/package.json b/apps/admin/package.json index 0e4115b..aaa9c7c 100644 --- a/apps/admin/package.json +++ b/apps/admin/package.json @@ -16,7 +16,7 @@ "@faker-js/faker": "^10.0.0", "react": "^19.2.0", "react-dom": "^19.2.0", - "@lottiefiles/dotlottie-react": "^0.17.7", + "@lottiefiles/dotlottie-react": "^0.17.15", "@noble/curves": "^2.0.1", "@stripe/react-stripe-js": "^5.4.0", "@stripe/stripe-js": "^8.5.2", diff --git a/apps/admin/public/assets/locales/en-US/auth.json b/apps/admin/public/assets/locales/en-US/auth.json index e2decec..06eebf3 100644 --- a/apps/admin/public/assets/locales/en-US/auth.json +++ b/apps/admin/public/assets/locales/en-US/auth.json @@ -1,4 +1,11 @@ { + "captcha": { + "clickToRefresh": "Click to refresh", + "noImage": "No Image", + "placeholder": "Enter captcha code...", + "refresh": "Refresh captcha", + "required": "Please enter captcha code" + }, "check": { "description": "Verify your identity", "title": "Verify" diff --git a/apps/admin/public/assets/locales/en-US/components.json b/apps/admin/public/assets/locales/en-US/components.json index 09e97b4..964814b 100644 --- a/apps/admin/public/assets/locales/en-US/components.json +++ b/apps/admin/public/assets/locales/en-US/components.json @@ -40,6 +40,8 @@ "40005": "You do not have access permission, please contact the administrator if you have any questions.", "50001": "Corresponding coupon information not found, please check and try again.", "50002": "The coupon has been used, cannot be used again.", + "50003": "This coupon code is not supported by the current purchase plan.", + "50004": "Coupon has insufficient remaining uses.", "60001": "Subscription has expired, please renew before using.", "60002": "Unable to use the subscription at the moment, please try again later.", "60003": "An existing subscription is detected. Please cancel it before proceeding.", diff --git a/apps/admin/public/assets/locales/en-US/group.json b/apps/admin/public/assets/locales/en-US/group.json new file mode 100644 index 0000000..cab6184 --- /dev/null +++ b/apps/admin/public/assets/locales/en-US/group.json @@ -0,0 +1,200 @@ +{ + "actions": "Actions", + "autoTrigger": "Auto", + "averageMode": "Average Grouping", + "cancel": "Cancel", + "completed": "Completed", + "confirm": "Confirm", + "confirmDelete": "Confirm Delete", + "config": "Config", + "create": "Create", + "created": "Created successfully", + "createdAt": "Created At", + "createNodeGroup": "Create Node Group", + "createUserGroup": "Create User Group", + "delete": "Delete", + "deleted": "Deleted successfully", + "deleteNodeGroupConfirm": "This will delete the node group. Nodes in this group will be reassigned.", + "deleteUserGroupConfirm": "This will delete the user group. Users in this group will be reassigned to the default group.", + "description": "Description", + "descriptionPlaceholder": "Enter description", + "edit": "Edit", + "editNodeGroup": "Edit Node Group", + "editUserGroup": "Edit User Group", + "editUserGroupDescription": "Edit user group assignment and lock status", + "selectGroup": "Select a group", + "endTime": "End Time", + "errorMessage": "Error Message", + "export": "Export", + "failed": "Failed", + "failedCount": "Failed", + "groupConfig": "Group Configuration", + "groupConfigDescription": "Manage node groups and automatically assign node groups to user subscriptions", + "groupDetails": "Group Details", + "groupEnabled": "Group Management Enabled", + "groupEnabledDescription": "Enable group management to control user access to nodes", + "groupHistory": "Group Calculation History", + "groupHistoryDescription": "View group recalculation history and results", + "groupHistoryDetail": "Group Calculation Detail", + "groupId": "Group ID", + "groupIdPlaceholder": "Enter unique group ID", + "groupMode": "Group Mode", + "groupModeDescription": "Select the grouping algorithm for assigning users to groups", + "groupName": "Group Name", + "groupNamePlaceholder": "Enter group name", + "groupRecalculation": "Group Recalculation", + "groupRecalculationDescription": "Manually trigger node group reassignment for all active user subscriptions based on current configuration", + "history": "History", + "historyId": "History ID", + "id": "ID", + "idPrefix": "#", + "idle": "Idle", + "separator": "/", + "loading": "Loading...", + "loadFailed": "Failed to load configuration", + "locked": "Locked", + "manualTrigger": "Manual", + "name": "Name", + "namePlaceholder": "Enter name", + "nodeCount": "Node Count", + "nodeGroup": "Node Group", + "nodeGroupFormDescription": "Configure node group settings", + "nodeGroups": "Node Groups", + "nodeGroupsDescription": "Manage node groups for user access control", + "noDetails": "No details available", + "operator": "Operator", + "progress": "Progress", + "recalculate": "Recalculate", + "recalculateAll": "Reassign Node Groups", + "recalculationCompleted": "Recalculation completed successfully", + "recalculationFailed": "Recalculation failed. Please try again.", + "recalculationStarted": "Recalculation started", + "recalculationWarning": "Recalculation will reassign node groups for all active user subscriptions based on current configuration. This operation cannot be undone.", + "running": "Running", + "save": "Save", + "scheduleTrigger": "Schedule", + "sort": "Sort", + "sortOrder": "Sort Order", + "startTime": "Start Time", + "subscribeMode": "Subscribe-based Grouping", + "successCount": "Success", + "title": "Group Management", + "totalUsers": "Total Users", + "totalNodes": "Total Nodes", + "totalGroups": "Total Groups", + "trafficMode": "Traffic-based Grouping", + "triggerType": "Trigger Type", + "userGroup": "User Group", + "userGroups": "User Groups", + "userGroupsDescription": "Manage user groups for node access control", + "updated": "Updated successfully", + "updateFailed": "Update failed", + "userCount": "User Count", + "viewDetail": "View Detail", + "warning": "Warning", + "yes": "Yes", + "no": "No", + "saving": "Saving...", + "enableGrouping": "Enable Grouping", + "enableGroupingDescription": "When enabled, user subscriptions will be automatically assigned node groups based on the distribution mode", + "groupingMode": "Grouping Mode", + "averageModeConfig": "Average Mode Configuration", + "subscribeModeConfig": "Subscribe Mode Configuration", + "trafficModeConfig": "Traffic Mode Configuration", + "averageModeDescription": "Randomly assign available node groups to active user subscriptions", + "subscribeModeDescription": "Set default node group for user groups based on subscription plans", + "trafficModeDescription": "Assign node groups to user subscriptions based on traffic usage", + "defaultUserGroupId": "Default User Group ID", + "defaultUserGroupDescription": "New users will be assigned to this group", + "defaultUserGroupForExpiredDescription": "Users with expired subscriptions will be assigned to this group", + "autoCreateGroup": "Auto Create Group", + "autoCreateGroupDescription": "Automatically create a new user group when a new subscription plan is added", + "lockGroup": "Lock Group", + "lockGroupDescription": "Prevent automatic recalculation from changing this user's group", + "trafficRangesComingSoon": "Traffic ranges configuration coming soon...", + "currentStatus": "Current Status", + "trafficRangesConfig": "Traffic Ranges Configuration", + "trafficRangesDescription": "Configure traffic ranges for grouping users. Traffic is calculated based on user's billing cycle.", + "minTrafficGB": "Min Traffic (GB)", + "maxTrafficGB": "Max Traffic (GB)", + "addRange": "Add Range", + "remove": "Remove", + "note": "Note", + "trafficRangesNote": "Ranges must not overlap and must cover all values without gaps. Users with traffic >= the upper limit of the last range will be assigned to the last group.", + "defaultUserGroup": "Default User Group", + "defaultUserGroupForTrafficDescription": "Users with traffic exceeding all defined ranges will be assigned to this group", + "rangeError": "Range Error", + "overlapError": "Overlap Error", + "gapError": "Gap Error", + "groupByTraffic": "Group by Traffic", + "resetGroups": "Reset All Groups", + "resetGroupsTitle": "Reset All Groups", + "resetGroupsDescription": "This action will delete all node groups and user groups, reset all users' group ID to 0, clear all products' node group IDs, and clear all nodes' node group IDs. This action cannot be undone.", + "resetSuccess": "All groups have been reset successfully", + "resetFailed": "Failed to reset groups", + "saved": "Configuration saved successfully", + "saveFailed": "Failed to save configuration", + "autoCalculated": "Auto-calculated", + "userGroupCountAutoCalculated": "Auto-calculated from actual user groups", + "userGroupCount": "User Group Count", + "nodeGroupCountAutoCalculated": "Auto-calculated from actual node groups", + "nodeGroupCount": "Node Group Count", + "arrow": " → ", + "availableNodeGroups": "Available Node Groups", + "currentGroupingResult": "Current Grouping Result", + "calculationInfo": "Calculation Information", + "groupingDetailsStatistics": "Grouping Details Statistics", + "successFailedCount": "Success/Failed", + "latestGroupingCalculation": "Latest grouping calculation details", + "userList": "User List", + "email": "Email", + "noUsers": "No users found", + "showing": "Showing", + "to": "to", + "of": "of", + "previous": "Previous", + "next": "Next", + "result": "Result", + "bindNodeGroup": "Bind Node Group", + "bindNodeGroupDescription": "Select a node group to bind to user groups: {{userGroups}}", + "selectNodeGroup": "Select Node Group", + "selectNodeGroupPlaceholder": "Select a node group...", + "selectNodeGroupRequired": "Please select a node group", + "unbound": "Unbound", + "bindSuccess": "Successfully bound {{userGroupCount}} user group(s) to node group", + "bindFailed": "Failed to bind node group", + "groupMapping": "Group Mapping", + "forCalculation": "For Calculation", + "trafficRange": "Traffic Range (GB)", + "configSaved": "Configuration saved successfully", + "subscribeGroupMappingTitle": "Subscribe-Node Group Mapping", + "subscribeName": "Subscribe Plan", + "userGroupName": "User Group", + "nodeGroupName": "Node Group", + "notMapped": "Not Mapped", + "noMappingData": "No mapping data available", + "forCalculationDescription": "Whether this node group participates in grouping calculation", + "trafficRangeGB": "Traffic Range (GB)", + "trafficRangeDescription": "Users with traffic >= Min and < Max will be assigned to this node group", + "minCannotExceedMax": "Minimum traffic cannot exceed maximum traffic", + "rangeOverlap": "Range overlaps with node group \"{{name}}\"", + "nodeGroupNotFound": "Node group not found", + "validationFailed": "Validation failed", + "totalNodeGroups": "Total Node Groups", + "invalidRange": "Minimum traffic must be less than maximum traffic", + "rangeConflict": "Traffic range conflicts with node group \"{{name}}\" (range: {{min}} - {{max}} GB)", + "isExpiredGroup": "Expired Node Group", + "isExpiredGroupDescription": "Allow expired users to use limited nodes", + "expiredDaysLimit": "Expired Days Limit", + "expiredDaysLimitDescription": "Number of days after expiration that users can still access nodes", + "maxTrafficGBExpired": "Max Traffic for Expired Users (GB)", + "maxTrafficGBExpiredDescription": "Maximum traffic allowed for expired users (0 = unlimited)", + "speedLimit": "Speed Limit (KB/s)", + "speedLimitDescription": "Speed limit for users in this node group (0 = unlimited)", + "expiredGroup": "Expired Only", + "expiredSettings": "Expired Settings", + "days": "days", + "expiredGroupExists": "System already has an expired node group: {{name}}", + "nodeGroupUsedBySubscribe": "This node group is used as default node group in subscription products, cannot set as expired group", + "expiredGroupForCalculationDescription": "Expired-only node groups cannot participate in group calculation" +} diff --git a/apps/admin/public/assets/locales/en-US/menu.json b/apps/admin/public/assets/locales/en-US/menu.json index 44462b9..db4da07 100644 --- a/apps/admin/public/assets/locales/en-US/menu.json +++ b/apps/admin/public/assets/locales/en-US/menu.json @@ -10,6 +10,7 @@ "Document Management": "Document Management", "Email": "Email", "Gift": "Gift", + "Group Management": "Group Management", "Login": "Login", "Logs & Analytics": "Logs & Analytics", "Maintenance": "Maintenance", diff --git a/apps/admin/public/assets/locales/en-US/nodes.json b/apps/admin/public/assets/locales/en-US/nodes.json index 05ed877..67b4fe6 100644 --- a/apps/admin/public/assets/locales/en-US/nodes.json +++ b/apps/admin/public/assets/locales/en-US/nodes.json @@ -1,5 +1,6 @@ { "address": "Address", + "all": "All", "cancel": "Cancel", "confirm": "Confirm", "confirmDeleteDesc": "This action cannot be undone.", @@ -17,15 +18,21 @@ "enabled_off": "Disabled", "enabled_on": "Enabled", "name": "Name", + "nodeGroup": "Node Group", + "nodeGroups": "Node Groups", + "nodeGroup_description": "Assign this node to multiple groups for user access control.", "pageTitle": "Nodes", "port": "Port", "protocol": "Protocol", + "public": "Public", + "selectNodeGroup": "Select node group…", "select_protocol": "Select protocol…", "select_server": "Select server…", "server": "Server", "sorted_success": "Sorted successfully", "tags": "Tags", "tags_description": "Permission grouping tag (incl. plan binding and delivery policies).", + "tags_groupMode_description": "Optional tags for display and filtering (node group name will be used as tag if empty).", "tags_placeholder": "Use Enter or comma (,) to add multiple tags", "updated": "Updated" } diff --git a/apps/admin/public/assets/locales/en-US/product.json b/apps/admin/public/assets/locales/en-US/product.json index f590049..71765be 100644 --- a/apps/admin/public/assets/locales/en-US/product.json +++ b/apps/admin/public/assets/locales/en-US/product.json @@ -1,4 +1,5 @@ { + "all": "All", "cancel": "Cancel", "confirm": "Confirm", "confirmDelete": "Are you sure you want to delete?", @@ -7,13 +8,16 @@ "create": "Create", "createSubscribe": "Create Subscription", "createSuccess": "Create Successful", + "currentUserGroup": "Current User Group", + "defaultNodeGroup": "Default Node Group", "delete": "Delete", + "nodeGroups": "Node Groups", + "nodes": "nodes", "deleteSuccess": "Delete Successful", "deleteWarning": "Data cannot be recovered after deletion. Please proceed with caution.", "deviceLimit": "IP Limit", "edit": "Edit", "editSubscribe": "Edit Subscription", - "sortSuccess": "Sort completed successfully", "form": { "annualReset": "Annual Reset", "basic": "Basic", @@ -30,7 +34,6 @@ "discountPercent": "Discount Percentage", "Hour": "Hour", "inventory": "Subscription Limit", - "unlimitedInventory": "Unlimited (enter -1)", "language": "Language", "languageDescription": "Leave empty for default without language restriction", "languagePlaceholder": "Language identifier for the subscription, e.g., en-US, zh-CN", @@ -40,7 +43,19 @@ "name": "Name", "node": "Node", "nodeGroup": "Node Group", - "nodes": "Nodes", + "nodeGroups": "Node Groups", + "nodeGroupsDescription": "Assign this product to multiple node groups. Users will get nodes from these groups.", + "nodeGroupsFirstSelectionDescription": "Select node groups for this product. The first selected group will be set as the default node group.", + "defaultNodeGroup": "Default Node Group", + "defaultNodeGroupDescription": "Select the default node group for this product. This will be automatically included in the backup node groups.", + "selectDefaultNodeGroup": "Select a default node group...", + "noDefaultNodeGroup": "No Default Node Group", + "backupNodeGroups": "Backup Node Groups", + "backupNodeGroupsDescription": "Select additional backup node groups. The default node group is automatically included.", + "nodes": "Linked Nodes", + "nodesDescription": "Select nodes for this subscription", + "nodesInGroup": "Nodes in this group:", + "nodesWithoutGroupsDescription": "Nodes without group assignment will be shown here (nodes that belong to groups are managed in the Node Groups section above)", "noLimit": "No Limit", "NoLimit": "No Limit", "noReset": "No Reset", @@ -59,18 +74,55 @@ "showOriginalPriceDescription": "When enabled, the subscription card will display both the original price and the discounted price to help users understand the discount amount", "speedLimit": "Speed Limit ", "traffic": "Traffic", + "trafficLimit": "Traffic Limit", + "trafficLimitRules": "Traffic Limit Rules", + "trafficLimitDescription": "Configure traffic-based speed limit rules. When traffic usage reaches the specified amount, the speed will be limited.", + "addTrafficLimitRule": "Add Traffic Limit Rule", + "statType": "Statistics Type", + "selectStatType": "Select type...", + "statTypeHour": "Hour", + "statTypeDay": "Day", + "statValue": "Time Value", + "trafficUsage": "Traffic Usage (GB)", + "speedLimitKb": "Speed Limit (kb)", "unitPrice": "Unit Price", "unitTime": "Unit Time", + "unlimitedInventory": "Unlimited (enter -1)", "Year": "Year" }, + "groupMapping": "Group Mapping", + "groupMappingTitle": "Group Mapping", + "groupMappingUpdateFailed": "Failed to update group mapping", + "groupMappingUpdateSuccess": "Group mapping updated successfully", + "migrateUsers": "Migrate Users", + "migrateUsersTitle": "Migrate Users", + "migrateUsersDescription": "Migrate all users from the current user group to another group", + "migrateUsersWarning": "This will migrate {count} users from \"{group}\" to the target group. This action cannot be undone.", + "migrateUsersSuccess": "Successfully migrated {count} users to the target group", + "migrateUsersFailed": "Failed to migrate users", + "targetUserGroup": "Target User Group", + "selectTargetGroup": "Select a target group...", + "selectTargetGroupFirst": "Please select a target group first", + "cannotMigrateToSameGroup": "Cannot migrate to the same group", + "noSourceGroup": "No source group available", + "selectedGroup": "Selected Group", + "userCount": "User Count", + "migrating": "Migrating...", "inventory": "Subscription Limit", "language": "Language", + "loading": "Loading...", "name": "Name", + "noMapping": "No mapping set", + "noNodes": "No nodes in this group", "quota": "Purchase Limit/Time", "replacement": "Reset Price/Time", + "save": "Save", + "selectGroupPlaceholder": "Select a group...", + "selectUserGroup": "Select User Group", "sell": "Sell", "show": "Display", "sold": "Subscription Count", + "sortSuccess": "Sort completed successfully", "traffic": "Traffic", "unitPrice": "Unit Price", "updateSuccess": "Update Successful" diff --git a/apps/admin/public/assets/locales/en-US/redemption.json b/apps/admin/public/assets/locales/en-US/redemption.json index 1abed9d..be07826 100644 --- a/apps/admin/public/assets/locales/en-US/redemption.json +++ b/apps/admin/public/assets/locales/en-US/redemption.json @@ -1,5 +1,4 @@ { - "active": "Active", "cancel": "Cancel", "code": "Redemption Code", "confirm": "Confirm", @@ -13,7 +12,6 @@ "duration": "Redemption Duration", "edit": "Edit", "editRedemptionCode": "Edit Redemption Code", - "exhausted": "Exhausted", "form": { "batchCount": "Batch Count", "batchCountPlaceholder": "Batch Count", @@ -26,16 +24,12 @@ "halfYear": "Half Year", "month": "Month", "quarter": "Quarter", - "quantityRequired": "Quantity is required", "selectPlan": "Select Redemption Plan", "selectUnitTime": "Select Redemption Duration Unit", "subscribePlan": "Redemption Plan", - "subscribePlanRequired": "Subscribe plan is required", "totalCount": "Available Uses", "totalCountPlaceholder": "Available Uses", - "totalCountRequired": "Total count is required", "unitTime": "Redemption Duration Unit", - "unitTimeRequired": "Unit time is required", "year": "Year" }, "id": "ID", @@ -50,8 +44,8 @@ "status": "Status", "subscribeId": "Subscribe ID", "subscribePlan": "Redemption Plan", - "totalCount": "Available Uses", "total": "Total", + "totalCount": "Available Uses", "unitTime": "Redemption Duration Unit", "updateSuccess": "Update Success", "usedCount": "Used", diff --git a/apps/admin/public/assets/locales/en-US/system.json b/apps/admin/public/assets/locales/en-US/system.json index 74e2395..0aa0cc1 100644 --- a/apps/admin/public/assets/locales/en-US/system.json +++ b/apps/admin/public/assets/locales/en-US/system.json @@ -20,6 +20,7 @@ "description": "Configure currency units, symbols, and exchange rate API settings", "title": "Currency Configuration" }, + "groupSettings": "Group Settings", "invite": { "description": "Configure user invitation and referral reward settings", "forcedInvite": "Require Invitation to Register", @@ -124,13 +125,20 @@ }, "userSecuritySettings": "User & Security", "verify": { - "description": "Configure Turnstile CAPTCHA and verification settings", - "enableLoginVerify": "Enable Verification on Login", - "enableLoginVerifyDescription": "When enabled, users must pass human verification during login", - "enablePasswordVerify": "Enable Verification on Password Reset", - "enablePasswordVerifyDescription": "When enabled, users must pass human verification during password reset", - "enableRegisterVerify": "Enable Verification on Registration", - "enableRegisterVerifyDescription": "When enabled, users must pass human verification during registration", + "captchaType": "Captcha Type", + "captchaTypeDescription": "Choose between local image captcha (offline) or Cloudflare Turnstile", + "captchaTypeLocal": "Local Image Captcha", + "captchaTypePlaceholder": "Select captcha type", + "captchaTypeTurnstile": "Cloudflare Turnstile", + "description": "Configure captcha type and verification settings", + "enableAdminLoginCaptcha": "Enable Admin Authentication Captcha", + "enableAdminLoginCaptchaDescription": "When enabled, administrators must pass captcha verification during login or password reset", + "enableUserLoginCaptcha": "Enable User Login Captcha", + "enableUserLoginCaptchaDescription": "When enabled, users must pass captcha verification during login", + "enableUserRegisterCaptcha": "Enable User Registration Captcha", + "enableUserRegisterCaptchaDescription": "When enabled, users must pass captcha verification during registration", + "enableUserResetPasswordCaptcha": "Enable User Password Reset Captcha", + "enableUserResetPasswordCaptchaDescription": "When enabled, users must pass captcha verification during password reset", "saveFailed": "Save Failed", "saveSuccess": "Save Successful", "title": "Security Verification", diff --git a/apps/admin/public/assets/locales/en-US/tool.json b/apps/admin/public/assets/locales/en-US/tool.json index 0bf5b5d..c1c61a4 100644 --- a/apps/admin/public/assets/locales/en-US/tool.json +++ b/apps/admin/public/assets/locales/en-US/tool.json @@ -12,6 +12,7 @@ "systemReboot": "System Reboot", "systemServices": "System Services", "update": "Update", + "updateDescription": "Are you sure you want to update?", "updateFailed": "Update failed", "updateServerDescription": "Are you sure you want to update the server version from {{current}} to {{latest}}?", "updateSuccess": "Update completed successfully", diff --git a/apps/admin/public/assets/locales/en-US/translation.json b/apps/admin/public/assets/locales/en-US/translation.json index d8c04fb..30bb51d 100644 --- a/apps/admin/public/assets/locales/en-US/translation.json +++ b/apps/admin/public/assets/locales/en-US/translation.json @@ -7,6 +7,10 @@ "serverRequired": "Please select a server" }, "form": { + "quantityRequired": "Quantity is required", + "subscribePlanRequired": "Subscribe plan is required", + "totalCountRequired": "Total count is required", + "unitTimeRequired": "Unit time is required", "validation": { "nameRequired": "Client name is required", "userAgentRequiredSuffix": "is required" diff --git a/apps/admin/public/assets/locales/en-US/user.json b/apps/admin/public/assets/locales/en-US/user.json index e0422bc..7e3f9da 100644 --- a/apps/admin/public/assets/locales/en-US/user.json +++ b/apps/admin/public/assets/locales/en-US/user.json @@ -2,6 +2,7 @@ "accountEnable": "Account Enable", "add": "Add", "administrator": "Administrator", + "all": "All", "areaCodePlaceholder": "Area code", "authMethodsTitle": "Auth Methods", "avatar": "Avatar", @@ -17,6 +18,9 @@ "confirm": "Confirm", "confirmDelete": "Confirm Delete", "confirmOffline": "Confirm Offline", + "confirmResetToken": "Confirm Reset Subscription Address", + "confirmResumeSubscribe": "Confirm Resume Subscription", + "confirmStopSubscribe": "Confirm Stop Subscription", "copySubscription": "Copy Subscription", "copySuccess": "Copied successfully", "create": "Create", @@ -30,7 +34,6 @@ "deleteDescription": "This action cannot be undone.", "deleteSubscriptionDescription": "This action cannot be undone.", "deleteSuccess": "Deleted successfully", - "isDeleted": "Status", "deviceLimit": "Device Limit", "deviceGroup": "Device Group", "deviceNo": "Device No.", @@ -38,7 +41,10 @@ "download": "Download", "downloadTraffic": "Download Traffic", "edit": "Edit", + "editGroup": "Edit Group", "editSubscription": "Edit Subscription", + "editUserGroup": "Edit User Group", + "editUserGroupDescription": "Edit user group assignment and lock status", "enable": "Enable", "enabled": "Enabled", "disabled": "Disabled", @@ -83,6 +89,7 @@ "inviteCount": "Invited Users", "inviteStats": "Invite Statistics", "invitedUsers": "Invited Users", + "isDeleted": "Status", "kickOfflineConfirm": "kickOfflineConfirm", "kickOfflineSuccess": "Device kicked offline", "lastSeen": "Last Seen", @@ -130,33 +137,33 @@ "resetSearch": "Reset", "resetTime": "Reset Time", "resetToken": "Reset Subscription Address", + "saving": "Saving...", "resetTokenDescription": "This will reset the subscription address and regenerate a new token.", "resetTokenSuccess": "Subscription address reset successfully", - "confirmResetToken": "Confirm Reset Subscription Address", + "resumeSubscribe": "Resume Subscription", + "selectGroup": "Select a group", + "resumeSubscribeDescription": "This will resume the subscription and allow the user to use it.", + "resumeSubscribeSuccess": "Subscription resumed successfully", + "save": "Save", + "shortCode": "Short Code", + "speedLimit": "Speed Limit", + "startTime": "startTime", + "status": "Status", + "statusActive": "Active", + "statusDeducted": "Deducted", + "statusExpired": "Expired", + "statusFinished": "Finished", + "statusPending": "Pending", + "statusStopped": "Stopped", "stopSubscribe": "Stop Subscription", "stopSubscribeDescription": "This will stop the subscription temporarily. User will not be able to use it.", "stopSubscribeSuccess": "Subscription stopped successfully", - "confirmStopSubscribe": "Confirm Stop Subscription", - "resumeSubscribe": "Resume Subscription", - "resumeSubscribeDescription": "This will resume the subscription and allow the user to use it.", - "resumeSubscribeSuccess": "Subscription resumed successfully", - "confirmResumeSubscribe": "Confirm Resume Subscription", - "status": "Status", - "statusPending": "Pending", - "statusActive": "Active", - "statusFinished": "Finished", - "statusExpired": "Expired", - "statusDeducted": "Deducted", - "statusStopped": "Stopped", - "save": "Save", "search": "Search", "searchPlaceholder": "Email / Invite Code / Device ID", "searchInputPlaceholder": "Enter search term", "sharedSubscription": "Shared", "sharedSubscriptionInfo": "This user is a device group member. Showing shared subscriptions from owner (ID: {{ownerId}})", "sharedSubscriptionList": "Shared Subscription List", - "speedLimit": "Speed Limit", - "startTime": "startTime", "subscription": "Subscription", "subscriptionId": "subscriptionId", "subscriptionInfo": "subscriptionInfo", @@ -173,11 +180,13 @@ "trafficDetails": "Traffic Details", "trafficLimit": "Traffic Limit", "trafficStats": "Traffic Stats", - "trafficUsage": "trafficUsage", + "trafficUsage": "Traffic Usage", + "remainingTraffic": "Remaining Traffic", "unlimited": "unlimited", "unverified": "Unverified", "update": "Update", "updateSuccess": "Updated successfully", + "groupUpdated": "Group updated successfully", "upload": "Upload", "uploadTraffic": "Upload Traffic", "userAgent": "User Agent", @@ -188,7 +197,20 @@ "userList": "User List", "userName": "Username", "userProfile": "User Profile", + "userGroup": "User Group", "verified": "Verified", "viewDeviceGroup": "View Device Group", - "viewOwner": "View Owner" + "viewOwner": "View Owner", + "locked": "Locked", + "lockGroup": "Lock Group", + "lockGroupDescription": "Prevent automatic grouping from changing this user's group", + "groupLocked": "Group Locked", + "previewNodes": "Preview Nodes", + "availableNodes": "Available Nodes", + "name": "Name", + "address": "Address", + "noNodesAvailable": "No nodes available", + "nodeGroup": "Node Group", + "publicNodes": "Public Nodes", + "subscriptionNodes": "Subscription Nodes" } diff --git a/apps/admin/public/assets/locales/zh-CN/auth.json b/apps/admin/public/assets/locales/zh-CN/auth.json index 2a4c8fa..86abb3c 100644 --- a/apps/admin/public/assets/locales/zh-CN/auth.json +++ b/apps/admin/public/assets/locales/zh-CN/auth.json @@ -1,4 +1,11 @@ { + "captcha": { + "clickToRefresh": "点击刷新", + "noImage": "无图片", + "placeholder": "请输入验证码...", + "refresh": "刷新验证码", + "required": "请输入验证码" + }, "check": { "description": "验证您的身份", "title": "验证" diff --git a/apps/admin/public/assets/locales/zh-CN/components.json b/apps/admin/public/assets/locales/zh-CN/components.json index 212f3c6..c0d0b17 100644 --- a/apps/admin/public/assets/locales/zh-CN/components.json +++ b/apps/admin/public/assets/locales/zh-CN/components.json @@ -40,6 +40,8 @@ "40005": "您没有访问权限,如有疑问请联系管理员。", "50001": "找不到对应的优惠券信息,请检查后重试。", "50002": "该优惠券已被使用,无法再次使用。", + "50003": "", + "50004": "", "60001": "订阅已过期,请续费后使用。", "60002": "暂时无法使用该订阅,请稍后再试。", "60003": "检测到现有订阅,请先取消后再继续。", diff --git a/apps/admin/public/assets/locales/zh-CN/group.json b/apps/admin/public/assets/locales/zh-CN/group.json new file mode 100644 index 0000000..ad5c6fb --- /dev/null +++ b/apps/admin/public/assets/locales/zh-CN/group.json @@ -0,0 +1,201 @@ +{ + "actions": "操作", + "autoTrigger": "自动", + "averageMode": "平均分组", + "cancel": "取消", + "completed": "已完成", + "confirm": "确认", + "confirmDelete": "确认删除", + "config": "配置", + "create": "创建", + "created": "创建成功", + "createdAt": "创建时间", + "createNodeGroup": "创建节点组", + "createUserGroup": "创建用户组", + "delete": "删除", + "deleted": "删除成功", + "deleteNodeGroupConfirm": "此操作将删除节点组。该组中的节点将被重新分配。", + "deleteUserGroupConfirm": "此操作将删除用户组。该组中的用户将被重新分配到默认组。", + "description": "描述", + "descriptionPlaceholder": "输入描述", + "edit": "编辑", + "editNodeGroup": "编辑节点组", + "editUserGroup": "编辑用户组", + "editUserGroupDescription": "编辑用户组分配和锁定状态", + "selectGroup": "选择一个组", + "endTime": "结束时间", + "errorMessage": "错误信息", + "export": "导出", + "failed": "失败", + "failedCount": "失败", + "groupConfig": "分组配置", + "groupConfigDescription": "管理节点组并自动为用户订阅分配节点组", + "groupDetails": "分组详情", + "groupEnabled": "启用分组管理", + "groupEnabledDescription": "启用分组管理以控制用户对节点的访问", + "groupHistory": "分组计算历史", + "groupHistoryDescription": "查看分组重算历史和结果", + "groupHistoryDetail": "分组计算详情", + "groupId": "分组ID", + "groupIdPlaceholder": "输入唯一的分组ID", + "groupMode": "分组模式", + "groupModeDescription": "选择分组算法以将用户分配到组", + "groupName": "分组名称", + "groupNamePlaceholder": "输入分组名称", + "groupRecalculation": "分组重新计算", + "groupRecalculationDescription": "根据当前配置手动触发所有有效用户订阅的节点组重新分配", + "history": "历史记录", + "historyId": "历史ID", + "id": "ID", + "idPrefix": "#", + "idle": "空闲", + "separator": ",", + "loading": "加载中...", + "loadFailed": "加载配置失败", + "locked": "已锁定", + "manualTrigger": "手动", + "name": "名称", + "namePlaceholder": "输入名称", + "nodeCount": "节点数", + "nodeGroup": "节点组", + "nodeGroupFormDescription": "配置节点组设置", + "nodeGroups": "节点组", + "nodeGroupsDescription": "管理节点组以控制用户访问权限", + "noDetails": "暂无详情", + "operator": "操作人", + "progress": "进度", + "recalculate": "重新计算", + "recalculateAll": "重新分配节点组", + "recalculationCompleted": "重新计算成功完成", + "recalculationFailed": "重新计算失败,请重试。", + "recalculationStarted": "重新计算已启动", + "recalculationWarning": "重新计算将根据当前配置重新分配所有有效用户订阅的节点组。此操作无法撤消。", + "running": "运行中", + "save": "保存", + "scheduleTrigger": "定时", + "sort": "排序", + "sortOrder": "排序顺序", + "startTime": "开始时间", + "subscribeMode": "套餐分组", + "successCount": "成功", + "title": "分组管理", + "totalUsers": "总用户数", + "totalNodes": "总节点数", + "totalGroups": "总分组数", + "trafficMode": "流量分组", + "triggerType": "触发类型", + "userGroup": "用户组", + "userGroups": "用户组", + "userGroupsDescription": "管理用户组以控制节点访问权限", + "updated": "更新成功", + "updateFailed": "更新失败", + "userCount": "用户数", + "viewDetail": "查看详情", + "warning": "警告", + "yes": "是", + "no": "否", + "saving": "保存中...", + "enableGrouping": "启用分组", + "enableGroupingDescription": "启用后,用户订阅将根据分配模式自动分配节点组", + "groupingMode": "分组方式", + "averageModeConfig": "平均模式配置", + "subscribeModeConfig": "订阅模式配置", + "trafficModeConfig": "流量模式配置", + "averageModeDescription": "为有效用户订阅随机分配可用节点组", + "subscribeModeDescription": "根据订阅套餐设置用户组的默认节点组", + "trafficModeDescription": "根据用户订阅的流量使用情况分配节点组", + "defaultUserGroupId": "默认用户组ID", + "defaultUserGroupDescription": "新用户将被分配到此组", + "defaultUserGroupForExpiredDescription": "订阅过期的用户将被分配到此组", + "autoCreateGroup": "自动创建组", + "autoCreateGroupDescription": "添加新订阅计划时自动创建新的用户组", + "lockGroup": "锁定分组", + "lockGroupDescription": "防止自动重新计算更改此用户的分组", + "trafficRangesComingSoon": "流量区间配置即将推出...", + "currentStatus": "当前状态", + "trafficRangesConfig": "流量区间配置", + "trafficRangesDescription": "配置用户流量分组区间。流量根据用户计费周期计算。", + "minTrafficGB": "最小流量 (GB)", + "maxTrafficGB": "最大流量 (GB)", + "addRange": "添加区间", + "remove": "移除", + "note": "注意", + "trafficRangesNote": "区间不能重叠且必须覆盖所有值而不留空档。流量大于最后一个区间上限的用户将被分配到最后一个组。", + "defaultUserGroup": "默认用户组", + "defaultUserGroupForTrafficDescription": "超出所有定义区间的用户将被分配到此组", + "rangeError": "区间错误", + "overlapError": "区间重叠错误", + "gapError": "存在空档错误", + "groupByTraffic": "按流量分组", + "resetGroups": "重置所有分组", + "resetGroupsTitle": "重置所有分组", + "resetGroupsDescription": "此操作将删除所有节点组和用户组,将所有用户的组ID重置为0,清空所有商品的节点组ID,清空所有节点的节点组ID。此操作无法撤消。", + "resetSuccess": "所有分组已成功重置", + "resetFailed": "重置分组失败", + "saved": "配置保存成功", + "saveFailed": "保存配置失败", + "autoCalculated": "自动统计", + "userGroupCountAutoCalculated": "自动统计实际用户组数量", + "userGroupCount": "用户组数", + "nodeGroupCountAutoCalculated": "自动统计实际节点组数量", + "nodeGroupCount": "节点组数", + "arrow": " → ", + "availableNodeGroups": "可用节点组", + "currentGroupingResult": "当前分组结果", + "calculationInfo": "计算信息", + "groupingDetailsStatistics": "分组详情统计", + "successFailedCount": "成功/失败", + "latestGroupingCalculation": "最新分组计算详情", + "userList": "用户列表", + "email": "邮箱", + "noUsers": "未找到用户", + "showing": "显示", + "to": "至", + "of": "共", + "previous": "上一页", + "next": "下一页", + "result": "结果", + "bindNodeGroup": "绑定节点组", + "bindNodeGroupDescription": "选择一个节点组绑定到以下用户组:{{userGroups}}", + "selectNodeGroup": "选择节点组", + "selectNodeGroupPlaceholder": "请选择节点组...", + "selectNodeGroupRequired": "请选择一个节点组", + "unbound": "未绑定", + "bindSuccess": "成功将 {{userGroupCount}} 个用户组绑定到节点组", + "bindFailed": "绑定节点组失败", + "groupMapping": "分组对应关系", + "forCalculation": "参与计算", + "trafficRange": "流量区间 (GB)", + "configSaved": "配置保存成功", + "subscribeGroupMappingTitle": "套餐-节点组对应关系", + "subscribeName": "订阅计划", + "userGroupName": "用户组", + "nodeGroupName": "节点组", + "notMapped": "未映射", + "noMappingData": "暂无映射数据", + "forCalculationDescription": "此节点组是否参与分组计算", + "trafficRangeGB": "流量区间 (GB)", + "trafficRangeDescription": "流量大于等于最小值且小于最大值的用户将被分配到此节点组", + "minCannotExceedMax": "最小流量不能超过最大流量", + "rangeOverlap": "区间与节点组 \"{{name}}\" 重叠", + "nodeGroupNotFound": "未找到节点组", + "validationFailed": "验证失败", + "totalNodeGroups": "总节点组数", + "invalidRange": "最小流量必须小于最大流量", + "rangeConflict": "流量区间与节点组 \"{{name}}\" 冲突(区间:{{min}} - {{max}} GB)", + "isExpiredGroup": "过期节点组", + "isExpiredGroupDescription": "允许过期用户使用受限节点", + "expiredDaysLimit": "过期天数限制", + "expiredDaysLimitDescription": "用户订阅过期后仍可访问节点的天数", + "maxTrafficGBExpired": "过期用户最大流量 (GB)", + "maxTrafficGBExpiredDescription": "过期用户允许使用的最大流量(0 = 不限制)", + "speedLimit": "限速 (KB/s)", + "speedLimitDescription": "该节点组用户的速度限制(0 = 不限制)", + "expiredGroup": "过期专用", + "expiredSettings": "过期设置", + "days": "天", + "expiredGroupExists": "系统中已存在过期节点组:{{name}}", + "nodeGroupUsedBySubscribe": "该节点组已被订阅商品设置为默认节点组,不能设为过期节点组", + "expiredGroupForCalculationDescription": "过期专用节点组不能参与分组计算" +} + diff --git a/apps/admin/public/assets/locales/zh-CN/menu.json b/apps/admin/public/assets/locales/zh-CN/menu.json index a024a96..faf2ae8 100644 --- a/apps/admin/public/assets/locales/zh-CN/menu.json +++ b/apps/admin/public/assets/locales/zh-CN/menu.json @@ -10,6 +10,7 @@ "Document Management": "文档管理", "Email": "邮件", "Gift": "赠送", + "Group Management": "分组管理", "Login": "登录", "Logs & Analytics": "日志与分析", "Maintenance": "维护", diff --git a/apps/admin/public/assets/locales/zh-CN/nodes.json b/apps/admin/public/assets/locales/zh-CN/nodes.json index a2634e9..3c67650 100644 --- a/apps/admin/public/assets/locales/zh-CN/nodes.json +++ b/apps/admin/public/assets/locales/zh-CN/nodes.json @@ -1,5 +1,6 @@ { "address": "地址", + "all": "全部", "cancel": "取消", "confirm": "确认", "confirmDeleteDesc": "此操作无法撤销。", @@ -17,15 +18,21 @@ "enabled_off": "已禁用", "enabled_on": "已启用", "name": "名称", + "nodeGroup": "节点分组", + "nodeGroups": "节点分组", + "nodeGroup_description": "将此节点分配到多个分组以控制用户访问。", "pageTitle": "节点", "port": "端口", "protocol": "协议", + "public": "公共", + "selectNodeGroup": "选择节点分组…", "select_protocol": "选择协议…", "select_server": "选择服务器…", "server": "服务器", "sorted_success": "排序成功", "tags": "标签", "tags_description": "权限分组标签(包含计划绑定和投递策略)。", + "tags_groupMode_description": "可选标签,用于显示和过滤(如果为空,节点组名称将作为标签使用)。", "tags_placeholder": "使用回车或逗号 (,) 添加多个标签", "updated": "已更新" } diff --git a/apps/admin/public/assets/locales/zh-CN/product.json b/apps/admin/public/assets/locales/zh-CN/product.json index d8a6e28..6ff9d46 100644 --- a/apps/admin/public/assets/locales/zh-CN/product.json +++ b/apps/admin/public/assets/locales/zh-CN/product.json @@ -1,4 +1,5 @@ { + "all": "全部", "cancel": "取消", "confirm": "确认", "confirmDelete": "确定要删除吗?", @@ -7,13 +8,16 @@ "create": "创建", "createSubscribe": "创建订阅", "createSuccess": "创建成功", + "currentUserGroup": "当前用户分组", + "defaultNodeGroup": "默认节点组", "delete": "删除", + "nodeGroups": "节点组", + "nodes": "个节点", "deleteSuccess": "删除成功", "deleteWarning": "删除后数据无法恢复,请谨慎操作。", "deviceLimit": "IP限制", "edit": "编辑", "editSubscribe": "编辑订阅", - "sortSuccess": "排序成功", "form": { "annualReset": "年度重置", "basic": "基本", @@ -30,7 +34,6 @@ "discountPercent": "折扣百分比", "Hour": "小时", "inventory": "订阅库存", - "unlimitedInventory": "无限制(输入 -1)", "language": "语言", "languageDescription": "留空为默认无语言限制", "languagePlaceholder": "订阅的语言标识符,例如 en-US、zh-CN", @@ -40,7 +43,19 @@ "name": "名称", "node": "节点", "nodeGroup": "节点组", - "nodes": "节点", + "nodeGroups": "节点组", + "nodeGroupsDescription": "将此商品分配到多个节点分组。用户将可以从这些分组获取节点。", + "nodeGroupsFirstSelectionDescription": "为此商品选择节点组。第一个选中的组将被设置为默认节点组。", + "defaultNodeGroup": "默认节点组", + "defaultNodeGroupDescription": "为此商品选择默认节点组。将自动包含在备用节点组中。", + "selectDefaultNodeGroup": "选择默认节点组...", + "noDefaultNodeGroup": "无默认节点组", + "backupNodeGroups": "备用节点组", + "backupNodeGroupsDescription": "选择其他备用节点组。默认节点组会自动包含。", + "nodes": "关联节点", + "nodesDescription": "选择此订阅的节点", + "nodesInGroup": "分组中的节点:", + "nodesWithoutGroupsDescription": "未分配到分组的节点将在此处显示(属于分组的节点在上方的节点组部分管理)", "noLimit": "无限制", "NoLimit": "无限制", "noReset": "不重置", @@ -59,18 +74,55 @@ "showOriginalPriceDescription": "开启后,在订阅卡片上将会显示原价和折后价,帮助用户了解优惠幅度", "speedLimit": "速度限制", "traffic": "流量", + "trafficLimit": "按量限速", + "trafficLimitRules": "按量限速规则", + "trafficLimitDescription": "配置基于流量的限速规则。当流量使用达到指定量时,将进行限速。", + "addTrafficLimitRule": "添加限速规则", + "statType": "统计类型", + "selectStatType": "选择类型...", + "statTypeHour": "小时", + "statTypeDay": "天", + "statValue": "时间值", + "trafficUsage": "使用流量(GB)", + "speedLimitKb": "限速(kb)", "unitPrice": "单价", "unitTime": "时间单位", + "unlimitedInventory": "无限制(输入 -1)", "Year": "年" }, + "groupMapping": "分组映射", + "groupMappingTitle": "分组映射", + "groupMappingUpdateFailed": "更新分组映射失败", + "groupMappingUpdateSuccess": "分组映射更新成功", + "migrateUsers": "迁移用户", + "migrateUsersTitle": "迁移用户", + "migrateUsersDescription": "将当前用户组的所有用户迁移到另一个用户组", + "migrateUsersWarning": "这将把 {count} 个用户从 \"{group}\" 迁移到目标用户组。此操作无法撤销。", + "migrateUsersSuccess": "成功将 {count} 个用户迁移到目标用户组", + "migrateUsersFailed": "迁移用户失败", + "targetUserGroup": "目标用户组", + "selectTargetGroup": "选择目标用户组...", + "selectTargetGroupFirst": "请先选择目标用户组", + "cannotMigrateToSameGroup": "无法迁移到相同的用户组", + "noSourceGroup": "没有可用的源用户组", + "selectedGroup": "已选择的分组", + "userCount": "用户数量", + "migrating": "迁移中...", "inventory": "订阅库存", "language": "语言", + "loading": "加载中...", "name": "名称", + "noMapping": "未设置映射", + "noNodes": "该分组下没有节点", "quota": "购买限制/次", "replacement": "重置价格/次", + "save": "保存", + "selectGroupPlaceholder": "选择分组...", + "selectUserGroup": "选择用户分组", "sell": "销售", "show": "显示", "sold": "订阅数量", + "sortSuccess": "排序成功", "traffic": "流量", "unitPrice": "单价", "updateSuccess": "更新成功" diff --git a/apps/admin/public/assets/locales/zh-CN/redemption.json b/apps/admin/public/assets/locales/zh-CN/redemption.json index 4752261..a74a702 100644 --- a/apps/admin/public/assets/locales/zh-CN/redemption.json +++ b/apps/admin/public/assets/locales/zh-CN/redemption.json @@ -1,5 +1,4 @@ { - "active": "有效", "cancel": "取消", "code": "兑换码", "confirm": "确认", @@ -13,7 +12,6 @@ "duration": "兑换可用时长", "edit": "编辑", "editRedemptionCode": "编辑兑换码", - "exhausted": "已用尽", "form": { "batchCount": "批次数量", "batchCountPlaceholder": "批次数量", @@ -26,16 +24,12 @@ "halfYear": "半年", "month": "月", "quarter": "季度", - "quantityRequired": "数量为必填项", "selectPlan": "选择兑换套餐", "selectUnitTime": "选择兑换时长单位", "subscribePlan": "兑换套餐", - "subscribePlanRequired": "兑换套餐为必填项", "totalCount": "兑换码可用次数", "totalCountPlaceholder": "兑换码可用次数", - "totalCountRequired": "兑换码可用次数为必填项", "unitTime": "兑换时长单位", - "unitTimeRequired": "兑换时长单位为必填项", "year": "年" }, "id": "ID", @@ -50,8 +44,8 @@ "status": "状态", "subscribeId": "套餐ID", "subscribePlan": "兑换套餐", - "totalCount": "兑换码可用次数", "total": "总计", + "totalCount": "兑换码可用次数", "unitTime": "兑换时长单位", "updateSuccess": "更新成功", "usedCount": "已使用数量", diff --git a/apps/admin/public/assets/locales/zh-CN/system.json b/apps/admin/public/assets/locales/zh-CN/system.json index cc6cdc3..840abcf 100644 --- a/apps/admin/public/assets/locales/zh-CN/system.json +++ b/apps/admin/public/assets/locales/zh-CN/system.json @@ -20,6 +20,7 @@ "description": "配置货币单位、符号和汇率 API 设置", "title": "货币配置" }, + "groupSettings": "", "invite": { "description": "配置用户邀请和推荐奖励设置", "forcedInvite": "强制邀请注册", @@ -124,13 +125,20 @@ }, "userSecuritySettings": "用户与安全", "verify": { - "description": "配置 Turnstile 验证码和验证设置", - "enableLoginVerify": "登录验证", - "enableLoginVerifyDescription": "启用后,用户登录时必须通过人机验证", - "enablePasswordVerify": "密码重置验证", - "enablePasswordVerifyDescription": "启用后,用户重置密码时必须通过人机验证", - "enableRegisterVerify": "注册验证", - "enableRegisterVerifyDescription": "启用后,用户注册时必须通过人机验证", + "captchaType": "验证码类型", + "captchaTypeDescription": "选择本地图形验证码(离线)或 Cloudflare Turnstile", + "captchaTypeLocal": "本地图形验证码", + "captchaTypePlaceholder": "选择验证码类型", + "captchaTypeTurnstile": "Cloudflare Turnstile", + "description": "配置验证码类型和验证设置", + "enableAdminLoginCaptcha": "启用管理端认证验证码", + "enableAdminLoginCaptchaDescription": "启用后,管理员登录或重置密码时必须通过验证码验证", + "enableUserLoginCaptcha": "启用用户端登录验证码", + "enableUserLoginCaptchaDescription": "启用后,用户登录时必须通过验证码验证", + "enableUserRegisterCaptcha": "启用用户端注册验证码", + "enableUserRegisterCaptchaDescription": "启用后,用户注册时必须通过验证码验证", + "enableUserResetPasswordCaptcha": "启用用户重置密码验证码", + "enableUserResetPasswordCaptchaDescription": "启用后,用户重置密码时必须通过验证码验证", "saveFailed": "保存失败", "saveSuccess": "保存成功", "title": "安全验证", diff --git a/apps/admin/public/assets/locales/zh-CN/tool.json b/apps/admin/public/assets/locales/zh-CN/tool.json index 32a6b2a..dad025d 100644 --- a/apps/admin/public/assets/locales/zh-CN/tool.json +++ b/apps/admin/public/assets/locales/zh-CN/tool.json @@ -12,6 +12,7 @@ "systemReboot": "系统重启", "systemServices": "系统服务", "update": "更新", + "updateDescription": "", "updateFailed": "更新失败", "updateServerDescription": "确定要将服务器版本从 {{current}} 更新到 {{latest}} 吗?", "updateSuccess": "更新成功", diff --git a/apps/admin/public/assets/locales/zh-CN/translation.json b/apps/admin/public/assets/locales/zh-CN/translation.json index bf51533..4890a5c 100644 --- a/apps/admin/public/assets/locales/zh-CN/translation.json +++ b/apps/admin/public/assets/locales/zh-CN/translation.json @@ -7,6 +7,10 @@ "serverRequired": "请选择服务器" }, "form": { + "quantityRequired": "", + "subscribePlanRequired": "", + "totalCountRequired": "", + "unitTimeRequired": "", "validation": { "nameRequired": "客户端名称必填", "userAgentRequiredSuffix": "是必填项" diff --git a/apps/admin/public/assets/locales/zh-CN/user.json b/apps/admin/public/assets/locales/zh-CN/user.json index 10734a2..100fe13 100644 --- a/apps/admin/public/assets/locales/zh-CN/user.json +++ b/apps/admin/public/assets/locales/zh-CN/user.json @@ -2,6 +2,7 @@ "accountEnable": "账户启用", "add": "添加", "administrator": "管理员", + "all": "全部", "areaCodePlaceholder": "区号", "authMethodsTitle": "认证方式", "avatar": "头像", @@ -17,6 +18,9 @@ "confirm": "确认", "confirmDelete": "确认删除", "confirmOffline": "确认下线", + "confirmResetToken": "确认重置订阅地址", + "confirmResumeSubscribe": "确认恢复订阅", + "confirmStopSubscribe": "确认暂停订阅", "copySubscription": "复制订阅", "copySuccess": "复制成功", "create": "创建", @@ -39,7 +43,10 @@ "downloadTraffic": "下载流量", "edit": "编辑", "email": "邮箱", + "editGroup": "编辑分组", "editSubscription": "编辑订阅", + "editUserGroup": "编辑用户组", + "editUserGroupDescription": "编辑用户组分配和锁定状态", "enable": "启用", "enabled": "启用", "disabled": "禁用", @@ -84,6 +91,7 @@ "inviteCount": "邀请用户数", "inviteStats": "邀请统计", "invitedUsers": "已邀请用户", + "isDeleted": "状态", "kickOfflineConfirm": "确认踢下线", "kickOfflineSuccess": "设备已踢下线", "lastSeen": "最后上线", @@ -132,32 +140,32 @@ "resetTime": "重置时间", "resetToken": "重置订阅地址", "resetTokenDescription": "这将重置订阅地址并重新生成新的令牌。", + "saving": "保存中...", "resetTokenSuccess": "订阅地址重置成功", - "confirmResetToken": "确认重置订阅地址", + "resumeSubscribe": "恢复订阅", + "selectGroup": "选择一个组", + "resumeSubscribeDescription": "这将恢复订阅,允许用户继续使用。", + "resumeSubscribeSuccess": "订阅已恢复", + "save": "保存", + "shortCode": "短码", + "speedLimit": "速度限制", + "startTime": "开始时间", + "status": "状态", + "statusActive": "活跃", + "statusDeducted": "已扣除", + "statusExpired": "已过期", + "statusFinished": "已完成", + "statusPending": "待处理", + "statusStopped": "已停止", "stopSubscribe": "暂停订阅", "stopSubscribeDescription": "这将暂时停止订阅。用户将无法使用。", "stopSubscribeSuccess": "订阅已暂停", - "confirmStopSubscribe": "确认暂停订阅", - "resumeSubscribe": "恢复订阅", - "resumeSubscribeDescription": "这将恢复订阅,允许用户继续使用。", - "resumeSubscribeSuccess": "订阅已恢复", - "confirmResumeSubscribe": "确认恢复订阅", - "status": "状态", - "statusPending": "待处理", - "statusActive": "活跃", - "statusFinished": "已完成", - "statusExpired": "已过期", - "statusDeducted": "已扣除", - "statusStopped": "已停止", - "save": "保存", "search": "搜索", "searchPlaceholder": "邮箱 / 邀请码 / 设备ID", "searchInputPlaceholder": "请输入搜索内容", "sharedSubscription": "共享", "sharedSubscriptionInfo": "该用户为设备组成员,当前显示所有者 (ID: {{ownerId}}) 的共享订阅", "sharedSubscriptionList": "共享订阅列表", - "speedLimit": "速度限制", - "startTime": "开始时间", "subscription": "订阅", "subscriptionId": "订阅 ID", "subscriptionInfo": "订阅信息", @@ -175,10 +183,12 @@ "trafficLimit": "流量限制", "trafficStats": "流量统计", "trafficUsage": "流量使用", + "remainingTraffic": "剩余流量", "unlimited": "无限制", "unverified": "未验证", "update": "更新", "updateSuccess": "更新成功", + "groupUpdated": "分组更新成功", "upload": "上传", "uploadTraffic": "上传流量", "userAgent": "用户代理", @@ -189,7 +199,20 @@ "userList": "用户列表", "userName": "用户名", "userProfile": "用户资料", + "userGroup": "用户分组", "verified": "已验证", "viewDeviceGroup": "查看设备组", - "viewOwner": "查看所有者" + "viewOwner": "查看所有者", + "locked": "锁定", + "lockGroup": "锁定分组", + "lockGroupDescription": "防止自动分组更改此用户的分组", + "groupLocked": "分组已锁定", + "previewNodes": "预览节点", + "availableNodes": "可用节点", + "name": "名称", + "address": "地址", + "noNodesAvailable": "无可用节点", + "nodeGroup": "节点组", + "publicNodes": "公共节点", + "subscriptionNodes": "套餐节点" } diff --git a/apps/admin/src/layout/navs.ts b/apps/admin/src/layout/navs.ts index 666957e..228d175 100644 --- a/apps/admin/src/layout/navs.ts +++ b/apps/admin/src/layout/navs.ts @@ -34,6 +34,11 @@ export function useNavs() { url: "/dashboard/nodes", icon: "flat-color-icons:mind-map", }, + { + title: t("Group Management", "Group Management"), + url: "/dashboard/group", + icon: "flat-color-icons:department", + }, { title: t("Subscribe Config", "Subscribe Config"), url: "/dashboard/subscribe", diff --git a/apps/admin/src/routeTree.gen.ts b/apps/admin/src/routeTree.gen.ts index ae694f6..eab2f6b 100644 --- a/apps/admin/src/routeTree.gen.ts +++ b/apps/admin/src/routeTree.gen.ts @@ -39,6 +39,8 @@ const DashboardOrderIndexLazyRouteImport = const DashboardMarketingIndexLazyRouteImport = createFileRoute( '/dashboard/marketing/', )() +const DashboardGroupIndexLazyRouteImport = + createFileRoute('/dashboard/group/')() const DashboardFamilyIndexLazyRouteImport = createFileRoute('/dashboard/family/')() const DashboardDocumentIndexLazyRouteImport = createFileRoute( @@ -191,6 +193,13 @@ const DashboardMarketingIndexLazyRoute = } as any).lazy(() => import('./routes/dashboard/marketing/index.lazy').then((d) => d.Route), ) +const DashboardGroupIndexLazyRoute = DashboardGroupIndexLazyRouteImport.update({ + id: '/group/', + path: '/group/', + getParentRoute: () => DashboardRouteLazyRoute, +} as any).lazy(() => + import('./routes/dashboard/group/index.lazy').then((d) => d.Route), +) const DashboardFamilyIndexLazyRoute = DashboardFamilyIndexLazyRouteImport.update({ id: '/family/', @@ -356,6 +365,7 @@ export interface FileRoutesByFullPath { '/dashboard/coupon': typeof DashboardCouponIndexLazyRoute '/dashboard/document': typeof DashboardDocumentIndexLazyRoute '/dashboard/family': typeof DashboardFamilyIndexLazyRoute + '/dashboard/group': typeof DashboardGroupIndexLazyRoute '/dashboard/marketing': typeof DashboardMarketingIndexLazyRoute '/dashboard/order': typeof DashboardOrderIndexLazyRoute '/dashboard/payment': typeof DashboardPaymentIndexLazyRoute @@ -389,6 +399,7 @@ export interface FileRoutesByTo { '/dashboard/coupon': typeof DashboardCouponIndexLazyRoute '/dashboard/document': typeof DashboardDocumentIndexLazyRoute '/dashboard/family': typeof DashboardFamilyIndexLazyRoute + '/dashboard/group': typeof DashboardGroupIndexLazyRoute '/dashboard/marketing': typeof DashboardMarketingIndexLazyRoute '/dashboard/order': typeof DashboardOrderIndexLazyRoute '/dashboard/payment': typeof DashboardPaymentIndexLazyRoute @@ -424,6 +435,7 @@ export interface FileRoutesById { '/dashboard/coupon/': typeof DashboardCouponIndexLazyRoute '/dashboard/document/': typeof DashboardDocumentIndexLazyRoute '/dashboard/family/': typeof DashboardFamilyIndexLazyRoute + '/dashboard/group/': typeof DashboardGroupIndexLazyRoute '/dashboard/marketing/': typeof DashboardMarketingIndexLazyRoute '/dashboard/order/': typeof DashboardOrderIndexLazyRoute '/dashboard/payment/': typeof DashboardPaymentIndexLazyRoute @@ -460,6 +472,7 @@ export interface FileRouteTypes { | '/dashboard/coupon' | '/dashboard/document' | '/dashboard/family' + | '/dashboard/group' | '/dashboard/marketing' | '/dashboard/order' | '/dashboard/payment' @@ -493,6 +506,7 @@ export interface FileRouteTypes { | '/dashboard/coupon' | '/dashboard/document' | '/dashboard/family' + | '/dashboard/group' | '/dashboard/marketing' | '/dashboard/order' | '/dashboard/payment' @@ -527,6 +541,7 @@ export interface FileRouteTypes { | '/dashboard/coupon/' | '/dashboard/document/' | '/dashboard/family/' + | '/dashboard/group/' | '/dashboard/marketing/' | '/dashboard/order/' | '/dashboard/payment/' @@ -643,6 +658,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof DashboardMarketingIndexLazyRouteImport parentRoute: typeof DashboardRouteLazyRoute } + '/dashboard/group/': { + id: '/dashboard/group/' + path: '/group' + fullPath: '/dashboard/group' + preLoaderRoute: typeof DashboardGroupIndexLazyRouteImport + parentRoute: typeof DashboardRouteLazyRoute + } '/dashboard/family/': { id: '/dashboard/family/' path: '/family' @@ -794,6 +816,7 @@ interface DashboardRouteLazyRouteChildren { DashboardCouponIndexLazyRoute: typeof DashboardCouponIndexLazyRoute DashboardDocumentIndexLazyRoute: typeof DashboardDocumentIndexLazyRoute DashboardFamilyIndexLazyRoute: typeof DashboardFamilyIndexLazyRoute + DashboardGroupIndexLazyRoute: typeof DashboardGroupIndexLazyRoute DashboardMarketingIndexLazyRoute: typeof DashboardMarketingIndexLazyRoute DashboardOrderIndexLazyRoute: typeof DashboardOrderIndexLazyRoute DashboardPaymentIndexLazyRoute: typeof DashboardPaymentIndexLazyRoute @@ -827,6 +850,7 @@ const DashboardRouteLazyRouteChildren: DashboardRouteLazyRouteChildren = { DashboardCouponIndexLazyRoute: DashboardCouponIndexLazyRoute, DashboardDocumentIndexLazyRoute: DashboardDocumentIndexLazyRoute, DashboardFamilyIndexLazyRoute: DashboardFamilyIndexLazyRoute, + DashboardGroupIndexLazyRoute: DashboardGroupIndexLazyRoute, DashboardMarketingIndexLazyRoute: DashboardMarketingIndexLazyRoute, DashboardOrderIndexLazyRoute: DashboardOrderIndexLazyRoute, DashboardPaymentIndexLazyRoute: DashboardPaymentIndexLazyRoute, diff --git a/apps/admin/src/routes/dashboard/group/index.lazy.tsx b/apps/admin/src/routes/dashboard/group/index.lazy.tsx new file mode 100644 index 0000000..f723df2 --- /dev/null +++ b/apps/admin/src/routes/dashboard/group/index.lazy.tsx @@ -0,0 +1,6 @@ +import { createLazyFileRoute } from "@tanstack/react-router"; +import Group from "@/sections/group"; + +export const Route = createLazyFileRoute("/dashboard/group/")({ + component: Group, +}); diff --git a/apps/admin/src/sections/auth/email/login-form.tsx b/apps/admin/src/sections/auth/email/login-form.tsx index 9f9014a..f402ecf 100644 --- a/apps/admin/src/sections/auth/email/login-form.tsx +++ b/apps/admin/src/sections/auth/email/login-form.tsx @@ -10,12 +10,13 @@ import { import { Input } from "@workspace/ui/components/input"; import { Icon } from "@workspace/ui/composed/icon"; import type { Dispatch, SetStateAction } from "react"; -import { useRef } from "react"; +import { useRef, useState } from "react"; import { useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { z } from "zod"; import { useGlobalStore } from "@/stores/global"; import CloudFlareTurnstile, { type TurnstileRef } from "../turnstile"; +import LocalCaptcha, { type LocalCaptchaRef } from "../local-captcha"; export default function LoginForm({ loading, @@ -33,14 +34,25 @@ export default function LoginForm({ const { t } = useTranslation("auth"); const { common } = useGlobalStore(); const { verify } = common; + const [captchaId, setCaptchaId] = useState(""); + + const isTurnstile = verify.captcha_type === "turnstile"; + const isLocal = verify.captcha_type === "local"; + const captchaEnabled = verify.enable_admin_login_captcha; const formSchema = z.object({ - email: z.email(t("login.email", "Email")), + email: z + .string() + .email(t("login.email", "Please enter a valid email address")), password: z.string(), cf_token: - verify.enable_login_verify && verify.turnstile_site_key + captchaEnabled && isTurnstile && verify.turnstile_site_key ? z.string() : z.string().optional(), + captcha_code: + captchaEnabled && isLocal + ? z.string().min(1, t("captcha.required", "Please enter captcha code")) + : z.string().optional(), }); const form = useForm>({ resolver: zodResolver(formSchema), @@ -48,11 +60,17 @@ export default function LoginForm({ }); const turnstile = useRef(null); + const localCaptcha = useRef(null); const handleSubmit = form.handleSubmit((data) => { try { + // Add captcha_id for local captcha + if (isLocal && captchaEnabled) { + (data as any).captcha_id = captchaId; + } onSubmit(data); } catch (_error) { turnstile.current?.reset(); + localCaptcha.current?.reset(); } }); @@ -98,7 +116,7 @@ export default function LoginForm({ )} /> - {verify.enable_login_verify && ( + {captchaEnabled && isTurnstile && ( )} + {captchaEnabled && isLocal && ( + ( + + + + + + + )} + /> + )} + + ); + } +); + +LocalCaptcha.displayName = "LocalCaptcha"; + +export default LocalCaptcha; diff --git a/apps/admin/src/sections/group/average-mode-tab.tsx b/apps/admin/src/sections/group/average-mode-tab.tsx new file mode 100644 index 0000000..4151bbf --- /dev/null +++ b/apps/admin/src/sections/group/average-mode-tab.tsx @@ -0,0 +1,264 @@ +"use client"; + +import { Badge } from "@workspace/ui/components/badge"; +import { Button } from "@workspace/ui/components/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@workspace/ui/components/card"; +import { Input } from "@workspace/ui/components/input"; +import { Label } from "@workspace/ui/components/label"; +import { Loader2 } from "lucide-react"; +import { useEffect, useState, useRef } from "react"; +import { useTranslation } from "react-i18next"; +import { useQuery } from "@tanstack/react-query"; +import { toast } from "sonner"; +import { + getGroupConfig, + getNodeGroupList, + getRecalculationStatus, + recalculateGroup, +} from "@workspace/ui/services/admin/group"; + +export default function AverageModeTab() { + const { t } = useTranslation("group"); + const [recalculating, setRecalculating] = useState(false); + const [loadingStatus, setLoadingStatus] = useState(false); + + const [averageConfig, setAverageConfig] = useState({ + node_group_count: 0, + }); + + const [status, setStatus] = useState<{ + state: string; + progress: number; + total: number; + } | null>(null); + + const hasLoadedConfig = useRef(true); + + const { data: nodeGroupsData } = useQuery({ + queryKey: ["nodeGroups"], + queryFn: async () => { + const { data } = await getNodeGroupList({ page: 1, size: 1000 }); + return data.data?.list || []; + }, + }); + + const loadConfig = async () => { + try { + const { data } = await getGroupConfig(); + if (data.data?.config?.average_config) { + setAverageConfig(data.data.config.average_config as any); + } + hasLoadedConfig.current = true; + } catch (error) { + console.error("Failed to load group config:", error); + toast.error(t("loadFailed", "Failed to load configuration")); + } + }; + + const loadStatus = async () => { + setLoadingStatus(true); + try { + const { data } = await getRecalculationStatus(); + if (data.data) { + setStatus(data.data); + } + } catch (error) { + console.error("Failed to load recalculation status:", error); + } finally { + setLoadingStatus(false); + } + }; + + useEffect(() => { + loadConfig(); + loadStatus(); + }, []); + + useEffect(() => { + if (nodeGroupsData) { + const nodeGroupCount = nodeGroupsData?.length || 0; + + if (averageConfig.node_group_count !== nodeGroupCount) { + setAverageConfig({ + ...averageConfig, + node_group_count: nodeGroupCount, + }); + } + } + }, [nodeGroupsData]); + + useEffect(() => { + const interval = setInterval(() => { + if (status?.state === "running") { + loadStatus(); + } + }, 2000); + return () => clearInterval(interval); + }, [status?.state]); + + const handleRecalculate = async () => { + setRecalculating(true); + try { + await recalculateGroup({ mode: "average" }); + toast.success(t("recalculationStarted", "Recalculation started")); + loadStatus(); + } catch (error) { + console.error("Failed to start recalculation:", error); + toast.error(t("recalculationFailed", "Failed to start recalculation")); + } finally { + setRecalculating(false); + } + }; + + const getStateLabel = (state: string) => { + switch (state) { + case "running": + return t("running", "Running"); + case "completed": + return t("completed", "Completed"); + case "failed": + return t("failed", "Failed"); + default: + return t("idle", "Idle"); + } + }; + + const getStateVariant = (state: string) => { + switch (state) { + case "running": + return "default"; + case "completed": + return "secondary"; + case "failed": + return "destructive"; + default: + return "outline"; + } + }; + + return ( +
+ {/* Configuration Card */} + + + {t("averageModeConfig", "Average Mode Configuration")} + + {t( + "averageModeDescription", + "Randomly assign node groups to user subscriptions based on subscribe configuration" + )} + + + +
+
+ + +

+ {t("nodeGroupCountAutoCalculated", "Auto-calculated from actual node groups")} +

+
+
+
+
+ + {/* Recalculation Card */} + + + {t("groupRecalculation", "Group Recalculation")} + + {t( + "groupRecalculationDescription", + "Manually trigger a full recalculation of all user groups based on current configuration" + )} + + + + {/* Current Status */} +
+
+ + {t("currentStatus", "Current Status")} + + {loadingStatus ? ( + + ) : status ? ( + + {getStateLabel(status.state)} + + ) : null} +
+ + {status?.state === "running" && ( +
+
+ {t("progress", "Progress")} + + {status.progress} / {status.total || 0} + +
+
+
0 ? (status.progress / status.total) * 100 : 0}%`, + }} + /> +
+
+ )} + + {status?.state === "completed" && ( +
+ {t("recalculationCompleted", "Recalculation completed successfully")} +
+ )} + + {status?.state === "failed" && ( +
+ {t("recalculationFailed", "Recalculation failed. Please try again.")} +
+ )} +
+ + {/* Recalculate Button */} +
+ +
+ + {/* Warning */} +
+ {t("warning", "Warning")}:{" "} + {t( + "recalculationWarning", + "Recalculation will reassign all users to new groups based on current configuration. This operation cannot be undone." + )} +
+ + +
+ ); +} diff --git a/apps/admin/src/sections/group/bind-node-groups-dialog.tsx b/apps/admin/src/sections/group/bind-node-groups-dialog.tsx new file mode 100644 index 0000000..debdeac --- /dev/null +++ b/apps/admin/src/sections/group/bind-node-groups-dialog.tsx @@ -0,0 +1,174 @@ +"use client"; + +import { Button } from "@workspace/ui/components/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@workspace/ui/components/dialog"; +import { Label } from "@workspace/ui/components/label"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@workspace/ui/components/select"; +import { Loader2 } from "lucide-react"; +import { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { useQuery } from "@tanstack/react-query"; +import { toast } from "sonner"; +import { getNodeGroupList, bindNodeGroups } from "@workspace/ui/services/admin/group"; + +interface BindNodeGroupsDialogProps { + userGroupIds: number[]; + userGroupNames: string[]; + onOpenChange?: (open: boolean) => void; + onSuccess?: () => void; +} + +export default function BindNodeGroupsDialog({ + userGroupIds, + userGroupNames, + onOpenChange, + onSuccess, +}: BindNodeGroupsDialogProps) { + const { t } = useTranslation("group"); + const [open, setOpen] = useState(false); + const [saving, setSaving] = useState(false); + const [selectedNodeGroupId, setSelectedNodeGroupId] = useState(); + + const { data: nodeGroupsData, isLoading } = useQuery({ + queryKey: ["nodeGroups"], + queryFn: async () => { + const { data } = await getNodeGroupList({ page: 1, size: 1000 }); + return data.data?.list || []; + }, + }); + + useEffect(() => { + if (open && nodeGroupsData) { + // Load current binding when dialog opens + loadCurrentBinding(); + } + }, [open]); + + const loadCurrentBinding = () => { + // Get first user group's current node group binding + // For batch binding, we'll default to unbound + setSelectedNodeGroupId(undefined); + }; + + const handleBind = async () => { + if (selectedNodeGroupId === undefined) { + toast.error(t("selectNodeGroupRequired", "Please select a node group")); + return; + } + + setSaving(true); + try { + await bindNodeGroups({ + user_group_ids: userGroupIds, + node_group_id: selectedNodeGroupId === 0 ? null : selectedNodeGroupId, + } as API.BindNodeGroupsRequest); + + toast.success( + t("bindSuccess", "Successfully bound {{userGroupCount}} user groups to node group").replace( + /{{userGroupCount}}/g, + String(userGroupIds.length) + ) + ); + + setOpen(false); + onOpenChange?.(false); + onSuccess?.(); + } catch (error) { + console.error("Failed to bind node group:", error); + toast.error(t("bindFailed", "Failed to bind node group")); + } finally { + setSaving(false); + } + }; + + const displayNames = + userGroupNames.length > 2 + ? `${userGroupNames.slice(0, 2).join(", ")}... (${userGroupIds.length})` + : userGroupNames.join(", "); + + return ( + { + setOpen(newOpen); + onOpenChange?.(newOpen); + }}> + + + + + + {t("bindNodeGroup", "Bind Node Group")} + + {t( + "bindNodeGroupDescription", + "Select a node group to bind to user groups: {{userGroups}}", + { userGroups: displayNames } + ).replace(/{{userGroups}}/g, displayNames)} + + + +
+ {isLoading ? ( +
+ +
+ ) : ( +
+ + +
+ )} +
+ + + + + +
+
+ ); +} diff --git a/apps/admin/src/sections/group/current-group-results.tsx b/apps/admin/src/sections/group/current-group-results.tsx new file mode 100644 index 0000000..c76e655 --- /dev/null +++ b/apps/admin/src/sections/group/current-group-results.tsx @@ -0,0 +1,375 @@ +"use client"; + +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@workspace/ui/components/card"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@workspace/ui/components/dialog"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@workspace/ui/components/table"; +import { Loader2 } from "lucide-react"; +import { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { useQuery } from "@tanstack/react-query"; +import { getGroupHistory, getGroupHistoryDetail, getNodeGroupList } from "@workspace/ui/services/admin/group"; + +export default function CurrentGroupResults() { + const { t } = useTranslation("group"); + const [loading, setLoading] = useState(true); + const [latestResult, setLatestResult] = useState(null); + const [latestDetails, setLatestDetails] = useState([]); + const [detailsLoading, setDetailsLoading] = useState(false); + + // User list dialog state + const [userListOpen, setUserListOpen] = useState(false); + const [selectedNodeGroupName, setSelectedNodeGroupName] = useState(""); + const [userList, setUserList] = useState([]); + const [userListLoading, setUserListLoading] = useState(false); + const [userListTotal, setUserListTotal] = useState(0); + + // Fetch node groups + const { data: nodeGroups } = useQuery({ + queryKey: ["nodeGroups"], + queryFn: async () => { + const { data } = await getNodeGroupList({ page: 1, size: 1000 }); + return data.data?.list || []; + }, + }); + + useEffect(() => { + const loadData = async () => { + try { + // Load latest result + const { data: historyData } = await getGroupHistory({ + page: 1, + size: 1, + }); + + if (historyData.data?.list && historyData.data.list.length > 0) { + const latest = historyData.data.list[0]; + if (!latest) return; + setLatestResult(latest); + + // Fetch details + setDetailsLoading(true); + try { + const { data: detailData } = await getGroupHistoryDetail({ + id: latest.id, + }); + + if (detailData.data?.config_snapshot?.group_details) { + setLatestDetails(detailData.data.config_snapshot.group_details); + } else { + setLatestDetails([]); + } + } catch (error) { + console.error("Failed to fetch latest result details:", error); + setLatestDetails([]); + } finally { + setDetailsLoading(false); + } + } + } catch (error) { + console.error("Failed to load data:", error); + } finally { + setLoading(false); + } + }; + + loadData(); + }, []); + + const handleShowUserList = async (nodeGroupId: number, nodeGroupName: string) => { + setSelectedNodeGroupName(nodeGroupName); + setUserListOpen(true); + setUserListLoading(true); + + // 从历史详情记录中获取用户数据 + const detail = latestDetails.find((d: any) => { + const detailNodeGroupId = d.NodeGroupId || d.node_group_id; + return detailNodeGroupId === nodeGroupId; + }); + + if (detail) { + const userDataJSON = detail.UserData || detail.user_data; + if (userDataJSON) { + try { + const userData = JSON.parse(userDataJSON); + setUserList(userData); + setUserListTotal(userData.length); + } catch (error) { + console.error("Failed to parse user data:", error); + setUserList([]); + setUserListTotal(0); + } + } else { + setUserList([]); + setUserListTotal(0); + } + } else { + setUserList([]); + setUserListTotal(0); + } + setUserListLoading(false); + }; + + if (loading) { + return ( + + + {t("currentGroupingResult", "Current Grouping Result")} + + {t("loading", "Loading...")} + + + + ); + } + + return ( +
+ {/* Latest Result Card */} + {!latestResult ? ( + + + {t("currentGroupingResult", "Current Grouping Result")} + + +
+ {t("noDetails", "No details available")} +
+
+
+ ) : ( + + + {t("currentGroupingResult", "Current Grouping Result")} + + {t("latestGroupingCalculation", "Latest grouping calculation details")} + + + + {/* Calculation Info */} +
+

{t("calculationInfo", "Calculation Information")}

+
+
+
{t("groupMode", "Group Mode")}
+
+ {(latestResult.GroupMode || latestResult.group_mode) === "average" + ? t("averageMode", "Average Mode") + : (latestResult.GroupMode || latestResult.group_mode) === "subscribe" + ? t("subscribeMode", "Subscribe Mode") + : t("trafficMode", "Traffic Mode")} +
+
+
+
{t("state", "State")}
+
+ {(latestResult.State || latestResult.state) === "completed" + ? t("completed", "Completed") + : (latestResult.State || latestResult.state) === "running" + ? t("running", "Running") + : (latestResult.State || latestResult.state) === "failed" + ? t("failed", "Failed") + : t("idle", "Idle")} +
+
+
+
{t("triggerType", "Trigger Type")}
+
+ {(latestResult.TriggerType || latestResult.trigger_type) === "manual" + ? t("manualTrigger", "Manual") + : (latestResult.TriggerType || latestResult.trigger_type) === "auto" + ? t("autoTrigger", "Auto") + : t("scheduleTrigger", "Schedule")} +
+
+
+
{t("successFailedCount", "Success/Failed")}
+
+ {latestResult.SuccessCount || latestResult.success_count || 0} / {latestResult.FailedCount || latestResult.failed_count || 0} +
+
+
+
{t("startTime", "Start Time")}
+
+ {latestResult.StartTime || latestResult.start_time + ? new Date((latestResult.StartTime || latestResult.start_time) * 1000).toLocaleString() + : "-"} +
+
+
+
{t("endTime", "End Time")}
+
+ {latestResult.EndTime || latestResult.end_time + ? new Date((latestResult.EndTime || latestResult.end_time) * 1000).toLocaleString() + : "-"} +
+
+
+
+ + {/* Grouping Details */} +
+

{t("groupingDetailsStatistics", "Grouping Details Statistics")}

+
+
+
+ {latestDetails.reduce((sum: number, d: any) => sum + (d.UserCount || d.user_count || 0), 0)} +
+
+ {t("totalUsers", "Total Users")} +
+
+
+
+ {latestDetails.reduce((sum: number, d: any) => sum + (d.NodeCount || d.node_count || 0), 0)} +
+
+ {t("totalNodes", "Total Nodes")} +
+
+
+
{latestDetails.length}
+
+ {t("totalNodeGroups", "Total Node Groups")} +
+
+
+
+ + {detailsLoading ? ( +
+ + + {t("loading", "Loading...")} + +
+ ) : latestDetails.length > 0 ? ( + <> + {/* Details Table */} +
+ + + + + + + + + + {latestDetails.map((detail: any, index: number) => { + const nodeGroupId = detail.NodeGroupId || detail.node_group_id; + const nodeGroup = nodeGroups?.find((ng) => ng.id === nodeGroupId); + const nodeGroupName = nodeGroup?.name || `${t("idPrefix", "#")}${nodeGroupId}`; + const userCount = detail.UserCount || detail.user_count || 0; + + return ( + + + + + + ); + })} + +
+ {t("nodeGroup", "Node Group")} + + {t("userCount", "User Count")} + + {t("nodeCount", "Node Count")} +
+
+
{nodeGroupName}
+
{t("id", "ID")}: {nodeGroupId}
+
+
+ + + {detail.NodeCount || detail.node_count || 0} +
+
+ + ) : ( +
+ {t("noDetails", "No details available")} +
+ )} +
+
+ )} + + {/* User List Dialog */} + + + + + {selectedNodeGroupName} - {t("userList", "User List")} + + + {t("totalUsers", "Total Users")}: {userListTotal} + + +
+ {userListLoading ? ( +
+ + + {t("loading", "Loading...")} + +
+ ) : userList.length > 0 ? ( + + + + {t("id", "ID")} + {t("email", "Email")} + + + + {userList.map((user) => ( + + {user.id} + + {user.email || "-"} + + + ))} + +
+ ) : ( +
+ {t("noUsers", "No users found")} +
+ )} +
+
+
+
+ ); +} diff --git a/apps/admin/src/sections/group/group-config.tsx b/apps/admin/src/sections/group/group-config.tsx new file mode 100644 index 0000000..2ec3dd0 --- /dev/null +++ b/apps/admin/src/sections/group/group-config.tsx @@ -0,0 +1,264 @@ +"use client"; + +import { Button } from "@workspace/ui/components/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@workspace/ui/components/card"; +import { Loader2 } from "lucide-react"; +import { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { toast } from "sonner"; +import { + getGroupConfig, + updateGroupConfig, + resetGroups, +} from "@workspace/ui/services/admin/group"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "@workspace/ui/components/alert-dialog"; + +export default function GroupConfig() { + const { t } = useTranslation("group"); + const [saving, setSaving] = useState(false); + const [resetting, setResetting] = useState(false); + const [showResetDialog, setShowResetDialog] = useState(false); + const [config, setConfig] = useState<{ + enabled: boolean; + mode: "average" | "subscribe" | "traffic"; + }>({ + enabled: false, + mode: "average", + }); + + const loadConfig = async () => { + try { + const { data } = await getGroupConfig(); + if (data.data) { + setConfig({ + enabled: data.data.enabled || false, + mode: (data.data.mode || "average") as "average" | "subscribe" | "traffic", + }); + } + } catch (error) { + console.error("Failed to load group config:", error); + toast.error(t("loadFailed", "Failed to load configuration")); + } + }; + + useEffect(() => { + loadConfig(); + }, []); + + const handleUpdateEnabled = async (enabled: boolean) => { + setSaving(true); + try { + const payload: any = { + enabled, + mode: config.mode, + }; + await updateGroupConfig(payload); + setConfig({ ...config, enabled }); + toast.success(t("saved", "Configuration saved successfully")); + } catch (error) { + console.error("Failed to update group config:", error); + toast.error(t("saveFailed", "Failed to save configuration")); + } finally { + setSaving(false); + } + }; + + const handleUpdateMode = async (mode: "average" | "subscribe" | "traffic") => { + setSaving(true); + try { + const payload: any = { + enabled: config.enabled, + mode, + }; + await updateGroupConfig(payload); + setConfig({ ...config, mode }); + toast.success(t("saved", "Configuration saved successfully")); + } catch (error) { + console.error("Failed to update group config:", error); + toast.error(t("saveFailed", "Failed to save configuration")); + } finally { + setSaving(false); + } + }; + + const handleResetGroups = async () => { + setResetting(true); + try { + await resetGroups({ confirm: true }); + toast.success(t("resetSuccess", "All groups have been reset successfully")); + setShowResetDialog(false); + // Reload config after reset + await loadConfig(); + } catch (error) { + console.error("Failed to reset groups:", error); + toast.error(t("resetFailed", "Failed to reset groups")); + } finally { + setResetting(false); + } + }; + + return ( +
+ + + {t("groupConfig", "Group Configuration")} + + {t( + "groupConfigDescription", + "Configure user group and node group settings" + )} + + + + {/* Enable/Disable */} +
+
+ +

+ {t( + "enableGroupingDescription", + "When enabled, users will only see nodes from their assigned group" + )} +

+
+ handleUpdateEnabled(e.target.checked)} + disabled={saving} + className="h-4 w-4" + /> +
+ + {/* Mode Selection */} + {config.enabled && ( +
+ +
+ + + + + +
+
+ )} + + {/* Reset Button */} +
+ + + + + + + + {t("resetGroupsTitle", "Reset All Groups")} + + + {t( + "resetGroupsDescription", + "This action will delete all node groups and user groups, reset all users' group ID to 0, clear all products' node group IDs, and clear all nodes' node group IDs. This action cannot be undone." + )} + + + + + {t("cancel", "Cancel")} + + + {resetting && } + {t("confirm", "Confirm")} + + + + +
+
+
+
+ ); +} diff --git a/apps/admin/src/sections/group/group-history.tsx b/apps/admin/src/sections/group/group-history.tsx new file mode 100644 index 0000000..140da99 --- /dev/null +++ b/apps/admin/src/sections/group/group-history.tsx @@ -0,0 +1,499 @@ +"use client"; + +import { Badge } from "@workspace/ui/components/badge"; +import { Button } from "@workspace/ui/components/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@workspace/ui/components/card"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@workspace/ui/components/dialog"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@workspace/ui/components/table"; +import { + ProTable, + type ProTableActions, +} from "@workspace/ui/composed/pro-table/pro-table"; +import { + getGroupHistory, + getGroupHistoryDetail, + getNodeGroupList, +} from "@workspace/ui/services/admin/group"; +import { useRef, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { formatDate } from "@/utils/common"; +import { Loader2 } from "lucide-react"; +import { useQuery } from "@tanstack/react-query"; + +export default function GroupHistory() { + const { t } = useTranslation("group"); + const ref = useRef(null); + const [detailOpen, setDetailOpen] = useState(false); + const [detailLoading, setDetailLoading] = useState(false); + const [selectedHistory, setSelectedHistory] = useState(null); + const [details, setDetails] = useState([]); + const [nodeGroupMap, setNodeGroupMap] = useState>(new Map()); + + // User list dialog state + const [userListOpen, setUserListOpen] = useState(false); + const [selectedNodeGroupName, setSelectedNodeGroupName] = useState(""); + const [userList, setUserList] = useState([]); + const [userListTotal, setUserListTotal] = useState(0); + + // Fetch all node groups + const { data: nodeGroups } = useQuery({ + queryKey: ["getNodeGroupListForDetail"], + queryFn: async () => { + const { data } = await getNodeGroupList({ + page: 1, + size: 100, + }); + return data.data?.list || []; + }, + }); + + // Build ID to name maps when groups are loaded + if (nodeGroups) { + const newNodeGroupMap = new Map(); + nodeGroups.forEach((ng: API.NodeGroup) => { + newNodeGroupMap.set(ng.id, ng.name); + }); + if (newNodeGroupMap.size !== nodeGroupMap.size) { + setNodeGroupMap(newNodeGroupMap); + } + } + + const getModeLabel = (mode: string) => { + switch (mode) { + case "average": + return t("averageMode", "Average"); + case "subscribe": + return t("subscribeMode", "Subscribe"); + case "traffic": + return t("trafficMode", "Traffic"); + default: + return mode; + } + }; + + const getTriggerTypeLabel = (type: string) => { + switch (type) { + case "manual": + return t("manualTrigger", "Manual"); + case "auto": + return t("autoTrigger", "Auto"); + case "schedule": + return t("scheduleTrigger", "Schedule"); + default: + return type; + } + }; + + const handleViewDetail = async (record: API.GroupHistory) => { + setSelectedHistory(record); + setDetailOpen(true); + setDetailLoading(true); + try { + const { data } = await getGroupHistoryDetail({ + id: record.id, + }); + + console.log("Group history detail response:", data); + + // 从返回的数据中获取详情列表 + // data.data.config_snapshot.group_details 包含分组详情 + if (data.data?.config_snapshot?.group_details) { + setDetails(data.data.config_snapshot.group_details); + } else { + console.warn("No group_details found in response:", data); + setDetails([]); + } + } catch (error) { + console.error("Failed to fetch history details:", error); + setDetails([]); + } finally { + setDetailLoading(false); + } + }; + + const handleShowUserList = async (nodeGroupId: number, nodeGroupName: string) => { + setSelectedNodeGroupName(nodeGroupName); + setUserListOpen(true); + + // 从历史详情记录中获取用户数据 + const detail = details.find((d: any) => { + const detailNodeGroupId = d.NodeGroupId || d.node_group_id; + return detailNodeGroupId === nodeGroupId; + }); + + if (detail) { + const userDataJSON = detail.UserData || detail.user_data; + if (userDataJSON) { + try { + const userData = JSON.parse(userDataJSON); + setUserList(userData); + setUserListTotal(userData.length); + } catch (error) { + console.error("Failed to parse user data:", error); + setUserList([]); + setUserListTotal(0); + } + } else { + setUserList([]); + setUserListTotal(0); + } + } else { + setUserList([]); + setUserListTotal(0); + } + }; + + return ( +
+ + + {t("groupHistory", "Group Calculation History")} + + {t("groupHistoryDescription", "View group recalculation history and results")} + + + + + action={ref} + request={async (params) => { + const { data } = await getGroupHistory({ + page: params.page || 1, + size: params.size || 10, + }); + return { + list: data.data?.list || [], + total: data.data?.total || 0, + }; + }} + columns={[ + { + id: "id", + accessorKey: "id", + header: t("id", "ID"), + cell: ({ row }: { row: any }) => ( + + {t("idPrefix", "#")}{row.getValue("id")} + + ), + }, + { + id: "group_mode", + accessorKey: "group_mode", + header: t("groupMode", "Group Mode"), + cell: ({ row }: { row: any }) => ( + + {getModeLabel(row.getValue("group_mode"))} + + ), + }, + { + id: "trigger_type", + accessorKey: "trigger_type", + header: t("triggerType", "Trigger Type"), + cell: ({ row }: { row: any }) => ( + + {getTriggerTypeLabel(row.getValue("trigger_type"))} + + ), + }, + { + id: "total_users", + accessorKey: "total_users", + header: t("totalUsers", "Total Users"), + cell: ({ row }: { row: any }) => ( + {row.getValue("total_users")} + ), + }, + { + id: "result", + accessorKey: "error_log", + header: t("result", "Result"), + cell: ({ row }: { row: any }) => { + const record = row.original; + return ( +
+
+ {t("successCount", "Success")}: {record.success_count} + {" "}{t("separator", "/")}{" "} + {t("failedCount", "Failed")}: {record.failed_count} +
+ {record.error_log && ( + + {t("failed", "Failed")} + + )} + {!record.error_log && record.failed_count === 0 && ( + + {t("completed", "Completed")} + + )} +
+ ); + }, + }, + { + id: "created_at", + accessorKey: "created_at", + header: t("createdAt", "Created At"), + cell: ({ row }: { row: any }) => formatDate(row.getValue("created_at")), + }, + ]} + actions={{ + render: (row: any) => [ + , + ], + }} + header={{ + title: t("groupHistory", "Group Calculation History"), + }} + /> +
+
+ + {/* Detail Dialog */} + + + + + {t("groupHistoryDetail", "Group Calculation Detail")} + + + {t("historyId", "History ID")}: {selectedHistory?.id} + + +
+ {selectedHistory && ( + <> +
+
+
+ {t("groupMode", "Group Mode")} +
+
+ {getModeLabel(selectedHistory.group_mode)} +
+
+
+
+ {t("triggerType", "Trigger Type")} +
+
+ {getTriggerTypeLabel(selectedHistory.trigger_type)} +
+
+
+
+ {t("totalUsers", "Total Users")} +
+
{selectedHistory.total_users}
+
+
+
+ {t("result", "Result")} +
+
+ {t("successCount", "Success")}: {selectedHistory.success_count} + {" "}{t("separator", "/")}{" "} + {t("failedCount", "Failed")}: {selectedHistory.failed_count} +
+
+ {selectedHistory.start_time && ( +
+
+ {t("startTime", "Start Time")} +
+
+ {formatDate(selectedHistory.start_time)} +
+
+ )} + {selectedHistory.end_time && ( +
+
+ {t("endTime", "End Time")} +
+
+ {formatDate(selectedHistory.end_time)} +
+
+ )} +
+ + {selectedHistory.error_log && ( +
+
+ {t("errorMessage", "Error Message")} +
+
+ {selectedHistory.error_log} +
+
+ )} + + )} + +
+
+ {t("groupDetails", "Group Details")} +
+ {detailLoading ? ( +
+ + + {t("loading", "Loading...")} + +
+ ) : details.length > 0 ? ( + <> + {/* 统计信息 */} +
+
+
+ {details.reduce((sum: number, d: any) => sum + (d.UserCount || d.user_count || 0), 0)} +
+
+ {t("totalUsers", "Total Users")} +
+
+
+
+ {details.reduce((sum: number, d: any) => sum + (d.NodeCount || d.node_count || 0), 0)} +
+
+ {t("totalNodes", "Total Nodes")} +
+
+
+
{details.length}
+
+ {t("totalNodeGroups", "Total Node Groups")} +
+
+
+ + {/* 详情表格 */} +
+ + + + + + + + + + {details.map((detail: any, index: number) => { + const nodeGroupId = detail.NodeGroupId || detail.node_group_id; + const nodeGroupName = nodeGroupMap.get(nodeGroupId) || `${t("idPrefix", "#")}${nodeGroupId}`; + + return ( + + + + + + ); + })} + +
+ {t("nodeGroup", "Node Group")} + + {t("userCount", "User Count")} + + {t("nodeCount", "Node Count")} +
+
+
{nodeGroupName}
+
{t("id", "ID")}: {nodeGroupId}
+
+
+ + + {detail.NodeCount || detail.node_count || 0} +
+
+ + ) : ( +
+ {t("noDetails", "No details available")} +
+ )} +
+
+
+
+ + {/* User List Dialog */} + + + + + {selectedNodeGroupName} - {t("userList", "User List")} + + + {t("totalUsers", "Total Users")}: {userListTotal} + + +
+ {userList.length > 0 ? ( + + + + {t("id", "ID")} + {t("email", "Email")} + + + + {userList.map((user) => ( + + {user.id} + + {user.email || "-"} + + + ))} + +
+ ) : ( +
+ {t("noUsers", "No users found")} +
+ )} +
+
+
+
+ ); +} diff --git a/apps/admin/src/sections/group/group-recalculate.tsx b/apps/admin/src/sections/group/group-recalculate.tsx new file mode 100644 index 0000000..07f01b4 --- /dev/null +++ b/apps/admin/src/sections/group/group-recalculate.tsx @@ -0,0 +1,228 @@ +"use client"; + +import { Badge } from "@workspace/ui/components/badge"; +import { Button } from "@workspace/ui/components/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@workspace/ui/components/card"; +import { Loader2 } from "lucide-react"; +import { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { toast } from "sonner"; +import { + getRecalculationStatus, + recalculateGroup, +} from "@workspace/ui/services/admin/group"; + +export default function GroupRecalculate() { + const { t } = useTranslation("group"); + const [recalculating, setRecalculating] = useState(null); + const [loadingStatus, setLoadingStatus] = useState(false); + const [status, setStatus] = useState<{ + state: string; + progress: number; + total: number; + } | null>(null); + + const loadStatus = async () => { + setLoadingStatus(true); + try { + const { data } = await getRecalculationStatus(); + if (data.data) { + setStatus(data.data); + } + } catch (error) { + console.error("Failed to load recalculation status:", error); + } finally { + setLoadingStatus(false); + } + }; + + useEffect(() => { + loadStatus(); + + // Poll status every 2 seconds when recalculating + const interval = setInterval(() => { + if (status?.state === "running") { + loadStatus(); + } + }, 2000); + return () => clearInterval(interval); + }, [status?.state]); + + const handleRecalculate = async (mode: "average" | "subscribe" | "traffic") => { + setRecalculating(mode); + try { + await recalculateGroup({ mode }); + toast.success(t("recalculationStarted", "Recalculation started")); + loadStatus(); + } catch (error) { + console.error("Failed to start recalculation:", error); + toast.error(t("recalculationFailed", "Failed to start recalculation")); + } finally { + setRecalculating(null); + } + }; + + const getStateLabel = (state: string) => { + switch (state) { + case "running": + return t("running", "Running"); + case "completed": + return t("completed", "Completed"); + case "failed": + return t("failed", "Failed"); + default: + return t("idle", "Idle"); + } + }; + + const getStateVariant = (state: string) => { + switch (state) { + case "running": + return "default"; + case "completed": + return "secondary"; + case "failed": + return "destructive"; + default: + return "outline"; + } + }; + + return ( +
+ + + {t("groupRecalculation", "Group Recalculation")} + + {t( + "groupRecalculationDescription", + "Manually trigger a full recalculation of all user groups based on current configuration" + )} + + + + {/* Current Status */} +
+
+ + {t("currentStatus", "Current Status")} + + {loadingStatus ? ( + + ) : status ? ( + + {getStateLabel(status.state)} + + ) : null} +
+ + {status?.state === "running" && ( +
+
+ {t("progress", "Progress")} + + {status.progress} / {status.total || 0} + +
+
+
0 ? (status.progress / status.total) * 100 : 0}%`, + }} + /> +
+
+ )} + + {status?.state === "completed" && ( +
+ {t("recalculationCompleted", "Recalculation completed successfully")} +
+ )} + + {status?.state === "failed" && ( +
+ {t("recalculationFailed", "Recalculation failed. Please try again.")} +
+ )} +
+ + {/* Recalculate Buttons */} +
+
+ {/* Average Mode Recalculate */} +
+
+ {t("averageMode", "Average Mode")} +
+ +
+ + {/* Subscribe Mode Recalculate */} +
+
+ {t("subscribeMode", "Subscribe Mode")} +
+ +
+ + {/* Traffic Mode Recalculate */} +
+
+ {t("trafficMode", "Traffic Mode")} +
+ +
+
+
+ + {/* Warning */} +
+ {t("warning", "Warning")}:{" "} + {t( + "recalculationWarning", + "Recalculation will reassign all users to new groups based on current configuration. This operation cannot be undone." + )} +
+ + +
+ ); +} diff --git a/apps/admin/src/sections/group/index.tsx b/apps/admin/src/sections/group/index.tsx new file mode 100644 index 0000000..12c397e --- /dev/null +++ b/apps/admin/src/sections/group/index.tsx @@ -0,0 +1,85 @@ +"use client"; + +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@workspace/ui/components/tabs"; +import { useTranslation } from "react-i18next"; +// import UserGroups from "./user-groups"; +import NodeGroups from "./node-groups"; +import GroupHistory from "./group-history"; +import GroupConfig from "./group-config"; +import AverageModeTab from "./average-mode-tab"; +import SubscribeModeTab from "./subscribe-mode-tab"; +import TrafficModeTab from "./traffic-mode-tab"; +import CurrentGroupResults from "./current-group-results"; + +export default function Group() { + const { t } = useTranslation("group"); + + return ( +
+

+ {t("title", "Group Management")} +

+ + + + + {t("config", "Config")} + + {/* + {t("userGroups", "User Groups")} + */} + + {t("nodeGroups", "Node Groups")} + + + {t("averageMode", "Average Mode")} + + + {t("subscribeMode", "Subscribe Mode")} + + + {t("trafficMode", "Traffic Mode")} + + + {t("currentGroupingResult", "Current Grouping Result")} + + + {t("history", "History")} + + + + + + + + {/* + + */} + + + + + + + + + + + + + + + + + + + + + + + + + +
+ ); +} diff --git a/apps/admin/src/sections/group/node-group-form.tsx b/apps/admin/src/sections/group/node-group-form.tsx new file mode 100644 index 0000000..ad97df2 --- /dev/null +++ b/apps/admin/src/sections/group/node-group-form.tsx @@ -0,0 +1,459 @@ +"use client"; + +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@workspace/ui/components/dialog"; +import { Input } from "@workspace/ui/components/input"; +import { Label } from "@workspace/ui/components/label"; +import { Textarea } from "@workspace/ui/components/textarea"; +import { Switch } from "@workspace/ui/components/switch"; +import { AlertCircle, Loader2 } from "lucide-react"; +import { forwardRef, useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; + +interface NodeGroupFormProps { + initialValues?: Partial; + allNodeGroups?: API.NodeGroup[]; + currentGroupId?: number; + loading?: boolean; + onSubmit: (values: Record) => Promise; + title: string; + trigger: React.ReactNode; +} + +const NodeGroupForm = forwardRef< + HTMLButtonElement, + NodeGroupFormProps +>(({ initialValues, allNodeGroups = [], currentGroupId, loading, onSubmit, title, trigger }, ref) => { + const { t } = useTranslation("group"); + const [open, setOpen] = useState(false); + const [submitting, setSubmitting] = useState(false); + const [conflictError, setConflictError] = useState(""); + + const [values, setValues] = useState({ + name: "", + description: "", + sort: 0, + for_calculation: true, + is_expired_group: false, + expired_days_limit: 7, + max_traffic_gb_expired: 0, + speed_limit: 0, + min_traffic_gb: 0, + max_traffic_gb: 0, + }); + + useEffect(() => { + if (open) { + setConflictError(""); // 重置冲突错误 + if (initialValues) { + setValues({ + name: initialValues.name || "", + description: initialValues.description || "", + sort: initialValues.sort ?? 0, + for_calculation: initialValues.for_calculation ?? true, + is_expired_group: initialValues.is_expired_group ?? false, + expired_days_limit: initialValues.expired_days_limit ?? 7, + max_traffic_gb_expired: initialValues.max_traffic_gb_expired ?? 0, + speed_limit: initialValues.speed_limit ?? 0, + min_traffic_gb: initialValues.min_traffic_gb ?? 0, + max_traffic_gb: initialValues.max_traffic_gb ?? 0, + }); + } else { + setValues({ + name: "", + description: "", + sort: 0, + for_calculation: true, + is_expired_group: false, + expired_days_limit: 7, + max_traffic_gb_expired: 0, + speed_limit: 0, + min_traffic_gb: 0, + max_traffic_gb: 0, + }); + } + } + }, [initialValues, open]); + + // 检测流量区间冲突 + const checkTrafficRangeConflict = (minTraffic: number, maxTraffic: number): string => { + // 如果 min=0 且 max=0,表示不参与流量分组,跳过所有验证 + if (minTraffic === 0 && maxTraffic === 0) { + return ""; + } + + // 验证区间有效性:min 必须 < max(除非 max=0 表示无上限) + if (minTraffic > 0 && maxTraffic > 0 && minTraffic >= maxTraffic) { + return t("invalidRange", "Min traffic must be less than max traffic"); + } + + // 处理 max=0 的情况,表示无上限,使用一个很大的数代替 + const actualMax = maxTraffic === 0 ? Number.MAX_VALUE : maxTraffic; + + // 检查与其他节点组的冲突 + for (const group of allNodeGroups) { + // 跳过当前编辑的节点组 + if (currentGroupId && group.id === currentGroupId) { + continue; + } + + // 跳过没有设置流量区间的节点组(min=0 且 max=0 表示未配置) + const existingMin = group.min_traffic_gb ?? 0; + const existingMax = group.max_traffic_gb ?? 0; + if (existingMin === 0 && existingMax === 0) { + continue; + } + + // 处理现有节点组 max=0 的情况 + const actualExistingMax = existingMax === 0 ? Number.MAX_VALUE : existingMax; + + // 检测区间重叠 + // 两个区间 [min1, max1] 和 [min2, max2] 重叠的条件: + // max1 > min2 && max2 > min1 + const hasOverlap = actualMax > existingMin && actualExistingMax > minTraffic; + + if (hasOverlap) { + return t("rangeConflict", { + name: group.name, + min: existingMin.toString(), + max: existingMax === 0 ? "∞" : existingMax.toString(), + }); + } + } + + return ""; + }; + + // 检测过期节点组冲突 + const checkExpiredGroupConflict = async (isExpiredGroup: boolean): Promise => { + if (!isExpiredGroup) { + return ""; + } + + // 检查是否已存在其他过期节点组 + const existingExpiredGroup = allNodeGroups.find( + (group) => group.is_expired_group && group.id !== currentGroupId + ); + + if (existingExpiredGroup) { + return t("expiredGroupExists", `System already has an expired node group: ${existingExpiredGroup.name}`); + } + + // 检查当前节点组是否被订阅商品使用 + if (currentGroupId) { + try { + const { getSubscribeList } = await import("@workspace/ui/services/admin/subscribe"); + const { data } = await getSubscribeList({ + page: 1, + size: 1, + node_group_id: currentGroupId + }); + + if (data.data && data.data.total > 0) { + return t("nodeGroupUsedBySubscribe", "This node group is used as default node group in subscription products, cannot set as expired group"); + } + } catch (error) { + console.error("Failed to check subscribe usage:", error); + } + } + + return ""; + }; + + // 检查是否存在其他过期节点组(用于隐藏开关) + const hasOtherExpiredGroup = allNodeGroups.some( + (group) => group.is_expired_group && group.id !== currentGroupId + ); + + // 当前是否是过期节点组(编辑模式下) + const isCurrentExpiredGroup = initialValues?.is_expired_group ?? false; + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + // 检测过期节点组冲突 + const expiredGroupConflict = await checkExpiredGroupConflict(values.is_expired_group); + if (expiredGroupConflict) { + setConflictError(expiredGroupConflict); + return; + } + + // 仅在非过期节点组时检测流量区间冲突 + if (!values.is_expired_group) { + const conflict = checkTrafficRangeConflict(values.min_traffic_gb, values.max_traffic_gb); + if (conflict) { + setConflictError(conflict); + return; + } + } + + setSubmitting(true); + const success = await onSubmit(values); + setSubmitting(false); + if (success) { + setOpen(false); + setConflictError(""); + setValues({ + name: "", + description: "", + sort: 0, + for_calculation: true, + is_expired_group: false, + expired_days_limit: 7, + max_traffic_gb_expired: 0, + speed_limit: 0, + min_traffic_gb: 0, + max_traffic_gb: 0, + }); + } + }; + + return ( + + + {trigger} + + + + {title} + + {t("nodeGroupFormDescription", "Configure node group settings")} + + +
+
+ + + setValues({ ...values, name: e.target.value }) + } + placeholder={t("namePlaceholder", "Enter name")} + required + /> +
+ +
+ +