From d70e2266e2c6f423facccbe46d1368f7cbd184c2 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Fri, 7 Jul 2023 04:22:36 +0800 Subject: [PATCH] fix --- .../qml/component/FileListItem.qml | 89 ++++++++++--------- AicsKnowledgeBase/qml/page/FavoritePage.qml | 69 +++++++++++++- AicsKnowledgeBase/qml/page/LocalPage.qml | 75 ++++++++++++++++ 3 files changed, 189 insertions(+), 44 deletions(-) diff --git a/AicsKnowledgeBase/qml/component/FileListItem.qml b/AicsKnowledgeBase/qml/component/FileListItem.qml index 67b234a..ffae7ee 100644 --- a/AicsKnowledgeBase/qml/component/FileListItem.qml +++ b/AicsKnowledgeBase/qml/component/FileListItem.qml @@ -84,40 +84,43 @@ FluArea { } } - MouseArea { - anchors.fill: row - acceptedButtons: Qt.LeftButton | Qt.RightButton - onDoubleClicked: { - fileItem.parent.doubleClicked() - } - onClicked: { - if (mouse.button === Qt.RightButton) { - menu.popup() - } - } - } - ColumnLayout { - id: clickable - anchors.fill: row - - RowLayout { - id: titleRow - Image { - id: icon - source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : "" - Layout.preferredHeight: 24 - Layout.preferredWidth: 24 - fillMode: Image.PreserveAspectFit + id: row + anchors.fill: parent + anchors.margins: 10 + spacing: 10 + ColumnLayout { + id: clickable + anchors.fill: row + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + onDoubleClicked: { + fileItem.parent.doubleClicked() + } + onClicked: { + if (mouse.button === Qt.RightButton) { + menu.popup() + } + } } - FluText { - id: title - font.bold: true - font.pointSize: 12 - text: fileItem.title - textFormat: Text.RichText + RowLayout { + id: titleRow + Image { + id: icon + source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : "" + Layout.preferredHeight: 24 + Layout.preferredWidth: 24 + fillMode: Image.PreserveAspectFit + } + FluText { + id: title + font.bold: true + font.pointSize: 12 + text: fileItem.title + textFormat: Text.RichText + } } - } FluText { id: brief @@ -159,18 +162,18 @@ FluArea { } } } - RowLayout { - visible: !fileItem.isDir - Repeater { - model: fileItem.tags - delegate: FluTextButton { - text: "#" + fileItem.tags[index] - normalColor: colorList[index % colorList.length] - font.pixelSize: 12 - Layout.preferredWidth: 50 - onClicked: { - emit: tagClicked(text) - } + } + RowLayout { + visible: !fileItem.isDir + Repeater { + model: fileItem.tags + delegate: FluTextButton { + text: "#" + fileItem.tags[index] + normalColor: colorList[index % colorList.length] + font.pixelSize: 12 + Layout.preferredWidth: 50 + onClicked: { + emit: tagClicked(text) } } } diff --git a/AicsKnowledgeBase/qml/page/FavoritePage.qml b/AicsKnowledgeBase/qml/page/FavoritePage.qml index 53c1804..d6e5473 100644 --- a/AicsKnowledgeBase/qml/page/FavoritePage.qml +++ b/AicsKnowledgeBase/qml/page/FavoritePage.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,72 @@ FluArea { Layout.topMargin: 20 FluText { + id: title Layout.topMargin: 20 - text: "Favorite" + text: "Favourite" + } + FileList { + anchors.top: title.bottom + disableHeader: true + width: parent.width + dataModel: listModel + } + ListModel { + id: listModel + } + Component.onCompleted: { + Request.get("/user", response => { + var files = JSON.parse(response).starredKnowledge + listModel.clear() + for (var i = 0; i < files.length; i++) { + var file = files[i] + console.log(file.name) + var modelItem = { + "title": file.knowledge.name, + "uuid": file.knowledge.id, + "date"// cut time after 'T' + : file.knowledge.createTime.substring(0, 10), + "fuuid": "0" + } + modelItem.isDir = false + modelItem.type = getType(file.suffix) + modelItem.size = file.size + modelItem.brief = file.brief + modelItem.pageView = file.pageView + modelItem.stars = 0 + var tagString = "" + for (var j = 0; j < file.tags.length; j++) { + if (j != 0) + tagString = tagString + "," + tagString = tagString + file.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/LocalPage.qml b/AicsKnowledgeBase/qml/page/LocalPage.qml index c8c832a..4f2e00c 100644 --- a/AicsKnowledgeBase/qml/page/LocalPage.qml +++ b/AicsKnowledgeBase/qml/page/LocalPage.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: "Local" } + FileList { + anchors.top: title.bottom + disableHeader: true + width: parent.width + dataModel: listModel + } + ListModel { + id: listModel + } + Component.onCompleted: { + var history = UserData.downloadedFiles + 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" + } }