FileList修改样式,上传

main
karlis 2023-07-05 22:31:14 +08:00
parent 0014cc018a
commit 5c1b23421c
4 changed files with 125 additions and 97 deletions

View File

@ -35,42 +35,14 @@ Item {
Component { Component {
id: fileListItemHeader id: fileListItemHeader
ColumnLayout {
RowLayout { function add(folderName, uuid) {
id: fileListItemHeaderItem console.log(header.items)
width: ListView.view.width header.items = header.items.concat([{
height: 48 "title": folderName,
"uuid": uuid
// 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)
}
fileListItemHeaderItem.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: {
fileListItemHeaderItem.update()
}
}
FluButton { FluButton {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: "上传" text: "上传"
@ -78,28 +50,25 @@ Item {
console.log("click") console.log("click")
fileDialog.open() fileDialog.open()
} }
FileDialog { FileDialog {
id: fileDialog id: fileDialog
onAccepted: function () { onAccepted: function () {
const size = FileTransferManager.getFileSize( const size = FileTransferManager.getFileSize(
selectedFile) selectedFile)
const md5 = FileTransferManager.getFileMd5(selectedFile) const md5 = FileTransferManager.getFileMd5(selectedFile)
if (size <= 0 || md5 === '') if (size <= 0 || md5 === '')
return return
var body = { var body = {
"name": "test2", "name": "test2",
"brief": "brief", "brief": "brief",
"size": size, "size": size,
"md5": md5, "md5": md5,
"tags": [], "tags": [],
"parentId": null "parentId": header.items.length
!== 0 ? header.items[header.items.length - 1].uuid : null
} }
console.log("begin") console.log("begin")
console.log(JSON.stringify(body)) console.log(JSON.stringify(body))
Request.post("knowledge/file", JSON.stringify(body), Request.post("knowledge/file", JSON.stringify(body),
function (res, data) { function (res, data) {
console.log(res) console.log(res)
@ -113,64 +82,112 @@ Item {
} }
} }
} }
RowLayout {
id: fileListItemHeaderItem
width: ListView.view.width
height: 48
function add(folderName, uuid) { // back to folder button
console.log(header.items) FluIconButton {
header.items = header.items.concat([{ Layout.alignment: Qt.AlignVCenter
"title": folderName, id: backButton
"uuid": uuid width: 24
}]) height: 24
} iconSource: FluentIcons.ForwardCall
onClicked: {
function getType(suffix) { if (header.count() > 0) {
if (suffix === "ppt" || suffix === "pptx") header.items = header.items.slice(
return "PPT" 0, header.count() - 1)
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) { fileListItemHeaderItem.update()
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
}
fileListModel.append(modelItem)
} }
console.log(fileListModel) }
listView.currentIndex = -1 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: {
fileListItemHeaderItem.update()
}
}
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"
}
function update() {
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)
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"// cut time after 'T'
: file.createTime.substring(0, 10)
}
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
}
fileListModel.append(modelItem)
}
console.log(fileListModel)
listView.currentIndex = -1
})
}
} }
} }
} }
@ -206,6 +223,7 @@ Item {
function doubleClicked() { function doubleClicked() {
listView.currentIndex = index listView.currentIndex = index
if (model.isDir) { if (model.isDir) {
console.log(listView.headerItem)
listView.headerItem.add(model.title, model.uuid) listView.headerItem.add(model.title, model.uuid)
} else { } else {
emit: SignalFileOperation.open(model.uuid) emit: SignalFileOperation.open(model.uuid)

View File

@ -39,11 +39,13 @@ FluArea {
Image { Image {
id: icon id: icon
source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : "" source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : ""
Layout.preferredHeight: 18 Layout.preferredHeight: 32
Layout.preferredWidth: 18 Layout.preferredWidth: 32
} }
FluText { FluText {
id: title id: title
font.bold: true
font.pointSize: 15
text: fileItem.title text: fileItem.title
} }
} }
@ -52,17 +54,23 @@ FluArea {
id: brief id: brief
visible: !fileItem.isDir visible: !fileItem.isDir
text: fileItem.brief text: fileItem.brief
Layout.fillWidth: true
wrapMode: Text.WrapAnywhere
elide: Text.ElideRight
maximumLineCount: 2
} }
RowLayout { RowLayout {
id: infoRow id: infoRow
visible: !fileItem.isDir visible: !fileItem.isDir
FluText { FluText {
id: date id: date
color: "#5F5F5F"
text: fileItem.date text: fileItem.date
} }
FluText { FluText {
id: size id: size
// cast Byte size to right text size // cast Byte size to right text size
color: "#5F5F5F"
text: fileItem.size > 1024 text: fileItem.size > 1024
* 1024 ? (fileItem.size / 1024 / 1024).toFixed( * 1024 ? (fileItem.size / 1024 / 1024).toFixed(
2) + "MB" : (fileItem.size / 1024).toFixed( 2) + "MB" : (fileItem.size / 1024).toFixed(
@ -70,10 +78,12 @@ FluArea {
} }
FluText { FluText {
id: pageView id: pageView
color: "#5F5F5F"
text: fileItem.pageView + "浏览" text: fileItem.pageView + "浏览"
} }
FluText { FluText {
id: stars id: stars
color: "#5F5F5F"
text: fileItem.stars + "收藏" text: fileItem.stars + "收藏"
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB