feat: unify directory tree select component and support file sorting (#110)

This commit is contained in:
duorameng
2026-06-10 17:33:23 +08:00
parent bf2cc7da0e
commit b1509a3afb
8 changed files with 225 additions and 154 deletions
+11 -3
View File
@@ -35,6 +35,7 @@ type FileNode struct {
Name string `json:"name"`
Path string `json:"path"`
IsDir bool `json:"isDir"`
ModTime int64 `json:"modTime"`
Children []*FileNode `json:"children,omitempty"`
}
@@ -84,6 +85,12 @@ func (fc *FileController) GetFileTree(c *gin.Context) {
relPath, _ := filepath.Rel(fc.workDir, path)
parts := strings.Split(relPath, string(filepath.Separator))
info, err := d.Info()
var modTime int64
if err == nil {
modTime = info.ModTime().UnixMilli()
}
current := root
for i, part := range parts {
found := false
@@ -98,9 +105,10 @@ func (fc *FileController) GetFileTree(c *gin.Context) {
isLast := i == len(parts)-1
isDir := !isLast || d.IsDir()
node := &FileNode{
Name: part,
Path: strings.Join(parts[:i+1], "/"),
IsDir: isDir,
Name: part,
Path: strings.Join(parts[:i+1], "/"),
IsDir: isDir,
ModTime: modTime,
}
if isDir {
node.Children = []*FileNode{}