AicsKnowledgeBase_client/AicsKnowledgeBase/qml/component/FileList.qml

130 lines
4.2 KiB
QML

import QtQuick 2.15
import QtQuick.Layouts
import FluentUI
Window {
id: fileListTestWindow
visible: true
width: 800
height: 600
title: "File List Test1"
Item {
anchors.fill: parent
ListView {
id: listView
anchors.fill: parent
spacing: 10
header: fileListItemHeader
model: fileListModel
delegate: fileListItemDelegate
}
Component {
id: fileListItemHeader
Item {
id: fileListItemHeaderItem
width: ListView.view.width
height: 48
FluBreadcrumbBar {
id: header
width: parent.width
height: parent.height
separator: ">"
items: [{
"title": "Home"
}, {
"title": "Documents"
}, {
"title": "File List"
}]
onClickItem: function (model) {
if (model.index + 1 !== count()) {
items = items.slice(0, model.index + 1)
}
}
onItemsChanged: {
fileListItemHeaderItem.update()
}
}
function add(folderName) {
listView.headerItem.children[0].items
= listView.headerItem.children[0].items.concat([{
"title": folderName
}])
}
function update() {
// combine all header items to a path
var path = ""
for (var i = 0; i < listView.headerItem.children[0].items.length; i++) {
path += listView.headerItem.children[0].items[i].title + "/"
}
console.log(path)
var newListModel = []
// http request for new list data
// fileListModel.clear()
// fileListModel.append(newListModel)
}
}
}
Component {
id: fileListItemDelegate
Rectangle {
id: fileListItemRect
width: ListView.view.width
height: 100
color: !ListView.isCurrentItem ? "lightgray" : "red"
FileListItem {
width: parent.width
height: parent.height
title: model.title
isDir: model.isDir
brief: model.brief
size: model.size
type: model.type
date: model.date
pageView: model.pageView
stars: model.stars
}
MouseArea {
anchors.fill: parent
onClicked: {
listView.currentIndex = index
if (model.isDir) {
listView.headerItem.add(model.title)
}
}
}
}
}
ListModel {
id: fileListModel
ListElement {
title: "File 1"
isDir: true
brief: "This is a test file"
type: "FOLDER"
}
ListElement {
title: "File 2"
isDir: false
brief: "This is a test file"
size: 500
type: "WORD"
date: "2020-09-09"
pageView: 100
stars: 10
}
ListElement {
title: "File 3"
isDir: false
brief: "This is a test file"
type: "PPT"
date: "2020-09-09"
pageView: 100
size: 10200000022
stars: 10
}
}
}
}