From 8bd68cb3ec8612f36ccdae5a9d6cfa8a3d1a5521 Mon Sep 17 00:00:00 2001 From: wuyize Date: Thu, 6 Jul 2023 21:16:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=8E=B7=E5=8F=96Markdown?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=86=85=E5=AE=B9=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AicsKnowledgeBase/qml/LoginWindow.qml | 2 + AicsKnowledgeBase/qml/MainWindow.qml | 69 ++++++++++++++----- AicsKnowledgeBase/qml/page/ContentPage.qml | 9 ++- AicsKnowledgeBase/src/FileTransferManager.cpp | 27 ++++++++ AicsKnowledgeBase/src/FileTransferManager.h | 21 ++++-- 5 files changed, 101 insertions(+), 27 deletions(-) diff --git a/AicsKnowledgeBase/qml/LoginWindow.qml b/AicsKnowledgeBase/qml/LoginWindow.qml index 9ff5ccd..2779d07 100644 --- a/AicsKnowledgeBase/qml/LoginWindow.qml +++ b/AicsKnowledgeBase/qml/LoginWindow.qml @@ -103,6 +103,8 @@ AppFluWindow { function (result, data) { console.log(result) console.log(data) + UserData.username = param.username + FluApp.navigate("/") window.close() }, function (p1, p2) { diff --git a/AicsKnowledgeBase/qml/MainWindow.qml b/AicsKnowledgeBase/qml/MainWindow.qml index d4cfa26..9ee29d7 100644 --- a/AicsKnowledgeBase/qml/MainWindow.qml +++ b/AicsKnowledgeBase/qml/MainWindow.qml @@ -18,6 +18,7 @@ FluWindow { CustomAppBar { id: title_bar title: window.title + username: UserData.username anchors { left: parent.left @@ -62,37 +63,67 @@ FluWindow { Layout.topMargin: 45 Layout.bottomMargin: 4 Layout.rightMargin: 4 - replaceEnter: null - replaceExit: null + pushEnter: Transition { + PropertyAnimation { + property: "opacity" + from: 0 + to: 1 + duration: 200 + } + } + pushExit: Transition { + PropertyAnimation { + property: "opacity" + from: 1 + to: 0 + duration: 200 + } + } + popEnter: Transition { + PropertyAnimation { + property: "opacity" + from: 0 + to: 1 + duration: 200 + } + } + popExit: Transition { + PropertyAnimation { + property: "opacity" + from: 1 + to: 0 + duration: 200 + } + } initialItem: create_note_view } Connections { target: SignalFileOperation function onOpen(file) { - stack_view.push(file_view, {knowledgeFileId: file}) + stack_view.push(file_view, { + "knowledgeFileId": file + }) } function onOpenNote(note) { - stack_view.push(note_view, {noteFileId: note}) + stack_view.push(note_view, { + "noteFileId": note + }) } function onBack() { - if(stack_view.depth > 0) + if (stack_view.depth > 0) stack_view.pop() } } Component { id: file_view - ContentPage { - - } + ContentPage {} } Component { id: note_view - NotePage { - - } + NotePage {} } Component { @@ -103,14 +134,14 @@ FluWindow { } -// ContentPage { -// Layout.fillHeight: true -// Layout.fillWidth: true -// Layout.topMargin: 45 -// Layout.bottomMargin: 4 -// Layout.rightMargin: 4 -// type: "md" -// } + // ContentPage { + // Layout.fillHeight: true + // Layout.fillWidth: true + // Layout.topMargin: 45 + // Layout.bottomMargin: 4 + // Layout.rightMargin: 4 + // type: "md" + // } /* diff --git a/AicsKnowledgeBase/qml/page/ContentPage.qml b/AicsKnowledgeBase/qml/page/ContentPage.qml index 0ad56ed..119931e 100644 --- a/AicsKnowledgeBase/qml/page/ContentPage.qml +++ b/AicsKnowledgeBase/qml/page/ContentPage.qml @@ -147,7 +147,7 @@ FluArea { FluText { id: text_title padding: 10 - text: content_page.title + text: content_page.title.split(".")[0] font { pointSize: 15 bold: true @@ -225,9 +225,16 @@ FluArea { } onClicked: { emit: content_area.download(content_area.knowledgeFileId) + //FileTransferManager.getMarkdown(content_page.fileId) FileTransferManager.download(content_page.fileId, content_page.title) } + // Connections { + // target: FileTransferManager + // onMarkdownData: data => { + // console.log(data) + // } + // } } } diff --git a/AicsKnowledgeBase/src/FileTransferManager.cpp b/AicsKnowledgeBase/src/FileTransferManager.cpp index 9720d88..6a4de75 100644 --- a/AicsKnowledgeBase/src/FileTransferManager.cpp +++ b/AicsKnowledgeBase/src/FileTransferManager.cpp @@ -397,3 +397,30 @@ QString FileTransferManager::getFileName(const QUrl &fileUrl) return fileUrl.fileName(); } + + + +void FileTransferManager::getMarkdown(const QString &fileId) +{ + QtConcurrent::run([fileId, this] { + qDebug() << "Start Get"; + std::string resData; + if (CURLE_OK != httpGet("File/" + fileId.toStdString() + "/status", resData)) + return; + qDebug() << resData.c_str(); + auto resJson = QJsonDocument::fromJson(resData.c_str()); + if (!resJson["isCompleted"].toBool()) { + qDebug() << "File Not Completed"; + return; + } + + auto size = resJson["size"].toInteger(); + auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), 0, size); + std::string fileData; + auto res = httpGet(fileUrl, fileData); + //qDebug() << fileData.c_str(); + emit markdownData(QString::fromStdString(fileData)); + //qDebug() << "End Get" << res; + }); +} + diff --git a/AicsKnowledgeBase/src/FileTransferManager.h b/AicsKnowledgeBase/src/FileTransferManager.h index 94a357f..0e1c3ad 100644 --- a/AicsKnowledgeBase/src/FileTransferManager.h +++ b/AicsKnowledgeBase/src/FileTransferManager.h @@ -12,21 +12,28 @@ #include "FileTransferListModel.h" - class FileTransferManager : public QObject { Q_OBJECT public: explicit FileTransferManager(QObject *parent = nullptr); - Q_INVOKABLE QString getFileName(const QUrl& fileUrl); - Q_INVOKABLE int64_t getFileSize(const QUrl& fileUrl); - Q_INVOKABLE QString getFileMd5(const QUrl& fileUrl); - Q_INVOKABLE void upload(const QUrl& fileUrl, const QString& fileId, const QString& ticket, const QString &fileName); + Q_INVOKABLE QString getFileName(const QUrl &fileUrl); - Q_INVOKABLE void download(const QString& fileId, const QString& fileName, bool resume = false); - Q_INVOKABLE void pause(const QString& fileId); + Q_INVOKABLE int64_t getFileSize(const QUrl &fileUrl); + Q_INVOKABLE QString getFileMd5(const QUrl &fileUrl); + + Q_INVOKABLE void upload(const QUrl &fileUrl, const QString &fileId, const QString &ticket, const QString &fileName); + + Q_INVOKABLE void download(const QString &fileId, const QString &fileName, bool resume = false); + + Q_INVOKABLE void pause(const QString &fileId); + + Q_INVOKABLE void getMarkdown(const QString &fileId); + +signals: + void markdownData(QString data); private: };