diff --git a/AicsKnowledgeBase/CMakeLists.txt b/AicsKnowledgeBase/CMakeLists.txt index d0c1ff4..69e1ce2 100644 --- a/AicsKnowledgeBase/CMakeLists.txt +++ b/AicsKnowledgeBase/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 20) -find_package(Qt6 COMPONENTS Quick WebEngineQuick REQUIRED) +find_package(Qt6 COMPONENTS Gui Quick WebEngineQuick REQUIRED) #遍历所有Cpp文件 file(GLOB_RECURSE CPP_FILES src/*.cpp src/*.h) diff --git a/AicsKnowledgeBase/qml/MainWindow.qml b/AicsKnowledgeBase/qml/MainWindow.qml index be9e4dc..9763a23 100644 --- a/AicsKnowledgeBase/qml/MainWindow.qml +++ b/AicsKnowledgeBase/qml/MainWindow.qml @@ -102,6 +102,7 @@ FluWindow { target: SignalFileOperation function onOpen(file) { stack_view.clear() + UserData.viewHistory.push(file) stack_view.push(file_view, { "knowledgeFileId": file }) diff --git a/AicsKnowledgeBase/qml/component/CustomAppBar.qml b/AicsKnowledgeBase/qml/component/CustomAppBar.qml index 56ead21..6285759 100644 --- a/AicsKnowledgeBase/qml/component/CustomAppBar.qml +++ b/AicsKnowledgeBase/qml/component/CustomAppBar.qml @@ -117,6 +117,20 @@ Rectangle { Layout.rightMargin: 10 iconSource: FluentIcons.PenPalette iconSize: 14 + onClicked: { + note_menu.open() + } + FluMenu { + id: note_menu + x: parent ? (parent.width - width) / 2 : 0 + y: parent ? parent.height : 0 + FluMenuItem { + text: "收藏的笔记" + } + FluMenuItem { + text: "我的笔记" + } + } } Text { @@ -218,5 +232,6 @@ Rectangle { frameless_helper.setHitTestVisible(btn_maximize) frameless_helper.setHitTestVisible(btn_close) frameless_helper.setHitTestVisible(btn_transfer) + frameless_helper.setHitTestVisible(btn_note) } } diff --git a/AicsKnowledgeBase/qml/component/FileListItem.qml b/AicsKnowledgeBase/qml/component/FileListItem.qml index f8e89ce..68c7053 100644 --- a/AicsKnowledgeBase/qml/component/FileListItem.qml +++ b/AicsKnowledgeBase/qml/component/FileListItem.qml @@ -37,12 +37,15 @@ FluArea { message: fileItem.title onPositiveClicked: text => { var param = { - "name": text, - "parentId": fuuid + "parentId": fileItem.fuuid, + "name": text } - Request.post("/knowledge", - JSON.stringify(param)) - refresh() + console.log(JSON.stringify(param)) + Request.put( + "/knowledge/" + fileItem.uuid, + JSON.stringify(param), () => { + refresh() + }) } } } @@ -63,6 +66,7 @@ FluArea { "parentId": uuid, "name": fileItem.title } + console.log(JSON.stringify(param)) Request.put( "/knowledge/" + fileItem.uuid, JSON.stringify(param), () => { @@ -114,6 +118,7 @@ FluArea { font.bold: true font.pointSize: 12 text: fileItem.title + textFormat: Text.RichText } } diff --git a/AicsKnowledgeBase/qml/component/Tag.qml b/AicsKnowledgeBase/qml/component/Tag.qml index 47cb448..5a609ab 100644 --- a/AicsKnowledgeBase/qml/component/Tag.qml +++ b/AicsKnowledgeBase/qml/component/Tag.qml @@ -4,6 +4,8 @@ import QtQuick.Window import QtQuick.Controls import QtQuick.Controls.Basic import FluentUI +import QtQml +import "qrc:///AicsKnowledgeBase/qml/global" Rectangle { id: input @@ -13,10 +15,32 @@ Rectangle { radius: 5 clip: true - border.color: textInput.activeFocus ? "#268CDC":"#979592" //gray100 + ListModel { id: tagListModel } property ListModel tagList: tagListModel + property var tagMap:[] + property var presetsTags:[] + property var presetsTagsItem:[] + Component.onCompleted: { + Request.get("tag?name", + function(result, data){ +// console.log("success") +// console.log(result) +// console.log(data.length) + for(var i =0;i { + console.log("onTransferComplete") + UserData.downloadedFiles.push(fileId) + console.log(UserData.downloadedFiles) + } + } + contentItem: FluScrollablePage { anchors.fill: parent anchors.topMargin: 10 @@ -30,42 +40,65 @@ Popup { Layout.fillWidth: true height: 50 - ColumnLayout { + Item { anchors.fill: parent - anchors.margins: 5 - spacing: 2 - Text { - text: name + anchors.topMargin: 5 + anchors.bottomMargin: 5 + anchors.leftMargin: 0 + Image { + id: icon + anchors.verticalCenter: parent.verticalCenter + width: 32 + height: 32 + source: download ? "qrc:/AicsKnowledgeBase/res/download.png" : "qrc:/AicsKnowledgeBase/res/upload.png" } - FluProgressBar { - Layout.fillWidth: true - progress: completedSize / totalSize - indeterminate: false - } + ColumnLayout { + anchors.left: icon.right + anchors.right: parent.right + anchors.leftMargin: 5 + spacing: 2 + Text { + text: name + } + Text { + visible: completedSize >= totalSize + text: "已完成" + color: FluColors.Grey130 + } + FluProgressBar { + Layout.fillWidth: true + progress: completedSize / totalSize + indeterminate: false + visible: completedSize < totalSize + } - Text { - color: FluColors.Grey130 - text: formatSize(speed) + "/s - " + formatSize( - completedSize) + "/" + formatSize( - totalSize) + Text { + visible: completedSize < totalSize + color: FluColors.Grey130 + text: formatSize(speed) + "/s - " + formatSize( + completedSize) + "/" + formatSize( + totalSize) - /** - * 格式化文件大小, 输出成带单位的字符串 - * @param {Number} size 文件大小 - * @param {Number} [pointLength=1] 精确到的小数点数。 - * @param {Array} [units=[ 'B', 'K', 'M', 'G', 'TB' ]] 单位数组。从字节,到千字节,一直往上指定。 - * 如果单位数组里面只指定了到了K(千字节),同时文件大小大于M, 此方法的输出将还是显示成多少K. - */ - function formatSize(size, pointLength, units) { - var unit - units = units || ['B', 'KB', 'MB', 'GB', 'TB'] - while ((unit = units.shift()) && size > 1024) { - size = size / 1024 + /** + * 格式化文件大小, 输出成带单位的字符串 + * @param {Number} size 文件大小 + * @param {Number} [pointLength=1] 精确到的小数点数。 + * @param {Array} [units=[ 'B', 'K', 'M', 'G', 'TB' ]] 单位数组。从字节,到千字节,一直往上指定。 + * 如果单位数组里面只指定了到了K(千字节),同时文件大小大于M, 此方法的输出将还是显示成多少K. + */ + function formatSize(size, pointLength, units) { + var unit + units = units + || ['B', 'KB', 'MB', 'GB', 'TB'] + while ((unit = units.shift()) + && size > 1024) { + size = size / 1024 + } + return (unit === 'B' ? size : size.toFixed( + pointLength === undefined ? 1 : pointLength)) + ' ' + unit } - return (unit === 'B' ? size : size.toFixed( - pointLength === undefined ? 1 : pointLength)) + ' ' + unit } } } @@ -73,7 +106,10 @@ Popup { MouseArea { anchors.fill: parent hoverEnabled: true - onEntered: file_buttons.visible = true + onEntered: { + if (completedSize < totalSize) + file_buttons.visible = true + } onExited: file_buttons.visible = false LinearGradient { diff --git a/AicsKnowledgeBase/qml/global/Request.qml b/AicsKnowledgeBase/qml/global/Request.qml index 9b91baa..98cdc73 100644 --- a/AicsKnowledgeBase/qml/global/Request.qml +++ b/AicsKnowledgeBase/qml/global/Request.qml @@ -6,6 +6,7 @@ QtObject { id: request property string baseUrl: "https://api.hammer-hfut.tk:233/aics/main/" + property string searchUrl: "https://api.hammer-hfut.tk:233/aics/query" //property string baseUrl: "http://192.168.156.74:8080/" // GET @@ -17,7 +18,26 @@ QtObject { } xhr.send() } - + // GET in searchUrl + function getSearch(url, success, failure) { + var xhr = new XMLHttpRequest + xhr.open("GET", searchUrl + url) + xhr.onreadystatechange = function () { + handleResponse(xhr, success, failure) + } + xhr.send() + } + // PUT in searchUrl + function putSearch(url, arg, success, failure) { + var xhr = new XMLHttpRequest + xhr.open("PUT", searchUrl + url) + xhr.setRequestHeader('Content-Type', 'application/json') + xhr.withCredentials = true + xhr.onreadystatechange = function () { + handleResponse(xhr, success, failure) + } + xhr.send(arg) + } function getAwait(url) { var xhr = new XMLHttpRequest xhr.open("GET", baseUrl + url, false) diff --git a/AicsKnowledgeBase/qml/global/UserData.qml b/AicsKnowledgeBase/qml/global/UserData.qml index 771ac90..4d7845f 100644 --- a/AicsKnowledgeBase/qml/global/UserData.qml +++ b/AicsKnowledgeBase/qml/global/UserData.qml @@ -5,4 +5,6 @@ import QtQuick QtObject { property string username property string userId + property var viewHistory: [] + property var downloadedFiles: [] } diff --git a/AicsKnowledgeBase/qml/page/AudioPage.qml b/AicsKnowledgeBase/qml/page/AudioPage.qml index b58495f..91b533c 100644 --- a/AicsKnowledgeBase/qml/page/AudioPage.qml +++ b/AicsKnowledgeBase/qml/page/AudioPage.qml @@ -4,18 +4,91 @@ import QtQuick.Window import QtQuick.Controls import QtQuick.Controls.Basic import FluentUI +import "qrc:///AicsKnowledgeBase/qml/component" +import "qrc:///AicsKnowledgeBase/qml/global" FluArea { property string url: '' backgroundColor: "#f9f9f9" - Layout.fillWidth: true Layout.fillHeight: true paddings: 10 Layout.topMargin: 20 FluText { + id: title Layout.topMargin: 20 text: "Audio" } + FileList { + anchors.top: title.bottom + disableHeader: true + width: parent.width + dataModel: listModel + } + ListModel { + id: listModel + } + Component.onCompleted: { + Request.get("/knowledge?type=AUDIO", response => { + var files = JSON.parse(response) + listModel.clear() + 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), + "fuuid": "0" + } + 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 + 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 + } + listModel.append(modelItem) + } + }) + } + 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" + } } diff --git a/AicsKnowledgeBase/qml/page/ContentPage.qml b/AicsKnowledgeBase/qml/page/ContentPage.qml index f5cbcc3..8c026a6 100644 --- a/AicsKnowledgeBase/qml/page/ContentPage.qml +++ b/AicsKnowledgeBase/qml/page/ContentPage.qml @@ -67,7 +67,7 @@ FluArea { property int shareCount: 0 property int browsCount: 555 property bool isFavorite: false - property bool isDownload: false + property bool isDownload: UserData.downloadedFiles.indexOf(fileId) != -1 property double fileSize: 0 property string title: "文章标题" property list tags: ["tag 1", "tag 2", "tag 3"] @@ -271,7 +271,7 @@ FluArea { FileTransferManager.download(content_page.fileId, content_page.title) else { - + FileTransferManager.openLocalFile(content_page.title) } } } diff --git a/AicsKnowledgeBase/qml/page/DocumentPage.qml b/AicsKnowledgeBase/qml/page/DocumentPage.qml index b4939f9..929b5eb 100644 --- a/AicsKnowledgeBase/qml/page/DocumentPage.qml +++ b/AicsKnowledgeBase/qml/page/DocumentPage.qml @@ -4,6 +4,8 @@ import QtQuick.Window import QtQuick.Controls import QtQuick.Controls.Basic import FluentUI +import "qrc:///AicsKnowledgeBase/qml/component" +import "qrc:///AicsKnowledgeBase/qml/global" FluArea { property string url: '' @@ -14,7 +16,79 @@ FluArea { Layout.topMargin: 20 FluText { + id: title Layout.topMargin: 20 text: "Document" } + FileList { + anchors.top: title.bottom + disableHeader: true + width: parent.width + dataModel: listModel + } + ListModel { + id: listModel + } + Component.onCompleted: { + Request.get("/knowledge?type=DOCUMENT", response => { + var files = JSON.parse(response) + listModel.clear() + 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), + "fuuid": "0" + } + 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 + 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 + } + listModel.append(modelItem) + } + }) + } + 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" + } } diff --git a/AicsKnowledgeBase/qml/page/HistoryPage.qml b/AicsKnowledgeBase/qml/page/HistoryPage.qml index b674143..19e1695 100644 --- a/AicsKnowledgeBase/qml/page/HistoryPage.qml +++ b/AicsKnowledgeBase/qml/page/HistoryPage.qml @@ -4,6 +4,8 @@ import QtQuick.Window import QtQuick.Controls import QtQuick.Controls.Basic import FluentUI +import "qrc:///AicsKnowledgeBase/qml/component" +import "qrc:///AicsKnowledgeBase/qml/global" FluArea { property string url: '' @@ -17,4 +19,77 @@ FluArea { Layout.topMargin: 20 text: "History" } + FileList { + anchors.top: title.bottom + disableHeader: true + width: parent.width + dataModel: listModel + } + ListModel { + id: listModel + } + Component.onCompleted: { + var history = UserData.viewHistory + console.log(history) + listModel.clear() + for (var i = 0; i < history.length; i++) { + Request.get("/knowledge/" + history[i] + "/detailed", response => { + var file = JSON.parse(response) + + var modelItem = { + "title": file.name, + "uuid": file.id, + "date"// cut time after 'T' + : file.createTime.substring(0, 10), + "fuuid": "" + } + 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 + } + listModel.append(modelItem) + }) + } + } + 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" + } } diff --git a/AicsKnowledgeBase/qml/page/SearchPage.qml b/AicsKnowledgeBase/qml/page/SearchPage.qml index 56cad27..773c728 100644 --- a/AicsKnowledgeBase/qml/page/SearchPage.qml +++ b/AicsKnowledgeBase/qml/page/SearchPage.qml @@ -8,6 +8,7 @@ import "qrc:///AicsKnowledgeBase/qml/global" import "qrc:///AicsKnowledgeBase/qml/component" FluArea { + id: searchPage property string url: '' backgroundColor: "#f9f9f9" Layout.fillHeight: true @@ -19,14 +20,17 @@ FluArea { // Layout.topMargin: 20 // text: "Search" // } + + /* 按标题,内容搜索 */ - ColumnLayout{ + ColumnLayout { width: parent.width - RowLayout{ - width:parent.width + RowLayout { + width: parent.width + // FluDropDownButton{ // id:select_model // Layout.alignment: Qt.AlignLeft @@ -52,105 +56,100 @@ FluArea { // } // ] // } - - FluTextBox{ - placeholderText:"对标题进行搜索……" + FluTextBox { + placeholderText: "对标题进行搜索……" Layout.fillWidth: true - } - FluIconButton{ + FluIconButton { Layout.alignment: Qt.AlignRight - iconSource:FluentIcons.Search - onClicked:{ + iconSource: FluentIcons.Search + onClicked: { var allTags = inputTags.getAllTags(tags.tagList) - var allTagId =[] + var allTagId = [] console.log(allTags) for (var i = 0; i < allTags.length; i++) { var url = "?name=" url = url + allTags[i] console.log(url) - Request.get(url, - function(result, data){ - allTagId.push() - } - - ) + Request.get(url, function (result, data) { + allTagId.push() + }) } } } - } - FluCheckBox{ - id:searchTitleAndContent - text:"同时搜索简介和内容" + FluCheckBox { + id: searchTitleAndContent + text: "同时搜索简介和内容" } //按文件类型 - RowLayout{ - id:selectFormat - width:parent.width - FluText{ + RowLayout { + id: selectFormat + width: parent.width + FluText { Layout.alignment: Qt.AlignLeft - text:"类型: " + text: "类型: " } - FluCheckBox{ - id:selectAllFormat - text:"all" - Component.onCompleted:{ + FluCheckBox { + id: selectAllFormat + text: "all" + Component.onCompleted: { clicked() } - onClicked:{ - selectVideo.checked=true - selectDoc.checked=true - selectAudio.checked=true + onClicked: { + selectVideo.checked = true + selectDoc.checked = true + selectAudio.checked = true } } - FluCheckBox{ - id:selectVideo - text:"Video" - onClicked:{ + FluCheckBox { + id: selectVideo + text: "Video" + onClicked: { selectFormat.setAllStatus() } } - FluCheckBox{ - id:selectDoc - text:"Doc" - onClicked:{ + FluCheckBox { + id: selectDoc + text: "Doc" + onClicked: { selectFormat.setAllStatus() } } - FluCheckBox{ - id:selectAudio - text:"Audio" - onClicked:{ + FluCheckBox { + id: selectAudio + text: "Audio" + onClicked: { selectFormat.setAllStatus() } } function setAllStatus() { - selectAllFormat.checked = selectVideo.checked && selectDoc.checked && selectAudio.checked + selectAllFormat.checked = selectVideo.checked + && selectDoc.checked && selectAudio.checked } } - RowLayout{ - id:inputTags - width:parent.width + RowLayout { + id: inputTags + width: parent.width height: 32 - FluText{ + FluText { Layout.alignment: Qt.AlignLeft - text:"标签: " + text: "标签: " } - Tag{ - id:tags + Tag { + id: tags width: 290 } - function getAllTags(tagList){ - var allTags=[]; + function getAllTags(tagList) { + var allTags = [] for (var i = 0; i < tagList.count; i++) { - var item = tagList.get(i); + var item = tagList.get(i) allTags.push(item.tag) } return allTags @@ -200,4 +199,45 @@ FluArea { } } } + function getKnowledgeDetail(uuid, title, brief, tags) { + var raw = Request.getAwait("/knowledget/" + uuid) + var data = JSON.parse(raw) + var item = { + "uuid": uuid, + "title": title, + "brief": brief, + "isDir": false, + "date": data.createTime, + "fuuid": data.parent.id, + "pageView": data.knowledgeFileAttribute.pageView, + "stars": data.knowledgeFileAttribute.stars, + "size": data.knowledgeFileAttribute.size, + "type": getType(data.knowledgeFileAttribute.suffix), + "tags": tags + } + } + 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" + } } diff --git a/AicsKnowledgeBase/qml/page/VideoPage.qml b/AicsKnowledgeBase/qml/page/VideoPage.qml index 52d56b9..ebb20fe 100644 --- a/AicsKnowledgeBase/qml/page/VideoPage.qml +++ b/AicsKnowledgeBase/qml/page/VideoPage.qml @@ -4,6 +4,8 @@ import QtQuick.Window import QtQuick.Controls import QtQuick.Controls.Basic import FluentUI +import "qrc:///AicsKnowledgeBase/qml/component" +import "qrc:///AicsKnowledgeBase/qml/global" FluArea { property string url: '' @@ -14,7 +16,79 @@ FluArea { Layout.topMargin: 20 FluText { + id: title Layout.topMargin: 20 text: "Video" } + FileList { + anchors.top: title.bottom + disableHeader: true + width: parent.width + dataModel: listModel + } + ListModel { + id: listModel + } + Component.onCompleted: { + Request.get("/knowledge?type=VIDEO", response => { + var files = JSON.parse(response) + listModel.clear() + 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), + "fuuid": "0" + } + 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 + 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 + } + listModel.append(modelItem) + } + }) + } + 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" + } } diff --git a/AicsKnowledgeBase/res/download.png b/AicsKnowledgeBase/res/download.png new file mode 100644 index 0000000..3bd31e8 Binary files /dev/null and b/AicsKnowledgeBase/res/download.png differ diff --git a/AicsKnowledgeBase/res/upload.png b/AicsKnowledgeBase/res/upload.png new file mode 100644 index 0000000..136a60f Binary files /dev/null and b/AicsKnowledgeBase/res/upload.png differ diff --git a/AicsKnowledgeBase/src/FileTransferListModel.cpp b/AicsKnowledgeBase/src/FileTransferListModel.cpp index 6cb46eb..46644e4 100644 --- a/AicsKnowledgeBase/src/FileTransferListModel.cpp +++ b/AicsKnowledgeBase/src/FileTransferListModel.cpp @@ -10,6 +10,8 @@ FileTransferListModel::FileTransferListModel(QObject *parent) m_roleName.insert(kTotalSizeRole, "totalSize"); m_roleName.insert(kSpeedRole, "speed"); m_roleName.insert(kPausedRole, "paused"); + + m_data.append({true, "id", "name", 30, 100, 30}); } diff --git a/AicsKnowledgeBase/src/FileTransferManager.cpp b/AicsKnowledgeBase/src/FileTransferManager.cpp index 3344a42..b34b871 100644 --- a/AicsKnowledgeBase/src/FileTransferManager.cpp +++ b/AicsKnowledgeBase/src/FileTransferManager.cpp @@ -8,6 +8,7 @@ #include #include #include +#include static const std::string baseUrl = "https://api.hammer-hfut.tk:233/aics/file/"; //static const std::string baseUrl = "http://127.0.0.1:4523/m1/2914957-0-6e5f2db1/"; @@ -73,8 +74,8 @@ static int xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ul fileTrans->completedSize += dlnow; fileTrans->speed = speed; - qDebug() << std::format("Downloading: {} / {}, Speed: {}", fileTrans->completedSize, fileTrans->totalSize, - speed).c_str(); + //qDebug() << std::format("Downloading: {} / {}, Speed: {}", fileTrans->completedSize, fileTrans->totalSize, + // speed).c_str(); auto item = static_cast(*fileTrans); QTimer::singleShot(0, qApp, [item]() { @@ -96,8 +97,8 @@ static int uploadInfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t curl_easy_getinfo(fileTrans->curlHandle, CURLINFO_SPEED_UPLOAD_T, &speed); fileTrans->completedSize += ulnow; fileTrans->speed = speed; - qDebug() << std::format("Uploading: {} / {}, Speed: {}", fileTrans->completedSize, fileTrans->totalSize, - speed).c_str(); + //qDebug() << std::format("Uploading: {} / {}, Speed: {}", fileTrans->completedSize, fileTrans->totalSize, + // speed).c_str(); auto item = static_cast(*fileTrans); QTimer::singleShot(0, qApp, [item]() { @@ -359,6 +360,10 @@ void FileTransferManager::download(const QString &fileId, const QString &fileNam auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), completedSize, size); auto res = httpDownload(fileUrl, savePath, item); + + if (QFileInfo(QString::fromLocal8Bit(savePath.c_str())).size() == size) + emit transferComplete(true, fileId, fileName); + qDebug() << "End Get" << res; }); } @@ -398,8 +403,6 @@ QString FileTransferManager::getFileName(const QUrl &fileUrl) } - - void FileTransferManager::getMarkdown(const QString &fileId) { QtConcurrent::run([fileId, this] { @@ -424,3 +427,8 @@ void FileTransferManager::getMarkdown(const QString &fileId) }); } +void FileTransferManager::openLocalFile(const QString &fileName) +{ + QDesktopServices::openUrl(QUrl::fromLocalFile("D:\\Downloads\\"+ fileName)); +} + diff --git a/AicsKnowledgeBase/src/FileTransferManager.h b/AicsKnowledgeBase/src/FileTransferManager.h index 0e1c3ad..3b73e4b 100644 --- a/AicsKnowledgeBase/src/FileTransferManager.h +++ b/AicsKnowledgeBase/src/FileTransferManager.h @@ -32,7 +32,10 @@ public: Q_INVOKABLE void getMarkdown(const QString &fileId); + Q_INVOKABLE void openLocalFile(const QString &fileName); + signals: + void transferComplete(bool download, QString fileId, QString fileName); void markdownData(QString data); private: