AicsKnowledgeBase_client/AicsKnowledgeBase/qml/component/FileList.qml

203 lines
7.1 KiB
QML
Raw Normal View History

2023-06-24 18:02:21 +08:00
import QtQuick 2.15
import QtQuick.Layouts
import FluentUI
2023-06-30 19:45:04 +08:00
import "qrc:///AicsKnowledgeBase/qml/global"
2023-06-24 18:02:21 +08:00
2023-06-30 23:31:28 +08:00
Item {
2023-07-01 08:56:14 +08:00
anchors.fill: parent
2023-06-28 14:47:52 +08:00
signal search(string tag)
signal open(string file)
property bool disableHeader: false
2023-07-05 13:58:03 +08:00
property bool autoRequest: false
property string url: "http://127.0.0.1:4523/m1/2914957-0-5604d062/"
property ListModel dataModel: ListModel {}
function setListData(listmodel) {
listView.model = listmodel
}
2023-07-01 08:56:14 +08:00
ListView {
id: listView
2023-06-24 18:02:21 +08:00
anchors.fill: parent
2023-07-01 08:56:14 +08:00
spacing: 10
2023-07-05 13:58:03 +08:00
header: disableHeader ? null : fileListItemHeader
2023-07-01 08:56:14 +08:00
model: fileListModel
delegate: fileListItemDelegate
Component.onCompleted: {
2023-07-05 13:58:03 +08:00
if (autoRequest) {
update()
} else {
listView.model = dataModel
}
2023-06-24 18:02:21 +08:00
}
2023-07-01 08:56:14 +08:00
}
2023-07-01 08:56:14 +08:00
Component {
id: fileListItemHeader
Item {
id: fileListItemHeaderItem
width: ListView.view.width
height: 48
RowLayout {
FluBreadcrumbBar {
id: header
width: parent.width
height: parent.height
separator: ">"
items: []
onClickItem: function (model) {
if (model.index + 1 !== count()) {
items = items.slice(0, model.index + 1)
2023-06-24 18:02:21 +08:00
}
}
2023-07-01 08:56:14 +08:00
onItemsChanged: {
fileListItemHeaderItem.update()
}
}
// back to folder button
FluIconButton {
Layout.alignment: Qt.AlignVCenter
id: backButton
width: 24
height: 24
iconSource: FluentIcons.ChromeBack
onClicked: {
if (header.count() > 0) {
header.items = header.items.slice(
0, header.count() - 1)
2023-06-28 14:47:52 +08:00
}
2023-07-01 08:56:14 +08:00
fileListItemHeaderItem.update()
2023-06-24 18:02:21 +08:00
}
}
2023-07-01 08:56:14 +08:00
}
2023-06-28 14:47:52 +08:00
2023-07-01 08:56:14 +08:00
function add(folderName, uuid) {
console.log(header.items)
header.items = header.items.concat([{
"title": folderName,
"uuid": uuid
}])
}
function getType(suffix) {
if (suffix === "ppt" || suffix === "pptx")
return "PPT"
else if (suffix === "doc" || suffix === "docx")
return "WORD"
}
function update() {
var uuid = header.items.length
=== 0 ? "null" : header.items[header.items.length - 1].uuid
Request.get(uuid, function (response) {
var data = JSON.parse(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": file.createTime
}
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
2023-06-30 19:45:04 +08:00
}
2023-07-01 08:56:14 +08:00
modelItem.tags = tagString
2023-06-30 19:45:04 +08:00
}
2023-07-01 08:56:14 +08:00
fileListModel.append(modelItem)
}
2023-07-05 13:58:03 +08:00
console.log(fileListModel)
2023-07-01 08:56:14 +08:00
listView.currentIndex = -1
})
2023-06-24 18:02:21 +08:00
}
}
2023-07-01 08:56:14 +08:00
}
Component {
id: fileListItemDelegate
Rectangle {
id: fileListItemRect
width: ListView.view.width
height: model.isDir ? 50 : 120
//color: !ListView.isCurrentItem ? "white" : "red"
FileListItem {
id: fileListItem
uuid: model.uuid
width: parent.width
height: parent.height
title: model.title
isDir: model.isDir
date: model.date
brief: isDir ? "" : model.brief
type: isDir ? "FOLDER" : model.type
pageView: isDir ? 0 : model.pageView
size: isDir ? 0 : model.size
stars: isDir ? 0 : model.stars
// split string to array
2023-07-05 13:58:03 +08:00
tags: isDir ? [] : model.tags.length === 0 ? [] : model.tags.split(
",")
2023-07-01 08:56:14 +08:00
onTagClicked: {
emit: search(tag)
console.log(tag)
2023-06-24 18:02:21 +08:00
}
2023-07-01 08:56:14 +08:00
}
function doubleClicked() {
listView.currentIndex = index
if (model.isDir) {
listView.headerItem.add(model.title, model.uuid)
} else {
emit: open(model.uuid)
2023-06-24 18:02:21 +08:00
}
}
}
2023-07-01 08:56:14 +08:00
}
ListModel {
id: fileListModel
2023-07-05 13:58:03 +08:00
ListElement {
title: "File 1"
isDir: true
brief: "This is a test file"
type: "FOLDER"
}
ListElement {
uuid: "2"
title: "File 2"
isDir: false
brief: "This is a test file"
size: 500
type: "WORD"
date: "2020-09-09"
pageView: 100
stars: 10
}
ListElement {
uuid: "3"
title: "File 3"
isDir: false
brief: "This is a test file"
type: "PPT"
date: "2020-09-09"
pageView: 100
size: 10200000022
stars: 10
}
2023-06-24 18:02:21 +08:00
}
}