文件树图标
This commit is contained in:
parent
f58bde2a5b
commit
4df665485d
|
@ -47,21 +47,16 @@ func GetFile(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
path := args["path"].(string)
|
path := args["path"].(string)
|
||||||
|
|
||||||
buf, _ := ioutil.ReadFile(path)
|
buf, _ := ioutil.ReadFile(path)
|
||||||
|
|
||||||
idx := strings.LastIndex(path, ".")
|
extension := filepath.Ext(path)
|
||||||
extension := ""
|
|
||||||
if 0 <= idx {
|
|
||||||
extension = path[idx:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// 通过文件扩展名判断是否是图片文件(图片在浏览器里新建 tab 打开)
|
// 通过文件扩展名判断是否是图片文件(图片在浏览器里新建 tab 打开)
|
||||||
if isImg(extension) {
|
if isImg(extension) {
|
||||||
data["mode"] = "img"
|
data["mode"] = "img"
|
||||||
|
|
||||||
path2 := strings.Replace(path, "\\", "/", -1)
|
path2 := strings.Replace(path, "\\", "/", -1)
|
||||||
idx = strings.Index(path2, "/data/user_workspaces")
|
idx := strings.Index(path2, "/data/user_workspaces")
|
||||||
data["path"] = path2[idx:]
|
data["path"] = path2[idx:]
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -171,7 +166,7 @@ func RemoveFile(w http.ResponseWriter, r *http.Request) {
|
||||||
type FileNode struct {
|
type FileNode struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
IconSkin string `json:"iconSkin"`
|
IconSkin string `json:"iconSkin"` // 值的末尾应该有一个空格
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
FileNodes []*FileNode `json:"children"`
|
FileNodes []*FileNode `json:"children"`
|
||||||
}
|
}
|
||||||
|
@ -200,14 +195,9 @@ func walk(path string, info os.FileInfo, node *FileNode) {
|
||||||
walk(fpath, fio, &child)
|
walk(fpath, fio, &child)
|
||||||
} else {
|
} else {
|
||||||
child.Type = "f"
|
child.Type = "f"
|
||||||
|
ext := filepath.Ext(fpath)
|
||||||
|
|
||||||
idx := strings.LastIndex(fpath, ".")
|
child.IconSkin = getIconSkin(ext)
|
||||||
extension := ""
|
|
||||||
if 0 <= idx {
|
|
||||||
extension = fpath[idx:]
|
|
||||||
}
|
|
||||||
|
|
||||||
child.IconSkin = getIconSkin(extension)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,6 +240,8 @@ func getIconSkin(filenameExtension string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch filenameExtension {
|
switch filenameExtension {
|
||||||
|
case ".gitignore":
|
||||||
|
return "ico-ztree-other "
|
||||||
case ".json":
|
case ".json":
|
||||||
return "ico-ztree-js "
|
return "ico-ztree-js "
|
||||||
case ".txt":
|
case ".txt":
|
||||||
|
|
Loading…
Reference in New Issue