mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-11-16 09:34:22 +08:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c147e52d72 | |||
| d483258eef | |||
| 79c28103d5 | |||
| f36bf1437c | |||
| 4ad3aa2c06 | |||
| 357a4b165e | |||
| a15be253f5 | |||
| 572d1c16a6 | |||
| 39e22c07de | |||
| ca24573803 | |||
| 0cb3263a2e | |||
| fb2189c924 | |||
| 1383174b31 | |||
| c95bde7055 | |||
| 57f5e3a1a3 | |||
| 66ad52c199 | |||
| 2081dc9658 | |||
| b93255df3d | |||
| e1aef8700e | |||
| d5b3a39774 | |||
| 022e9e3807 | |||
| d333d463f6 | |||
| abc9f21ab9 | |||
| d216567c02 | |||
| 45bfd35a20 |
@@ -268,3 +268,6 @@ sql/
|
|||||||
!go-backend/internal/store/postgres/sql/
|
!go-backend/internal/store/postgres/sql/
|
||||||
!go-backend/internal/store/postgres/sql/schema.sql
|
!go-backend/internal/store/postgres/sql/schema.sql
|
||||||
!go-backend/internal/store/postgres/sql/data.sql
|
!go-backend/internal/store/postgres/sql/data.sql
|
||||||
|
go-backend/gost.db-shm
|
||||||
|
.gitignore
|
||||||
|
go-backend/gost.db-wal
|
||||||
|
|||||||
@@ -360,6 +360,8 @@ func (h *Handler) diagnoseForwardRuntime(forward *forwardRecord) (map[string]int
|
|||||||
return nil, errors.New("隧道配置不完整")
|
return nil, errors.New("隧道配置不完整")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipPreference := h.repo.GetTunnelIPPreference(forward.TunnelID)
|
||||||
|
|
||||||
inNodes, chainHops, outNodes := splitChainNodeGroups(chainRows)
|
inNodes, chainHops, outNodes := splitChainNodeGroups(chainRows)
|
||||||
results := make([]map[string]interface{}, 0, len(chainRows)*2+len(targets))
|
results := make([]map[string]interface{}, 0, len(chainRows)*2+len(targets))
|
||||||
nodeCache := map[int64]*nodeRecord{}
|
nodeCache := map[int64]*nodeRecord{}
|
||||||
@@ -383,7 +385,7 @@ func (h *Handler) diagnoseForwardRuntime(forward *forwardRecord) (map[string]int
|
|||||||
"fromChainType": 1,
|
"fromChainType": 1,
|
||||||
"toChainType": 2,
|
"toChainType": 2,
|
||||||
"toInx": firstNode.Inx,
|
"toInx": firstNode.Inx,
|
||||||
}, "")
|
}, ipPreference)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, outNode := range outNodes {
|
for _, outNode := range outNodes {
|
||||||
@@ -391,7 +393,7 @@ func (h *Handler) diagnoseForwardRuntime(forward *forwardRecord) (map[string]int
|
|||||||
h.appendChainHopDiagnosis(&results, nodeCache, inNode.NodeID, outNode, description, map[string]interface{}{
|
h.appendChainHopDiagnosis(&results, nodeCache, inNode.NodeID, outNode, description, map[string]interface{}{
|
||||||
"fromChainType": 1,
|
"fromChainType": 1,
|
||||||
"toChainType": 3,
|
"toChainType": 3,
|
||||||
}, "")
|
}, ipPreference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,7 +408,7 @@ func (h *Handler) diagnoseForwardRuntime(forward *forwardRecord) (map[string]int
|
|||||||
"fromInx": currentNode.Inx,
|
"fromInx": currentNode.Inx,
|
||||||
"toChainType": 2,
|
"toChainType": 2,
|
||||||
"toInx": nextNode.Inx,
|
"toInx": nextNode.Inx,
|
||||||
}, "")
|
}, ipPreference)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, outNode := range outNodes {
|
for _, outNode := range outNodes {
|
||||||
@@ -415,7 +417,7 @@ func (h *Handler) diagnoseForwardRuntime(forward *forwardRecord) (map[string]int
|
|||||||
"fromChainType": 2,
|
"fromChainType": 2,
|
||||||
"fromInx": currentNode.Inx,
|
"fromInx": currentNode.Inx,
|
||||||
"toChainType": 3,
|
"toChainType": 3,
|
||||||
}, "")
|
}, ipPreference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -479,7 +481,7 @@ func (h *Handler) diagnoseTunnelRuntime(tunnelID int64) (map[string]interface{},
|
|||||||
case 1:
|
case 1:
|
||||||
for _, inNode := range inNodes {
|
for _, inNode := range inNodes {
|
||||||
description := fmt.Sprintf("入口(%s)->外网", inNode.NodeName)
|
description := fmt.Sprintf("入口(%s)->外网", inNode.NodeName)
|
||||||
h.appendPathDiagnosis(&results, nodeCache, inNode.NodeID, "www.google.com", 443, description, map[string]interface{}{
|
h.appendPathDiagnosis(&results, nodeCache, inNode.NodeID, "www.bing.com", 443, description, map[string]interface{}{
|
||||||
"fromChainType": 1,
|
"fromChainType": 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -532,14 +534,14 @@ func (h *Handler) diagnoseTunnelRuntime(tunnelID int64) (map[string]interface{},
|
|||||||
|
|
||||||
for _, outNode := range outNodes {
|
for _, outNode := range outNodes {
|
||||||
description := fmt.Sprintf("出口(%s)->外网", outNode.NodeName)
|
description := fmt.Sprintf("出口(%s)->外网", outNode.NodeName)
|
||||||
h.appendPathDiagnosis(&results, nodeCache, outNode.NodeID, "www.google.com", 443, description, map[string]interface{}{
|
h.appendPathDiagnosis(&results, nodeCache, outNode.NodeID, "www.bing.com", 443, description, map[string]interface{}{
|
||||||
"fromChainType": 3,
|
"fromChainType": 3,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
for _, inNode := range inNodes {
|
for _, inNode := range inNodes {
|
||||||
description := fmt.Sprintf("入口(%s)->外网", inNode.NodeName)
|
description := fmt.Sprintf("入口(%s)->外网", inNode.NodeName)
|
||||||
h.appendPathDiagnosis(&results, nodeCache, inNode.NodeID, "www.google.com", 443, description, map[string]interface{}{
|
h.appendPathDiagnosis(&results, nodeCache, inNode.NodeID, "www.bing.com", 443, description, map[string]interface{}{
|
||||||
"fromChainType": 1,
|
"fromChainType": 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ type Handler struct {
|
|||||||
jobsCancel context.CancelFunc
|
jobsCancel context.CancelFunc
|
||||||
jobsStarted bool
|
jobsStarted bool
|
||||||
jobsWG sync.WaitGroup
|
jobsWG sync.WaitGroup
|
||||||
|
|
||||||
|
upgradeMu sync.Mutex
|
||||||
|
pendingUpgradeRedeploy map[int64]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type loginRequest struct {
|
type loginRequest struct {
|
||||||
@@ -70,12 +73,15 @@ type flowItem struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(repo *repo.Repository, jwtSecret string) *Handler {
|
func New(repo *repo.Repository, jwtSecret string) *Handler {
|
||||||
return &Handler{
|
h := &Handler{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
jwtSecret: jwtSecret,
|
jwtSecret: jwtSecret,
|
||||||
wsServer: ws.NewServer(repo, jwtSecret),
|
wsServer: ws.NewServer(repo, jwtSecret),
|
||||||
captchaTokens: make(map[string]int64),
|
captchaTokens: make(map[string]int64),
|
||||||
|
pendingUpgradeRedeploy: make(map[int64]struct{}),
|
||||||
}
|
}
|
||||||
|
h.wsServer.SetNodeOnlineHook(h.onNodeOnline)
|
||||||
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) WebSocketHandler() http.Handler {
|
func (h *Handler) WebSocketHandler() http.Handler {
|
||||||
|
|||||||
@@ -355,11 +355,28 @@ func (h *Handler) nodeInstall(w http.ResponseWriter, r *http.Request) {
|
|||||||
response.WriteJSON(w, response.ErrDefault("请求失败"))
|
response.WriteJSON(w, response.ErrDefault("请求失败"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
id := idFromBody(r, w)
|
|
||||||
if id <= 0 {
|
var req struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Channel string `json:"channel"`
|
||||||
|
}
|
||||||
|
if err := decodeJSON(r.Body, &req); err != nil {
|
||||||
|
response.WriteJSON(w, response.ErrDefault("请求参数错误"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
secret, err := h.repo.GetNodeSecret(id)
|
if req.ID <= 0 {
|
||||||
|
response.WriteJSON(w, response.ErrDefault("参数错误"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
channel := normalizeReleaseChannel(req.Channel)
|
||||||
|
version, err := resolveLatestReleaseByChannel(channel)
|
||||||
|
if err != nil {
|
||||||
|
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取最新%s失败: %v", releaseChannelLabel(channel), err)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
secret, err := h.repo.GetNodeSecret(req.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteJSON(w, response.ErrDefault("节点不存在"))
|
response.WriteJSON(w, response.ErrDefault("节点不存在"))
|
||||||
return
|
return
|
||||||
@@ -373,7 +390,7 @@ func (h *Handler) nodeInstall(w http.ResponseWriter, r *http.Request) {
|
|||||||
response.WriteJSON(w, response.Err(-2, err.Error()))
|
response.WriteJSON(w, response.Err(-2, err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd := fmt.Sprintf("curl -L https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flvx/releases/latest/download/install.sh -o ./install.sh && chmod +x ./install.sh && ./install.sh -a %s -s %s", processServerAddress(panelAddr), secret)
|
cmd := fmt.Sprintf("curl -L https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flvx/releases/download/%s/install.sh -o ./install.sh && chmod +x ./install.sh && VERSION=%s ./install.sh -a %s -s %s", version, version, processServerAddress(panelAddr), secret)
|
||||||
response.WriteJSON(w, response.OK(cmd))
|
response.WriteJSON(w, response.OK(cmd))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -901,6 +918,58 @@ func (h *Handler) reconstructTunnelState(tunnelID int64) (*tunnelCreateState, er
|
|||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) redeployTunnelAndForwards(tunnelID int64) error {
|
||||||
|
tunnel, err := h.getTunnelRecord(tunnelID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if tunnel.Type == 2 {
|
||||||
|
h.cleanupTunnelRuntime(tunnelID)
|
||||||
|
h.cleanupFederationRuntime(tunnelID)
|
||||||
|
state, err := h.reconstructTunnelState(tunnelID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
federationBindings, federationReleaseRefs, fedErr := h.applyFederationRuntime(state, h.federationLocalDomain())
|
||||||
|
if fedErr != nil {
|
||||||
|
return fedErr
|
||||||
|
}
|
||||||
|
tx := h.repo.BeginTx()
|
||||||
|
if tx.Error != nil {
|
||||||
|
h.releaseFederationRuntimeRefs(federationReleaseRefs)
|
||||||
|
return tx.Error
|
||||||
|
}
|
||||||
|
if replaceErr := h.repo.ReplaceFederationTunnelBindingsTx(tx, tunnelID, federationBindings); replaceErr != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
h.releaseFederationRuntimeRefs(federationReleaseRefs)
|
||||||
|
return replaceErr
|
||||||
|
}
|
||||||
|
if commitErr := tx.Commit().Error; commitErr != nil {
|
||||||
|
h.releaseFederationRuntimeRefs(federationReleaseRefs)
|
||||||
|
return commitErr
|
||||||
|
}
|
||||||
|
_, _, applyErr := h.applyTunnelRuntime(state)
|
||||||
|
if applyErr != nil {
|
||||||
|
h.releaseFederationRuntimeRefs(federationReleaseRefs)
|
||||||
|
_ = h.repo.DeleteFederationTunnelBindingsByTunnel(tunnelID)
|
||||||
|
return applyErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
forwards, err := h.listForwardsByTunnel(tunnelID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i := range forwards {
|
||||||
|
if err := h.syncForwardServices(&forwards[i], "UpdateService", true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) tunnelBatchRedeploy(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) tunnelBatchRedeploy(w http.ResponseWriter, r *http.Request) {
|
||||||
ids := idsFromBody(r, w)
|
ids := idsFromBody(r, w)
|
||||||
if ids == nil {
|
if ids == nil {
|
||||||
@@ -909,72 +978,11 @@ func (h *Handler) tunnelBatchRedeploy(w http.ResponseWriter, r *http.Request) {
|
|||||||
success := 0
|
success := 0
|
||||||
fail := 0
|
fail := 0
|
||||||
for _, tunnelID := range ids {
|
for _, tunnelID := range ids {
|
||||||
tunnel, err := h.getTunnelRecord(tunnelID)
|
if err := h.redeployTunnelAndForwards(tunnelID); err != nil {
|
||||||
if err != nil {
|
|
||||||
fail++
|
fail++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
success++
|
||||||
if tunnel.Type == 2 {
|
|
||||||
h.cleanupTunnelRuntime(tunnelID)
|
|
||||||
h.cleanupFederationRuntime(tunnelID)
|
|
||||||
state, err := h.reconstructTunnelState(tunnelID)
|
|
||||||
if err != nil {
|
|
||||||
fail++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
federationBindings, federationReleaseRefs, fedErr := h.applyFederationRuntime(state, h.federationLocalDomain())
|
|
||||||
if fedErr != nil {
|
|
||||||
fail++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tx := h.repo.BeginTx()
|
|
||||||
if tx.Error != nil {
|
|
||||||
h.releaseFederationRuntimeRefs(federationReleaseRefs)
|
|
||||||
fail++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if replaceErr := h.repo.ReplaceFederationTunnelBindingsTx(tx, tunnelID, federationBindings); replaceErr != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
h.releaseFederationRuntimeRefs(federationReleaseRefs)
|
|
||||||
fail++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if commitErr := tx.Commit().Error; commitErr != nil {
|
|
||||||
h.releaseFederationRuntimeRefs(federationReleaseRefs)
|
|
||||||
fail++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, _, applyErr := h.applyTunnelRuntime(state)
|
|
||||||
if applyErr != nil {
|
|
||||||
h.releaseFederationRuntimeRefs(federationReleaseRefs)
|
|
||||||
_ = h.repo.DeleteFederationTunnelBindingsByTunnel(tunnelID)
|
|
||||||
fail++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
forwards, err := h.listForwardsByTunnel(tunnelID)
|
|
||||||
if err != nil {
|
|
||||||
fail++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(forwards) == 0 {
|
|
||||||
success++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
ok := true
|
|
||||||
for i := range forwards {
|
|
||||||
if err := h.syncForwardServices(&forwards[i], "UpdateService", true); err != nil {
|
|
||||||
ok = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
success++
|
|
||||||
} else {
|
|
||||||
fail++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
response.WriteJSON(w, response.OK(map[string]interface{}{"successCount": success, "failCount": fail}))
|
response.WriteJSON(w, response.OK(map[string]interface{}{"successCount": success, "failCount": fail}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -19,8 +20,104 @@ const (
|
|||||||
githubHTMLBase = "https://github.com"
|
githubHTMLBase = "https://github.com"
|
||||||
upgradeTimeout = 5 * time.Minute
|
upgradeTimeout = 5 * time.Minute
|
||||||
batchWorkers = 5
|
batchWorkers = 5
|
||||||
|
|
||||||
|
releaseChannelStable = "stable"
|
||||||
|
releaseChannelDev = "dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
stableVersionPattern = regexp.MustCompile(`^\d+(?:\.\d+)+$`)
|
||||||
|
testKeywordPattern = regexp.MustCompile(`(?i)(alpha|beta|rc)`)
|
||||||
|
)
|
||||||
|
|
||||||
|
type githubRelease struct {
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
PublishedAt string `json:"published_at"`
|
||||||
|
Prerelease bool `json:"prerelease"`
|
||||||
|
Draft bool `json:"draft"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeReleaseChannel(channel string) string {
|
||||||
|
switch strings.ToLower(strings.TrimSpace(channel)) {
|
||||||
|
case releaseChannelDev:
|
||||||
|
return releaseChannelDev
|
||||||
|
default:
|
||||||
|
return releaseChannelStable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func releaseChannelFromTag(tag string) string {
|
||||||
|
normalized := strings.ToLower(strings.TrimSpace(tag))
|
||||||
|
if normalized == "" {
|
||||||
|
return releaseChannelDev
|
||||||
|
}
|
||||||
|
if testKeywordPattern.MatchString(normalized) {
|
||||||
|
return releaseChannelDev
|
||||||
|
}
|
||||||
|
if stableVersionPattern.MatchString(normalized) {
|
||||||
|
return releaseChannelStable
|
||||||
|
}
|
||||||
|
|
||||||
|
return releaseChannelDev
|
||||||
|
}
|
||||||
|
|
||||||
|
func releaseChannelLabel(channel string) string {
|
||||||
|
if normalizeReleaseChannel(channel) == releaseChannelDev {
|
||||||
|
return "测试版"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "正式版"
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchGitHubReleases(perPage int) ([]githubRelease, error) {
|
||||||
|
if perPage <= 0 {
|
||||||
|
perPage = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{Timeout: 15 * time.Second}
|
||||||
|
resp, err := client.Get(fmt.Sprintf("%s/repos/%s/releases?per_page=%d", githubAPIBase, githubRepo, perPage))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("请求GitHub API失败: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
|
||||||
|
return nil, fmt.Errorf("GitHub API返回 %d: %s", resp.StatusCode, string(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
var releases []githubRelease
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&releases); err != nil {
|
||||||
|
return nil, fmt.Errorf("解析GitHub API响应失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return releases, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveLatestReleaseByChannel(channel string) (string, error) {
|
||||||
|
normalizedChannel := normalizeReleaseChannel(channel)
|
||||||
|
releases, err := fetchGitHubReleases(50)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range releases {
|
||||||
|
if r.Draft {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tag := strings.TrimSpace(r.TagName)
|
||||||
|
if tag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if releaseChannelFromTag(tag) == normalizedChannel {
|
||||||
|
return tag, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", fmt.Errorf("未找到%s版本号", releaseChannelLabel(normalizedChannel))
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
response.WriteJSON(w, response.ErrDefault("请求失败"))
|
response.WriteJSON(w, response.ErrDefault("请求失败"))
|
||||||
@@ -30,6 +127,7 @@ func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
var req struct {
|
var req struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
Channel string `json:"channel"`
|
||||||
}
|
}
|
||||||
if err := decodeJSON(r.Body, &req); err != nil {
|
if err := decodeJSON(r.Body, &req); err != nil {
|
||||||
response.WriteJSON(w, response.ErrDefault("请求参数错误"))
|
response.WriteJSON(w, response.ErrDefault("请求参数错误"))
|
||||||
@@ -40,12 +138,13 @@ func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
channel := normalizeReleaseChannel(req.Channel)
|
||||||
version := strings.TrimSpace(req.Version)
|
version := strings.TrimSpace(req.Version)
|
||||||
if version == "" {
|
if version == "" {
|
||||||
var err error
|
var err error
|
||||||
version, err = resolveLatestRelease()
|
version, err = resolveLatestReleaseByChannel(channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取最新版本失败: %v", err)))
|
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取最新%s失败: %v", releaseChannelLabel(channel), err)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,6 +166,7 @@ func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("升级失败: %v", err)))
|
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("升级失败: %v", err)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
h.markNodePendingUpgradeRedeploy(req.ID)
|
||||||
|
|
||||||
response.WriteJSON(w, response.OK(map[string]interface{}{
|
response.WriteJSON(w, response.OK(map[string]interface{}{
|
||||||
"version": version,
|
"version": version,
|
||||||
@@ -75,61 +175,11 @@ func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolveLatestRelease() (string, error) {
|
func resolveLatestRelease() (string, error) {
|
||||||
client := &http.Client{
|
return resolveLatestReleaseByChannel(releaseChannelStable)
|
||||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
||||||
return http.ErrUseLastResponse
|
|
||||||
},
|
|
||||||
Timeout: 10 * time.Second,
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := client.Get(githubProxy + "/" + githubHTMLBase + "/" + githubRepo + "/releases/latest")
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("请求GitHub失败: %v", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusFound && resp.StatusCode != http.StatusMovedPermanently {
|
|
||||||
return resolveLatestReleaseAPI()
|
|
||||||
}
|
|
||||||
|
|
||||||
location := resp.Header.Get("Location")
|
|
||||||
if location == "" {
|
|
||||||
return resolveLatestReleaseAPI()
|
|
||||||
}
|
|
||||||
|
|
||||||
parts := strings.Split(location, "/")
|
|
||||||
tag := parts[len(parts)-1]
|
|
||||||
if tag == "" || tag == "latest" {
|
|
||||||
return resolveLatestReleaseAPI()
|
|
||||||
}
|
|
||||||
|
|
||||||
return tag, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveLatestReleaseAPI() (string, error) {
|
func resolveLatestReleaseAPI() (string, error) {
|
||||||
client := &http.Client{Timeout: 10 * time.Second}
|
return resolveLatestReleaseByChannel(releaseChannelStable)
|
||||||
resp, err := client.Get(githubAPIBase + "/repos/" + githubRepo + "/releases/latest")
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("请求GitHub API失败: %v", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
|
|
||||||
return "", fmt.Errorf("GitHub API返回 %d: %s", resp.StatusCode, string(body))
|
|
||||||
}
|
|
||||||
|
|
||||||
var release struct {
|
|
||||||
TagName string `json:"tag_name"`
|
|
||||||
}
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
|
|
||||||
return "", fmt.Errorf("解析GitHub API响应失败: %v", err)
|
|
||||||
}
|
|
||||||
if strings.TrimSpace(release.TagName) == "" {
|
|
||||||
return "", fmt.Errorf("无法从GitHub获取最新版本号")
|
|
||||||
}
|
|
||||||
|
|
||||||
return release.TagName, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) nodeBatchUpgrade(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) nodeBatchUpgrade(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -141,6 +191,7 @@ func (h *Handler) nodeBatchUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
var req struct {
|
var req struct {
|
||||||
IDs []int64 `json:"ids"`
|
IDs []int64 `json:"ids"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
Channel string `json:"channel"`
|
||||||
}
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
response.WriteJSON(w, response.ErrDefault("请求参数错误"))
|
response.WriteJSON(w, response.ErrDefault("请求参数错误"))
|
||||||
@@ -151,12 +202,13 @@ func (h *Handler) nodeBatchUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
channel := normalizeReleaseChannel(req.Channel)
|
||||||
version := strings.TrimSpace(req.Version)
|
version := strings.TrimSpace(req.Version)
|
||||||
if version == "" {
|
if version == "" {
|
||||||
var err error
|
var err error
|
||||||
version, err = resolveLatestRelease()
|
version, err = resolveLatestReleaseByChannel(channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取最新版本失败: %v", err)))
|
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取最新%s失败: %v", releaseChannelLabel(channel), err)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,6 +247,7 @@ func (h *Handler) nodeBatchUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
results[index] = upgradeResult{ID: nodeID, Success: false, Message: err.Error()}
|
results[index] = upgradeResult{ID: nodeID, Success: false, Message: err.Error()}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
h.markNodePendingUpgradeRedeploy(nodeID)
|
||||||
results[index] = upgradeResult{ID: nodeID, Success: true, Message: result.Message}
|
results[index] = upgradeResult{ID: nodeID, Success: true, Message: result.Message}
|
||||||
}(i, id)
|
}(i, id)
|
||||||
}
|
}
|
||||||
@@ -212,37 +265,28 @@ func (h *Handler) listReleases(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &http.Client{Timeout: 15 * time.Second}
|
var req struct {
|
||||||
resp, err := client.Get(githubAPIBase + "/repos/" + githubRepo + "/releases?per_page=20")
|
Channel string `json:"channel"`
|
||||||
|
}
|
||||||
|
if err := decodeJSON(r.Body, &req); err != nil && err != io.EOF {
|
||||||
|
response.WriteJSON(w, response.ErrDefault("请求参数错误"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
channel := normalizeReleaseChannel(req.Channel)
|
||||||
|
|
||||||
|
releases, err := fetchGitHubReleases(50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取版本列表失败: %v", err)))
|
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取版本列表失败: %v", err)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
|
|
||||||
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取版本列表失败: GitHub API返回 %d: %s", resp.StatusCode, string(body))))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var releases []struct {
|
|
||||||
TagName string `json:"tag_name"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
PublishedAt string `json:"published_at"`
|
|
||||||
Prerelease bool `json:"prerelease"`
|
|
||||||
Draft bool `json:"draft"`
|
|
||||||
}
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&releases); err != nil {
|
|
||||||
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("解析版本列表失败: %v", err)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type releaseItem struct {
|
type releaseItem struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PublishedAt string `json:"publishedAt"`
|
PublishedAt string `json:"publishedAt"`
|
||||||
Prerelease bool `json:"prerelease"`
|
Prerelease bool `json:"prerelease"`
|
||||||
|
Channel string `json:"channel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]releaseItem, 0, len(releases))
|
items := make([]releaseItem, 0, len(releases))
|
||||||
@@ -250,11 +294,20 @@ func (h *Handler) listReleases(w http.ResponseWriter, r *http.Request) {
|
|||||||
if r.Draft {
|
if r.Draft {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
tag := strings.TrimSpace(r.TagName)
|
||||||
|
if tag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
itemChannel := releaseChannelFromTag(tag)
|
||||||
|
if itemChannel != channel {
|
||||||
|
continue
|
||||||
|
}
|
||||||
items = append(items, releaseItem{
|
items = append(items, releaseItem{
|
||||||
Version: r.TagName,
|
Version: tag,
|
||||||
Name: r.Name,
|
Name: r.Name,
|
||||||
PublishedAt: r.PublishedAt,
|
PublishedAt: r.PublishedAt,
|
||||||
Prerelease: r.Prerelease,
|
Prerelease: itemChannel == releaseChannelDev,
|
||||||
|
Channel: itemChannel,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,3 +342,66 @@ func (h *Handler) nodeRollback(w http.ResponseWriter, r *http.Request) {
|
|||||||
"message": result.Message,
|
"message": result.Message,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) markNodePendingUpgradeRedeploy(nodeID int64) {
|
||||||
|
if h == nil || nodeID <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.upgradeMu.Lock()
|
||||||
|
h.pendingUpgradeRedeploy[nodeID] = struct{}{}
|
||||||
|
h.upgradeMu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) consumeNodePendingUpgradeRedeploy(nodeID int64) bool {
|
||||||
|
if h == nil || nodeID <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
h.upgradeMu.Lock()
|
||||||
|
_, ok := h.pendingUpgradeRedeploy[nodeID]
|
||||||
|
if ok {
|
||||||
|
delete(h.pendingUpgradeRedeploy, nodeID)
|
||||||
|
}
|
||||||
|
h.upgradeMu.Unlock()
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) onNodeOnline(nodeID int64) {
|
||||||
|
if !h.consumeNodePendingUpgradeRedeploy(nodeID) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.redeployNodeRuntimeAfterUpgrade(nodeID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) redeployNodeRuntimeAfterUpgrade(nodeID int64) {
|
||||||
|
tunnelIDs, err := h.repo.ListActiveTunnelIDsByNode(nodeID)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("post-upgrade redeploy: list tunnels for node %d failed: %v\n", nodeID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
forwardIDs, err := h.repo.ListActiveForwardIDsByNode(nodeID)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("post-upgrade redeploy: list forwards for node %d failed: %v\n", nodeID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tunnelFailed := make(map[int64]struct{})
|
||||||
|
for _, tunnelID := range tunnelIDs {
|
||||||
|
if err := h.redeployTunnelAndForwards(tunnelID); err != nil {
|
||||||
|
tunnelFailed[tunnelID] = struct{}{}
|
||||||
|
fmt.Printf("post-upgrade redeploy: tunnel %d failed on node %d: %v\n", tunnelID, nodeID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, forwardID := range forwardIDs {
|
||||||
|
forward, getErr := h.getForwardRecord(forwardID)
|
||||||
|
if getErr != nil || forward == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, skipped := tunnelFailed[forward.TunnelID]; skipped {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := h.syncForwardServices(forward, "UpdateService", true); err != nil {
|
||||||
|
fmt.Printf("post-upgrade redeploy: forward %d failed on node %d: %v\n", forwardID, nodeID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestReleaseChannelFromTag(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
tag string
|
||||||
|
expects string
|
||||||
|
}{
|
||||||
|
{name: "stable semantic version", tag: "2.1.4", expects: releaseChannelStable},
|
||||||
|
{name: "v prefix should be dev", tag: "v2.1.4", expects: releaseChannelDev},
|
||||||
|
{name: "rc release", tag: "2.1.4-rc2", expects: releaseChannelDev},
|
||||||
|
{name: "beta release", tag: "2.1.4-beta.1", expects: releaseChannelDev},
|
||||||
|
{name: "alpha release", tag: "2.1.4-alpha", expects: releaseChannelDev},
|
||||||
|
{name: "non numeric tag", tag: "nightly", expects: releaseChannelDev},
|
||||||
|
{name: "empty tag", tag: "", expects: releaseChannelDev},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
if got := releaseChannelFromTag(tc.tag); got != tc.expects {
|
||||||
|
t.Fatalf("releaseChannelFromTag(%q) = %q, want %q", tc.tag, got, tc.expects)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNormalizeReleaseChannel(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
expects string
|
||||||
|
}{
|
||||||
|
{input: "", expects: releaseChannelStable},
|
||||||
|
{input: "stable", expects: releaseChannelStable},
|
||||||
|
{input: "dev", expects: releaseChannelDev},
|
||||||
|
{input: "DEV", expects: releaseChannelDev},
|
||||||
|
{input: "preview", expects: releaseChannelStable},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
if got := normalizeReleaseChannel(tc.input); got != tc.expects {
|
||||||
|
t.Fatalf("normalizeReleaseChannel(%q) = %q, want %q", tc.input, got, tc.expects)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,6 +56,40 @@ func (r *Repository) ListForwardsByTunnel(tunnelID int64) ([]model.ForwardRecord
|
|||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Repository) ListActiveTunnelIDsByNode(nodeID int64) ([]int64, error) {
|
||||||
|
if r == nil || r.db == nil {
|
||||||
|
return nil, errors.New("repository not initialized")
|
||||||
|
}
|
||||||
|
var ids []int64
|
||||||
|
err := r.db.Model(&model.ChainTunnel{}).
|
||||||
|
Joins("JOIN tunnel ON tunnel.id = chain_tunnel.tunnel_id").
|
||||||
|
Where("chain_tunnel.node_id = ? AND tunnel.status = 1", nodeID).
|
||||||
|
Select("DISTINCT chain_tunnel.tunnel_id").
|
||||||
|
Order("chain_tunnel.tunnel_id ASC").
|
||||||
|
Pluck("chain_tunnel.tunnel_id", &ids).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) ListActiveForwardIDsByNode(nodeID int64) ([]int64, error) {
|
||||||
|
if r == nil || r.db == nil {
|
||||||
|
return nil, errors.New("repository not initialized")
|
||||||
|
}
|
||||||
|
var ids []int64
|
||||||
|
err := r.db.Model(&model.ForwardPort{}).
|
||||||
|
Joins("JOIN forward ON forward.id = forward_port.forward_id").
|
||||||
|
Where("forward_port.node_id = ? AND forward.status = 1", nodeID).
|
||||||
|
Select("DISTINCT forward_port.forward_id").
|
||||||
|
Order("forward_port.forward_id ASC").
|
||||||
|
Pluck("forward_port.forward_id", &ids).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Repository) ListForwardPorts(forwardID int64) ([]model.ForwardPortRecord, error) {
|
func (r *Repository) ListForwardPorts(forwardID int64) ([]model.ForwardPortRecord, error) {
|
||||||
if r == nil || r.db == nil {
|
if r == nil || r.db == nil {
|
||||||
return nil, errors.New("repository not initialized")
|
return nil, errors.New("repository not initialized")
|
||||||
|
|||||||
@@ -68,9 +68,10 @@ type CommandResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
repo *repo.Repository
|
repo *repo.Repository
|
||||||
jwtSecret string
|
jwtSecret string
|
||||||
upgrader websocket.Upgrader
|
upgrader websocket.Upgrader
|
||||||
|
onNodeOnline func(nodeID int64)
|
||||||
|
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
admins map[*connWrap]struct{}
|
admins map[*connWrap]struct{}
|
||||||
@@ -79,6 +80,15 @@ type Server struct {
|
|||||||
pending map[string]pendingRequest
|
pending map[string]pendingRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) SetNodeOnlineHook(fn func(nodeID int64)) {
|
||||||
|
if s == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.mu.Lock()
|
||||||
|
s.onNodeOnline = fn
|
||||||
|
s.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
func NewServer(repo *repo.Repository, jwtSecret string) *Server {
|
func NewServer(repo *repo.Repository, jwtSecret string) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
@@ -183,6 +193,13 @@ func (s *Server) handleNode(w http.ResponseWriter, r *http.Request, nodeID int64
|
|||||||
_ = s.repo.UpdateNodeOnline(nodeID, 1, version, httpVal, tlsVal, socksVal)
|
_ = s.repo.UpdateNodeOnline(nodeID, 1, version, httpVal, tlsVal, socksVal)
|
||||||
s.broadcastStatus(nodeID, 1)
|
s.broadcastStatus(nodeID, 1)
|
||||||
|
|
||||||
|
s.mu.RLock()
|
||||||
|
onlineHook := s.onNodeOnline
|
||||||
|
s.mu.RUnlock()
|
||||||
|
if onlineHook != nil {
|
||||||
|
go onlineHook(nodeID)
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
close(done)
|
close(done)
|
||||||
needOfflineBroadcast := false
|
needOfflineBroadcast := false
|
||||||
|
|||||||
@@ -193,6 +193,126 @@ func TestDiagnosisChainCoverageContracts(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestForwardDiagnosisRespectsTunnelIPPreferenceContract(t *testing.T) {
|
||||||
|
secret := "contract-jwt-secret"
|
||||||
|
router, r := setupDiagnosisContractRouter(t, secret)
|
||||||
|
now := time.Now().UnixMilli()
|
||||||
|
|
||||||
|
if err := r.DB().Exec(`
|
||||||
|
INSERT INTO user(id, user, pwd, role_id, exp_time, flow, in_flow, out_flow, flow_reset_time, num, created_time, updated_time, status)
|
||||||
|
VALUES(2, 'normal_user', '3c85cdebade1c51cf64ca9f3c09d182d', 1, 2727251700000, 99999, 0, 0, 1, 99999, ?, ?, 1)
|
||||||
|
`, now, now).Error; err != nil {
|
||||||
|
t.Fatalf("insert user: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.DB().Exec(`
|
||||||
|
INSERT INTO tunnel(name, traffic_ratio, type, protocol, flow, created_time, updated_time, status, in_ip, inx, ip_preference)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
`, "diagnose-ip-pref-forward", 1.0, 2, "tls", 99999, now, now, 1, nil, 0, "v6").Error; err != nil {
|
||||||
|
t.Fatalf("insert tunnel: %v", err)
|
||||||
|
}
|
||||||
|
tunnelID := mustLastInsertID(t, r, "diagnose-ip-pref-forward")
|
||||||
|
|
||||||
|
insertNode := func(name, v4, v6 string) int64 {
|
||||||
|
if err := r.DB().Exec(`
|
||||||
|
INSERT INTO node(name, secret, server_ip, server_ip_v4, server_ip_v6, port, interface_name, version, http, tls, socks, created_time, updated_time, status, tcp_listen_addr, udp_listen_addr, inx)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
`, name, name+"-secret", v4, v4, v6, "30000-30010", "", "v1", 1, 1, 1, now, now, 1, "[::]", "[::]", 0).Error; err != nil {
|
||||||
|
t.Fatalf("insert node %s: %v", name, err)
|
||||||
|
}
|
||||||
|
return mustLastInsertID(t, r, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
entryNodeID := insertNode("entry-node-v6", "10.10.1.10", "2001:db8:10::10")
|
||||||
|
chainNodeID := insertNode("chain-node-v6", "10.10.1.20", "2001:db8:10::20")
|
||||||
|
exitNodeID := insertNode("exit-node-v6", "10.10.1.30", "2001:db8:10::30")
|
||||||
|
|
||||||
|
if err := r.DB().Exec(`
|
||||||
|
INSERT INTO chain_tunnel(tunnel_id, chain_type, node_id, port, strategy, inx, protocol)
|
||||||
|
VALUES(?, 1, ?, 30001, 'round', 1, 'tls')
|
||||||
|
`, tunnelID, entryNodeID).Error; err != nil {
|
||||||
|
t.Fatalf("insert entry chain: %v", err)
|
||||||
|
}
|
||||||
|
if err := r.DB().Exec(`
|
||||||
|
INSERT INTO chain_tunnel(tunnel_id, chain_type, node_id, port, strategy, inx, protocol)
|
||||||
|
VALUES(?, 2, ?, 30002, 'round', 1, 'tls')
|
||||||
|
`, tunnelID, chainNodeID).Error; err != nil {
|
||||||
|
t.Fatalf("insert middle chain: %v", err)
|
||||||
|
}
|
||||||
|
if err := r.DB().Exec(`
|
||||||
|
INSERT INTO chain_tunnel(tunnel_id, chain_type, node_id, port, strategy, inx, protocol)
|
||||||
|
VALUES(?, 3, ?, 30003, 'round', 1, 'tls')
|
||||||
|
`, tunnelID, exitNodeID).Error; err != nil {
|
||||||
|
t.Fatalf("insert exit chain: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.DB().Exec(`
|
||||||
|
INSERT INTO forward(user_id, user_name, name, tunnel_id, remote_addr, strategy, in_flow, out_flow, created_time, updated_time, status, inx)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?, 0, 0, ?, ?, 1, ?)
|
||||||
|
`, 2, "normal_user", "ip-pref-forward", tunnelID, "8.8.8.8:53", "fifo", now, now, 0).Error; err != nil {
|
||||||
|
t.Fatalf("insert forward: %v", err)
|
||||||
|
}
|
||||||
|
forwardID := mustLastInsertID(t, r, "ip-pref-forward")
|
||||||
|
|
||||||
|
userToken, err := auth.GenerateToken(2, "normal_user", 1, secret)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("generate user token: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/forward/diagnose", bytes.NewBufferString(`{"forwardId":`+strconv.FormatInt(forwardID, 10)+`}`))
|
||||||
|
req.Header.Set("Authorization", userToken)
|
||||||
|
res := httptest.NewRecorder()
|
||||||
|
|
||||||
|
router.ServeHTTP(res, req)
|
||||||
|
|
||||||
|
var out response.R
|
||||||
|
if err := json.NewDecoder(res.Body).Decode(&out); err != nil {
|
||||||
|
t.Fatalf("decode response: %v", err)
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
t.Fatalf("expected code 0, got %d (%s)", out.Code, out.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
payload, ok := out.Data.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected object payload, got %T", out.Data)
|
||||||
|
}
|
||||||
|
results, ok := payload["results"].([]interface{})
|
||||||
|
if !ok || len(results) == 0 {
|
||||||
|
t.Fatalf("expected non-empty results, got %v", payload["results"])
|
||||||
|
}
|
||||||
|
|
||||||
|
hasEntryToChain := false
|
||||||
|
hasChainToExit := false
|
||||||
|
for _, raw := range results {
|
||||||
|
item, ok := raw.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
from := valueAsInt(item["fromChainType"])
|
||||||
|
to := valueAsInt(item["toChainType"])
|
||||||
|
targetIP := strings.TrimSpace(valueAsString(item["targetIp"]))
|
||||||
|
|
||||||
|
if from == 1 && to == 2 {
|
||||||
|
hasEntryToChain = true
|
||||||
|
if targetIP != "2001:db8:10::20" {
|
||||||
|
t.Fatalf("expected entry->chain diagnosis target to use IPv6, got %q", targetIP)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if from == 2 && to == 3 {
|
||||||
|
hasChainToExit = true
|
||||||
|
if targetIP != "2001:db8:10::30" {
|
||||||
|
t.Fatalf("expected chain->exit diagnosis target to use IPv6, got %q", targetIP)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hasEntryToChain || !hasChainToExit {
|
||||||
|
t.Fatalf("expected entry->chain and chain->exit steps, got entry=%v chain=%v", hasEntryToChain, hasChainToExit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDiagnosisUsesFederationRuntimeForRemoteNodes(t *testing.T) {
|
func TestDiagnosisUsesFederationRuntimeForRemoteNodes(t *testing.T) {
|
||||||
secret := "contract-jwt-secret"
|
secret := "contract-jwt-secret"
|
||||||
router, r := setupDiagnosisContractRouter(t, secret)
|
router, r := setupDiagnosisContractRouter(t, secret)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
"@dnd-kit/core": "^6.3.1",
|
"@dnd-kit/core": "^6.3.1",
|
||||||
"@dnd-kit/sortable": "^10.0.0",
|
"@dnd-kit/sortable": "^10.0.0",
|
||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
|
"@internationalized/date": "^3.10.0",
|
||||||
|
"@marsidev/react-turnstile": "^1.1.0",
|
||||||
"@radix-ui/react-accordion": "^1.2.0",
|
"@radix-ui/react-accordion": "^1.2.0",
|
||||||
"@radix-ui/react-checkbox": "^1.1.0",
|
"@radix-ui/react-checkbox": "^1.1.0",
|
||||||
"@radix-ui/react-dialog": "^1.1.0",
|
"@radix-ui/react-dialog": "^1.1.0",
|
||||||
@@ -25,8 +27,6 @@
|
|||||||
"@radix-ui/react-slot": "^1.1.0",
|
"@radix-ui/react-slot": "^1.1.0",
|
||||||
"@radix-ui/react-switch": "^1.1.0",
|
"@radix-ui/react-switch": "^1.1.0",
|
||||||
"@radix-ui/react-tabs": "^1.1.0",
|
"@radix-ui/react-tabs": "^1.1.0",
|
||||||
"@marsidev/react-turnstile": "^1.1.0",
|
|
||||||
"@internationalized/date": "^3.10.0",
|
|
||||||
"@react-aria/i18n": "^3.12.12",
|
"@react-aria/i18n": "^3.12.12",
|
||||||
"@react-aria/visually-hidden": "3.8.25",
|
"@react-aria/visually-hidden": "3.8.25",
|
||||||
"@react-types/shared": "3.30.0",
|
"@react-types/shared": "3.30.0",
|
||||||
@@ -43,8 +43,11 @@
|
|||||||
"react-dom": "18.3.1",
|
"react-dom": "18.3.1",
|
||||||
"react-hot-toast": "^2.5.2",
|
"react-hot-toast": "^2.5.2",
|
||||||
"react-is": "^19.2.4",
|
"react-is": "^19.2.4",
|
||||||
|
"react-markdown": "^10.1.0",
|
||||||
"react-router-dom": "6.30.3",
|
"react-router-dom": "6.30.3",
|
||||||
"recharts": "^3.1.1",
|
"recharts": "^3.1.1",
|
||||||
|
"rehype-sanitize": "^6.0.0",
|
||||||
|
"remark-gfm": "^4.0.1",
|
||||||
"sonner": "^2.0.6",
|
"sonner": "^2.0.6",
|
||||||
"tailwind-merge": "^2.5.5",
|
"tailwind-merge": "^2.5.5",
|
||||||
"tailwind-variants": "1.0.0",
|
"tailwind-variants": "1.0.0",
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import axios from "axios";
|
|||||||
|
|
||||||
import Network from "./network";
|
import Network from "./network";
|
||||||
|
|
||||||
|
export type ReleaseChannel = "stable" | "dev";
|
||||||
|
|
||||||
// 登陆相关接口
|
// 登陆相关接口
|
||||||
export interface LoginData {
|
export interface LoginData {
|
||||||
username: string;
|
username: string;
|
||||||
@@ -66,8 +68,10 @@ export const getNodeList = () => Network.post<NodeApiItem[]>("/node/list");
|
|||||||
export const updateNode = (data: NodeMutationPayload) =>
|
export const updateNode = (data: NodeMutationPayload) =>
|
||||||
Network.post("/node/update", data);
|
Network.post("/node/update", data);
|
||||||
export const deleteNode = (id: number) => Network.post("/node/delete", { id });
|
export const deleteNode = (id: number) => Network.post("/node/delete", { id });
|
||||||
export const getNodeInstallCommand = (id: number) =>
|
export const getNodeInstallCommand = (
|
||||||
Network.post<string>("/node/install", { id });
|
id: number,
|
||||||
|
channel: ReleaseChannel = "stable",
|
||||||
|
) => Network.post<string>("/node/install", { id, channel });
|
||||||
export const updateNodeOrder = (data: {
|
export const updateNodeOrder = (data: {
|
||||||
nodes: Array<{ id: number; inx: number }>;
|
nodes: Array<{ id: number; inx: number }>;
|
||||||
}) => Network.post("/node/update-order", data);
|
}) => Network.post("/node/update-order", data);
|
||||||
@@ -77,20 +81,28 @@ export const checkNodeStatus = (nodeId?: number) => {
|
|||||||
return Network.post("/node/check-status", params);
|
return Network.post("/node/check-status", params);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const upgradeNode = (id: number, version?: string) =>
|
export const upgradeNode = (
|
||||||
|
id: number,
|
||||||
|
version?: string,
|
||||||
|
channel: ReleaseChannel = "stable",
|
||||||
|
) =>
|
||||||
Network.post(
|
Network.post(
|
||||||
"/node/upgrade",
|
"/node/upgrade",
|
||||||
{ id, version: version || "" },
|
{ id, version: version || "", channel },
|
||||||
{ timeout: 5 * 60 * 1000 },
|
{ timeout: 5 * 60 * 1000 },
|
||||||
);
|
);
|
||||||
export const batchUpgradeNodes = (ids: number[], version?: string) =>
|
export const batchUpgradeNodes = (
|
||||||
|
ids: number[],
|
||||||
|
version?: string,
|
||||||
|
channel: ReleaseChannel = "stable",
|
||||||
|
) =>
|
||||||
Network.post(
|
Network.post(
|
||||||
"/node/batch-upgrade",
|
"/node/batch-upgrade",
|
||||||
{ ids, version: version || "" },
|
{ ids, version: version || "", channel },
|
||||||
{ timeout: 15 * 60 * 1000 },
|
{ timeout: 15 * 60 * 1000 },
|
||||||
);
|
);
|
||||||
export const getNodeReleases = () =>
|
export const getNodeReleases = (channel: ReleaseChannel = "stable") =>
|
||||||
Network.post<NodeReleaseApiItem[]>("/node/releases");
|
Network.post<NodeReleaseApiItem[]>("/node/releases", { channel });
|
||||||
export const rollbackNode = (id: number) =>
|
export const rollbackNode = (id: number) =>
|
||||||
Network.post("/node/rollback", { id });
|
Network.post("/node/rollback", { id });
|
||||||
|
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ export interface NodeReleaseApiItem {
|
|||||||
name: string;
|
name: string;
|
||||||
publishedAt: string;
|
publishedAt: string;
|
||||||
prerelease: boolean;
|
prerelease: boolean;
|
||||||
|
channel: "stable" | "dev";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserPackageInfoApiData {
|
export interface UserPackageInfoApiData {
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import { motion } from "framer-motion";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps page content with a smooth fade-in + slide-up entrance animation.
|
||||||
|
* Use this as the outermost wrapper inside each page component.
|
||||||
|
*/
|
||||||
|
export const AnimatedPage = ({
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
}) => (
|
||||||
|
<motion.div
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className={className}
|
||||||
|
exit={{ opacity: 0, y: -8 }}
|
||||||
|
initial={{ opacity: 0, y: 16 }}
|
||||||
|
transition={{ duration: 0.28, ease: [0.25, 0.46, 0.45, 0.94] }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stagger container — apply to the parent of a list/grid of animated items.
|
||||||
|
* Children should use `staggerItem` as their `variants` prop.
|
||||||
|
*/
|
||||||
|
export const staggerContainer = {
|
||||||
|
hidden: { opacity: 0 },
|
||||||
|
show: {
|
||||||
|
opacity: 1,
|
||||||
|
transition: {
|
||||||
|
staggerChildren: 0.05,
|
||||||
|
delayChildren: 0.05,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Individual stagger item variant — fade-in + slide-up.
|
||||||
|
*/
|
||||||
|
export const staggerItem = {
|
||||||
|
hidden: { opacity: 0, y: 12 },
|
||||||
|
show: {
|
||||||
|
opacity: 1,
|
||||||
|
y: 0,
|
||||||
|
transition: { duration: 0.25, ease: [0.25, 0.46, 0.45, 0.94] },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience wrapper for a stagger list.
|
||||||
|
* Renders a `motion.div` (or `motion.ul/motion.tbody`) with stagger behaviour.
|
||||||
|
*/
|
||||||
|
export const StaggerList = ({
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
as = "div",
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
as?: "div" | "ul" | "tbody";
|
||||||
|
}) => {
|
||||||
|
const Component = motion[as] as React.ElementType;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Component
|
||||||
|
animate="show"
|
||||||
|
className={className}
|
||||||
|
initial="hidden"
|
||||||
|
variants={staggerContainer}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Component>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Individual animated item for use inside StaggerList.
|
||||||
|
*/
|
||||||
|
export const StaggerItem = ({
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
as = "div",
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
as?: "div" | "li" | "tr";
|
||||||
|
}) => {
|
||||||
|
const Component = motion[as] as React.ElementType;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Component className={className} variants={staggerItem}>
|
||||||
|
{children}
|
||||||
|
</Component>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple fade-in animation for standalone elements (chips, badges, counters, etc.)
|
||||||
|
* Uses opacity + translateY to avoid font blurriness caused by scale transforms.
|
||||||
|
*/
|
||||||
|
export const FadeIn = ({
|
||||||
|
children,
|
||||||
|
delay = 0,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
delay?: number;
|
||||||
|
className?: string;
|
||||||
|
}) => (
|
||||||
|
<motion.div
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className={className}
|
||||||
|
initial={{ opacity: 0, y: 8 }}
|
||||||
|
transition={{ duration: 0.2, delay, ease: "easeOut" }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import { motion, AnimatePresence } from "framer-motion";
|
||||||
|
|
||||||
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
|
import { Input } from "@/shadcn-bridge/heroui/input";
|
||||||
|
import { SearchIcon } from "@/components/icons";
|
||||||
|
|
||||||
|
interface SearchBarProps {
|
||||||
|
isVisible: boolean;
|
||||||
|
value: string;
|
||||||
|
placeholder?: string;
|
||||||
|
onOpen: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SearchBar({
|
||||||
|
isVisible,
|
||||||
|
value,
|
||||||
|
placeholder = "搜索",
|
||||||
|
onOpen,
|
||||||
|
onClose,
|
||||||
|
onChange,
|
||||||
|
}: SearchBarProps) {
|
||||||
|
return (
|
||||||
|
// Fixed h-8 so the container never changes height — eliminates the vertical jitter
|
||||||
|
<div className="flex items-center gap-2 h-8 overflow-hidden">
|
||||||
|
<AnimatePresence initial={false} mode="wait">
|
||||||
|
{!isVisible ? (
|
||||||
|
<motion.div
|
||||||
|
key="search-btn"
|
||||||
|
animate={{ opacity: 1, scale: 1 }}
|
||||||
|
exit={{ opacity: 0 }}
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
transition={{ duration: 0.12 }}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
aria-label="搜索"
|
||||||
|
className="text-default-600"
|
||||||
|
color="default"
|
||||||
|
size="sm"
|
||||||
|
variant="flat"
|
||||||
|
onPress={onOpen}
|
||||||
|
>
|
||||||
|
<SearchIcon className="w-4 h-4" />
|
||||||
|
</Button>
|
||||||
|
</motion.div>
|
||||||
|
) : (
|
||||||
|
<motion.div
|
||||||
|
key="search-input"
|
||||||
|
animate={{ opacity: 1, x: 0 }}
|
||||||
|
className="flex w-full items-center gap-2"
|
||||||
|
exit={{ opacity: 0, x: -8 }}
|
||||||
|
initial={{ opacity: 0, x: -16 }}
|
||||||
|
transition={{ duration: 0.18, ease: [0.25, 0.46, 0.45, 0.94] }}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
autoFocus
|
||||||
|
classNames={{
|
||||||
|
base: "bg-default-100",
|
||||||
|
input:
|
||||||
|
"bg-transparent text-sm focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:outline-none",
|
||||||
|
inputWrapper: "bg-default-100 border-0 shadow-none h-8 min-h-8",
|
||||||
|
}}
|
||||||
|
placeholder={placeholder}
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => onChange(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
aria-label="关闭搜索"
|
||||||
|
className="text-default-600 shrink-0"
|
||||||
|
color="default"
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
onPress={() => {
|
||||||
|
onClose();
|
||||||
|
onChange("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
className="w-4 h-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</Button>
|
||||||
|
</motion.div>
|
||||||
|
)}
|
||||||
|
</AnimatePresence>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors transition-transform duration-100 active:scale-95 disabled:active:scale-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ function Checkbox({
|
|||||||
return (
|
return (
|
||||||
<CheckboxPrimitive.Root
|
<CheckboxPrimitive.Root
|
||||||
className={cn(
|
className={cn(
|
||||||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow transition-transform duration-100 active:scale-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
data-slot="checkbox"
|
data-slot="checkbox"
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<CheckboxPrimitive.Indicator
|
<CheckboxPrimitive.Indicator
|
||||||
className="flex items-center justify-center text-current"
|
className="flex items-center justify-center text-current data-[state=checked]:animate-in data-[state=checked]:zoom-in-75 data-[state=checked]:duration-150"
|
||||||
data-slot="checkbox-indicator"
|
data-slot="checkbox-indicator"
|
||||||
>
|
>
|
||||||
<CheckIcon className="h-3.5 w-3.5" />
|
<CheckIcon className="h-3.5 w-3.5" />
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function DialogContent({
|
|||||||
<DialogOverlay />
|
<DialogOverlay />
|
||||||
<DialogPrimitive.Content
|
<DialogPrimitive.Content
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-default-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 sm:rounded-lg dark:bg-default-50",
|
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-default-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=open]:slide-in-from-bottom-4 data-[state=closed]:slide-out-to-bottom-2 sm:rounded-lg dark:bg-default-50",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
data-slot="dialog-content"
|
data-slot="dialog-content"
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ function DropdownMenuSubContent({
|
|||||||
return (
|
return (
|
||||||
<DropdownMenuPrimitive.SubContent
|
<DropdownMenuPrimitive.SubContent
|
||||||
className={cn(
|
className={cn(
|
||||||
"z-50 min-w-32 overflow-hidden rounded-md border border-default-200 bg-white p-1 text-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out dark:bg-default-50",
|
"z-50 min-w-32 overflow-hidden rounded-md border border-default-200 bg-white p-1 text-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=top]:slide-in-from-bottom-2 data-[side=bottom]:slide-in-from-top-2 dark:bg-default-50",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
data-slot="dropdown-menu-sub-content"
|
data-slot="dropdown-menu-sub-content"
|
||||||
@@ -103,7 +103,7 @@ function DropdownMenuContent({
|
|||||||
<DropdownMenuPrimitive.Portal>
|
<DropdownMenuPrimitive.Portal>
|
||||||
<DropdownMenuPrimitive.Content
|
<DropdownMenuPrimitive.Content
|
||||||
className={cn(
|
className={cn(
|
||||||
"z-50 min-w-32 overflow-hidden rounded-md border border-default-200 bg-white p-1 text-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out dark:bg-default-50",
|
"z-50 min-w-32 overflow-hidden rounded-md border border-default-200 bg-white p-1 text-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=top]:slide-in-from-bottom-2 data-[side=bottom]:slide-in-from-top-2 dark:bg-default-50",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
data-slot="dropdown-menu-content"
|
data-slot="dropdown-menu-content"
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ function SelectContent({
|
|||||||
<SelectPrimitive.Portal>
|
<SelectPrimitive.Portal>
|
||||||
<SelectPrimitive.Content
|
<SelectPrimitive.Content
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-default-200 bg-white text-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out dark:bg-default-50",
|
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-default-200 bg-white text-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=top]:slide-in-from-bottom-2 data-[side=bottom]:slide-in-from-top-2 dark:bg-default-50",
|
||||||
position === "popper" &&
|
position === "popper" &&
|
||||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||||
className,
|
className,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useNavigate, useLocation } from "react-router-dom";
|
import { useNavigate, useLocation } from "react-router-dom";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
|
import { AnimatePresence, motion } from "framer-motion";
|
||||||
|
|
||||||
import { Button } from "@/shadcn-bridge/heroui/button";
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
import {
|
import {
|
||||||
@@ -335,21 +336,44 @@ export default function AdminLayout({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<li key={item.path}>
|
<li key={item.path}>
|
||||||
<button
|
<motion.button
|
||||||
className={`
|
className={`
|
||||||
w-full flex items-center gap-3 px-4 py-3 rounded-lg text-left
|
w-full flex items-center gap-3 px-4 py-3 rounded-lg text-left
|
||||||
transition-colors duration-200 min-h-[44px]
|
relative min-h-[44px]
|
||||||
${
|
${
|
||||||
isActive
|
isActive
|
||||||
? "bg-primary-100 dark:bg-primary-600/20 text-primary-600 dark:text-primary-300"
|
? "text-primary-600 dark:text-primary-300"
|
||||||
: "text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-900"
|
: "text-gray-700 dark:text-gray-200"
|
||||||
}
|
}
|
||||||
`}
|
`}
|
||||||
|
transition={{ duration: 0.15 }}
|
||||||
onClick={() => handleMenuClick(item.path)}
|
onClick={() => handleMenuClick(item.path)}
|
||||||
>
|
>
|
||||||
<div className="flex-shrink-0">{item.icon}</div>
|
{isActive && (
|
||||||
<span className="font-medium text-sm">{item.label}</span>
|
<motion.div
|
||||||
</button>
|
className="absolute inset-0 rounded-lg bg-primary-100 dark:bg-primary-600/20"
|
||||||
|
layoutId="sidebar-active"
|
||||||
|
transition={{
|
||||||
|
type: "spring",
|
||||||
|
stiffness: 380,
|
||||||
|
damping: 30,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{!isActive && (
|
||||||
|
<motion.div
|
||||||
|
className="absolute inset-0 rounded-lg bg-gray-100 dark:bg-gray-900 opacity-0"
|
||||||
|
transition={{ duration: 0.15 }}
|
||||||
|
whileHover={{ opacity: 1 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<div className="flex-shrink-0 relative z-10">
|
||||||
|
{item.icon}
|
||||||
|
</div>
|
||||||
|
<span className="font-medium text-sm relative z-10">
|
||||||
|
{item.label}
|
||||||
|
</span>
|
||||||
|
</motion.button>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -476,9 +500,20 @@ export default function AdminLayout({
|
|||||||
|
|
||||||
{/* 主内容 */}
|
{/* 主内容 */}
|
||||||
<main
|
<main
|
||||||
className={`flex-1 bg-gray-100 dark:bg-black ${isMobile ? "" : "overflow-y-auto"}`}
|
className={`flex-1 bg-gray-100 dark:bg-black overflow-hidden ${isMobile ? "" : "overflow-y-scroll"}`}
|
||||||
>
|
>
|
||||||
{children}
|
<AnimatePresence mode="wait">
|
||||||
|
<motion.div
|
||||||
|
key={location.pathname}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="h-full"
|
||||||
|
exit={{ opacity: 0, y: -6 }}
|
||||||
|
initial={{ opacity: 0, y: 10 }}
|
||||||
|
transition={{ duration: 0.22, ease: [0.25, 0.46, 0.45, 0.94] }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</motion.div>
|
||||||
|
</AnimatePresence>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { useState, useEffect, useRef } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
import { Button } from "@/shadcn-bridge/heroui/button";
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
||||||
import { Input } from "@/shadcn-bridge/heroui/input";
|
import { Input } from "@/shadcn-bridge/heroui/input";
|
||||||
@@ -16,8 +18,6 @@ import {
|
|||||||
ModalFooter,
|
ModalFooter,
|
||||||
ModalHeader,
|
ModalHeader,
|
||||||
} from "@/shadcn-bridge/heroui/modal";
|
} from "@/shadcn-bridge/heroui/modal";
|
||||||
import toast from "react-hot-toast";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
updateConfigs,
|
updateConfigs,
|
||||||
exportBackup,
|
exportBackup,
|
||||||
@@ -649,9 +649,9 @@ export default function ConfigPage() {
|
|||||||
{hasChanges && (
|
{hasChanges && (
|
||||||
<Card className="mt-4 bg-warning-50 dark:bg-warning-900/20 border-warning-200 dark:border-warning-800">
|
<Card className="mt-4 bg-warning-50 dark:bg-warning-900/20 border-warning-200 dark:border-warning-800">
|
||||||
<CardBody className="py-3">
|
<CardBody className="py-3">
|
||||||
<div className="flex items-center gap-2 text-warning-700 dark:text-warning-300">
|
<div className="w-full flex items-center justify-center gap-2 text-warning-700 dark:text-warning-300">
|
||||||
<div className="w-2 h-2 bg-warning-500 rounded-full animate-pulse" />
|
<div className="w-2 h-2 bg-warning-500 rounded-full animate-pulse" />
|
||||||
<span className="text-sm">
|
<span className="text-sm font-medium">
|
||||||
检测到配置变更,请记得保存您的修改
|
检测到配置变更,请记得保存您的修改
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -702,13 +702,16 @@ export default function ConfigPage() {
|
|||||||
<Textarea
|
<Textarea
|
||||||
label="公告内容"
|
label="公告内容"
|
||||||
minRows={4}
|
minRows={4}
|
||||||
placeholder="请输入公告内容"
|
placeholder="支持 Markdown,例如:**加粗**、[链接](https://example.com)、- 列表"
|
||||||
value={announcement.content}
|
value={announcement.content}
|
||||||
variant="bordered"
|
variant="bordered"
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setAnnouncement({ ...announcement, content: e.target.value })
|
setAnnouncement({ ...announcement, content: e.target.value })
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
公告支持 Markdown 语法,链接会在新标签页打开
|
||||||
|
</p>
|
||||||
|
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
|
import { AnimatedPage } from "@/components/animated-page";
|
||||||
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
||||||
import { Button } from "@/shadcn-bridge/heroui/button";
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
import {
|
import {
|
||||||
@@ -524,7 +525,7 @@ export default function DashboardPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-3 lg:px-6 py-2 lg:py-4">
|
<AnimatedPage className="px-3 lg:px-6 py-2 lg:py-4">
|
||||||
{announcement && <AnnouncementBanner announcement={announcement} />}
|
{announcement && <AnnouncementBanner announcement={announcement} />}
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3 lg:gap-4 mb-6 lg:mb-8">
|
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3 lg:gap-4 mb-6 lg:mb-8">
|
||||||
<MetricCard
|
<MetricCard
|
||||||
@@ -978,6 +979,6 @@ export default function DashboardPage() {
|
|||||||
</ModalBody>
|
</ModalBody>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</AnimatedPage>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import type { AnnouncementData } from "@/api";
|
import type { AnnouncementData } from "@/api";
|
||||||
|
|
||||||
|
import ReactMarkdown from "react-markdown";
|
||||||
|
import rehypeSanitize from "rehype-sanitize";
|
||||||
|
import remarkGfm from "remark-gfm";
|
||||||
|
|
||||||
import { Card, CardBody } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody } from "@/shadcn-bridge/heroui/card";
|
||||||
|
|
||||||
interface AnnouncementBannerProps {
|
interface AnnouncementBannerProps {
|
||||||
@@ -14,13 +18,13 @@ export const AnnouncementBanner = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="mb-4 lg:mb-6 border border-blue-200 dark:border-blue-500/30 bg-gradient-to-r from-blue-50 to-purple-50 dark:from-blue-500/10 dark:to-purple-500/10">
|
<Card className="mb-4 lg:mb-6 border border-blue-100 dark:border-blue-500/20 bg-gradient-to-br from-blue-50/80 to-indigo-50/80 dark:from-blue-500/5 dark:to-indigo-500/5 shadow-sm">
|
||||||
<CardBody className="p-4">
|
<CardBody className="p-4 sm:p-5">
|
||||||
<div className="flex items-center justify-start gap-3">
|
<div className="flex items-center gap-3.5 sm:gap-4">
|
||||||
<div className="p-2 bg-blue-100 dark:bg-blue-500/20 rounded-lg flex-shrink-0">
|
<div className="w-10 h-10 sm:w-11 sm:h-11 bg-white dark:bg-blue-500/10 rounded-full flex-shrink-0 flex items-center justify-center shadow-sm border border-blue-100 dark:border-blue-500/20">
|
||||||
<svg
|
<svg
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className="w-5 h-5 text-blue-600 dark:text-blue-400"
|
className="w-5 h-5 sm:w-5 sm:h-5 text-blue-500 dark:text-blue-400"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
viewBox="0 0 20 20"
|
viewBox="0 0 20 20"
|
||||||
>
|
>
|
||||||
@@ -32,12 +36,57 @@ export const AnnouncementBanner = ({
|
|||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<h3 className="text-sm lg:text-base font-semibold text-blue-900 dark:text-blue-100 mb-1">
|
<h3 className="text-[15px] font-semibold text-blue-900 dark:text-blue-100 tracking-wide mb-1 sm:mb-1.5 mt-1.5">
|
||||||
公告
|
公告
|
||||||
</h3>
|
</h3>
|
||||||
<p className="text-xs lg:text-sm text-blue-800 dark:text-blue-200 whitespace-pre-wrap break-words">
|
<div className="text-sm text-blue-800/90 dark:text-blue-100/90 break-words leading-relaxed">
|
||||||
{announcement.content}
|
<ReactMarkdown
|
||||||
</p>
|
components={{
|
||||||
|
p: ({ children }) => (
|
||||||
|
<p className="mb-2 last:mb-0">{children}</p>
|
||||||
|
),
|
||||||
|
a: ({ children, href }) => (
|
||||||
|
<a
|
||||||
|
className="underline decoration-blue-500/70 underline-offset-2 hover:text-blue-700 dark:hover:text-blue-100"
|
||||||
|
href={href}
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
),
|
||||||
|
ul: ({ children }) => (
|
||||||
|
<ul className="list-disc pl-5 space-y-1 mb-2 last:mb-0">
|
||||||
|
{children}
|
||||||
|
</ul>
|
||||||
|
),
|
||||||
|
ol: ({ children }) => (
|
||||||
|
<ol className="list-decimal pl-5 space-y-1 mb-2 last:mb-0">
|
||||||
|
{children}
|
||||||
|
</ol>
|
||||||
|
),
|
||||||
|
code: ({ children }) => (
|
||||||
|
<code className="rounded bg-blue-100/80 dark:bg-blue-900/40 px-1 py-0.5 text-[0.92em]">
|
||||||
|
{children}
|
||||||
|
</code>
|
||||||
|
),
|
||||||
|
pre: ({ children }) => (
|
||||||
|
<pre className="mb-2 overflow-x-auto rounded-md bg-blue-100/70 dark:bg-blue-900/40 p-2.5 text-xs leading-relaxed">
|
||||||
|
{children}
|
||||||
|
</pre>
|
||||||
|
),
|
||||||
|
blockquote: ({ children }) => (
|
||||||
|
<blockquote className="mb-2 border-l-2 border-blue-300/80 dark:border-blue-500/60 pl-3 italic">
|
||||||
|
{children}
|
||||||
|
</blockquote>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
rehypePlugins={[rehypeSanitize]}
|
||||||
|
remarkPlugins={[remarkGfm]}
|
||||||
|
>
|
||||||
|
{announcement.content}
|
||||||
|
</ReactMarkdown>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
|
|||||||
+495
-287
@@ -15,15 +15,26 @@ import {
|
|||||||
SortableContext,
|
SortableContext,
|
||||||
sortableKeyboardCoordinates,
|
sortableKeyboardCoordinates,
|
||||||
rectSortingStrategy,
|
rectSortingStrategy,
|
||||||
|
verticalListSortingStrategy,
|
||||||
} from "@dnd-kit/sortable";
|
} from "@dnd-kit/sortable";
|
||||||
import { useSortable } from "@dnd-kit/sortable";
|
import { useSortable } from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
import { CSS } from "@dnd-kit/utilities";
|
||||||
|
|
||||||
|
import { SearchBar } from "@/components/search-bar";
|
||||||
|
import { AnimatedPage } from "@/components/animated-page";
|
||||||
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
||||||
import { Button } from "@/shadcn-bridge/heroui/button";
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
import { Input } from "@/shadcn-bridge/heroui/input";
|
import { Input } from "@/shadcn-bridge/heroui/input";
|
||||||
import { Textarea } from "@/shadcn-bridge/heroui/input";
|
import { Textarea } from "@/shadcn-bridge/heroui/input";
|
||||||
import { Select, SelectItem } from "@/shadcn-bridge/heroui/select";
|
import { Select, SelectItem } from "@/shadcn-bridge/heroui/select";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableColumn,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/shadcn-bridge/heroui/table";
|
||||||
import {
|
import {
|
||||||
Modal,
|
Modal,
|
||||||
ModalContent,
|
ModalContent,
|
||||||
@@ -35,7 +46,6 @@ import { Chip } from "@/shadcn-bridge/heroui/chip";
|
|||||||
import { Spinner } from "@/shadcn-bridge/heroui/spinner";
|
import { Spinner } from "@/shadcn-bridge/heroui/spinner";
|
||||||
import { Switch } from "@/shadcn-bridge/heroui/switch";
|
import { Switch } from "@/shadcn-bridge/heroui/switch";
|
||||||
import { Alert } from "@/shadcn-bridge/heroui/alert";
|
import { Alert } from "@/shadcn-bridge/heroui/alert";
|
||||||
import { Accordion, AccordionItem } from "@/shadcn-bridge/heroui/accordion";
|
|
||||||
import { Checkbox } from "@/shadcn-bridge/heroui/checkbox";
|
import { Checkbox } from "@/shadcn-bridge/heroui/checkbox";
|
||||||
import {
|
import {
|
||||||
createForward,
|
createForward,
|
||||||
@@ -111,24 +121,13 @@ interface ForwardForm {
|
|||||||
strategy: string;
|
strategy: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加分组接口
|
|
||||||
interface UserGroup {
|
|
||||||
userId: number | null;
|
|
||||||
userName: string;
|
|
||||||
tunnelGroups: TunnelGroup[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TunnelGroup {
|
|
||||||
tunnelId: number;
|
|
||||||
tunnelName: string;
|
|
||||||
forwards: Forward[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ForwardPage() {
|
export default function ForwardPage() {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [forwards, setForwards] = useState<Forward[]>([]);
|
const [forwards, setForwards] = useState<Forward[]>([]);
|
||||||
const [tunnels, setTunnels] = useState<Tunnel[]>([]);
|
const [tunnels, setTunnels] = useState<Tunnel[]>([]);
|
||||||
const isMobile = useMobileBreakpoint();
|
const isMobile = useMobileBreakpoint();
|
||||||
|
const [searchKeyword, setSearchKeyword] = useState("");
|
||||||
|
const [isSearchVisible, setIsSearchVisible] = useState(false);
|
||||||
|
|
||||||
// 显示模式状态 - 从localStorage读取,默认为平铺显示
|
// 显示模式状态 - 从localStorage读取,默认为平铺显示
|
||||||
const [viewMode, setViewMode] = useState<"grouped" | "direct">(() => {
|
const [viewMode, setViewMode] = useState<"grouped" | "direct">(() => {
|
||||||
@@ -136,16 +135,21 @@ export default function ForwardPage() {
|
|||||||
const savedMode = localStorage.getItem("forward-view-mode");
|
const savedMode = localStorage.getItem("forward-view-mode");
|
||||||
|
|
||||||
return (savedMode as "grouped" | "direct") || "direct";
|
return (savedMode as "grouped" | "direct") || "direct";
|
||||||
} catch {
|
} catch (e) {
|
||||||
return "direct";
|
return "direct";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 筛选状态
|
||||||
|
const [filterUserId, setFilterUserId] = useState<string>("all");
|
||||||
|
const [filterTunnelId, setFilterTunnelId] = useState<string>("all");
|
||||||
|
|
||||||
// 拖拽排序相关状态
|
// 拖拽排序相关状态
|
||||||
const [forwardOrder, setForwardOrder] = useState<number[]>([]);
|
const [forwardOrder, setForwardOrder] = useState<number[]>([]);
|
||||||
|
|
||||||
// 模态框状态
|
// 模态框状态
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [isFilterModalOpen, setIsFilterModalOpen] = useState(false);
|
||||||
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
|
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
|
||||||
const [addressModalOpen, setAddressModalOpen] = useState(false);
|
const [addressModalOpen, setAddressModalOpen] = useState(false);
|
||||||
const [diagnosisModalOpen, setDiagnosisModalOpen] = useState(false);
|
const [diagnosisModalOpen, setDiagnosisModalOpen] = useState(false);
|
||||||
@@ -220,21 +224,6 @@ export default function ForwardPage() {
|
|||||||
setViewMode(newMode);
|
setViewMode(newMode);
|
||||||
try {
|
try {
|
||||||
localStorage.setItem("forward-view-mode", newMode);
|
localStorage.setItem("forward-view-mode", newMode);
|
||||||
|
|
||||||
// 切换到直接显示模式时,初始化拖拽排序顺序
|
|
||||||
if (newMode === "direct") {
|
|
||||||
const currentUserId = JwtUtil.getUserIdFromToken();
|
|
||||||
const { order, fromDatabase } = buildForwardOrder(
|
|
||||||
forwards,
|
|
||||||
currentUserId,
|
|
||||||
);
|
|
||||||
|
|
||||||
setForwardOrder(order);
|
|
||||||
|
|
||||||
if (fromDatabase) {
|
|
||||||
saveOrder(FORWARD_ORDER_KEY, order);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {}
|
} catch {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -257,18 +246,16 @@ export default function ForwardPage() {
|
|||||||
setForwards(forwardsData);
|
setForwards(forwardsData);
|
||||||
|
|
||||||
// 初始化拖拽排序顺序
|
// 初始化拖拽排序顺序
|
||||||
if (viewMode === "direct") {
|
const currentUserId = JwtUtil.getUserIdFromToken();
|
||||||
const currentUserId = JwtUtil.getUserIdFromToken();
|
const { order, fromDatabase } = buildForwardOrder(
|
||||||
const { order, fromDatabase } = buildForwardOrder(
|
forwardsData,
|
||||||
forwardsData,
|
currentUserId,
|
||||||
currentUserId,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
setForwardOrder(order);
|
setForwardOrder(order);
|
||||||
|
|
||||||
if (fromDatabase) {
|
if (fromDatabase) {
|
||||||
saveOrder(FORWARD_ORDER_KEY, order);
|
saveOrder(FORWARD_ORDER_KEY, order);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error(forwardsRes.msg || "获取转发列表失败");
|
toast.error(forwardsRes.msg || "获取转发列表失败");
|
||||||
@@ -285,53 +272,6 @@ export default function ForwardPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 按用户和隧道分组转发数据
|
|
||||||
const groupForwardsByUserAndTunnel = (): UserGroup[] => {
|
|
||||||
const userMap = new Map<string, UserGroup>();
|
|
||||||
|
|
||||||
// 获取排序后的转发列表
|
|
||||||
sortedForwards.forEach((forward) => {
|
|
||||||
const userKey = forward.userId ? forward.userId.toString() : "unknown";
|
|
||||||
const userName = forward.userName || "未知用户";
|
|
||||||
|
|
||||||
if (!userMap.has(userKey)) {
|
|
||||||
userMap.set(userKey, {
|
|
||||||
userId: forward.userId || null,
|
|
||||||
userName,
|
|
||||||
tunnelGroups: [],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const userGroup = userMap.get(userKey)!;
|
|
||||||
let tunnelGroup = userGroup.tunnelGroups.find(
|
|
||||||
(tg) => tg.tunnelId === forward.tunnelId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!tunnelGroup) {
|
|
||||||
tunnelGroup = {
|
|
||||||
tunnelId: forward.tunnelId,
|
|
||||||
tunnelName: forward.tunnelName,
|
|
||||||
forwards: [],
|
|
||||||
};
|
|
||||||
userGroup.tunnelGroups.push(tunnelGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
tunnelGroup.forwards.push(forward);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 排序:先按用户名,再按隧道名
|
|
||||||
const result = Array.from(userMap.values());
|
|
||||||
|
|
||||||
result.sort((a, b) => a.userName.localeCompare(b.userName));
|
|
||||||
result.forEach((userGroup) => {
|
|
||||||
userGroup.tunnelGroups.sort((a, b) =>
|
|
||||||
a.tunnelName.localeCompare(b.tunnelName),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 表单验证
|
// 表单验证
|
||||||
const validateForm = (): boolean => {
|
const validateForm = (): boolean => {
|
||||||
const newErrors: { [key: string]: string } = {};
|
const newErrors: { [key: string]: string } = {};
|
||||||
@@ -707,26 +647,10 @@ export default function ForwardPage() {
|
|||||||
setExportLoading(true);
|
setExportLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 根据当前显示模式获取要导出的转发列表
|
// 获取要导出的转发列表
|
||||||
let forwardsToExport: Forward[] = [];
|
const forwardsToExport = sortedForwards.filter(
|
||||||
|
(forward) => forward.tunnelId === selectedTunnelForExport,
|
||||||
if (viewMode === "grouped") {
|
);
|
||||||
// 分组模式下,获取指定隧道的转发
|
|
||||||
const userGroups = groupForwardsByUserAndTunnel();
|
|
||||||
|
|
||||||
forwardsToExport = userGroups.flatMap((userGroup) =>
|
|
||||||
userGroup.tunnelGroups
|
|
||||||
.filter(
|
|
||||||
(tunnelGroup) => tunnelGroup.tunnelId === selectedTunnelForExport,
|
|
||||||
)
|
|
||||||
.flatMap((tunnelGroup) => tunnelGroup.forwards),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// 直接显示模式下,过滤指定隧道的转发
|
|
||||||
forwardsToExport = sortedForwards.filter(
|
|
||||||
(forward) => forward.tunnelId === selectedTunnelForExport,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (forwardsToExport.length === 0) {
|
if (forwardsToExport.length === 0) {
|
||||||
toast.error("所选隧道没有转发数据");
|
toast.error("所选隧道没有转发数据");
|
||||||
@@ -1168,15 +1092,32 @@ export default function ForwardPage() {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在平铺模式下,只显示当前用户的转发
|
|
||||||
let filteredForwards = forwards;
|
let filteredForwards = forwards;
|
||||||
|
|
||||||
if (viewMode === "direct") {
|
if (filterUserId !== "all") {
|
||||||
if (tokenUserId !== null) {
|
const targetUserId = parseInt(filterUserId);
|
||||||
filteredForwards = forwards.filter(
|
|
||||||
(forward) => forward.userId === tokenUserId,
|
filteredForwards = filteredForwards.filter(
|
||||||
);
|
(f) => f.userId === targetUserId || (targetUserId === 0 && !f.userId),
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
if (filterTunnelId !== "all") {
|
||||||
|
const targetTunnelId = parseInt(filterTunnelId);
|
||||||
|
|
||||||
|
filteredForwards = filteredForwards.filter(
|
||||||
|
(f) => f.tunnelId === targetTunnelId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (searchKeyword.trim()) {
|
||||||
|
const lowerKeyword = searchKeyword.toLowerCase();
|
||||||
|
|
||||||
|
filteredForwards = filteredForwards.filter(
|
||||||
|
(f) =>
|
||||||
|
(f.name && f.name.toLowerCase().includes(lowerKeyword)) ||
|
||||||
|
(f.remoteAddr && f.remoteAddr.toLowerCase().includes(lowerKeyword)) ||
|
||||||
|
(f.userName && f.userName.toLowerCase().includes(lowerKeyword)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保过滤后的转发列表有效
|
// 确保过滤后的转发列表有效
|
||||||
@@ -1220,7 +1161,15 @@ export default function ForwardPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return sortedByDb;
|
return sortedByDb;
|
||||||
}, [forwards, forwardOrder, viewMode, tokenUserId]);
|
}, [
|
||||||
|
forwards,
|
||||||
|
forwardOrder,
|
||||||
|
viewMode,
|
||||||
|
tokenUserId,
|
||||||
|
filterUserId,
|
||||||
|
filterTunnelId,
|
||||||
|
searchKeyword,
|
||||||
|
]);
|
||||||
|
|
||||||
const sortableForwardIds = useMemo(
|
const sortableForwardIds = useMemo(
|
||||||
() => sortedForwards.map((f) => f.id).filter((id) => id > 0),
|
() => sortedForwards.map((f) => f.id).filter((id) => id > 0),
|
||||||
@@ -1238,11 +1187,14 @@ export default function ForwardPage() {
|
|||||||
isDragging,
|
isDragging,
|
||||||
} = useSortable({ id: forward.id });
|
} = useSortable({ id: forward.id });
|
||||||
|
|
||||||
const style = {
|
const style: React.CSSProperties = {
|
||||||
transform: transform ? CSS.Transform.toString(transform) : undefined,
|
transform: transform ? CSS.Transform.toString(transform) : undefined,
|
||||||
transition: isDragging ? undefined : transition || undefined,
|
transition: isDragging ? undefined : transition || undefined,
|
||||||
opacity: isDragging ? 0.5 : 1,
|
opacity: isDragging ? 0.5 : 1,
|
||||||
willChange: "transform",
|
willChange: "transform",
|
||||||
|
backfaceVisibility: "hidden",
|
||||||
|
WebkitFontSmoothing: "antialiased",
|
||||||
|
MozOsxFontSmoothing: "grayscale",
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -1252,6 +1204,231 @@ export default function ForwardPage() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 生成用作筛选项的用户和隧道列表
|
||||||
|
const uniqueUsers = useMemo(() => {
|
||||||
|
const userMap = new Map<number, { id: number; name: string }>();
|
||||||
|
|
||||||
|
forwards.forEach((f) => {
|
||||||
|
const uId = f.userId || 0;
|
||||||
|
|
||||||
|
if (!userMap.has(uId)) {
|
||||||
|
userMap.set(uId, { id: uId, name: f.userName || "未知用户" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Array.from(userMap.values());
|
||||||
|
}, [forwards]);
|
||||||
|
|
||||||
|
// 可拖拽的表格行组件
|
||||||
|
const SortableTableRow = ({
|
||||||
|
forward,
|
||||||
|
selectMode,
|
||||||
|
selectedIds,
|
||||||
|
toggleSelect,
|
||||||
|
getStrategyDisplay,
|
||||||
|
formatInAddress,
|
||||||
|
formatRemoteAddress,
|
||||||
|
handleServiceToggle,
|
||||||
|
handleEdit,
|
||||||
|
handleDelete,
|
||||||
|
handleDiagnose,
|
||||||
|
showAddressModal,
|
||||||
|
hasMultipleAddresses,
|
||||||
|
formatFlow,
|
||||||
|
}: any) => {
|
||||||
|
const {
|
||||||
|
attributes,
|
||||||
|
listeners,
|
||||||
|
setNodeRef,
|
||||||
|
transform,
|
||||||
|
transition,
|
||||||
|
isDragging,
|
||||||
|
} = useSortable({ id: forward.id });
|
||||||
|
|
||||||
|
const style = {
|
||||||
|
transform: transform ? CSS.Transform.toString(transform) : undefined,
|
||||||
|
transition: isDragging ? undefined : transition || undefined,
|
||||||
|
opacity: isDragging ? 0.5 : 1,
|
||||||
|
backgroundColor: isDragging ? "var(--nextui-default-100)" : undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
const strategyDisplay = getStrategyDisplay(forward.strategy);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableRow key={forward.id} ref={setNodeRef} style={style}>
|
||||||
|
{selectMode && (
|
||||||
|
<TableCell>
|
||||||
|
<Checkbox
|
||||||
|
isSelected={selectedIds.has(forward.id)}
|
||||||
|
onValueChange={() => toggleSelect(forward.id)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
)}
|
||||||
|
<TableCell>
|
||||||
|
<div
|
||||||
|
className="cursor-grab active:cursor-grabbing p-1 text-default-400 hover:text-default-600 transition-colors"
|
||||||
|
{...attributes}
|
||||||
|
{...listeners}
|
||||||
|
title="拖拽排序"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
className="w-4 h-4"
|
||||||
|
fill="currentColor"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
>
|
||||||
|
<path d="M7 2a2 2 0 1 1 .001 4.001A2 2 0 0 1 7 2zm0 6a2 2 0 1 1 .001 4.001A2 2 0 0 1 7 8zm0 6a2 2 0 1 1 .001 4.001A2 2 0 0 1 7 14zm6-8a2 2 0 1 1-.001-4.001A2 2 0 0 1 13 6zm0 2a2 2 0 1 1 .001 4.001A2 2 0 0 1 13 8zm0 6a2 2 0 1 1 .001 4.001A2 2 0 0 1 13 14z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="whitespace-nowrap">
|
||||||
|
<span className="text-sm font-medium text-default-700">
|
||||||
|
{forward.userName || "未知用户"}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="whitespace-nowrap">
|
||||||
|
<Chip
|
||||||
|
className="border-none bg-secondary/10 px-2"
|
||||||
|
color="secondary"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<span className="font-medium text-secondary-700">
|
||||||
|
{forward.tunnelName}
|
||||||
|
</span>
|
||||||
|
</Chip>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="whitespace-nowrap font-semibold text-foreground">
|
||||||
|
{forward.name}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="max-w-[220px]">
|
||||||
|
<button
|
||||||
|
className={`w-full truncate rounded-md bg-default-100/50 px-2.5 py-1.5 text-left font-mono text-xs font-medium text-default-700 transition-all ${
|
||||||
|
hasMultipleAddresses(forward.inIp)
|
||||||
|
? "hover:bg-default-200 hover:shadow-sm"
|
||||||
|
: ""
|
||||||
|
}`}
|
||||||
|
title={formatInAddress(forward.inIp, forward.inPort)}
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
showAddressModal(forward.inIp, forward.inPort, "入口端口")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{formatInAddress(forward.inIp, forward.inPort)}
|
||||||
|
</button>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="max-w-[240px]">
|
||||||
|
<button
|
||||||
|
className={`w-full truncate rounded-md bg-default-100/50 px-2.5 py-1.5 text-left font-mono text-xs font-medium text-default-700 transition-all ${
|
||||||
|
hasMultipleAddresses(forward.remoteAddr)
|
||||||
|
? "hover:bg-default-200 hover:shadow-sm"
|
||||||
|
: ""
|
||||||
|
}`}
|
||||||
|
title={formatRemoteAddress(forward.remoteAddr)}
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
showAddressModal(forward.remoteAddr, null, "目标地址")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{formatRemoteAddress(forward.remoteAddr)}
|
||||||
|
</button>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Chip
|
||||||
|
className="text-xs font-medium"
|
||||||
|
color={strategyDisplay.color as any}
|
||||||
|
size="sm"
|
||||||
|
variant="flat"
|
||||||
|
>
|
||||||
|
{strategyDisplay.text}
|
||||||
|
</Chip>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="whitespace-nowrap">
|
||||||
|
<span className="text-sm font-medium text-default-600 font-mono">
|
||||||
|
{formatFlow((forward.inFlow || 0) + (forward.outFlow || 0))}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex items-center gap-2.5 whitespace-nowrap">
|
||||||
|
<Switch
|
||||||
|
color="success"
|
||||||
|
isDisabled={forward.status !== 1 && forward.status !== 0}
|
||||||
|
isSelected={forward.serviceRunning}
|
||||||
|
size="sm"
|
||||||
|
onValueChange={() => handleServiceToggle(forward)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex justify-end gap-2">
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
className="bg-primary/10 text-primary hover:bg-primary/20"
|
||||||
|
size="sm"
|
||||||
|
title="编辑"
|
||||||
|
onPress={() => handleEdit(forward)}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
className="h-4 w-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
className="bg-warning/10 text-warning hover:bg-warning/20"
|
||||||
|
size="sm"
|
||||||
|
title="诊断"
|
||||||
|
onPress={() => handleDiagnose(forward)}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
className="h-4 w-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
className="bg-danger/10 text-danger hover:bg-danger/20"
|
||||||
|
size="sm"
|
||||||
|
title="删除"
|
||||||
|
onPress={() => handleDelete(forward)}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
className="h-4 w-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// 渲染转发卡片
|
// 渲染转发卡片
|
||||||
const renderForwardCard = (forward: Forward, listeners?: any) => {
|
const renderForwardCard = (forward: Forward, listeners?: any) => {
|
||||||
const statusDisplay = getStatusDisplay(forward.status);
|
const statusDisplay = getStatusDisplay(forward.status);
|
||||||
@@ -1516,14 +1693,58 @@ export default function ForwardPage() {
|
|||||||
return <PageLoadingState message="正在加载..." />;
|
return <PageLoadingState message="正在加载..." />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userGroups = groupForwardsByUserAndTunnel();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-3 lg:px-6 py-8">
|
<AnimatedPage className="px-3 lg:px-6 py-8">
|
||||||
{/* 页面头部 */}
|
{/* 页面头部 */}
|
||||||
<div className="flex items-center justify-between mb-6 gap-2">
|
<div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-between mb-6 gap-3">
|
||||||
<div className="flex-1" />
|
<div className="flex-1 max-w-sm flex items-center gap-2">
|
||||||
|
<SearchBar
|
||||||
|
isVisible={isSearchVisible}
|
||||||
|
placeholder="搜索转发名称、地址或用户名"
|
||||||
|
value={searchKeyword}
|
||||||
|
onChange={setSearchKeyword}
|
||||||
|
onClose={() => setIsSearchVisible(false)}
|
||||||
|
onOpen={() => setIsSearchVisible(true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="flex flex-wrap items-center justify-end gap-2 sm:gap-3">
|
<div className="flex flex-wrap items-center justify-end gap-2 sm:gap-3">
|
||||||
|
{/* 筛选按钮 */}
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
aria-label="筛选条件"
|
||||||
|
className={
|
||||||
|
filterUserId !== "all" || filterTunnelId !== "all"
|
||||||
|
? "bg-primary/20 text-primary relative"
|
||||||
|
: "text-default-600 relative"
|
||||||
|
}
|
||||||
|
color={
|
||||||
|
filterUserId !== "all" || filterTunnelId !== "all"
|
||||||
|
? "primary"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
|
size="sm"
|
||||||
|
title="筛选条件"
|
||||||
|
variant="flat"
|
||||||
|
onPress={() => setIsFilterModalOpen(true)}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
className="w-4 h-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
{(filterUserId !== "all" || filterTunnelId !== "all") && (
|
||||||
|
<span className="absolute top-1.5 right-1.5 flex h-1.5 w-1.5 rounded-full bg-primary" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
{/* 显示模式切换按钮 */}
|
{/* 显示模式切换按钮 */}
|
||||||
<Button
|
<Button
|
||||||
isIconOnly
|
isIconOnly
|
||||||
@@ -1584,7 +1805,7 @@ export default function ForwardPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
color="default"
|
color={selectMode ? "secondary" : "default"}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant={selectMode ? "solid" : "flat"}
|
variant={selectMode ? "solid" : "flat"}
|
||||||
onPress={toggleSelectMode}
|
onPress={toggleSelectMode}
|
||||||
@@ -1669,147 +1890,75 @@ export default function ForwardPage() {
|
|||||||
|
|
||||||
{/* 根据显示模式渲染不同内容 */}
|
{/* 根据显示模式渲染不同内容 */}
|
||||||
{viewMode === "grouped" ? (
|
{viewMode === "grouped" ? (
|
||||||
/* 按用户和隧道分组的转发列表 */
|
sortedForwards.length > 0 ? (
|
||||||
userGroups.length > 0 ? (
|
<div className="overflow-hidden rounded-xl border border-divider bg-content1 shadow-md">
|
||||||
<div className="space-y-6">
|
<DndContext
|
||||||
{userGroups.map((userGroup) => (
|
collisionDetection={closestCenter}
|
||||||
<Card
|
sensors={sensors}
|
||||||
key={userGroup.userId || "unknown"}
|
onDragEnd={handleDragEnd}
|
||||||
className="shadow-sm border border-divider w-full overflow-hidden"
|
>
|
||||||
|
<Table
|
||||||
|
aria-label="全部转发列表"
|
||||||
|
classNames={{
|
||||||
|
th: "bg-default-100/50 text-default-600 font-semibold text-sm border-b border-divider py-3 uppercase tracking-wider",
|
||||||
|
td: "py-3 border-b border-divider/50 group-data-[last=true]:border-b-0",
|
||||||
|
tr: "hover:bg-default-50/50 transition-colors",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<CardHeader className="pb-2 md:pb-2">
|
<TableHeader>
|
||||||
<div className="flex items-center justify-between w-full min-w-0">
|
{selectMode && (
|
||||||
<div className="flex items-center gap-3 min-w-0 flex-1">
|
<TableColumn className="w-14">选择</TableColumn>
|
||||||
<div className="w-10 h-10 bg-primary-100 dark:bg-primary-900/30 rounded-full flex items-center justify-center flex-shrink-0">
|
)}
|
||||||
<svg
|
<TableColumn className="w-10 pl-4" />
|
||||||
aria-hidden="true"
|
<TableColumn>用户</TableColumn>
|
||||||
className="w-5 h-5 text-primary"
|
<TableColumn>隧道</TableColumn>
|
||||||
fill="currentColor"
|
<TableColumn>名称</TableColumn>
|
||||||
viewBox="0 0 20 20"
|
<TableColumn>入口</TableColumn>
|
||||||
>
|
<TableColumn>目标</TableColumn>
|
||||||
<path
|
<TableColumn>策略</TableColumn>
|
||||||
clipRule="evenodd"
|
<TableColumn>总流量</TableColumn>
|
||||||
d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z"
|
<TableColumn>状态</TableColumn>
|
||||||
fillRule="evenodd"
|
<TableColumn className="text-right">操作</TableColumn>
|
||||||
/>
|
</TableHeader>
|
||||||
</svg>
|
<TableBody emptyContent="暂无转发配置" items={sortedForwards}>
|
||||||
</div>
|
{(forward) => (
|
||||||
<div className="min-w-0 flex-1">
|
<SortableContext
|
||||||
<h2 className="text-base font-medium text-foreground truncate max-w-[150px] sm:max-w-[250px] md:max-w-[350px] lg:max-w-[450px]">
|
key={forward.id}
|
||||||
{userGroup.userName}
|
items={sortableForwardIds}
|
||||||
</h2>
|
strategy={verticalListSortingStrategy}
|
||||||
<p className="text-xs text-default-500 truncate max-w-[150px] sm:max-w-[250px] md:max-w-[350px] lg:max-w-[450px]">
|
|
||||||
{userGroup.tunnelGroups.length} 个隧道,
|
|
||||||
{userGroup.tunnelGroups.reduce(
|
|
||||||
(total, tg) => total + tg.forwards.length,
|
|
||||||
0,
|
|
||||||
)}{" "}
|
|
||||||
个转发
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<Chip
|
|
||||||
className="text-xs flex-shrink-0 ml-2"
|
|
||||||
color="primary"
|
|
||||||
size="sm"
|
|
||||||
variant="flat"
|
|
||||||
>
|
>
|
||||||
用户
|
<SortableTableRow
|
||||||
</Chip>
|
formatFlow={formatFlow}
|
||||||
</div>
|
formatInAddress={formatInAddress}
|
||||||
</CardHeader>
|
formatRemoteAddress={formatRemoteAddress}
|
||||||
|
forward={forward}
|
||||||
<CardBody className="pt-0 md:pt-0">
|
getStrategyDisplay={getStrategyDisplay}
|
||||||
<Accordion className="px-0" variant="splitted">
|
handleDelete={handleDelete}
|
||||||
{userGroup.tunnelGroups.map((tunnelGroup) => (
|
handleDiagnose={handleDiagnose}
|
||||||
<AccordionItem
|
handleEdit={handleEdit}
|
||||||
key={tunnelGroup.tunnelId}
|
handleServiceToggle={handleServiceToggle}
|
||||||
aria-label={tunnelGroup.tunnelName}
|
hasMultipleAddresses={hasMultipleAddresses}
|
||||||
className="shadow-none border border-divider"
|
selectMode={selectMode}
|
||||||
title={
|
selectedIds={selectedIds}
|
||||||
<div className="flex items-center justify-between w-full min-w-0 pr-4">
|
showAddressModal={showAddressModal}
|
||||||
<div className="flex items-center gap-3 min-w-0 flex-1">
|
toggleSelect={toggleSelect}
|
||||||
<div className="w-8 h-8 bg-success-100 dark:bg-success-900/30 rounded-lg flex items-center justify-center flex-shrink-0">
|
/>
|
||||||
<svg
|
</SortableContext>
|
||||||
aria-hidden="true"
|
)}
|
||||||
className="w-4 h-4 text-success"
|
</TableBody>
|
||||||
fill="none"
|
</Table>
|
||||||
stroke="currentColor"
|
</DndContext>
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M13 10V3L4 14h7v7l9-11h-7z"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
strokeWidth={2}
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<h3 className="text-sm font-medium text-foreground truncate max-w-[120px] sm:max-w-[200px] md:max-w-[300px] lg:max-w-[400px]">
|
|
||||||
{tunnelGroup.tunnelName}
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-2 flex-shrink-0 ml-2">
|
|
||||||
<Chip
|
|
||||||
className="text-xs"
|
|
||||||
size="sm"
|
|
||||||
variant="flat"
|
|
||||||
>
|
|
||||||
{
|
|
||||||
tunnelGroup.forwards.filter(
|
|
||||||
(f) => f.serviceRunning,
|
|
||||||
).length
|
|
||||||
}
|
|
||||||
/{tunnelGroup.forwards.length}
|
|
||||||
</Chip>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 p-4">
|
|
||||||
{tunnelGroup.forwards.map((forward) =>
|
|
||||||
renderForwardCard(forward, undefined),
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</AccordionItem>
|
|
||||||
))}
|
|
||||||
</Accordion>
|
|
||||||
</CardBody>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
/* 空状态 */
|
/* 空状态 */
|
||||||
<Card className="shadow-sm border border-gray-200 dark:border-gray-700">
|
<Card className="shadow-sm border border-gray-200 dark:border-gray-700 bg-default-50/50">
|
||||||
<CardBody className="text-center py-16">
|
<CardBody className="text-center py-20 flex flex-col items-center justify-center min-h-[240px]">
|
||||||
<div className="flex flex-col items-center gap-4">
|
<h3 className="text-xl font-medium text-foreground tracking-tight mb-2">
|
||||||
<div className="w-16 h-16 bg-default-100 rounded-full flex items-center justify-center">
|
暂无转发配置
|
||||||
<svg
|
</h3>
|
||||||
aria-hidden="true"
|
<p className="text-default-500 text-sm max-w-xs mx-auto leading-relaxed">
|
||||||
className="w-8 h-8 text-default-400"
|
还没有创建任何转发配置,点击上方按钮开始创建
|
||||||
fill="none"
|
</p>
|
||||||
stroke="currentColor"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M8 9l4-4 4 4m0 6l-4 4-4-4"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
strokeWidth={1.5}
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 className="text-lg font-semibold text-foreground">
|
|
||||||
暂无转发配置
|
|
||||||
</h3>
|
|
||||||
<p className="text-default-500 text-sm mt-1">
|
|
||||||
还没有创建任何转发配置,点击上方按钮开始创建
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
@@ -1836,34 +1985,14 @@ export default function ForwardPage() {
|
|||||||
</DndContext>
|
</DndContext>
|
||||||
) : (
|
) : (
|
||||||
/* 空状态 */
|
/* 空状态 */
|
||||||
<Card className="shadow-sm border border-gray-200 dark:border-gray-700">
|
<Card className="shadow-sm border border-gray-200 dark:border-gray-700 bg-default-50/50">
|
||||||
<CardBody className="text-center py-16">
|
<CardBody className="text-center py-20 flex flex-col items-center justify-center min-h-[240px]">
|
||||||
<div className="flex flex-col items-center gap-4">
|
<h3 className="text-xl font-medium text-foreground tracking-tight mb-2">
|
||||||
<div className="w-16 h-16 bg-default-100 rounded-full flex items-center justify-center">
|
暂无转发配置
|
||||||
<svg
|
</h3>
|
||||||
aria-hidden="true"
|
<p className="text-default-500 text-sm max-w-xs mx-auto leading-relaxed">
|
||||||
className="w-8 h-8 text-default-400"
|
还没有创建任何转发配置,点击上方按钮开始创建
|
||||||
fill="none"
|
</p>
|
||||||
stroke="currentColor"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M8 9l4-4 4 4m0 6l-4 4-4-4"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
strokeWidth={1.5}
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 className="text-lg font-semibold text-foreground">
|
|
||||||
暂无转发配置
|
|
||||||
</h3>
|
|
||||||
<p className="text-default-500 text-sm mt-1">
|
|
||||||
还没有创建任何转发配置,点击上方按钮开始创建
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
@@ -3015,6 +3144,85 @@ export default function ForwardPage() {
|
|||||||
)}
|
)}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
|
||||||
|
{/* 筛选模态框 */}
|
||||||
|
<Modal
|
||||||
|
isOpen={isFilterModalOpen}
|
||||||
|
placement="center"
|
||||||
|
size="md"
|
||||||
|
onOpenChange={setIsFilterModalOpen}
|
||||||
|
>
|
||||||
|
<ModalContent>
|
||||||
|
{(onClose) => (
|
||||||
|
<>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
筛选条件
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<div className="flex flex-col gap-4 py-2">
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<label className="text-sm font-medium">按用户筛选</label>
|
||||||
|
<Select
|
||||||
|
aria-label="筛选用户"
|
||||||
|
className="w-full"
|
||||||
|
selectedKeys={[filterUserId]}
|
||||||
|
variant="bordered"
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const key = Array.from(keys)[0] as string;
|
||||||
|
|
||||||
|
setFilterUserId(key || "all");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectItem key="all">全部用户</SelectItem>
|
||||||
|
{uniqueUsers.map((user) => (
|
||||||
|
<SelectItem key={user.id.toString()}>
|
||||||
|
{user.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<label className="text-sm font-medium">按隧道筛选</label>
|
||||||
|
<Select
|
||||||
|
aria-label="筛选隧道"
|
||||||
|
className="w-full"
|
||||||
|
selectedKeys={[filterTunnelId]}
|
||||||
|
variant="bordered"
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const key = Array.from(keys)[0] as string;
|
||||||
|
|
||||||
|
setFilterTunnelId(key || "all");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectItem key="all">全部隧道</SelectItem>
|
||||||
|
{tunnels.map((tunnel) => (
|
||||||
|
<SelectItem key={tunnel.id.toString()}>
|
||||||
|
{tunnel.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button
|
||||||
|
color="default"
|
||||||
|
variant="flat"
|
||||||
|
onPress={() => {
|
||||||
|
setFilterUserId("all");
|
||||||
|
setFilterTunnelId("all");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
<Button color="primary" onPress={onClose}>
|
||||||
|
完成
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
</AnimatedPage>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useState } from "react";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { Turnstile } from "@marsidev/react-turnstile";
|
import { Turnstile } from "@marsidev/react-turnstile";
|
||||||
|
import { motion } from "framer-motion";
|
||||||
|
|
||||||
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
||||||
import { Input } from "@/shadcn-bridge/heroui/input";
|
import { Input } from "@/shadcn-bridge/heroui/input";
|
||||||
@@ -152,7 +153,12 @@ export default function IndexPage() {
|
|||||||
return (
|
return (
|
||||||
<DefaultLayout>
|
<DefaultLayout>
|
||||||
<section className="flex flex-col items-center justify-center gap-4 py-4 sm:py-8 md:py-10 pb-20 min-h-[calc(100dvh-120px)] sm:min-h-[calc(100dvh-200px)]">
|
<section className="flex flex-col items-center justify-center gap-4 py-4 sm:py-8 md:py-10 pb-20 min-h-[calc(100dvh-120px)] sm:min-h-[calc(100dvh-200px)]">
|
||||||
<div className="w-full max-w-md px-4 sm:px-0">
|
<motion.div
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="w-full max-w-md px-4 sm:px-0"
|
||||||
|
initial={{ opacity: 0, y: 24 }}
|
||||||
|
transition={{ duration: 0.35, ease: [0.25, 0.46, 0.45, 0.94] }}
|
||||||
|
>
|
||||||
<Card className="w-full">
|
<Card className="w-full">
|
||||||
<CardHeader className="pb-0 pt-6 px-6 flex-col items-center">
|
<CardHeader className="pb-0 pt-6 px-6 flex-col items-center">
|
||||||
<h1 className={title({ size: "sm" })}>登陆</h1>
|
<h1 className={title({ size: "sm" })}>登陆</h1>
|
||||||
@@ -203,7 +209,7 @@ export default function IndexPage() {
|
|||||||
</div>
|
</div>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</motion.div>
|
||||||
|
|
||||||
{/* 版权信息 - 固定在底部,不占据布局空间 */}
|
{/* 版权信息 - 固定在底部,不占据布局空间 */}
|
||||||
|
|
||||||
|
|||||||
+136
-130
@@ -1,6 +1,12 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect, useMemo } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
|
import {
|
||||||
|
AnimatedPage,
|
||||||
|
StaggerList,
|
||||||
|
StaggerItem,
|
||||||
|
} from "@/components/animated-page";
|
||||||
|
import { SearchBar } from "@/components/search-bar";
|
||||||
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
||||||
import { Button } from "@/shadcn-bridge/heroui/button";
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
import { Input } from "@/shadcn-bridge/heroui/input";
|
import { Input } from "@/shadcn-bridge/heroui/input";
|
||||||
@@ -51,6 +57,19 @@ export default function LimitPage() {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [rules, setRules] = useState<SpeedLimitRule[]>([]);
|
const [rules, setRules] = useState<SpeedLimitRule[]>([]);
|
||||||
const [tunnels, setTunnels] = useState<Tunnel[]>([]);
|
const [tunnels, setTunnels] = useState<Tunnel[]>([]);
|
||||||
|
const [searchKeyword, setSearchKeyword] = useState("");
|
||||||
|
const [isSearchVisible, setIsSearchVisible] = useState(false);
|
||||||
|
|
||||||
|
const filteredRules = useMemo(() => {
|
||||||
|
if (!searchKeyword.trim()) return rules;
|
||||||
|
const lowerKeyword = searchKeyword.toLowerCase();
|
||||||
|
|
||||||
|
return rules.filter(
|
||||||
|
(r) =>
|
||||||
|
(r.name && r.name.toLowerCase().includes(lowerKeyword)) ||
|
||||||
|
(r.tunnelName && r.tunnelName.toLowerCase().includes(lowerKeyword)),
|
||||||
|
);
|
||||||
|
}, [rules, searchKeyword]);
|
||||||
|
|
||||||
// 模态框状态
|
// 模态框状态
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
@@ -219,10 +238,18 @@ export default function LimitPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-3 lg:px-6 py-8">
|
<AnimatedPage className="px-3 lg:px-6 py-8">
|
||||||
{/* 页面头部 */}
|
<div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-between mb-6 gap-3">
|
||||||
<div className="flex items-center justify-between mb-6">
|
<div className="flex-1 max-w-sm flex items-center gap-2">
|
||||||
<div className="flex-1" />
|
<SearchBar
|
||||||
|
isVisible={isSearchVisible}
|
||||||
|
placeholder="搜索规则名称或绑定隧道"
|
||||||
|
value={searchKeyword}
|
||||||
|
onChange={setSearchKeyword}
|
||||||
|
onClose={() => setIsSearchVisible(false)}
|
||||||
|
onOpen={() => setIsSearchVisible(true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Button color="primary" size="sm" variant="flat" onPress={handleAdd}>
|
<Button color="primary" size="sm" variant="flat" onPress={handleAdd}>
|
||||||
新增
|
新增
|
||||||
@@ -230,138 +257,117 @@ export default function LimitPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 统一卡片网格 */}
|
{/* 统一卡片网格 */}
|
||||||
{rules.length > 0 ? (
|
{filteredRules.length > 0 ? (
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4">
|
<StaggerList className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4">
|
||||||
{rules.map((rule) => (
|
{filteredRules.map((rule) => (
|
||||||
<Card
|
<StaggerItem key={rule.id}>
|
||||||
key={rule.id}
|
<Card className="shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden h-full">
|
||||||
className="shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden"
|
<CardHeader className="pb-2 md:pb-2">
|
||||||
>
|
<div className="flex justify-between items-start w-full">
|
||||||
<CardHeader className="pb-2 md:pb-2">
|
<div>
|
||||||
<div className="flex justify-between items-start w-full">
|
<h3 className="font-semibold text-foreground">
|
||||||
<div>
|
{rule.name}
|
||||||
<h3 className="font-semibold text-foreground">
|
</h3>
|
||||||
{rule.name}
|
</div>
|
||||||
</h3>
|
<Chip
|
||||||
</div>
|
color={rule.status === 1 ? "success" : "danger"}
|
||||||
<Chip
|
size="sm"
|
||||||
color={rule.status === 1 ? "success" : "danger"}
|
variant="flat"
|
||||||
size="sm"
|
>
|
||||||
variant="flat"
|
{rule.status === 1 ? "运行" : "异常"}
|
||||||
>
|
|
||||||
{rule.status === 1 ? "运行" : "异常"}
|
|
||||||
</Chip>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
<CardBody className="pt-0 pb-3 md:pt-0 md:pb-3">
|
|
||||||
<div className="space-y-3">
|
|
||||||
<div className="flex justify-between items-center">
|
|
||||||
<span className="text-small text-default-600">
|
|
||||||
速度限制
|
|
||||||
</span>
|
|
||||||
<Chip color="secondary" size="sm" variant="flat">
|
|
||||||
{rule.speed} Mbps
|
|
||||||
</Chip>
|
</Chip>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between items-center">
|
</CardHeader>
|
||||||
<span className="text-small text-default-600">
|
<CardBody className="pt-0 pb-3 md:pt-0 md:pb-3">
|
||||||
绑定隧道
|
<div className="space-y-3">
|
||||||
</span>
|
<div className="flex justify-between items-center">
|
||||||
{rule.tunnelName ? (
|
<span className="text-small text-default-600">
|
||||||
<Chip color="primary" size="sm" variant="flat">
|
速度限制
|
||||||
{rule.tunnelName}
|
|
||||||
</Chip>
|
|
||||||
) : (
|
|
||||||
<span className="text-default-400 text-small">
|
|
||||||
未绑定
|
|
||||||
</span>
|
</span>
|
||||||
)}
|
<Chip color="secondary" size="sm" variant="flat">
|
||||||
|
{rule.speed} Mbps
|
||||||
|
</Chip>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between items-center">
|
||||||
|
<span className="text-small text-default-600">
|
||||||
|
绑定隧道
|
||||||
|
</span>
|
||||||
|
{rule.tunnelName ? (
|
||||||
|
<Chip color="primary" size="sm" variant="flat">
|
||||||
|
{rule.tunnelName}
|
||||||
|
</Chip>
|
||||||
|
) : (
|
||||||
|
<span className="text-default-400 text-small">
|
||||||
|
未绑定
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex gap-2 mt-4">
|
<div className="flex gap-2 mt-4">
|
||||||
<Button
|
<Button
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
color="primary"
|
color="primary"
|
||||||
size="sm"
|
size="sm"
|
||||||
startContent={
|
startContent={
|
||||||
<svg
|
<svg
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className="w-4 h-4"
|
className="w-4 h-4"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
viewBox="0 0 20 20"
|
viewBox="0 0 20 20"
|
||||||
>
|
>
|
||||||
<path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z" />
|
<path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z" />
|
||||||
</svg>
|
</svg>
|
||||||
}
|
}
|
||||||
variant="flat"
|
variant="flat"
|
||||||
onPress={() => handleEdit(rule)}
|
onPress={() => handleEdit(rule)}
|
||||||
>
|
>
|
||||||
编辑
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
color="danger"
|
color="danger"
|
||||||
size="sm"
|
size="sm"
|
||||||
startContent={
|
startContent={
|
||||||
<svg
|
<svg
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className="w-4 h-4"
|
className="w-4 h-4"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
viewBox="0 0 20 20"
|
viewBox="0 0 20 20"
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
clipRule="evenodd"
|
clipRule="evenodd"
|
||||||
d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"
|
d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"
|
||||||
fillRule="evenodd"
|
fillRule="evenodd"
|
||||||
/>
|
/>
|
||||||
<path
|
<path
|
||||||
clipRule="evenodd"
|
clipRule="evenodd"
|
||||||
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8 7a1 1 0 012 0v4a1 1 0 11-2 0V7zM12 7a1 1 0 012 0v4a1 1 0 11-2 0V7z"
|
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8 7a1 1 0 012 0v4a1 1 0 11-2 0V7zM12 7a1 1 0 012 0v4a1 1 0 11-2 0V7z"
|
||||||
fillRule="evenodd"
|
fillRule="evenodd"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
}
|
}
|
||||||
variant="flat"
|
variant="flat"
|
||||||
onPress={() => handleDelete(rule)}
|
onPress={() => handleDelete(rule)}
|
||||||
>
|
>
|
||||||
删除
|
删除
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
|
</StaggerItem>
|
||||||
))}
|
))}
|
||||||
</div>
|
</StaggerList>
|
||||||
) : (
|
) : (
|
||||||
/* 空状态 */
|
/* 空状态 */
|
||||||
<Card className="shadow-sm border border-gray-200 dark:border-gray-700">
|
<Card className="shadow-sm border border-gray-200 dark:border-gray-700 bg-default-50/50">
|
||||||
<CardBody className="text-center py-16">
|
<CardBody className="text-center py-20 flex flex-col items-center justify-center min-h-[240px]">
|
||||||
<div className="flex flex-col items-center gap-4">
|
<h3 className="text-xl font-medium text-foreground tracking-tight mb-2">
|
||||||
<div className="w-16 h-16 bg-default-100 rounded-full flex items-center justify-center">
|
暂无限速规则
|
||||||
<svg
|
</h3>
|
||||||
aria-hidden="true"
|
<p className="text-default-500 text-sm max-w-xs mx-auto leading-relaxed">
|
||||||
className="w-8 h-8 text-default-400"
|
还没有创建任何限速规则,点击上方按钮开始创建
|
||||||
fill="none"
|
</p>
|
||||||
stroke="currentColor"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M12 6v6l4 2m6-6a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
strokeWidth={1.5}
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 className="text-lg font-semibold text-foreground">
|
|
||||||
暂无限速规则
|
|
||||||
</h3>
|
|
||||||
<p className="text-default-500 text-sm mt-1">
|
|
||||||
还没有创建任何限速规则,点击上方按钮开始创建
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
@@ -524,6 +530,6 @@ export default function LimitPage() {
|
|||||||
)}
|
)}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</AnimatedPage>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import {
|
|||||||
} from "@dnd-kit/sortable";
|
} from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
import { CSS } from "@dnd-kit/utilities";
|
||||||
|
|
||||||
|
import { SearchBar } from "@/components/search-bar";
|
||||||
|
import { AnimatedPage } from "@/components/animated-page";
|
||||||
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
||||||
import { Button } from "@/shadcn-bridge/heroui/button";
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
import { Input } from "@/shadcn-bridge/heroui/input";
|
import { Input } from "@/shadcn-bridge/heroui/input";
|
||||||
@@ -49,6 +51,7 @@ import {
|
|||||||
batchUpgradeNodes,
|
batchUpgradeNodes,
|
||||||
getNodeReleases,
|
getNodeReleases,
|
||||||
rollbackNode,
|
rollbackNode,
|
||||||
|
type ReleaseChannel,
|
||||||
} from "@/api";
|
} from "@/api";
|
||||||
import { PageEmptyState, PageLoadingState } from "@/components/page-state";
|
import { PageEmptyState, PageLoadingState } from "@/components/page-state";
|
||||||
import {
|
import {
|
||||||
@@ -126,11 +129,14 @@ const SortableItem = ({
|
|||||||
isDragging,
|
isDragging,
|
||||||
} = useSortable({ id });
|
} = useSortable({ id });
|
||||||
|
|
||||||
const style = {
|
const style: React.CSSProperties = {
|
||||||
transform: transform ? CSS.Transform.toString(transform) : undefined,
|
transform: transform ? CSS.Transform.toString(transform) : undefined,
|
||||||
transition: isDragging ? undefined : transition || undefined,
|
transition: isDragging ? undefined : transition || undefined,
|
||||||
opacity: isDragging ? 0.5 : 1,
|
opacity: isDragging ? 0.5 : 1,
|
||||||
willChange: "transform",
|
willChange: "transform",
|
||||||
|
backfaceVisibility: "hidden",
|
||||||
|
WebkitFontSmoothing: "antialiased",
|
||||||
|
MozOsxFontSmoothing: "grayscale",
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -149,6 +155,8 @@ export default function NodePage() {
|
|||||||
const [nodeList, setNodeList] = useState<Node[]>([]);
|
const [nodeList, setNodeList] = useState<Node[]>([]);
|
||||||
const [nodeOrder, setNodeOrder] = useState<number[]>([]);
|
const [nodeOrder, setNodeOrder] = useState<number[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [searchKeyword, setSearchKeyword] = useState("");
|
||||||
|
const [isSearchVisible, setIsSearchVisible] = useState(false);
|
||||||
const [dialogVisible, setDialogVisible] = useState(false);
|
const [dialogVisible, setDialogVisible] = useState(false);
|
||||||
const [dialogTitle, setDialogTitle] = useState("");
|
const [dialogTitle, setDialogTitle] = useState("");
|
||||||
const [isEdit, setIsEdit] = useState(false);
|
const [isEdit, setIsEdit] = useState(false);
|
||||||
@@ -183,6 +191,10 @@ export default function NodePage() {
|
|||||||
const [installCommandModal, setInstallCommandModal] = useState(false);
|
const [installCommandModal, setInstallCommandModal] = useState(false);
|
||||||
const [installCommand, setInstallCommand] = useState("");
|
const [installCommand, setInstallCommand] = useState("");
|
||||||
const [currentNodeName, setCurrentNodeName] = useState("");
|
const [currentNodeName, setCurrentNodeName] = useState("");
|
||||||
|
const [installSelectorOpen, setInstallSelectorOpen] = useState(false);
|
||||||
|
const [installTargetNode, setInstallTargetNode] = useState<Node | null>(null);
|
||||||
|
const [installChannel, setInstallChannel] =
|
||||||
|
useState<ReleaseChannel>("stable");
|
||||||
|
|
||||||
// 升级相关状态
|
// 升级相关状态
|
||||||
const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);
|
const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);
|
||||||
@@ -198,9 +210,12 @@ export default function NodePage() {
|
|||||||
name: string;
|
name: string;
|
||||||
publishedAt: string;
|
publishedAt: string;
|
||||||
prerelease: boolean;
|
prerelease: boolean;
|
||||||
|
channel: ReleaseChannel;
|
||||||
}>
|
}>
|
||||||
>([]);
|
>([]);
|
||||||
const [releasesLoading, setReleasesLoading] = useState(false);
|
const [releasesLoading, setReleasesLoading] = useState(false);
|
||||||
|
const [releaseChannel, setReleaseChannel] =
|
||||||
|
useState<ReleaseChannel>("stable");
|
||||||
const [selectedVersion, setSelectedVersion] = useState("");
|
const [selectedVersion, setSelectedVersion] = useState("");
|
||||||
const [batchUpgradeLoading, setBatchUpgradeLoading] = useState(false);
|
const [batchUpgradeLoading, setBatchUpgradeLoading] = useState(false);
|
||||||
const [upgradeProgress, setUpgradeProgress] = useState<
|
const [upgradeProgress, setUpgradeProgress] = useState<
|
||||||
@@ -609,20 +624,31 @@ export default function NodePage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openInstallSelector = (node: Node) => {
|
||||||
|
setInstallTargetNode(node);
|
||||||
|
setInstallChannel("stable");
|
||||||
|
setInstallSelectorOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
// 复制安装命令
|
// 复制安装命令
|
||||||
const handleCopyInstallCommand = async (node: Node) => {
|
const handleCopyInstallCommand = async (
|
||||||
|
node: Node,
|
||||||
|
channel: ReleaseChannel,
|
||||||
|
) => {
|
||||||
setNodeList((prev) =>
|
setNodeList((prev) =>
|
||||||
prev.map((n) => (n.id === node.id ? { ...n, copyLoading: true } : n)),
|
prev.map((n) => (n.id === node.id ? { ...n, copyLoading: true } : n)),
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getNodeInstallCommand(node.id);
|
const res = await getNodeInstallCommand(node.id, channel);
|
||||||
|
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
const copied = await tryCopyInstallCommand(res.data);
|
const copied = await tryCopyInstallCommand(res.data);
|
||||||
|
|
||||||
if (copied) {
|
if (copied) {
|
||||||
toast.success("安装命令已复制到剪贴板");
|
toast.success(
|
||||||
|
`${channel === "stable" ? "正式版" : "测试版"}安装命令已复制到剪贴板`,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
setInstallCommand(res.data);
|
setInstallCommand(res.data);
|
||||||
setCurrentNodeName(node.name);
|
setCurrentNodeName(node.name);
|
||||||
@@ -640,6 +666,13 @@ export default function NodePage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleConfirmInstallCommand = async () => {
|
||||||
|
if (!installTargetNode) return;
|
||||||
|
|
||||||
|
setInstallSelectorOpen(false);
|
||||||
|
await handleCopyInstallCommand(installTargetNode, installChannel);
|
||||||
|
};
|
||||||
|
|
||||||
// 手动复制安装命令
|
// 手动复制安装命令
|
||||||
const handleManualCopy = async () => {
|
const handleManualCopy = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -651,18 +684,10 @@ export default function NodePage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 打开版本选择弹窗
|
const loadReleasesByChannel = useCallback(async (channel: ReleaseChannel) => {
|
||||||
const openUpgradeModal = async (
|
|
||||||
target: "single" | "batch",
|
|
||||||
nodeId?: number,
|
|
||||||
) => {
|
|
||||||
setUpgradeTarget(target);
|
|
||||||
setUpgradeTargetNodeId(nodeId || null);
|
|
||||||
setSelectedVersion("");
|
|
||||||
setUpgradeModalOpen(true);
|
|
||||||
setReleasesLoading(true);
|
setReleasesLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await getNodeReleases();
|
const res = await getNodeReleases(channel);
|
||||||
|
|
||||||
if (res.code === 0 && Array.isArray(res.data)) {
|
if (res.code === 0 && Array.isArray(res.data)) {
|
||||||
setReleases(res.data);
|
setReleases(res.data);
|
||||||
@@ -674,6 +699,21 @@ export default function NodePage() {
|
|||||||
} finally {
|
} finally {
|
||||||
setReleasesLoading(false);
|
setReleasesLoading(false);
|
||||||
}
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 打开版本选择弹窗
|
||||||
|
const openUpgradeModal = async (
|
||||||
|
target: "single" | "batch",
|
||||||
|
nodeId?: number,
|
||||||
|
) => {
|
||||||
|
const defaultChannel: ReleaseChannel = "stable";
|
||||||
|
|
||||||
|
setUpgradeTarget(target);
|
||||||
|
setUpgradeTargetNodeId(nodeId || null);
|
||||||
|
setReleaseChannel(defaultChannel);
|
||||||
|
setSelectedVersion("");
|
||||||
|
setUpgradeModalOpen(true);
|
||||||
|
await loadReleasesByChannel(defaultChannel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 确认升级(从版本弹窗)
|
// 确认升级(从版本弹窗)
|
||||||
@@ -692,7 +732,11 @@ export default function NodePage() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
const res = await upgradeNode(upgradeTargetNodeId, version);
|
const res = await upgradeNode(
|
||||||
|
upgradeTargetNodeId,
|
||||||
|
version,
|
||||||
|
releaseChannel,
|
||||||
|
);
|
||||||
|
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
toast.success(`节点升级命令已发送,节点将自动重启`);
|
toast.success(`节点升级命令已发送,节点将自动重启`);
|
||||||
@@ -712,7 +756,11 @@ export default function NodePage() {
|
|||||||
setBatchUpgradeLoading(true);
|
setBatchUpgradeLoading(true);
|
||||||
setUpgradeModalOpen(false);
|
setUpgradeModalOpen(false);
|
||||||
try {
|
try {
|
||||||
const res = await batchUpgradeNodes(Array.from(selectedIds), version);
|
const res = await batchUpgradeNodes(
|
||||||
|
Array.from(selectedIds),
|
||||||
|
version,
|
||||||
|
releaseChannel,
|
||||||
|
);
|
||||||
|
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
toast.success(`批量升级命令已发送到 ${selectedIds.size} 个节点`);
|
toast.success(`批量升级命令已发送到 ${selectedIds.size} 个节点`);
|
||||||
@@ -953,7 +1001,21 @@ export default function NodePage() {
|
|||||||
const sortedNodes = useMemo((): Node[] => {
|
const sortedNodes = useMemo((): Node[] => {
|
||||||
if (!nodeList || nodeList.length === 0) return [];
|
if (!nodeList || nodeList.length === 0) return [];
|
||||||
|
|
||||||
const sortedByDb = [...nodeList].sort((a, b) => {
|
let filteredNodes = nodeList;
|
||||||
|
|
||||||
|
if (searchKeyword.trim()) {
|
||||||
|
const lowerKeyword = searchKeyword.toLowerCase();
|
||||||
|
|
||||||
|
filteredNodes = filteredNodes.filter(
|
||||||
|
(n) =>
|
||||||
|
(n.name && n.name.toLowerCase().includes(lowerKeyword)) ||
|
||||||
|
(n.serverIp && n.serverIp.toLowerCase().includes(lowerKeyword)) ||
|
||||||
|
(n.serverIpV4 && n.serverIpV4.toLowerCase().includes(lowerKeyword)) ||
|
||||||
|
(n.serverIpV6 && n.serverIpV6.toLowerCase().includes(lowerKeyword)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortedByDb = [...filteredNodes].sort((a, b) => {
|
||||||
const aInx = a.inx ?? 0;
|
const aInx = a.inx ?? 0;
|
||||||
const bInx = b.inx ?? 0;
|
const bInx = b.inx ?? 0;
|
||||||
|
|
||||||
@@ -966,7 +1028,7 @@ export default function NodePage() {
|
|||||||
nodeOrder.length > 0 &&
|
nodeOrder.length > 0 &&
|
||||||
sortedByDb.every((n) => n.inx === undefined || n.inx === 0)
|
sortedByDb.every((n) => n.inx === undefined || n.inx === 0)
|
||||||
) {
|
) {
|
||||||
const nodeMap = new Map(nodeList.map((n) => [n.id, n] as const));
|
const nodeMap = new Map(filteredNodes.map((n) => [n.id, n] as const));
|
||||||
const localSorted: Node[] = [];
|
const localSorted: Node[] = [];
|
||||||
|
|
||||||
nodeOrder.forEach((id) => {
|
nodeOrder.forEach((id) => {
|
||||||
@@ -975,7 +1037,7 @@ export default function NodePage() {
|
|||||||
if (node) localSorted.push(node);
|
if (node) localSorted.push(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
nodeList.forEach((node) => {
|
filteredNodes.forEach((node) => {
|
||||||
if (!nodeOrder.includes(node.id)) {
|
if (!nodeOrder.includes(node.id)) {
|
||||||
localSorted.push(node);
|
localSorted.push(node);
|
||||||
}
|
}
|
||||||
@@ -985,7 +1047,7 @@ export default function NodePage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return sortedByDb;
|
return sortedByDb;
|
||||||
}, [nodeList, nodeOrder]);
|
}, [nodeList, nodeOrder, searchKeyword]);
|
||||||
|
|
||||||
const sortableNodeIds = useMemo(
|
const sortableNodeIds = useMemo(
|
||||||
() => sortedNodes.map((n) => n.id),
|
() => sortedNodes.map((n) => n.id),
|
||||||
@@ -993,14 +1055,22 @@ export default function NodePage() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-3 lg:px-6 py-8">
|
<AnimatedPage className="px-3 lg:px-6 py-8">
|
||||||
{/* 页面头部 */}
|
<div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-between mb-6 gap-3">
|
||||||
<div className="flex items-center justify-between mb-6">
|
<div className="flex-1 max-w-sm flex items-center gap-2">
|
||||||
<div className="flex-1" />
|
<SearchBar
|
||||||
|
isVisible={isSearchVisible}
|
||||||
|
placeholder="搜索节点名称或IP"
|
||||||
|
value={searchKeyword}
|
||||||
|
onChange={setSearchKeyword}
|
||||||
|
onClose={() => setIsSearchVisible(false)}
|
||||||
|
onOpen={() => setIsSearchVisible(true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex gap-2 items-center">
|
<div className="flex gap-2 items-center">
|
||||||
<Button
|
<Button
|
||||||
color="default"
|
color={selectMode ? "secondary" : "default"}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant={selectMode ? "solid" : "flat"}
|
variant={selectMode ? "solid" : "flat"}
|
||||||
onPress={toggleSelectMode}
|
onPress={toggleSelectMode}
|
||||||
@@ -1367,7 +1437,7 @@ export default function NodePage() {
|
|||||||
isLoading={node.copyLoading}
|
isLoading={node.copyLoading}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="flat"
|
variant="flat"
|
||||||
onPress={() => handleCopyInstallCommand(node)}
|
onPress={() => openInstallSelector(node)}
|
||||||
>
|
>
|
||||||
安装
|
安装
|
||||||
</Button>
|
</Button>
|
||||||
@@ -1811,6 +1881,55 @@ export default function NodePage() {
|
|||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
backdrop="blur"
|
||||||
|
isOpen={installSelectorOpen}
|
||||||
|
placement="center"
|
||||||
|
size="md"
|
||||||
|
onOpenChange={setInstallSelectorOpen}
|
||||||
|
>
|
||||||
|
<ModalContent>
|
||||||
|
{(onClose) => (
|
||||||
|
<>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
<h2 className="text-xl font-bold">
|
||||||
|
选择安装通道
|
||||||
|
{installTargetNode ? ` - ${installTargetNode.name}` : ""}
|
||||||
|
</h2>
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Select
|
||||||
|
label="版本通道"
|
||||||
|
selectedKeys={[installChannel]}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selected = Array.from(keys)[0] as ReleaseChannel;
|
||||||
|
|
||||||
|
setInstallChannel(selected || "stable");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectItem key="stable" textValue="stable">
|
||||||
|
正式版(纯数字版本,如 2.1.4)
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem key="dev" textValue="dev">
|
||||||
|
测试版(含 alpha / beta / rc)
|
||||||
|
</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button variant="light" onPress={onClose}>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button color="primary" onPress={handleConfirmInstallCommand}>
|
||||||
|
生成命令
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
{/* 安装命令模态框 */}
|
{/* 安装命令模态框 */}
|
||||||
<Modal
|
<Modal
|
||||||
backdrop="blur"
|
backdrop="blur"
|
||||||
@@ -1891,9 +2010,28 @@ export default function NodePage() {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
<Select
|
||||||
|
label="版本通道"
|
||||||
|
selectedKeys={[releaseChannel]}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selected =
|
||||||
|
(Array.from(keys)[0] as ReleaseChannel) || "stable";
|
||||||
|
|
||||||
|
setReleaseChannel(selected);
|
||||||
|
setSelectedVersion("");
|
||||||
|
void loadReleasesByChannel(selected);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectItem key="stable" textValue="stable">
|
||||||
|
正式版(纯数字版本,如 2.1.4)
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem key="dev" textValue="dev">
|
||||||
|
测试版(含 alpha / beta / rc)
|
||||||
|
</SelectItem>
|
||||||
|
</Select>
|
||||||
<Select
|
<Select
|
||||||
label="选择版本"
|
label="选择版本"
|
||||||
placeholder="留空则使用最新版本"
|
placeholder="留空则使用当前通道最新版本"
|
||||||
selectedKeys={selectedVersion ? [selectedVersion] : []}
|
selectedKeys={selectedVersion ? [selectedVersion] : []}
|
||||||
onSelectionChange={(keys) => {
|
onSelectionChange={(keys) => {
|
||||||
const selected = Array.from(keys)[0] as string;
|
const selected = Array.from(keys)[0] as string;
|
||||||
@@ -1909,14 +2047,14 @@ export default function NodePage() {
|
|||||||
{r.publishedAt
|
{r.publishedAt
|
||||||
? new Date(r.publishedAt).toLocaleDateString()
|
? new Date(r.publishedAt).toLocaleDateString()
|
||||||
: ""}
|
: ""}
|
||||||
{r.prerelease && (
|
{r.channel === "dev" && (
|
||||||
<Chip
|
<Chip
|
||||||
className="ml-1"
|
className="ml-1"
|
||||||
color="warning"
|
color="warning"
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="flat"
|
variant="flat"
|
||||||
>
|
>
|
||||||
预览
|
测试
|
||||||
</Chip>
|
</Chip>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
@@ -1927,7 +2065,7 @@ export default function NodePage() {
|
|||||||
<p className="text-sm text-default-500">
|
<p className="text-sm text-default-500">
|
||||||
{selectedVersion
|
{selectedVersion
|
||||||
? `将升级到版本 ${selectedVersion}`
|
? `将升级到版本 ${selectedVersion}`
|
||||||
: "未选择版本,将自动使用最新稳定版"}
|
: `未选择版本,将自动使用最新${releaseChannel === "stable" ? "正式" : "测试"}版`}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -1989,6 +2127,6 @@ export default function NodePage() {
|
|||||||
)}
|
)}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</AnimatedPage>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -409,14 +409,15 @@ export default function PanelSharingPage() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Card>
|
<Card>
|
||||||
<CardBody className="space-y-5 pt-4 md:pt-6">
|
<CardBody className="space-y-5">
|
||||||
<div className="flex flex-col gap-4 rounded-lg border border-divider bg-default-50/60 dark:bg-default-100/20 p-4 md:flex-row md:items-center md:justify-between">
|
<div className="mt-4 flex flex-col gap-4 rounded-lg border border-divider bg-default-50/60 dark:bg-default-100/20 p-4 md:flex-row md:items-center md:justify-between">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<h2 className="text-lg font-semibold text-foreground">
|
<h2 className="text-lg font-semibold text-foreground">
|
||||||
Provider 共享
|
Provider 共享
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-sm text-default-500">
|
<p className="text-sm text-default-500">
|
||||||
将本地节点分享给其他面板,统一管理 Token、端口范围和到期策略。
|
将本地节点分享给其他面板,统一管理
|
||||||
|
Token、端口范围和到期策略。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
@@ -429,7 +430,9 @@ export default function PanelSharingPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="text-center py-12 text-default-500">加载中...</div>
|
<div className="text-center py-12 text-default-500">
|
||||||
|
加载中...
|
||||||
|
</div>
|
||||||
) : shares.length === 0 ? (
|
) : shares.length === 0 ? (
|
||||||
<div className="rounded-lg border border-dashed border-divider bg-default-50/60 dark:bg-default-100/20 px-6 py-10 text-center">
|
<div className="rounded-lg border border-dashed border-divider bg-default-50/60 dark:bg-default-100/20 px-6 py-10 text-center">
|
||||||
<p className="text-base font-semibold text-foreground">
|
<p className="text-base font-semibold text-foreground">
|
||||||
@@ -554,8 +557,8 @@ export default function PanelSharingPage() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Card>
|
<Card>
|
||||||
<CardBody className="space-y-5 pt-4 md:pt-6">
|
<CardBody className="space-y-5">
|
||||||
<div className="flex flex-col gap-4 rounded-lg border border-divider bg-default-50/60 dark:bg-default-100/20 p-4 md:flex-row md:items-center md:justify-between">
|
<div className="mt-4 flex flex-col gap-4 rounded-lg border border-divider bg-default-50/60 dark:bg-default-100/20 p-4 md:flex-row md:items-center md:justify-between">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<h2 className="text-lg font-semibold text-foreground">
|
<h2 className="text-lg font-semibold text-foreground">
|
||||||
Consumer 接入
|
Consumer 接入
|
||||||
@@ -574,7 +577,9 @@ export default function PanelSharingPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{remoteUsageLoading ? (
|
{remoteUsageLoading ? (
|
||||||
<div className="text-center py-12 text-default-500">加载中...</div>
|
<div className="text-center py-12 text-default-500">
|
||||||
|
加载中...
|
||||||
|
</div>
|
||||||
) : remoteUsageNodes.length === 0 ? (
|
) : remoteUsageNodes.length === 0 ? (
|
||||||
<div className="rounded-lg border border-dashed border-divider bg-default-50/60 dark:bg-default-100/20 px-6 py-10 text-center">
|
<div className="rounded-lg border border-dashed border-divider bg-default-50/60 dark:bg-default-100/20 px-6 py-10 text-center">
|
||||||
<p className="text-base font-semibold text-foreground">
|
<p className="text-base font-semibold text-foreground">
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { useState, useEffect, useMemo } from "react";
|
import { useState, useEffect, useMemo } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import { AnimatedPage } from "@/components/animated-page";
|
||||||
|
import { SearchBar } from "@/components/search-bar";
|
||||||
import {
|
import {
|
||||||
DndContext,
|
DndContext,
|
||||||
KeyboardSensor,
|
KeyboardSensor,
|
||||||
@@ -17,7 +19,6 @@ import {
|
|||||||
useSortable,
|
useSortable,
|
||||||
} from "@dnd-kit/sortable";
|
} from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
import { CSS } from "@dnd-kit/utilities";
|
||||||
|
|
||||||
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
||||||
import { Button } from "@/shadcn-bridge/heroui/button";
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
import { Input, Textarea } from "@/shadcn-bridge/heroui/input";
|
import { Input, Textarea } from "@/shadcn-bridge/heroui/input";
|
||||||
@@ -111,6 +112,8 @@ export default function TunnelPage() {
|
|||||||
const [tunnels, setTunnels] = useState<Tunnel[]>([]);
|
const [tunnels, setTunnels] = useState<Tunnel[]>([]);
|
||||||
const [tunnelOrder, setTunnelOrder] = useState<number[]>([]);
|
const [tunnelOrder, setTunnelOrder] = useState<number[]>([]);
|
||||||
const [nodes, setNodes] = useState<Node[]>([]);
|
const [nodes, setNodes] = useState<Node[]>([]);
|
||||||
|
const [searchKeyword, setSearchKeyword] = useState("");
|
||||||
|
const [isSearchVisible, setIsSearchVisible] = useState(false);
|
||||||
|
|
||||||
// 模态框状态
|
// 模态框状态
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
@@ -597,7 +600,17 @@ export default function TunnelPage() {
|
|||||||
const sortedTunnels = useMemo((): Tunnel[] => {
|
const sortedTunnels = useMemo((): Tunnel[] => {
|
||||||
if (!tunnels || tunnels.length === 0) return [];
|
if (!tunnels || tunnels.length === 0) return [];
|
||||||
|
|
||||||
const sortedByDb = [...tunnels].sort((a, b) => {
|
let filteredTunnels = tunnels;
|
||||||
|
|
||||||
|
if (searchKeyword.trim()) {
|
||||||
|
const lowerKeyword = searchKeyword.toLowerCase();
|
||||||
|
filteredTunnels = filteredTunnels.filter(t =>
|
||||||
|
(t.name && t.name.toLowerCase().includes(lowerKeyword)) ||
|
||||||
|
(t.inIp && t.inIp.toLowerCase().includes(lowerKeyword))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortedByDb = [...filteredTunnels].sort((a, b) => {
|
||||||
const aInx = a.inx ?? 0;
|
const aInx = a.inx ?? 0;
|
||||||
const bInx = b.inx ?? 0;
|
const bInx = b.inx ?? 0;
|
||||||
|
|
||||||
@@ -610,7 +623,7 @@ export default function TunnelPage() {
|
|||||||
tunnelOrder.length > 0 &&
|
tunnelOrder.length > 0 &&
|
||||||
sortedByDb.every((t) => t.inx === undefined || t.inx === 0)
|
sortedByDb.every((t) => t.inx === undefined || t.inx === 0)
|
||||||
) {
|
) {
|
||||||
const tunnelMap = new Map(tunnels.map((t) => [t.id, t] as const));
|
const tunnelMap = new Map(filteredTunnels.map((t) => [t.id, t] as const));
|
||||||
const localSorted: Tunnel[] = [];
|
const localSorted: Tunnel[] = [];
|
||||||
|
|
||||||
tunnelOrder.forEach((id) => {
|
tunnelOrder.forEach((id) => {
|
||||||
@@ -619,7 +632,7 @@ export default function TunnelPage() {
|
|||||||
if (tunnel) localSorted.push(tunnel);
|
if (tunnel) localSorted.push(tunnel);
|
||||||
});
|
});
|
||||||
|
|
||||||
tunnels.forEach((tunnel) => {
|
filteredTunnels.forEach((tunnel) => {
|
||||||
if (!tunnelOrder.includes(tunnel.id)) {
|
if (!tunnelOrder.includes(tunnel.id)) {
|
||||||
localSorted.push(tunnel);
|
localSorted.push(tunnel);
|
||||||
}
|
}
|
||||||
@@ -629,7 +642,7 @@ export default function TunnelPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return sortedByDb;
|
return sortedByDb;
|
||||||
}, [tunnels, tunnelOrder]);
|
}, [tunnels, tunnelOrder, searchKeyword]);
|
||||||
|
|
||||||
const sortableTunnelIds = useMemo(
|
const sortableTunnelIds = useMemo(
|
||||||
() => sortedTunnels.map((t) => t.id),
|
() => sortedTunnels.map((t) => t.id),
|
||||||
@@ -652,11 +665,17 @@ export default function TunnelPage() {
|
|||||||
isDragging,
|
isDragging,
|
||||||
} = useSortable({ id });
|
} = useSortable({ id });
|
||||||
|
|
||||||
const style = {
|
const style: React.CSSProperties = {
|
||||||
transform: transform ? CSS.Transform.toString(transform) : undefined,
|
transform: transform
|
||||||
|
? CSS.Transform.toString({
|
||||||
|
...transform,
|
||||||
|
x: Math.round(transform.x),
|
||||||
|
y: Math.round(transform.y),
|
||||||
|
})
|
||||||
|
: undefined,
|
||||||
transition: isDragging ? undefined : transition || undefined,
|
transition: isDragging ? undefined : transition || undefined,
|
||||||
opacity: isDragging ? 0.5 : 1,
|
opacity: isDragging ? 0.5 : 1,
|
||||||
willChange: "transform",
|
willChange: isDragging ? "transform" : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -671,14 +690,22 @@ export default function TunnelPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-3 lg:px-6 py-8">
|
<AnimatedPage className="px-3 lg:px-6 py-8">
|
||||||
{/* 页面头部 */}
|
<div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-between mb-6 gap-3">
|
||||||
<div className="flex items-center justify-between mb-6">
|
<div className="flex-1 max-w-sm flex items-center gap-2">
|
||||||
<div className="flex-1" />
|
<SearchBar
|
||||||
|
isVisible={isSearchVisible}
|
||||||
|
placeholder="搜索隧道名称或IP"
|
||||||
|
value={searchKeyword}
|
||||||
|
onChange={setSearchKeyword}
|
||||||
|
onClose={() => setIsSearchVisible(false)}
|
||||||
|
onOpen={() => setIsSearchVisible(true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
color="default"
|
color={selectMode ? "secondary" : "default"}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant={selectMode ? "solid" : "flat"}
|
variant={selectMode ? "solid" : "flat"}
|
||||||
onPress={toggleSelectMode}
|
onPress={toggleSelectMode}
|
||||||
@@ -1014,34 +1041,14 @@ export default function TunnelPage() {
|
|||||||
</DndContext>
|
</DndContext>
|
||||||
) : (
|
) : (
|
||||||
/* 空状态 */
|
/* 空状态 */
|
||||||
<Card className="shadow-sm border border-gray-200 dark:border-gray-700">
|
<Card className="shadow-sm border border-gray-200 dark:border-gray-700 bg-default-50/50">
|
||||||
<CardBody className="text-center py-16">
|
<CardBody className="text-center py-20 flex flex-col items-center justify-center min-h-[240px]">
|
||||||
<div className="flex flex-col items-center gap-4">
|
<h3 className="text-xl font-medium text-foreground tracking-tight mb-2">
|
||||||
<div className="w-16 h-16 bg-default-100 rounded-full flex items-center justify-center">
|
暂无隧道配置
|
||||||
<svg
|
</h3>
|
||||||
aria-hidden="true"
|
<p className="text-default-500 text-sm max-w-xs mx-auto leading-relaxed">
|
||||||
className="w-8 h-8 text-default-400"
|
还没有创建任何隧道配置,点击上方按钮开始创建
|
||||||
fill="none"
|
</p>
|
||||||
stroke="currentColor"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.141 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
strokeWidth={1.5}
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 className="text-lg font-semibold text-foreground">
|
|
||||||
暂无隧道配置
|
|
||||||
</h3>
|
|
||||||
<p className="text-default-500 text-sm mt-1">
|
|
||||||
还没有创建任何隧道配置,点击上方按钮开始创建
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
@@ -1127,11 +1134,6 @@ export default function TunnelPage() {
|
|||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
endContent={
|
|
||||||
<div className="pointer-events-none flex items-center">
|
|
||||||
<span className="text-default-400 text-small">x</span>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
errorMessage={errors.trafficRatio}
|
errorMessage={errors.trafficRatio}
|
||||||
isInvalid={!!errors.trafficRatio}
|
isInvalid={!!errors.trafficRatio}
|
||||||
label="流量倍率"
|
label="流量倍率"
|
||||||
@@ -1384,6 +1386,7 @@ export default function TunnelPage() {
|
|||||||
.filter((id) => id !== -1)
|
.filter((id) => id !== -1)
|
||||||
.map((id) => id.toString()),
|
.map((id) => id.toString()),
|
||||||
]}
|
]}
|
||||||
|
dropdownPlacement="top"
|
||||||
label="节点"
|
label="节点"
|
||||||
placeholder="选择节点(可多选)"
|
placeholder="选择节点(可多选)"
|
||||||
selectedKeys={groupNodes
|
selectedKeys={groupNodes
|
||||||
@@ -1599,6 +1602,7 @@ export default function TunnelPage() {
|
|||||||
id.toString(),
|
id.toString(),
|
||||||
),
|
),
|
||||||
]}
|
]}
|
||||||
|
dropdownPlacement="top"
|
||||||
errorMessage={errors.outNodeId}
|
errorMessage={errors.outNodeId}
|
||||||
isInvalid={!!errors.outNodeId}
|
isInvalid={!!errors.outNodeId}
|
||||||
label="节点"
|
label="节点"
|
||||||
@@ -2444,6 +2448,6 @@ export default function TunnelPage() {
|
|||||||
)}
|
)}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</AnimatedPage>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+228
-200
@@ -2,6 +2,11 @@ import { useState, useEffect } from "react";
|
|||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { parseDate } from "@internationalized/date";
|
import { parseDate } from "@internationalized/date";
|
||||||
|
|
||||||
|
import {
|
||||||
|
AnimatedPage,
|
||||||
|
StaggerList,
|
||||||
|
StaggerItem,
|
||||||
|
} from "@/components/animated-page";
|
||||||
import { Button } from "@/shadcn-bridge/heroui/button";
|
import { Button } from "@/shadcn-bridge/heroui/button";
|
||||||
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
import { Card, CardBody, CardHeader } from "@/shadcn-bridge/heroui/card";
|
||||||
import { Input } from "@/shadcn-bridge/heroui/input";
|
import { Input } from "@/shadcn-bridge/heroui/input";
|
||||||
@@ -57,7 +62,6 @@ import {
|
|||||||
SearchIcon,
|
SearchIcon,
|
||||||
EditIcon,
|
EditIcon,
|
||||||
DeleteIcon,
|
DeleteIcon,
|
||||||
UserIcon,
|
|
||||||
SettingsIcon,
|
SettingsIcon,
|
||||||
} from "@/components/icons";
|
} from "@/components/icons";
|
||||||
import { PageLoadingState } from "@/components/page-state";
|
import { PageLoadingState } from "@/components/page-state";
|
||||||
@@ -122,6 +126,7 @@ export default function UserPage() {
|
|||||||
const [users, setUsers] = useState<User[]>([]);
|
const [users, setUsers] = useState<User[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [searchKeyword, setSearchKeyword] = useState("");
|
const [searchKeyword, setSearchKeyword] = useState("");
|
||||||
|
const [isSearchVisible, setIsSearchVisible] = useState(false);
|
||||||
const [pagination, setPagination] = useState<PaginationType>({
|
const [pagination, setPagination] = useState<PaginationType>({
|
||||||
current: 1,
|
current: 1,
|
||||||
size: 10,
|
size: 10,
|
||||||
@@ -610,67 +615,89 @@ export default function UserPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-3 lg:px-6 py-8">
|
<AnimatedPage className="px-3 lg:px-6 py-8">
|
||||||
{/* 页面头部 */}
|
{/* 页面头部 */}
|
||||||
<div className="flex flex-col gap-4 mb-6">
|
<div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-between mb-6 gap-3">
|
||||||
<div className="flex items-center gap-3" />
|
<div className="flex-1 max-w-sm flex items-center gap-2">
|
||||||
|
{!isSearchVisible ? (
|
||||||
<div className="flex flex-col sm:flex-row gap-3 items-stretch sm:items-center justify-between">
|
|
||||||
<div className="flex items-center gap-3 flex-1 max-w-md">
|
|
||||||
<Input
|
|
||||||
className="flex-1"
|
|
||||||
classNames={{
|
|
||||||
base: "bg-default-100",
|
|
||||||
input: "bg-transparent",
|
|
||||||
inputWrapper:
|
|
||||||
"bg-default-100 border-2 border-default-200 hover:border-default-300 data-[hover=true]:border-default-300",
|
|
||||||
}}
|
|
||||||
placeholder="搜索用户名"
|
|
||||||
value={searchKeyword}
|
|
||||||
onChange={(e) => setSearchKeyword(e.target.value)}
|
|
||||||
onKeyDown={(e) => e.key === "Enter" && handleSearch()}
|
|
||||||
/>
|
|
||||||
<Button
|
<Button
|
||||||
isIconOnly
|
isIconOnly
|
||||||
aria-label="搜索用户"
|
aria-label="搜索"
|
||||||
className="min-h-10 w-10"
|
className="text-default-600"
|
||||||
color="primary"
|
color="default"
|
||||||
variant="solid"
|
size="sm"
|
||||||
onPress={handleSearch}
|
variant="flat"
|
||||||
|
onPress={() => setIsSearchVisible(true)}
|
||||||
>
|
>
|
||||||
<SearchIcon className="w-4 h-4" />
|
<SearchIcon className="w-4 h-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
) : (
|
||||||
|
<div className="flex w-full items-center gap-2 animate-appearance-in">
|
||||||
<Button color="primary" variant="flat" onPress={handleAdd}>
|
<Input
|
||||||
新增
|
autoFocus
|
||||||
</Button>
|
classNames={{
|
||||||
|
base: "bg-default-100",
|
||||||
|
input: "bg-transparent",
|
||||||
|
inputWrapper:
|
||||||
|
"bg-default-100 border-2 border-default-200 hover:border-default-300 data-[hover=true]:border-default-300",
|
||||||
|
}}
|
||||||
|
placeholder="搜索用户名"
|
||||||
|
value={searchKeyword}
|
||||||
|
onChange={(e) => setSearchKeyword(e.target.value)}
|
||||||
|
onKeyDown={(e) => e.key === "Enter" && handleSearch()}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
aria-label="关闭搜索"
|
||||||
|
className="text-default-600 shrink-0"
|
||||||
|
color="default"
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
onPress={() => {
|
||||||
|
setIsSearchVisible(false);
|
||||||
|
setSearchKeyword("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
className="w-4 h-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Button color="primary" size="sm" variant="flat" onPress={handleAdd}>
|
||||||
|
新增
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 用户列表 */}
|
{/* 用户列表 */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<PageLoadingState message="正在加载..." />
|
<PageLoadingState message="正在加载..." />
|
||||||
) : users.length === 0 ? (
|
) : users.length === 0 ? (
|
||||||
<Card className="shadow-sm border border-gray-200 dark:border-gray-700">
|
<Card className="shadow-sm border border-gray-200 dark:border-gray-700 bg-default-50/50">
|
||||||
<CardBody className="text-center py-16">
|
<CardBody className="text-center py-20 flex flex-col items-center justify-center min-h-[240px]">
|
||||||
<div className="flex flex-col items-center gap-4">
|
<h3 className="text-xl font-medium text-foreground tracking-tight mb-2">
|
||||||
<div className="w-16 h-16 bg-default-100 rounded-full flex items-center justify-center">
|
暂无用户数据
|
||||||
<UserIcon className="w-8 h-8 text-default-400" />
|
</h3>
|
||||||
</div>
|
<p className="text-default-500 text-sm max-w-xs mx-auto leading-relaxed">
|
||||||
<div>
|
还没有创建任何用户,点击上方按钮开始创建
|
||||||
<h3 className="text-lg font-semibold text-foreground">
|
</p>
|
||||||
暂无用户数据
|
|
||||||
</h3>
|
|
||||||
<p className="text-default-500 text-sm mt-1">
|
|
||||||
还没有创建任何用户,点击上方按钮开始创建
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4">
|
<StaggerList className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4">
|
||||||
{users.map((user) => {
|
{users.map((user) => {
|
||||||
const userStatus = getUserStatus(user);
|
const userStatus = getUserStatus(user);
|
||||||
const expStatus = user.expTime
|
const expStatus = user.expTime
|
||||||
@@ -686,169 +713,170 @@ export default function UserPage() {
|
|||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<StaggerItem key={user.id}>
|
||||||
key={user.id}
|
<Card className="shadow-sm border border-divider hover:shadow-md transition-shadow duration-200 overflow-hidden h-full">
|
||||||
className="shadow-sm border border-divider hover:shadow-md transition-shadow duration-200 overflow-hidden"
|
<CardHeader className="pb-2 md:pb-2">
|
||||||
>
|
<div className="flex justify-between items-start w-full">
|
||||||
<CardHeader className="pb-2 md:pb-2">
|
<div className="flex-1 min-w-0">
|
||||||
<div className="flex justify-between items-start w-full">
|
<h3 className="font-semibold text-foreground truncate text-sm">
|
||||||
<div className="flex-1 min-w-0">
|
{user.name || user.user}
|
||||||
<h3 className="font-semibold text-foreground truncate text-sm">
|
</h3>
|
||||||
{user.name || user.user}
|
<p className="text-xs text-default-500 truncate">
|
||||||
</h3>
|
@{user.user}
|
||||||
<p className="text-xs text-default-500 truncate">
|
</p>
|
||||||
@{user.user}
|
</div>
|
||||||
</p>
|
<div className="flex items-center gap-1.5 ml-2">
|
||||||
|
<Chip
|
||||||
|
className="text-xs"
|
||||||
|
color={userStatus.color}
|
||||||
|
size="sm"
|
||||||
|
variant="flat"
|
||||||
|
>
|
||||||
|
{userStatus.text}
|
||||||
|
</Chip>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-1.5 ml-2">
|
</CardHeader>
|
||||||
<Chip
|
|
||||||
className="text-xs"
|
|
||||||
color={userStatus.color}
|
|
||||||
size="sm"
|
|
||||||
variant="flat"
|
|
||||||
>
|
|
||||||
{userStatus.text}
|
|
||||||
</Chip>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardBody className="pt-0 pb-3 md:pt-0 md:pb-3">
|
<CardBody className="pt-0 pb-3 md:pt-0 md:pb-3">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{/* 流量信息 */}
|
{/* 流量信息 */}
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<div className="flex justify-between text-sm">
|
|
||||||
<span className="text-default-600">流量限制</span>
|
|
||||||
<span className="font-medium text-xs">
|
|
||||||
{formatFlow(user.flow, "gb")}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex justify-between text-sm">
|
|
||||||
<span className="text-default-600">已使用</span>
|
|
||||||
<span className="font-medium text-xs text-danger">
|
|
||||||
{formatFlow(usedFlow)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<Progress
|
|
||||||
aria-label={`流量使用 ${flowPercent.toFixed(1)}%`}
|
|
||||||
className="mt-1"
|
|
||||||
color={
|
|
||||||
flowPercent > 90
|
|
||||||
? "danger"
|
|
||||||
: flowPercent > 70
|
|
||||||
? "warning"
|
|
||||||
: "success"
|
|
||||||
}
|
|
||||||
size="sm"
|
|
||||||
value={flowPercent}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 其他信息 */}
|
|
||||||
<div className="space-y-1.5 pt-2 border-t border-divider">
|
|
||||||
<div className="flex justify-between text-sm">
|
|
||||||
<span className="text-default-600">转发数量</span>
|
|
||||||
<span className="font-medium text-xs">{user.num}</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex justify-between text-sm">
|
|
||||||
<span className="text-default-600">重置日期</span>
|
|
||||||
<span className="text-xs">
|
|
||||||
{user.flowResetTime === 0
|
|
||||||
? "不重置"
|
|
||||||
: `每月${user.flowResetTime}号`}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{user.expTime && (
|
|
||||||
<div className="flex justify-between text-sm">
|
<div className="flex justify-between text-sm">
|
||||||
<span className="text-default-600">过期时间</span>
|
<span className="text-default-600">流量限制</span>
|
||||||
<div className="text-right">
|
<span className="font-medium text-xs">
|
||||||
{expStatus && expStatus.color === "success" ? (
|
{formatFlow(user.flow, "gb")}
|
||||||
<div className="text-xs">
|
</span>
|
||||||
{formatDate(user.expTime)}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Chip
|
|
||||||
className="text-xs"
|
|
||||||
color={expStatus?.color || "default"}
|
|
||||||
size="sm"
|
|
||||||
variant="flat"
|
|
||||||
>
|
|
||||||
{expStatus?.text || "未知状态"}
|
|
||||||
</Chip>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
<div className="flex justify-between text-sm">
|
||||||
</div>
|
<span className="text-default-600">已使用</span>
|
||||||
</div>
|
<span className="font-medium text-xs text-danger">
|
||||||
|
{formatFlow(usedFlow)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Progress
|
||||||
|
aria-label={`流量使用 ${flowPercent.toFixed(1)}%`}
|
||||||
|
className="mt-1"
|
||||||
|
color={
|
||||||
|
flowPercent > 90
|
||||||
|
? "danger"
|
||||||
|
: flowPercent > 70
|
||||||
|
? "warning"
|
||||||
|
: "success"
|
||||||
|
}
|
||||||
|
size="sm"
|
||||||
|
value={flowPercent}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="space-y-1.5 mt-3">
|
{/* 其他信息 */}
|
||||||
{/* 第一行:编辑和重置 */}
|
<div className="space-y-1.5 pt-2 border-t border-divider">
|
||||||
<div className="flex gap-1.5">
|
<div className="flex justify-between text-sm">
|
||||||
<Button
|
<span className="text-default-600">转发数量</span>
|
||||||
className="flex-1 min-h-8"
|
<span className="font-medium text-xs">
|
||||||
color="primary"
|
{user.num}
|
||||||
size="sm"
|
</span>
|
||||||
startContent={<EditIcon className="w-3 h-3" />}
|
</div>
|
||||||
variant="flat"
|
<div className="flex justify-between text-sm">
|
||||||
onPress={() => handleEdit(user)}
|
<span className="text-default-600">重置日期</span>
|
||||||
>
|
<span className="text-xs">
|
||||||
编辑
|
{user.flowResetTime === 0
|
||||||
</Button>
|
? "不重置"
|
||||||
<Button
|
: `每月${user.flowResetTime}号`}
|
||||||
className="flex-1 min-h-8"
|
</span>
|
||||||
color="warning"
|
</div>
|
||||||
size="sm"
|
{user.expTime && (
|
||||||
startContent={
|
<div className="flex justify-between text-sm">
|
||||||
<svg
|
<span className="text-default-600">过期时间</span>
|
||||||
aria-hidden="true"
|
<div className="text-right">
|
||||||
className="w-3 h-3"
|
{expStatus && expStatus.color === "success" ? (
|
||||||
fill="currentColor"
|
<div className="text-xs">
|
||||||
viewBox="0 0 20 20"
|
{formatDate(user.expTime)}
|
||||||
>
|
</div>
|
||||||
<path
|
) : (
|
||||||
clipRule="evenodd"
|
<Chip
|
||||||
d="M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z"
|
className="text-xs"
|
||||||
fillRule="evenodd"
|
color={expStatus?.color || "default"}
|
||||||
/>
|
size="sm"
|
||||||
</svg>
|
variant="flat"
|
||||||
}
|
>
|
||||||
variant="flat"
|
{expStatus?.text || "未知状态"}
|
||||||
onPress={() => handleResetFlow(user)}
|
</Chip>
|
||||||
>
|
)}
|
||||||
重置
|
</div>
|
||||||
</Button>
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 第二行:权限和删除 */}
|
<div className="space-y-1.5 mt-3">
|
||||||
<div className="flex gap-1.5">
|
{/* 第一行:编辑和重置 */}
|
||||||
<Button
|
<div className="flex gap-1.5">
|
||||||
className="flex-1 min-h-8"
|
<Button
|
||||||
color="success"
|
className="flex-1 min-h-8"
|
||||||
size="sm"
|
color="primary"
|
||||||
startContent={<SettingsIcon className="w-3 h-3" />}
|
size="sm"
|
||||||
variant="flat"
|
startContent={<EditIcon className="w-3 h-3" />}
|
||||||
onPress={() => handleManageTunnels(user)}
|
variant="flat"
|
||||||
>
|
onPress={() => handleEdit(user)}
|
||||||
权限
|
>
|
||||||
</Button>
|
编辑
|
||||||
<Button
|
</Button>
|
||||||
className="flex-1 min-h-8"
|
<Button
|
||||||
color="danger"
|
className="flex-1 min-h-8"
|
||||||
size="sm"
|
color="warning"
|
||||||
startContent={<DeleteIcon className="w-3 h-3" />}
|
size="sm"
|
||||||
variant="flat"
|
startContent={
|
||||||
onPress={() => handleDelete(user)}
|
<svg
|
||||||
>
|
aria-hidden="true"
|
||||||
删除
|
className="w-3 h-3"
|
||||||
</Button>
|
fill="currentColor"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
clipRule="evenodd"
|
||||||
|
d="M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z"
|
||||||
|
fillRule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
}
|
||||||
|
variant="flat"
|
||||||
|
onPress={() => handleResetFlow(user)}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 第二行:权限和删除 */}
|
||||||
|
<div className="flex gap-1.5">
|
||||||
|
<Button
|
||||||
|
className="flex-1 min-h-8"
|
||||||
|
color="success"
|
||||||
|
size="sm"
|
||||||
|
startContent={<SettingsIcon className="w-3 h-3" />}
|
||||||
|
variant="flat"
|
||||||
|
onPress={() => handleManageTunnels(user)}
|
||||||
|
>
|
||||||
|
权限
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
className="flex-1 min-h-8"
|
||||||
|
color="danger"
|
||||||
|
size="sm"
|
||||||
|
startContent={<DeleteIcon className="w-3 h-3" />}
|
||||||
|
variant="flat"
|
||||||
|
onPress={() => handleDelete(user)}
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</CardBody>
|
||||||
</CardBody>
|
</Card>
|
||||||
</Card>
|
</StaggerItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</StaggerList>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 用户表单模态框 */}
|
{/* 用户表单模态框 */}
|
||||||
@@ -1767,6 +1795,6 @@ export default function UserPage() {
|
|||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</AnimatedPage>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { CalendarIcon } from "lucide-react";
|
|
||||||
|
|
||||||
import { FieldContainer, type FieldMetaProps } from "./shared";
|
import { FieldContainer, type FieldMetaProps } from "./shared";
|
||||||
|
|
||||||
@@ -88,7 +87,6 @@ export function DatePicker({
|
|||||||
value,
|
value,
|
||||||
}: DatePickerProps) {
|
}: DatePickerProps) {
|
||||||
const id = React.useId();
|
const id = React.useId();
|
||||||
const nativePickerRef = React.useRef<HTMLInputElement | null>(null);
|
|
||||||
const formattedValue = React.useMemo(() => formatDateValue(value), [value]);
|
const formattedValue = React.useMemo(() => formatDateValue(value), [value]);
|
||||||
const [textValue, setTextValue] = React.useState(formattedValue);
|
const [textValue, setTextValue] = React.useState(formattedValue);
|
||||||
|
|
||||||
@@ -160,30 +158,6 @@ export function DatePicker({
|
|||||||
setTextValue(formattedValue);
|
setTextValue(formattedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
const openNativePicker = () => {
|
|
||||||
if (isDisabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const picker = nativePickerRef.current;
|
|
||||||
|
|
||||||
if (!picker) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pickerWithShow = picker as HTMLInputElement & {
|
|
||||||
showPicker?: () => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (typeof pickerWithShow.showPicker === "function") {
|
|
||||||
pickerWithShow.showPicker();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
picker.focus();
|
|
||||||
picker.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FieldContainer
|
<FieldContainer
|
||||||
description={description}
|
description={description}
|
||||||
@@ -193,71 +167,40 @@ export function DatePicker({
|
|||||||
isRequired={isRequired}
|
isRequired={isRequired}
|
||||||
label={label}
|
label={label}
|
||||||
>
|
>
|
||||||
{shouldUseTextInput ? (
|
<Input
|
||||||
<div className="flex items-center gap-2">
|
aria-invalid={isInvalid}
|
||||||
<Input
|
className={cn(className)}
|
||||||
aria-invalid={isInvalid}
|
disabled={isDisabled}
|
||||||
className={cn("flex-1", className)}
|
id={id}
|
||||||
disabled={isDisabled}
|
inputMode={shouldUseTextInput ? "numeric" : undefined}
|
||||||
id={id}
|
placeholder={shouldUseTextInput ? "YYYY-MM-DD" : undefined}
|
||||||
inputMode="numeric"
|
required={isRequired}
|
||||||
placeholder="YYYY-MM-DD"
|
type={shouldUseTextInput ? "text" : "date"}
|
||||||
required={isRequired}
|
value={shouldUseTextInput ? textValue : formattedValue}
|
||||||
type="text"
|
onBlur={shouldUseTextInput ? commitTextInput : undefined}
|
||||||
value={textValue}
|
onChange={(event) => {
|
||||||
onBlur={commitTextInput}
|
const nextValue = event.target.value;
|
||||||
onChange={(event) => {
|
|
||||||
const nextValue = event.target.value;
|
|
||||||
|
|
||||||
setTextValue(nextValue);
|
if (shouldUseTextInput) {
|
||||||
notifyTextDateChange(nextValue);
|
setTextValue(nextValue);
|
||||||
}}
|
notifyTextDateChange(nextValue);
|
||||||
onKeyDown={(event) => {
|
|
||||||
if (event.key === "Enter") {
|
return;
|
||||||
event.preventDefault();
|
}
|
||||||
commitTextInput();
|
|
||||||
|
notifyNativeDateChange(nextValue);
|
||||||
|
}}
|
||||||
|
onKeyDown={
|
||||||
|
shouldUseTextInput
|
||||||
|
? (event) => {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
event.preventDefault();
|
||||||
|
commitTextInput();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
: undefined
|
||||||
/>
|
}
|
||||||
<button
|
/>
|
||||||
aria-label="打开日历选择器"
|
|
||||||
className="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-input bg-background text-default-600 shadow-sm transition-colors hover:bg-default-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
|
|
||||||
disabled={isDisabled}
|
|
||||||
type="button"
|
|
||||||
onClick={openNativePicker}
|
|
||||||
>
|
|
||||||
<CalendarIcon className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
<input
|
|
||||||
ref={nativePickerRef}
|
|
||||||
aria-hidden="true"
|
|
||||||
className="sr-only"
|
|
||||||
disabled={isDisabled}
|
|
||||||
tabIndex={-1}
|
|
||||||
type="date"
|
|
||||||
value={formattedValue}
|
|
||||||
onChange={(event) => {
|
|
||||||
const nextValue = event.target.value;
|
|
||||||
|
|
||||||
setTextValue(nextValue);
|
|
||||||
notifyNativeDateChange(nextValue);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Input
|
|
||||||
aria-invalid={isInvalid}
|
|
||||||
className={cn(className)}
|
|
||||||
disabled={isDisabled}
|
|
||||||
id={id}
|
|
||||||
required={isRequired}
|
|
||||||
type="date"
|
|
||||||
value={formattedValue}
|
|
||||||
onChange={(event) => {
|
|
||||||
notifyNativeDateChange(event.target.value);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</FieldContainer>
|
</FieldContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export interface SelectProps<T = unknown> extends FieldMetaProps {
|
|||||||
selectionMode?: SelectionMode;
|
selectionMode?: SelectionMode;
|
||||||
size?: "sm" | "md" | "lg";
|
size?: "sm" | "md" | "lg";
|
||||||
variant?: string;
|
variant?: string;
|
||||||
|
dropdownPlacement?: "bottom" | "top";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectItemProps {
|
export interface SelectItemProps {
|
||||||
@@ -163,6 +164,7 @@ export function Select<T>({
|
|||||||
selectedKeys,
|
selectedKeys,
|
||||||
selectionMode = "single",
|
selectionMode = "single",
|
||||||
size,
|
size,
|
||||||
|
dropdownPlacement = "bottom",
|
||||||
}: SelectProps<T>) {
|
}: SelectProps<T>) {
|
||||||
const generatedId = React.useId();
|
const generatedId = React.useId();
|
||||||
const options = React.useMemo(
|
const options = React.useMemo(
|
||||||
@@ -284,19 +286,22 @@ export function Select<T>({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const placementClasses =
|
||||||
|
dropdownPlacement === "top" ? "bottom-full mb-1" : "top-full mt-1";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="absolute left-0 top-full z-50 mt-1 max-h-56 w-full space-y-1 overflow-y-auto rounded-md border border-divider bg-background p-2 shadow-md"
|
|
||||||
id={`${generatedId}-listbox`}
|
|
||||||
ref={listboxRef}
|
ref={listboxRef}
|
||||||
|
className={cn(
|
||||||
|
"absolute left-0 z-50 w-full space-y-1 overflow-y-auto rounded-md border border-divider bg-background p-2 shadow-md max-h-56",
|
||||||
|
placementClasses,
|
||||||
|
)}
|
||||||
|
id={`${generatedId}-listbox`}
|
||||||
role="listbox"
|
role="listbox"
|
||||||
>
|
>
|
||||||
{options.length === 0 ? (
|
{options.length === 0 ? (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn("px-2 py-1 text-default-500", textSizeClass(size))}
|
||||||
"px-2 py-1 text-default-500",
|
|
||||||
textSizeClass(size),
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
暂无可选项
|
暂无可选项
|
||||||
</div>
|
</div>
|
||||||
@@ -325,9 +330,7 @@ export function Select<T>({
|
|||||||
className={cn(
|
className={cn(
|
||||||
"min-w-0 flex-1 truncate text-left text-foreground",
|
"min-w-0 flex-1 truncate text-left text-foreground",
|
||||||
textSizeClass(size),
|
textSizeClass(size),
|
||||||
optionDisabled
|
optionDisabled ? "cursor-not-allowed" : "cursor-pointer",
|
||||||
? "cursor-not-allowed"
|
|
||||||
: "cursor-pointer",
|
|
||||||
)}
|
)}
|
||||||
disabled={optionDisabled}
|
disabled={optionDisabled}
|
||||||
type="button"
|
type="button"
|
||||||
@@ -354,13 +357,7 @@ export function Select<T>({
|
|||||||
label={label}
|
label={label}
|
||||||
>
|
>
|
||||||
{selectionMode === "multiple" ? (
|
{selectionMode === "multiple" ? (
|
||||||
<div
|
<div ref={containerRef} className={cn("relative w-full", className)}>
|
||||||
ref={containerRef}
|
|
||||||
className={cn(
|
|
||||||
"relative w-full",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
aria-controls={`${generatedId}-listbox`}
|
aria-controls={`${generatedId}-listbox`}
|
||||||
aria-expanded={isExpanded}
|
aria-expanded={isExpanded}
|
||||||
|
|||||||
@@ -4,11 +4,15 @@ import { cn } from "@/lib/utils";
|
|||||||
|
|
||||||
interface TableClassNames {
|
interface TableClassNames {
|
||||||
th?: string;
|
th?: string;
|
||||||
|
td?: string;
|
||||||
|
tr?: string;
|
||||||
wrapper?: string;
|
wrapper?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TableStyleContextValue {
|
interface TableStyleContextValue {
|
||||||
thClassName?: string;
|
thClassName?: string;
|
||||||
|
tdClassName?: string;
|
||||||
|
trClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TableStyleContext = React.createContext<TableStyleContextValue>({});
|
const TableStyleContext = React.createContext<TableStyleContextValue>({});
|
||||||
@@ -24,7 +28,13 @@ export function Table({
|
|||||||
...props
|
...props
|
||||||
}: TableProps) {
|
}: TableProps) {
|
||||||
return (
|
return (
|
||||||
<TableStyleContext.Provider value={{ thClassName: classNames?.th }}>
|
<TableStyleContext.Provider
|
||||||
|
value={{
|
||||||
|
thClassName: classNames?.th,
|
||||||
|
tdClassName: classNames?.td,
|
||||||
|
trClassName: classNames?.tr,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
className={cn("w-full overflow-auto rounded-md", classNames?.wrapper)}
|
className={cn("w-full overflow-auto rounded-md", classNames?.wrapper)}
|
||||||
>
|
>
|
||||||
@@ -62,18 +72,24 @@ interface TableBodyProps<T>
|
|||||||
loadingContent?: React.ReactNode;
|
loadingContent?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TableBody<T>({
|
export const TableBody = React.forwardRef<
|
||||||
children,
|
HTMLTableSectionElement,
|
||||||
className,
|
TableBodyProps<any>
|
||||||
emptyContent,
|
>(function TableBody<T>(
|
||||||
isLoading,
|
{
|
||||||
items,
|
children,
|
||||||
loadingContent,
|
className,
|
||||||
...props
|
emptyContent,
|
||||||
}: TableBodyProps<T>) {
|
isLoading,
|
||||||
|
items,
|
||||||
|
loadingContent,
|
||||||
|
...props
|
||||||
|
}: TableBodyProps<T>,
|
||||||
|
ref: React.Ref<HTMLTableSectionElement>,
|
||||||
|
) {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<tbody className={className} {...props}>
|
<tbody ref={ref} className={className} {...props}>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="p-4 text-center text-default-500" colSpan={999}>
|
<td className="p-4 text-center text-default-500" colSpan={999}>
|
||||||
{loadingContent ?? "加载中..."}
|
{loadingContent ?? "加载中..."}
|
||||||
@@ -86,7 +102,7 @@ export function TableBody<T>({
|
|||||||
if (items && typeof children === "function") {
|
if (items && typeof children === "function") {
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
return (
|
return (
|
||||||
<tbody className={className} {...props}>
|
<tbody ref={ref} className={className} {...props}>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="p-4 text-center text-default-500" colSpan={999}>
|
<td className="p-4 text-center text-default-500" colSpan={999}>
|
||||||
{emptyContent ?? "暂无数据"}
|
{emptyContent ?? "暂无数据"}
|
||||||
@@ -97,7 +113,7 @@ export function TableBody<T>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tbody className={className} {...props}>
|
<tbody ref={ref} className={className} {...props}>
|
||||||
{items.map((item) => {
|
{items.map((item) => {
|
||||||
const key =
|
const key =
|
||||||
typeof item === "object" && item !== null && "id" in item
|
typeof item === "object" && item !== null && "id" in item
|
||||||
@@ -115,7 +131,7 @@ export function TableBody<T>({
|
|||||||
|
|
||||||
if (staticChildren.length === 0) {
|
if (staticChildren.length === 0) {
|
||||||
return (
|
return (
|
||||||
<tbody className={className} {...props}>
|
<tbody ref={ref} className={className} {...props}>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="p-4 text-center text-default-500" colSpan={999}>
|
<td className="p-4 text-center text-default-500" colSpan={999}>
|
||||||
{emptyContent ?? "暂无数据"}
|
{emptyContent ?? "暂无数据"}
|
||||||
@@ -126,11 +142,11 @@ export function TableBody<T>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tbody className={className} {...props}>
|
<tbody ref={ref} className={className} {...props}>
|
||||||
{typeof children === "function" ? null : children}
|
{typeof children === "function" ? null : children}
|
||||||
</tbody>
|
</tbody>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
export function TableColumn({
|
export function TableColumn({
|
||||||
className,
|
className,
|
||||||
@@ -150,12 +166,29 @@ export function TableColumn({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
export const TableRow = React.forwardRef<
|
||||||
|
HTMLTableRowElement,
|
||||||
|
React.ComponentProps<"tr">
|
||||||
|
>(({ className, ...props }, ref) => {
|
||||||
|
const { trClassName } = React.useContext(TableStyleContext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr className={cn("border-b last:border-b-0", className)} {...props} />
|
<tr
|
||||||
|
ref={ref}
|
||||||
|
className={cn("border-b last:border-b-0", trClassName, className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
TableRow.displayName = "TableRow";
|
||||||
|
|
||||||
export function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
export function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||||
return <td className={cn("px-3 py-2 align-middle", className)} {...props} />;
|
const { tdClassName } = React.useContext(TableStyleContext);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
className={cn("px-3 py-2 align-middle", tdClassName, className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
@import "tw-animate-css";
|
@import "tw-animate-css";
|
||||||
@import "./tailwind-theme.pcss";
|
@import "./tailwind-theme.pcss";
|
||||||
|
|
||||||
|
/* GPU acceleration helper - prevents font blurriness during transforms */
|
||||||
|
.gpu-accelerated {
|
||||||
|
will-change: transform;
|
||||||
|
backface-visibility: hidden;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--safe-area-top: env(safe-area-inset-top, 0px);
|
--safe-area-top: env(safe-area-inset-top, 0px);
|
||||||
--safe-area-bottom: env(safe-area-inset-bottom, 0px);
|
--safe-area-bottom: env(safe-area-inset-bottom, 0px);
|
||||||
@@ -181,12 +189,12 @@ body {
|
|||||||
@keyframes captchaModalIn {
|
@keyframes captchaModalIn {
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: scale(0.9) translateY(-20px);
|
transform: translateY(-20px);
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: scale(1) translateY(0);
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user