添加FileListItem右键菜单和部分事件

main
karlis 2023-07-06 16:09:26 +08:00
parent f85d98082e
commit 42b9ecf2ff
2 changed files with 141 additions and 80 deletions

View File

@ -38,6 +38,7 @@ Item {
Component { Component {
id: fileListItemHeader id: fileListItemHeader
ColumnLayout { ColumnLayout {
id: topColumnLayout
function add(folderName, uuid) { function add(folderName, uuid) {
console.log(header.items) console.log(header.items)
header.items = header.items.concat([{ header.items = header.items.concat([{
@ -45,6 +46,77 @@ Item {
"uuid": uuid "uuid": uuid
}]) }])
} }
function update() {
var uuid = header.items.length
=== 0 ? "null" : header.items[header.items.length - 1].uuid
Request.get("/knowledge/" + uuid, function (response) {
var data = JSON.parse(response)
console.log(response)
console.log(data.knowledgeFileAttribute)
fileListModel.clear()
var files = data.children
for (var i = 0; i < files.length; i++) {
var file = files[i]
console.log(file.name)
var modelItem = {
"title": file.name,
"uuid": file.id,
"date"// cut time after 'T'
: file.createTime.substring(0, 10),
"fuuid": uuid
}
if (file.knowledgeFileAttribute === null) {
modelItem.type = "folder"
modelItem.isDir = true
modelItem.size = 0
} else {
modelItem.isDir = false
modelItem.type = getType(
file.knowledgeFileAttribute.suffix)
modelItem.size = file.knowledgeFileAttribute.size
modelItem.brief = file.knowledgeFileAttribute.brief
modelItem.pageView = file.knowledgeFileAttribute.pageView
modelItem.stars = 0
// merge file.knowledgeFileAttribute.tags array to a string
var tagString = ""
for (var j = 0; j < file.knowledgeFileAttribute.tags.length; j++) {
if (j != 0)
tagString = tagString + ","
tagString = tagString + file.knowledgeFileAttribute.tags[j].name
}
modelItem.tags = tagString
}
fileListModel.append(modelItem)
}
console.log(fileListModel.count)
listView.currentIndex = -1
})
}
function getType(suffix) {
if (suffix === "ppt" || suffix === "pptx")
return "PPT"
else if (suffix === "doc" || suffix === "docx")
return "WORD"
else if (suffix === "pdf")
return "PDF"
else if (suffix === "txt")
return "TXT"
else if (suffix === "xls" || suffix === "xlsx")
return "EXCEL"
else if (suffix === "zip" || suffix === "rar")
return "ZIP"
else if (suffix === "png" || suffix === "jpg"
|| suffix === "jpeg" || suffix === "gif")
return "IMAGE"
else if (suffix === "mp3" || suffix === "wav")
return "AUDIO"
else if (suffix === "mp4" || suffix === "avi"
|| suffix === "rmvb" || suffix === "rm"
|| suffix === "wmv" || suffix === "mkv")
return "VIDEO"
else
return "OTHER"
}
RowLayout { RowLayout {
Layout.preferredWidth: parent.width Layout.preferredWidth: parent.width
Item { Item {
@ -53,14 +125,21 @@ Item {
width: 28 width: 28
InputDialog { InputDialog {
id: dialog id: dialog
title: "新建文件夹" title: "新建文件夹"
buttonFlags: FluContentDialog.PositiveButton buttonFlags: FluContentDialog.PositiveButton
| FluContentDialog.NegativeButton | FluContentDialog.NegativeButton
negativeText: "取消" negativeText: "取消"
positiveText: "确定" positiveText: "确定"
message: "请输入文件夹名称" message: "请输入文件夹名称"
onPositiveClicked: text => { onPositiveClicked: text => {
console.log(text) var param = {
"name": text,
"parentId": header.items[header.items.length
- 1].uuid
}
Request.post(
"/knowledge",
JSON.stringify(param))
} }
} }
@ -77,7 +156,7 @@ Item {
} }
FluButton { FluButton {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: "上传" text: "上传"
onClicked: function () { onClicked: function () {
console.log("click") console.log("click")
fileDialog.open() fileDialog.open()
@ -135,7 +214,7 @@ Item {
header.items = header.items.slice( header.items = header.items.slice(
0, header.count() - 1) 0, header.count() - 1)
} }
fileListItemHeaderItem.update() topColumnLayout.update()
} }
} }
FluBreadcrumbBar { FluBreadcrumbBar {
@ -150,81 +229,9 @@ Item {
} }
} }
onItemsChanged: { onItemsChanged: {
fileListItemHeaderItem.update() topColumnLayout.update()
} }
} }
function getType(suffix) {
if (suffix === "ppt" || suffix === "pptx")
return "PPT"
else if (suffix === "doc" || suffix === "docx")
return "WORD"
else if (suffix === "pdf")
return "PDF"
else if (suffix === "txt")
return "TXT"
else if (suffix === "xls" || suffix === "xlsx")
return "EXCEL"
else if (suffix === "zip" || suffix === "rar")
return "ZIP"
else if (suffix === "png" || suffix === "jpg"
|| suffix === "jpeg" || suffix === "gif")
return "IMAGE"
else if (suffix === "mp3" || suffix === "wav")
return "AUDIO"
else if (suffix === "mp4" || suffix === "avi"
|| suffix === "rmvb" || suffix === "rm"
|| suffix === "wmv" || suffix === "mkv")
return "VIDEO"
else
return "OTHER"
}
function update() {
var uuid = header.items.length
=== 0 ? "null" : header.items[header.items.length - 1].uuid
Request.get("/knowledge/" + uuid, function (response) {
var data = JSON.parse(response)
console.log(response)
console.log(data.knowledgeFileAttribute)
fileListModel.clear()
var files = data.children
for (var i = 0; i < files.length; i++) {
var file = files[i]
console.log(file.name)
var modelItem = {
"title": file.name,
"uuid": file.id,
"date"// cut time after 'T'
: file.createTime.substring(0, 10)
}
if (file.knowledgeFileAttribute === null) {
modelItem.type = "folder"
modelItem.isDir = true
modelItem.size = 0
} else {
modelItem.isDir = false
modelItem.type = getType(
file.knowledgeFileAttribute.suffix)
modelItem.size = file.knowledgeFileAttribute.size
modelItem.brief = file.knowledgeFileAttribute.brief
modelItem.pageView = file.knowledgeFileAttribute.pageView
modelItem.stars = 0
// merge file.knowledgeFileAttribute.tags array to a string
var tagString = ""
for (var j = 0; j < file.knowledgeFileAttribute.tags.length; j++) {
if (j != 0)
tagString = tagString + ","
tagString = tagString + file.knowledgeFileAttribute.tags[j].name
}
modelItem.tags = tagString
}
fileListModel.append(modelItem)
}
console.log(fileListModel.count)
listView.currentIndex = -1
})
}
} }
} }
} }
@ -238,6 +245,7 @@ Item {
FileListItem { FileListItem {
id: fileListItem id: fileListItem
uuid: model.uuid uuid: model.uuid
fuuid: model.fuuid
width: parent.width width: parent.width
height: parent.height height: parent.height
title: model.title title: model.title
@ -256,6 +264,9 @@ Item {
emit: search(tag) emit: search(tag)
console.log(tag) console.log(tag)
} }
onRefresh: {
listView.headerItem.update()
}
} }
function doubleClicked() { function doubleClicked() {
listView.currentIndex = index listView.currentIndex = index
@ -275,6 +286,7 @@ Item {
isDir: true isDir: true
brief: "This is a test file" brief: "This is a test file"
type: "FOLDER" type: "FOLDER"
fuuid: "1"
} }
ListElement { ListElement {
uuid: "2" uuid: "2"
@ -286,6 +298,7 @@ Item {
date: "2020-09-09" date: "2020-09-09"
pageView: 100 pageView: 100
stars: 10 stars: 10
fuuid: "1"
} }
ListElement { ListElement {
uuid: "3" uuid: "3"
@ -297,6 +310,7 @@ Item {
pageView: 100 pageView: 100
size: 10200000022 size: 10200000022
stars: 10 stars: 10
fuuid: "1"
} }
} }
} }

View File

@ -5,6 +5,7 @@ import QtQuick.Layouts
FluArea { FluArea {
id: fileItem id: fileItem
property string uuid property string uuid
property string fuuid: null
property string title property string title
property string brief property string brief
property string date property string date
@ -18,6 +19,46 @@ FluArea {
property int stars property int stars
property var colorList: ["blue", "green", "orange", "red", "yellow", "purple", "pink", "brown", "teal", "cyan", "gray", "darkgray"] property var colorList: ["blue", "green", "orange", "red", "yellow", "purple", "pink", "brown", "teal", "cyan", "gray", "darkgray"]
signal tagClicked(string tag) signal tagClicked(string tag)
signal refresh
FluMenu {
id: menu
FluMenuItem {
text: "重命名"
onClicked: {
dialog.open()
}
InputDialog {
id: dialog
title: "重命名"
buttonFlags: FluContentDialog.PositiveButton | FluContentDialog.NegativeButton
negativeText: "取消"
positiveText: "确定"
message: fileItem.title
onPositiveClicked: text => {
var param = {
"name": text,
"parentId": fuuid
}
Request.post("/knowledge",
JSON.stringify(param))
refresh()
}
}
}
FluMenuItem {
text: "移动至"
onClicked: {
refresh()
}
}
FluMenuItem {
text: "删除"
onClicked: {
Request.delete("/knowledge/" + uuid)
refresh()
}
}
}
ColumnLayout { ColumnLayout {
id: row id: row
@ -30,9 +71,15 @@ FluArea {
anchors.fill: parent anchors.fill: parent
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onDoubleClicked: { onDoubleClicked: {
fileItem.parent.doubleClicked() fileItem.parent.doubleClicked()
} }
onClicked: {
if (mouse.button === Qt.RightButton) {
menu.popup()
}
}
} }
RowLayout { RowLayout {
id: titleRow id: titleRow