From d56a2364663b7f108b7ac955f53be6c7d7a0809a Mon Sep 17 00:00:00 2001 From: wuyize Date: Sat, 8 Jul 2023 13:51:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=94=E8=BE=A9=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AicsKnowledgeBase/qml/MainWindow.qml | 4 +- AicsKnowledgeBase/qml/global/NavItems.qml | 14 ++--- AicsKnowledgeBase/qml/global/Request.qml | 7 ++- .../qml/global/SignalFileOperation.qml | 2 +- AicsKnowledgeBase/qml/page/ContentPage.qml | 16 +++--- AicsKnowledgeBase/qml/page/CreateNotePage.qml | 56 +++++++++---------- AicsKnowledgeBase/qml/page/NoteEditPage.qml | 1 + AicsKnowledgeBase/qml/page/NotePage.qml | 4 +- AicsKnowledgeBase/src/FileTransferManager.cpp | 26 +++++++++ AicsKnowledgeBase/src/FileTransferManager.h | 5 ++ 10 files changed, 81 insertions(+), 54 deletions(-) diff --git a/AicsKnowledgeBase/qml/MainWindow.qml b/AicsKnowledgeBase/qml/MainWindow.qml index eab537c..944376d 100644 --- a/AicsKnowledgeBase/qml/MainWindow.qml +++ b/AicsKnowledgeBase/qml/MainWindow.qml @@ -128,12 +128,14 @@ FluWindow { "fileTitle": fileTitle }) } - function onModifyNote(file, fileType, fileTitle, note) { + function onModifyNote(file, fileType, fileTitle, note, noteTitle, noteContent) { stack_view.push(create_note_view, { "knowledgeFileId": file, "fileType": fileType, "fileTitle": fileTitle, "noteFileId": note, + "noteTitle": noteTitle, + "noteContent": noteContent, "isModifying": true }) } diff --git a/AicsKnowledgeBase/qml/global/NavItems.qml b/AicsKnowledgeBase/qml/global/NavItems.qml index c8ee738..7ecad3e 100644 --- a/AicsKnowledgeBase/qml/global/NavItems.qml +++ b/AicsKnowledgeBase/qml/global/NavItems.qml @@ -7,14 +7,6 @@ FluObject { property var navigationView - FluPaneItem { - title: "探索" - icon: FluentIcons.Home - onTap: { - navigationView.push("qrc:/AicsKnowledgeBase/qml/page/HomePage.qml") - } - } - FluPaneItem { title: "全部" icon: FluentIcons.FileExplorer @@ -27,7 +19,8 @@ FluObject { title: "文档" icon: FluentIcons.Document onTap: { - navigationView.push("qrc:/AicsKnowledgeBase/qml/page/DocumentPage.qml") + navigationView.push( + "qrc:/AicsKnowledgeBase/qml/page/DocumentPage.qml") } } @@ -51,7 +44,8 @@ FluObject { title: "搜索" icon: FluentIcons.Search onTap: { - navigationView.push("qrc:/AicsKnowledgeBase/qml/page/SearchPage.qml") + navigationView.push( + "qrc:/AicsKnowledgeBase/qml/page/SearchPage.qml") } } diff --git a/AicsKnowledgeBase/qml/global/Request.qml b/AicsKnowledgeBase/qml/global/Request.qml index 968632c..64777b0 100644 --- a/AicsKnowledgeBase/qml/global/Request.qml +++ b/AicsKnowledgeBase/qml/global/Request.qml @@ -72,11 +72,14 @@ QtObject { function putForm(url, arg, success, failure) { var xhr = new XMLHttpRequest - xhr.open("POST", baseUrl + url) - xhr.setRequestHeader("Content-Length", arg.length) + xhr.open("PUT", baseUrl + url) + //xhr.setRequestHeader("Content-Length", arg.length) xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;") xhr.onreadystatechange = function () { + if (this.readyState === 4) { + console.log(this.responseText) + } handleResponse(xhr, success, failure) } xhr.send(arg) diff --git a/AicsKnowledgeBase/qml/global/SignalFileOperation.qml b/AicsKnowledgeBase/qml/global/SignalFileOperation.qml index 19eaf27..7a8019b 100644 --- a/AicsKnowledgeBase/qml/global/SignalFileOperation.qml +++ b/AicsKnowledgeBase/qml/global/SignalFileOperation.qml @@ -6,6 +6,6 @@ QtObject { signal open(string file) signal openNote(string note, string authorId) signal createNote(string file, string fileType, string fileTitle) - signal modifyNote(string file, string fileType, string fileTitle, string note) + signal modifyNote(string file, string fileType, string fileTitle, string note, string noteTitle, string noteContent) signal back } diff --git a/AicsKnowledgeBase/qml/page/ContentPage.qml b/AicsKnowledgeBase/qml/page/ContentPage.qml index 07a3628..414ae38 100644 --- a/AicsKnowledgeBase/qml/page/ContentPage.qml +++ b/AicsKnowledgeBase/qml/page/ContentPage.qml @@ -32,7 +32,7 @@ FluArea { backgroundColor: "#f9f9f9" NoteList { id: noteList - //noteListModel: noteListModel2 + noteListModel: noteListModel2 onOpen: function handle(noteId, authorId) { emit: SignalFileOperation.openNote(noteId, authorId) popup.close() @@ -125,7 +125,8 @@ FluArea { isFavorite = false var starers = data.knowledgeFileAttribute.starers for (var i = 0; i < starers.length; i++) { - if (starers[i].id === UserData.userId) { + if (starers[i].id.toString( + ) === UserData.userId) { isFavorite = true } } @@ -263,13 +264,10 @@ FluArea { content_page.isFavorite = !content_page.isFavorite console.log(content_page.isFavorite) content_page.favoriteCount += (content_page.isFavorite ? 1 : -1) - Request.put("knowledge/" + knowledgeFileId + "/star", { - "active": content_page.isFavorite - }, response => { - console.log(response) - }, response => { - console.log(response) - }) + var form = "active=" + content_page.isFavorite ? "true" : "false" + Request.putForm( + "knowledge/" + knowledgeFileId + "/star", + form) } } FluText { diff --git a/AicsKnowledgeBase/qml/page/CreateNotePage.qml b/AicsKnowledgeBase/qml/page/CreateNotePage.qml index 42bc6a7..f61b7dc 100644 --- a/AicsKnowledgeBase/qml/page/CreateNotePage.qml +++ b/AicsKnowledgeBase/qml/page/CreateNotePage.qml @@ -25,23 +25,19 @@ FluArea { property bool isModifying: false Component.onCompleted: { - console.log(knowledgeFileId) - isModifying = false if (isModifying) { Request.getSearch("/search/note/" + noteFileId + "/content", - function (response, data) { - input_title.text = data.title - input_md.contentMd = data.content - tags = data.tags + function (response) { + input_title.text = noteTitle }) + } else { + noteTitle = Qt.binding(function () { + return input_title.text + }) + noteContent = Qt.binding(function () { + return input_md.contentMd + }) } - - noteTitle = Qt.binding(function () { - return input_title.text - }) - noteContent = Qt.binding(function () { - return input_md.contentMd - }) } FluScrollablePage { @@ -92,24 +88,23 @@ FluArea { Item { Layout.fillWidth: true implicitHeight: 50 - FluText { - id: text_title - padding: 10 - text: "标题" - font { - pointSize: 15 - bold: true + RowLayout { + Layout.fillWidth: true + FluText { + id: text_title + padding: 10 + text: "标题" + font { + pointSize: 15 + bold: true + } } - } - FluTextBox { - id: input_title - padding: 10 - placeholderText: "单行输入框" - implicitWidth: parent.width - font.pointSize: 12 - anchors { - left: text_title.right - verticalCenter: text_title.verticalCenter + FluTextBox { + id: input_title + padding: 10 + placeholderText: "单行输入框" + implicitWidth: parent.width + font.pointSize: 12 } } } @@ -130,6 +125,7 @@ FluArea { height: width * 9 / 16 isEditable: true isEditing: true + contentMd: noteContent } RowLayout { diff --git a/AicsKnowledgeBase/qml/page/NoteEditPage.qml b/AicsKnowledgeBase/qml/page/NoteEditPage.qml index 90d5b12..d874347 100644 --- a/AicsKnowledgeBase/qml/page/NoteEditPage.qml +++ b/AicsKnowledgeBase/qml/page/NoteEditPage.qml @@ -46,6 +46,7 @@ FluArea { } textArea_edit.text = edit_area.contentMd + edit_area.contentMd = Qt.binding(function () { return textArea_edit.text }) diff --git a/AicsKnowledgeBase/qml/page/NotePage.qml b/AicsKnowledgeBase/qml/page/NotePage.qml index e4d2a5c..0129c8a 100644 --- a/AicsKnowledgeBase/qml/page/NotePage.qml +++ b/AicsKnowledgeBase/qml/page/NotePage.qml @@ -155,7 +155,9 @@ FluArea { emit: SignalFileOperation.modifyNote(note_page.fileId, note_page.fileType, note_page.fileTitle, - noteFileId) + noteFileId, + note_page.title, + text_view.contentMd) } anchors { left: text_title.right diff --git a/AicsKnowledgeBase/src/FileTransferManager.cpp b/AicsKnowledgeBase/src/FileTransferManager.cpp index b34b871..0b48372 100644 --- a/AicsKnowledgeBase/src/FileTransferManager.cpp +++ b/AicsKnowledgeBase/src/FileTransferManager.cpp @@ -432,3 +432,29 @@ void FileTransferManager::openLocalFile(const QString &fileName) QDesktopServices::openUrl(QUrl::fromLocalFile("D:\\Downloads\\"+ fileName)); } +void FileTransferManager::putForm(QString knowledgeId, bool active) +{ + CURL *curl = curl_easy_init(); + if (!curl) { + qCritical() << "CURL INIT FAILED!"; + return; + } + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_easy_setopt(curl, CURLOPT_URL, ("https://api.hammer-hfut.tk:233/aics/main/knowledge/"+knowledgeId+"/star").toStdString().c_str()); + curl_easy_setopt(curl, CURLOPT_VERBOSE, true); + curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3000); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true); + curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https"); + curl_mime *mime; + curl_mimepart *part; + mime = curl_mime_init(curl); + part = curl_mime_addpart(mime); + curl_mime_name(part, "active"); + curl_mime_data(part, active?"true":"false", CURL_ZERO_TERMINATED); + curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime); + auto res = curl_easy_perform(curl); + curl_mime_free(mime); + curl_easy_cleanup(curl); +} + diff --git a/AicsKnowledgeBase/src/FileTransferManager.h b/AicsKnowledgeBase/src/FileTransferManager.h index 3b73e4b..e322dee 100644 --- a/AicsKnowledgeBase/src/FileTransferManager.h +++ b/AicsKnowledgeBase/src/FileTransferManager.h @@ -34,9 +34,14 @@ public: Q_INVOKABLE void openLocalFile(const QString &fileName); + Q_INVOKABLE void putForm(QString knowledgeId, bool active); + signals: + void transferComplete(bool download, QString fileId, QString fileName); + void markdownData(QString data); + private: };