2023-06-24 18:02:21 +08:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import FluentUI
|
2023-07-05 21:49:04 +08:00
|
|
|
import QtQuick.Dialogs
|
2023-07-06 15:10:13 +08:00
|
|
|
import QtQuick.Controls
|
2023-06-30 19:45:04 +08:00
|
|
|
import "qrc:///AicsKnowledgeBase/qml/global"
|
2023-07-05 20:04:43 +08:00
|
|
|
import SignalFileOperation 1.0
|
2023-07-05 23:50:11 +08:00
|
|
|
import AicsKB.FileTransferManager
|
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)
|
2023-07-04 13:38:01 +08:00
|
|
|
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) {
|
2023-07-06 21:50:19 +08:00
|
|
|
topColumnLayout.update()
|
2023-07-05 13:58:03 +08:00
|
|
|
} else {
|
|
|
|
listView.model = dataModel
|
|
|
|
}
|
2023-06-24 18:02:21 +08:00
|
|
|
}
|
2023-07-01 08:56:14 +08:00
|
|
|
}
|
2023-07-04 13:38:01 +08:00
|
|
|
|
2023-07-01 08:56:14 +08:00
|
|
|
Component {
|
|
|
|
id: fileListItemHeader
|
2023-07-05 22:31:14 +08:00
|
|
|
ColumnLayout {
|
2023-07-06 16:09:26 +08:00
|
|
|
id: topColumnLayout
|
2023-07-05 22:31:14 +08:00
|
|
|
function add(folderName, uuid) {
|
|
|
|
console.log(header.items)
|
|
|
|
header.items = header.items.concat([{
|
|
|
|
"title": folderName,
|
|
|
|
"uuid": uuid
|
|
|
|
}])
|
2023-07-05 21:49:04 +08:00
|
|
|
}
|
2023-07-06 16:09:26 +08:00
|
|
|
function update() {
|
2023-07-06 21:50:19 +08:00
|
|
|
console.log("1231231")
|
2023-07-06 16:09:26 +08:00
|
|
|
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()
|
2023-07-06 21:50:19 +08:00
|
|
|
|
2023-07-06 16:09:26 +08:00
|
|
|
var files = data.children
|
2023-07-06 21:50:19 +08:00
|
|
|
var items = []
|
2023-07-06 16:09:26 +08:00
|
|
|
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
|
|
|
|
}
|
2023-07-06 21:50:19 +08:00
|
|
|
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])
|
2023-07-06 16:09:26 +08:00
|
|
|
}
|
|
|
|
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"
|
|
|
|
}
|
2023-07-06 15:10:13 +08:00
|
|
|
RowLayout {
|
|
|
|
Layout.preferredWidth: parent.width
|
|
|
|
Item {
|
2023-07-06 21:50:19 +08:00
|
|
|
anchors.right: uploadBtn.left
|
2023-07-06 15:10:13 +08:00
|
|
|
height: 28
|
|
|
|
width: 28
|
|
|
|
InputDialog {
|
|
|
|
id: dialog
|
2023-07-06 16:09:26 +08:00
|
|
|
title: "新建文件夹"
|
2023-07-06 15:10:13 +08:00
|
|
|
buttonFlags: FluContentDialog.PositiveButton
|
|
|
|
| FluContentDialog.NegativeButton
|
2023-07-06 16:09:26 +08:00
|
|
|
negativeText: "取消"
|
|
|
|
positiveText: "确定"
|
|
|
|
message: "请输入文件夹名称"
|
2023-07-06 15:10:13 +08:00
|
|
|
onPositiveClicked: text => {
|
2023-07-06 16:09:26 +08:00
|
|
|
var param = {
|
|
|
|
"name": text,
|
2023-07-06 21:50:19 +08:00
|
|
|
"parentId": header.items.length === 0 ? null : header.items[header.items.length - 1].uuid
|
2023-07-06 16:09:26 +08:00
|
|
|
}
|
2023-07-06 21:50:19 +08:00
|
|
|
Request.post("/knowledge",
|
|
|
|
JSON.stringify(
|
|
|
|
param)).then(
|
|
|
|
function (response) {
|
|
|
|
topColumnLayout.update()
|
|
|
|
})
|
2023-07-06 15:10:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
source: "qrc:/AicsKnowledgeBase/res/createFolder.png"
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
dialog.open()
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 21:49:04 +08:00
|
|
|
}
|
2023-07-06 15:10:13 +08:00
|
|
|
FluButton {
|
2023-07-06 21:50:19 +08:00
|
|
|
id: uploadIcon
|
2023-07-06 15:10:13 +08:00
|
|
|
Layout.alignment: Qt.AlignRight
|
2023-07-06 16:09:26 +08:00
|
|
|
text: "上传"
|
2023-07-06 15:10:13 +08:00
|
|
|
onClicked: function () {
|
|
|
|
console.log("click")
|
|
|
|
fileDialog.open()
|
|
|
|
}
|
|
|
|
FileDialog {
|
|
|
|
id: fileDialog
|
|
|
|
onAccepted: function () {
|
|
|
|
let name = FileTransferManager.getFileName(
|
|
|
|
selectedFile)
|
|
|
|
const size = FileTransferManager.getFileSize(
|
|
|
|
selectedFile)
|
|
|
|
const md5 = FileTransferManager.getFileMd5(
|
|
|
|
selectedFile)
|
|
|
|
if (size <= 0 || md5 === '')
|
|
|
|
return
|
|
|
|
var body = {
|
|
|
|
"name": name,
|
|
|
|
"brief": "brief",
|
|
|
|
"size": size,
|
|
|
|
"md5": md5,
|
|
|
|
"tags": [],
|
|
|
|
"parentId": header.items.length !== 0 ? header.items[header.items.length - 1].uuid : null
|
|
|
|
}
|
|
|
|
console.log("begin")
|
|
|
|
Request.post("knowledge/file",
|
|
|
|
JSON.stringify(body),
|
|
|
|
function (res, data) {
|
|
|
|
console.log(res)
|
|
|
|
console.log(data)
|
|
|
|
FileTransferManager.upload(
|
|
|
|
selectedFile, data.id,
|
|
|
|
data.ticket, name)
|
|
|
|
}, function (res, data) {
|
|
|
|
console.log(res)
|
|
|
|
})
|
2023-06-28 14:47:52 +08:00
|
|
|
}
|
2023-06-24 18:02:21 +08:00
|
|
|
}
|
|
|
|
}
|
2023-07-01 08:56:14 +08:00
|
|
|
}
|
2023-07-05 22:31:14 +08:00
|
|
|
RowLayout {
|
|
|
|
id: fileListItemHeaderItem
|
|
|
|
width: ListView.view.width
|
|
|
|
height: 48
|
2023-06-28 14:47:52 +08:00
|
|
|
|
2023-07-05 22:31:14 +08:00
|
|
|
// 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)
|
|
|
|
}
|
2023-07-06 16:09:26 +08:00
|
|
|
topColumnLayout.update()
|
2023-07-05 22:31:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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: {
|
2023-07-06 16:09:26 +08:00
|
|
|
topColumnLayout.update()
|
2023-07-05 22:31:14 +08:00
|
|
|
}
|
|
|
|
}
|
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
|
2023-07-06 16:09:26 +08:00
|
|
|
fuuid: model.fuuid
|
2023-07-01 08:56:14 +08:00
|
|
|
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 20:59:57 +08:00
|
|
|
tags: isDir ? [] : model.tags === null
|
|
|
|
|| model.tags === undefined
|
|
|
|
|| model.tags === "" ? [] : 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-06 16:09:26 +08:00
|
|
|
onRefresh: {
|
2023-07-06 21:50:19 +08:00
|
|
|
console.log("------------" + listView.headerItem)
|
|
|
|
parent.refresh()
|
2023-07-06 16:09:26 +08:00
|
|
|
}
|
2023-07-01 08:56:14 +08:00
|
|
|
}
|
2023-07-06 21:50:19 +08:00
|
|
|
function refresh() {
|
|
|
|
console.log("refresh")
|
|
|
|
listView.headerItem.update()
|
|
|
|
}
|
|
|
|
|
2023-07-01 08:56:14 +08:00
|
|
|
function doubleClicked() {
|
|
|
|
listView.currentIndex = index
|
|
|
|
if (model.isDir) {
|
2023-07-05 22:31:14 +08:00
|
|
|
console.log(listView.headerItem)
|
2023-07-01 08:56:14 +08:00
|
|
|
listView.headerItem.add(model.title, model.uuid)
|
|
|
|
} else {
|
2023-07-05 20:04:43 +08:00
|
|
|
emit: SignalFileOperation.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"
|
2023-07-06 16:09:26 +08:00
|
|
|
fuuid: "1"
|
2023-07-05 13:58:03 +08:00
|
|
|
}
|
|
|
|
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
|
2023-07-06 16:09:26 +08:00
|
|
|
fuuid: "1"
|
2023-07-05 13:58:03 +08:00
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
uuid: "3"
|
|
|
|
title: "File 3"
|
|
|
|
isDir: false
|
2023-07-06 22:23:15 +08:00
|
|
|
brief: "在<em>多</em><em>线</em><em>程</em>编<em>程</em>中,同步是确保<em>多</em>个<em>线</em><em>程</em>能够正确协同工作的关键。"
|
2023-07-05 13:58:03 +08:00
|
|
|
type: "PPT"
|
|
|
|
date: "2020-09-09"
|
|
|
|
pageView: 100
|
|
|
|
size: 10200000022
|
|
|
|
stars: 10
|
2023-07-06 16:09:26 +08:00
|
|
|
fuuid: "1"
|
2023-07-05 13:58:03 +08:00
|
|
|
}
|
2023-06-24 18:02:21 +08:00
|
|
|
}
|
|
|
|
}
|