296 lines
11 KiB
QML
296 lines
11 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Layouts
|
|
import FluentUI
|
|
import QtQuick.Dialogs
|
|
import QtQuick.Controls
|
|
import "qrc:///AicsKnowledgeBase/qml/global"
|
|
import SignalFileOperation 1.0
|
|
import AicsKB.FileTransferManager
|
|
|
|
Item {
|
|
anchors.fill: parent
|
|
signal search(string tag)
|
|
signal open(string file)
|
|
property bool disableHeader: false
|
|
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
|
|
}
|
|
|
|
ListView {
|
|
id: listView
|
|
anchors.fill: parent
|
|
spacing: 10
|
|
header: disableHeader ? null : fileListItemHeader
|
|
model: fileListModel
|
|
delegate: fileListItemDelegate
|
|
Component.onCompleted: {
|
|
if (autoRequest) {
|
|
topColumnLayout.update()
|
|
} else {
|
|
listView.model = dataModel
|
|
}
|
|
}
|
|
}
|
|
|
|
Component {
|
|
id: fileListItemHeader
|
|
ColumnLayout {
|
|
id: topColumnLayout
|
|
function add(folderName, uuid) {
|
|
console.log(header.items)
|
|
header.items = header.items.concat([{
|
|
"title": folderName,
|
|
"uuid": uuid
|
|
}])
|
|
}
|
|
function update() {
|
|
console.log("1231231")
|
|
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)
|
|
fileListModel.clear()
|
|
|
|
var files = data.children
|
|
var items = []
|
|
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
|
|
}
|
|
items.push(modelItem)
|
|
}
|
|
fileListModel.clear()
|
|
for (i = 0; i < items.length; i++) {
|
|
if (items[i].isDir)
|
|
fileListModel.insert(0, items[i])
|
|
else
|
|
fileListModel.append(items[i])
|
|
}
|
|
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.alignment: Qt.AlignRight
|
|
//Layout.preferredWidth: parent.width
|
|
layoutDirection: Qt.RightToLeft
|
|
UploadButton {
|
|
//Layout.alignment: Qt.AlignRight
|
|
header: header
|
|
}
|
|
Item {
|
|
//anchors.right: uploadBtn.left
|
|
height: 28
|
|
width: 28
|
|
InputDialog {
|
|
id: dialog
|
|
title: "新建文件夹"
|
|
buttonFlags: FluContentDialog.PositiveButton
|
|
| FluContentDialog.NegativeButton
|
|
negativeText: "取消"
|
|
positiveText: "确定"
|
|
message: "请输入文件夹名称"
|
|
onPositiveClicked: text => {
|
|
var param = {
|
|
"name": text,
|
|
"parentId": header.items.length === 0 ? null : header.items[header.items.length - 1].uuid
|
|
}
|
|
Request.post("/knowledge",
|
|
JSON.stringify(
|
|
param)).then(
|
|
function (response) {
|
|
topColumnLayout.update()
|
|
})
|
|
}
|
|
}
|
|
|
|
FluIconButton {
|
|
anchors.fill: parent
|
|
iconSource: FluentIcons.NewFolder
|
|
onClicked: {
|
|
dialog.open()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
RowLayout {
|
|
id: fileListItemHeaderItem
|
|
width: ListView.view.width
|
|
height: 48
|
|
|
|
// back to folder button
|
|
FluIconButton {
|
|
Layout.alignment: Qt.AlignVCenter
|
|
id: backButton
|
|
width: 24
|
|
height: 24
|
|
iconSource: FluentIcons.ForwardCall
|
|
onClicked: {
|
|
if (header.count() > 0) {
|
|
header.items = header.items.slice(
|
|
0, header.count() - 1)
|
|
}
|
|
topColumnLayout.update()
|
|
}
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
onItemsChanged: {
|
|
topColumnLayout.update()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Component {
|
|
id: fileListItemDelegate
|
|
Rectangle {
|
|
id: fileListItemRect
|
|
width: ListView.view.width
|
|
//set the height to fit model.brief
|
|
height: model.isDir ? 50 : Math.max(120,
|
|
model.brief.length / 3 + 80)
|
|
//color: !ListView.isCurrentItem ? "white" : "red"
|
|
FileListItem {
|
|
id: fileListItem
|
|
uuid: model.uuid
|
|
fuuid: model.fuuid
|
|
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
|
|
tags: isDir ? [] : model.tags === null
|
|
|| model.tags === undefined
|
|
|| model.tags === "" ? [] : model.tags.split(",")
|
|
onTagClicked: {
|
|
emit: search(tag)
|
|
console.log(tag)
|
|
}
|
|
onRefresh: {
|
|
console.log("------------" + listView.headerItem)
|
|
parent.refresh()
|
|
}
|
|
}
|
|
function refresh() {
|
|
console.log("refresh")
|
|
listView.headerItem.update()
|
|
}
|
|
|
|
function doubleClicked() {
|
|
listView.currentIndex = index
|
|
if (model.isDir) {
|
|
console.log(listView.headerItem)
|
|
listView.headerItem.add(model.title, model.uuid)
|
|
} else {
|
|
emit: SignalFileOperation.open(model.uuid)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ListModel {
|
|
id: fileListModel
|
|
ListElement {
|
|
title: "File 1"
|
|
isDir: true
|
|
brief: "This is a test file"
|
|
type: "FOLDER"
|
|
fuuid: "1"
|
|
}
|
|
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
|
|
fuuid: "1"
|
|
}
|
|
ListElement {
|
|
uuid: "3"
|
|
title: "File 3"
|
|
isDir: false
|
|
brief: "在<em>多</em><em>线</em><em>程</em>编<em>程</em>中,同步是确保<em>多</em>个<em>线</em><em>程</em>能够正确协同工作的关键。"
|
|
type: "PPT"
|
|
date: "2020-09-09"
|
|
pageView: 100
|
|
size: 10200000022
|
|
stars: 10
|
|
fuuid: "1"
|
|
}
|
|
}
|
|
}
|