添加输入文件简介对话框

main
wuyize 2023-07-06 17:15:55 +08:00
parent c1e2eba4d1
commit 1c6aba5baf
3 changed files with 17 additions and 56 deletions

View File

@ -154,47 +154,8 @@ Item {
} }
} }
} }
FluButton { UploadButton {
Layout.alignment: Qt.AlignRight header: header
text: "上传"
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")
console.log(JSON.stringify(body))
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)
})
}
}
} }
} }
RowLayout { RowLayout {

View File

@ -34,12 +34,12 @@ FluButton {
implicitWidth: Window.window == null ? 400 : Math.min( implicitWidth: Window.window == null ? 400 : Math.min(
Window.window.width, 400) Window.window.width, 400)
implicitHeight: text_title.height + text_message.height + layout_actions.height implicitHeight: text_title.height + content.height + layout_actions.height
color: 'transparent' color: 'transparent'
radius: 5 radius: 5
FluText { FluText {
id: text_title id: text_title
font: FluTextStyle.TitleLarge font: FluTextStyle.Title
text: "上传知识文件" text: "上传知识文件"
topPadding: 20 topPadding: 20
leftPadding: 20 leftPadding: 20
@ -51,11 +51,9 @@ FluButton {
right: parent.right right: parent.right
} }
} }
FluText {
id: text_message Row {
font: FluTextStyle.Body id: content
wrapMode: Text.WrapAnywhere
text: "content"
topPadding: 14 topPadding: 14
leftPadding: 20 leftPadding: 20
rightPadding: 20 rightPadding: 20
@ -65,7 +63,13 @@ FluButton {
left: parent.left left: parent.left
right: parent.right right: parent.right
} }
FluMultilineTextBox {
id: brief_textbox
width: parent.width - parent.leftPadding - parent.rightPadding
placeholderText: "请输入简介"
}
} }
Rectangle { Rectangle {
id: layout_actions id: layout_actions
height: 68 height: 68
@ -76,7 +80,7 @@ FluButton {
243 / 255, 243 / 255, 243 / 255, 243 / 255, 243 / 255, 243 / 255,
blurBackground ? blurOpacity - 0.4 : 1) blurBackground ? blurOpacity - 0.4 : 1)
anchors { anchors {
top: text_message.bottom top: content.bottom
left: parent.left left: parent.left
right: parent.right right: parent.right
} }
@ -113,7 +117,7 @@ FluButton {
return return
var body = { var body = {
"name": name, "name": name,
"brief": "brief", "brief": brief_textbox.text,
"size": size, "size": size,
"md5": md5, "md5": md5,
"tags": [], "tags": [],

View File

@ -304,7 +304,7 @@ bool httpDownload(const std::string &url, const std::string &savePath, const Fil
if (!obj.curlHandle) if (!obj.curlHandle)
return false; return false;
obj.totalSize = item.totalSize;//原始文件大小 obj.totalSize = item.totalSize;//原始文件大小
obj.file = std::ofstream(savePath, std::ios::binary); obj.file = std::ofstream(savePath, std::ios::binary | std::ios::app);
if (!obj.file.is_open()) { if (!obj.file.is_open()) {
qDebug() << "Open File Failed"; qDebug() << "Open File Failed";
curl_easy_cleanup(obj.curlHandle); curl_easy_cleanup(obj.curlHandle);
@ -349,7 +349,7 @@ void FileTransferManager::download(const QString &fileId, const QString &fileNam
auto size = resJson["size"].toInteger(); auto size = resJson["size"].toInteger();
std::string savePath = "D:\\Downloads\\" + fileName.toLocal8Bit().toStdString(); std::string savePath = "D:\\Downloads\\" + fileName.toLocal8Bit().toStdString();
qDebug() << savePath.c_str(); qDebug() << savePath.c_str();
QFileInfo fileInfo(savePath.c_str()); QFileInfo fileInfo(QString::fromLocal8Bit(savePath.c_str()));
int64_t completedSize = fileInfo.exists() ? fileInfo.size() : 0; int64_t completedSize = fileInfo.exists() ? fileInfo.size() : 0;
FileItem item{true, fileId, fileName, completedSize, size}; FileItem item{true, fileId, fileName, completedSize, size};
if (!resume) if (!resume)
@ -359,10 +359,6 @@ void FileTransferManager::download(const QString &fileId, const QString &fileNam
auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), completedSize, size); auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), completedSize, size);
auto res = httpDownload(fileUrl, savePath, item); auto res = httpDownload(fileUrl, savePath, item);
/*auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), 0, size / 2);
auto res = httpDownload(fileUrl, savePath, item);
fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), size / 2, size);
res = httpDownload(fileUrl, savePath, item);*/
qDebug() << "End Get" << res; qDebug() << "End Get" << res;
}); });