Compare commits

..

2 Commits

2 changed files with 141 additions and 80 deletions

View File

@ -38,6 +38,7 @@ Item {
Component {
id: fileListItemHeader
ColumnLayout {
id: topColumnLayout
function add(folderName, uuid) {
console.log(header.items)
header.items = header.items.concat([{
@ -45,6 +46,77 @@ Item {
"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 {
Layout.preferredWidth: parent.width
Item {
@ -53,14 +125,21 @@ Item {
width: 28
InputDialog {
id: dialog
title: "新建文件夹"
title: "新建文件夹"
buttonFlags: FluContentDialog.PositiveButton
| FluContentDialog.NegativeButton
negativeText: "取消"
positiveText: "确定"
message: "请输入文件夹名称"
negativeText: "取消"
positiveText: "确定"
message: "请输入文件夹名称"
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 {
Layout.alignment: Qt.AlignRight
text: "上传"
text: "上传"
onClicked: function () {
console.log("click")
fileDialog.open()
@ -135,7 +214,7 @@ Item {
header.items = header.items.slice(
0, header.count() - 1)
}
fileListItemHeaderItem.update()
topColumnLayout.update()
}
}
FluBreadcrumbBar {
@ -150,81 +229,9 @@ Item {
}
}
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 {
id: fileListItem
uuid: model.uuid
fuuid: model.fuuid
width: parent.width
height: parent.height
title: model.title
@ -256,6 +264,9 @@ Item {
emit: search(tag)
console.log(tag)
}
onRefresh: {
listView.headerItem.update()
}
}
function doubleClicked() {
listView.currentIndex = index
@ -275,6 +286,7 @@ Item {
isDir: true
brief: "This is a test file"
type: "FOLDER"
fuuid: "1"
}
ListElement {
uuid: "2"
@ -286,6 +298,7 @@ Item {
date: "2020-09-09"
pageView: 100
stars: 10
fuuid: "1"
}
ListElement {
uuid: "3"
@ -297,6 +310,7 @@ Item {
pageView: 100
size: 10200000022
stars: 10
fuuid: "1"
}
}
}

View File

@ -5,6 +5,7 @@ import QtQuick.Layouts
FluArea {
id: fileItem
property string uuid
property string fuuid: null
property string title
property string brief
property string date
@ -18,6 +19,46 @@ FluArea {
property int stars
property var colorList: ["blue", "green", "orange", "red", "yellow", "purple", "pink", "brown", "teal", "cyan", "gray", "darkgray"]
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 {
id: row
@ -30,9 +71,15 @@ FluArea {
anchors.fill: parent
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onDoubleClicked: {
fileItem.parent.doubleClicked()
}
onClicked: {
if (mouse.button === Qt.RightButton) {
menu.popup()
}
}
}
RowLayout {
id: titleRow