AicsKnowledgeBase_client/AicsKnowledgeBase/qml/component/FileListItem.qml

179 lines
5.8 KiB
QML

import QtQuick 2.15
import FluentUI
import QtQuick.Layouts
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea {
id: fileItem
property string uuid
property var fuuid: null
property string title
property string brief
property string date
property string type
property string suffix
property bool isDir: false
property int size
property int pageView
property var tags: []
property var notes: []
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 = {
"parentId": fileItem.fuuid,
"name": text
}
console.log(JSON.stringify(param))
Request.put(
"/knowledge/" + fileItem.uuid,
JSON.stringify(param), () => {
refresh()
})
}
}
}
FluMenuItem {
text: "移动至"
onClicked: {
moveDialog.load()
moveDialog.open()
}
TreeViewDialog {
id: moveDialog
title: "选择目标文件夹"
buttonFlags: FluContentDialog.PositiveButton | FluContentDialog.NegativeButton
negativeText: "取消"
positiveText: "确定"
onPositiveClicked: uuid => {
var param = {
"parentId": uuid,
"name": fileItem.title
}
console.log(JSON.stringify(param))
Request.put(
"/knowledge/" + fileItem.uuid,
JSON.stringify(param), () => {
refresh()
})
}
}
}
FluMenuItem {
text: "删除"
onClicked: {
Request.delete("/knowledge/" + uuid)
refresh()
}
}
}
MouseArea {
anchors.fill: row
acceptedButtons: Qt.LeftButton | Qt.RightButton
onDoubleClicked: {
fileItem.parent.doubleClicked()
}
onClicked: {
if (mouse.button === Qt.RightButton) {
menu.popup()
}
}
}
ColumnLayout {
id: clickable
anchors.fill: row
RowLayout {
id: titleRow
Image {
id: icon
source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : ""
Layout.preferredHeight: 24
Layout.preferredWidth: 24
fillMode: Image.PreserveAspectFit
}
FluText {
id: title
font.bold: true
font.pointSize: 12
text: fileItem.title
textFormat: Text.RichText
}
}
FluText {
id: brief
visible: !fileItem.isDir
text: fileItem.brief
Layout.fillWidth: true
wrapMode: Text.WordWrap
elide: Text.ElideRight
maximumLineCount: 4
textFormat: Text.RichText
fontSizeMode: Text.Fit
}
RowLayout {
id: infoRow
visible: !fileItem.isDir
FluText {
id: date
color: "#5F5F5F"
text: fileItem.date
}
FluText {
id: size
// cast Byte size to right text size
color: "#5F5F5F"
text: fileItem.size > 1024
* 1024 ? (fileItem.size / 1024 / 1024).toFixed(
2) + "MB" : (fileItem.size / 1024).toFixed(
2) + "KB"
}
FluText {
id: pageView
color: "#5F5F5F"
text: fileItem.pageView + "浏览"
}
FluText {
id: stars
color: "#5F5F5F"
text: fileItem.stars + "收藏"
}
}
}
RowLayout {
visible: !fileItem.isDir
Repeater {
model: fileItem.tags
delegate: FluTextButton {
text: "#" + fileItem.tags[index]
normalColor: colorList[index % colorList.length]
font.pixelSize: 12
Layout.preferredWidth: 50
onClicked: {
emit: tagClicked(text)
}
}
}
}
}
}