AicsKnowledgeBase_client/AicsKnowledgeBase/qml/component/UploadButton.qml

162 lines
5.8 KiB
QML
Raw Normal View History

2023-07-06 14:14:24 +08:00
import QtQuick 2.15
import QtQuick.Layouts
import FluentUI
import QtQuick.Dialogs
import "qrc:///AicsKnowledgeBase/qml/global"
import SignalFileOperation 1.0
import AicsKB.FileTransferManager
FluButton {
property var header
property var currentSelectedFile: null
Layout.alignment: Qt.AlignRight
text: "上传"
onClicked: function () {
console.log("click")
2023-07-07 01:57:39 +08:00
//fileDialog.open()
popup.open()
2023-07-06 14:14:24 +08:00
}
FileDialog {
id: fileDialog
onAccepted: function () {
currentSelectedFile = selectedFile
popup.open()
}
onRejected: currentSelectedFile = null
}
FluPopup {
id: popup
focus: true
Rectangle {
id: layout_content
anchors.fill: parent
implicitWidth: Window.window == null ? 400 : Math.min(
Window.window.width, 400)
2023-07-06 17:15:55 +08:00
implicitHeight: text_title.height + content.height + layout_actions.height
2023-07-06 14:14:24 +08:00
color: 'transparent'
radius: 5
FluText {
id: text_title
2023-07-06 17:15:55 +08:00
font: FluTextStyle.Title
2023-07-06 14:14:24 +08:00
text: "上传知识文件"
topPadding: 20
leftPadding: 20
rightPadding: 20
wrapMode: Text.WrapAnywhere
anchors {
top: parent.top
left: parent.left
right: parent.right
}
}
2023-07-06 17:15:55 +08:00
2023-07-07 01:57:39 +08:00
Column {
2023-07-06 17:15:55 +08:00
id: content
2023-07-06 14:14:24 +08:00
topPadding: 14
leftPadding: 20
rightPadding: 20
bottomPadding: 14
anchors {
top: text_title.bottom
left: parent.left
right: parent.right
}
2023-07-06 17:15:55 +08:00
FluMultilineTextBox {
id: brief_textbox
width: parent.width - parent.leftPadding - parent.rightPadding
placeholderText: "请输入简介"
}
2023-07-07 02:28:21 +08:00
Tag {
id: tags
}
2023-07-06 14:14:24 +08:00
}
2023-07-06 17:15:55 +08:00
2023-07-06 14:14:24 +08:00
Rectangle {
id: layout_actions
height: 68
radius: 5
color: FluTheme.dark ? Qt.rgba(
32 / 255, 32 / 255, 32 / 255,
blurBackground ? blurOpacity - 0.4 : 1) : Qt.rgba(
243 / 255, 243 / 255, 243 / 255,
blurBackground ? blurOpacity - 0.4 : 1)
anchors {
2023-07-06 17:15:55 +08:00
top: content.bottom
2023-07-06 14:14:24 +08:00
left: parent.left
right: parent.right
}
RowLayout {
anchors {
centerIn: parent
margins: spacing
fill: parent
}
spacing: 15
FluButton {
id: negative_btn
Layout.fillWidth: true
Layout.fillHeight: true
text: "取消"
onClicked: {
popup.close()
}
}
FluFilledButton {
id: positive_btn
Layout.fillWidth: true
Layout.fillHeight: true
text: "上传"
onClicked: {
2023-07-07 02:28:21 +08:00
for (var i = 0; i < tags.tagList.count; i++) {
console.log(tags.tagList.get(i).tag)
console.log(tags.tagList.get(i).id)
}
return
2023-07-06 14:14:24 +08:00
popup.close()
let name = FileTransferManager.getFileName(
currentSelectedFile)
const size = FileTransferManager.getFileSize(
currentSelectedFile)
const md5 = FileTransferManager.getFileMd5(
currentSelectedFile)
if (size <= 0 || md5 === '')
return
var body = {
"name": name,
2023-07-06 17:15:55 +08:00
"brief": brief_textbox.text,
2023-07-06 14:14:24 +08:00
"size": size,
"md5": md5,
"tags": [],
"parentId": currentParentId()
}
console.log("begin")
console.log(JSON.stringify(body))
Request.post("knowledge/file",
JSON.stringify(body),
function (res, data) {
console.log(res)
console.log(data)
FileTransferManager.upload(
currentSelectedFile,
data.id, data.ticket,
name)
}, function (res, data) {
console.log(res)
})
}
}
}
}
}
}
function currentParentId() {
return header.items.length !== 0 ? header.items[header.items.length - 1].uuid : null
}
}