# Conflicts:
#	AicsKnowledgeBase/qml/page/SearchPage.qml
main
shmily744 2023-07-07 01:08:43 +08:00
commit 6868d82753
15 changed files with 386 additions and 79 deletions

View File

@ -102,6 +102,7 @@ FluWindow {
target: SignalFileOperation target: SignalFileOperation
function onOpen(file) { function onOpen(file) {
stack_view.clear() stack_view.clear()
UserData.viewHistory.push(file)
stack_view.push(file_view, { stack_view.push(file_view, {
"knowledgeFileId": file "knowledgeFileId": file
}) })

View File

@ -37,12 +37,15 @@ FluArea {
message: fileItem.title message: fileItem.title
onPositiveClicked: text => { onPositiveClicked: text => {
var param = { var param = {
"name": text, "parentId": fileItem.fuuid,
"parentId": fuuid "name": text
} }
Request.post("/knowledge", console.log(JSON.stringify(param))
JSON.stringify(param)) Request.put(
refresh() "/knowledge/" + fileItem.uuid,
JSON.stringify(param), () => {
refresh()
})
} }
} }
} }
@ -63,6 +66,7 @@ FluArea {
"parentId": uuid, "parentId": uuid,
"name": fileItem.title "name": fileItem.title
} }
console.log(JSON.stringify(param))
Request.put( Request.put(
"/knowledge/" + fileItem.uuid, "/knowledge/" + fileItem.uuid,
JSON.stringify(param), () => { JSON.stringify(param), () => {
@ -114,6 +118,7 @@ FluArea {
font.bold: true font.bold: true
font.pointSize: 12 font.pointSize: 12
text: fileItem.title text: fileItem.title
textFormat: Text.RichText
} }
} }

View File

@ -5,6 +5,7 @@ import QtQuick.Layouts
import Qt5Compat.GraphicalEffects import Qt5Compat.GraphicalEffects
import FluentUI import FluentUI
import AicsKB.FileTransferManager import AicsKB.FileTransferManager
import "qrc:///AicsKnowledgeBase/qml/global"
Popup { Popup {
id: transfer_popup id: transfer_popup
@ -18,6 +19,15 @@ Popup {
FluShadow {} FluShadow {}
} }
Connections {
target: FileTransferManager
onTransferComplete: (download, fileId, fileName) => {
console.log("onTransferComplete")
UserData.downloadedFiles.push(fileId)
console.log(UserData.downloadedFiles)
}
}
contentItem: FluScrollablePage { contentItem: FluScrollablePage {
anchors.fill: parent anchors.fill: parent
anchors.topMargin: 10 anchors.topMargin: 10
@ -30,42 +40,65 @@ Popup {
Layout.fillWidth: true Layout.fillWidth: true
height: 50 height: 50
ColumnLayout { Item {
anchors.fill: parent anchors.fill: parent
anchors.margins: 5 anchors.topMargin: 5
spacing: 2 anchors.bottomMargin: 5
Text { anchors.leftMargin: 0
text: name Image {
id: icon
anchors.verticalCenter: parent.verticalCenter
width: 32
height: 32
source: download ? "qrc:/AicsKnowledgeBase/res/download.png" : "qrc:/AicsKnowledgeBase/res/upload.png"
} }
FluProgressBar { ColumnLayout {
Layout.fillWidth: true anchors.left: icon.right
progress: completedSize / totalSize anchors.right: parent.right
indeterminate: false 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 { Text {
color: FluColors.Grey130 visible: completedSize < totalSize
text: formatSize(speed) + "/s - " + formatSize( color: FluColors.Grey130
completedSize) + "/" + formatSize( text: formatSize(speed) + "/s - " + formatSize(
totalSize) completedSize) + "/" + formatSize(
totalSize)
/** /**
* , * ,
* @param {Number} size * @param {Number} size
* @param {Number} [pointLength=1] * @param {Number} [pointLength=1]
* @param {Array} [units=[ 'B', 'K', 'M', 'G', 'TB' ]] * @param {Array} [units=[ 'B', 'K', 'M', 'G', 'TB' ]]
* K()M, K. * K()M, K.
*/ */
function formatSize(size, pointLength, units) { function formatSize(size, pointLength, units) {
var unit var unit
units = units || ['B', 'KB', 'MB', 'GB', 'TB'] units = units
while ((unit = units.shift()) && size > 1024) { || ['B', 'KB', 'MB', 'GB', 'TB']
size = size / 1024 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 { MouseArea {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onEntered: file_buttons.visible = true onEntered: {
if (completedSize < totalSize)
file_buttons.visible = true
}
onExited: file_buttons.visible = false onExited: file_buttons.visible = false
LinearGradient { LinearGradient {

View File

@ -5,4 +5,6 @@ import QtQuick
QtObject { QtObject {
property string username property string username
property string userId property string userId
property var viewHistory: []
property var downloadedFiles: []
} }

View File

@ -4,18 +4,91 @@ import QtQuick.Window
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
import FluentUI import FluentUI
import "qrc:///AicsKnowledgeBase/qml/component"
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea { FluArea {
property string url: '' property string url: ''
backgroundColor: "#f9f9f9" backgroundColor: "#f9f9f9"
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
paddings: 10 paddings: 10
Layout.topMargin: 20 Layout.topMargin: 20
FluText { FluText {
id: title
Layout.topMargin: 20 Layout.topMargin: 20
text: "Audio" 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"
}
} }

View File

@ -4,6 +4,8 @@ import QtQuick.Window
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
import FluentUI import FluentUI
import "qrc:///AicsKnowledgeBase/qml/component"
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea { FluArea {
property string url: '' property string url: ''
@ -14,7 +16,79 @@ FluArea {
Layout.topMargin: 20 Layout.topMargin: 20
FluText { FluText {
id: title
Layout.topMargin: 20 Layout.topMargin: 20
text: "Document" 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"
}
} }

View File

@ -4,6 +4,8 @@ import QtQuick.Window
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
import FluentUI import FluentUI
import "qrc:///AicsKnowledgeBase/qml/component"
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea { FluArea {
property string url: '' property string url: ''
@ -17,4 +19,75 @@ FluArea {
Layout.topMargin: 20 Layout.topMargin: 20
text: "History" text: "History"
} }
FileList {
anchors.top: title.bottom
disableHeader: true
width: parent.width
dataModel: listModel
}
ListModel {
id: listModel
}
Component.onCompleted: {
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"
}
} }

View File

@ -46,7 +46,6 @@ FluArea {
property list<string> tags: ["tag 1", "tag 2", "tag 3"] property list<string> tags: ["tag 1", "tag 2", "tag 3"]
property string publishTime: "2020-01-01" property string publishTime: "2020-01-01"
property string brief: "这是一个简介" property string brief: "这是一个简介"
property var fromFile
function getType(suffix) { function getType(suffix) {
if (suffix === "md") if (suffix === "md")
@ -63,29 +62,7 @@ FluArea {
} }
Component.onCompleted: { Component.onCompleted: {
Request.get("knowledge/", function (response, data) {
fromFile = {
"uuid": data.id,
"fuuid": data.knowledgeFileAttribute.id,
"title": data.name,
"date": data.createTime,
"brief": data.knowledgeFileAttribute.brief,
"suffix": data.knowledgeFileAttribute.suffix,
"type": getType(data.knowledgeFileAttribute.suffix),
"pageView": data.knowledgeFileAttribute.pageView,
"size": data.knowledgeFileAttribute.size
}
fromFile.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
}
fromFile.tags = tagString
})
} }
FluIconButton { FluIconButton {
@ -222,19 +199,5 @@ FluArea {
width: parent.width width: parent.width
implicitHeight: 400 implicitHeight: 400
} }
// FistListItem {
// id: fileListItem
// uuid: fromFile.uuid
// fuuid: fromFile.fuuid
// title: fromFile.title
// date: fromFile.date
// brief: fromFile.brief
// type: fromFile.type
// pageView: fromFile.pageView
// size: fromFile.size
// stars: fromFile.stars
// tags: fromFile.tags === null || fromFile.tags === undefined
// || fromFile.tags === "" ? [] : fromFile.tags.split(",")
// }
} }
} }

View File

@ -21,6 +21,7 @@ FluArea {
// text: "Search" // text: "Search"
// } // }
/* /*
*/ */

View File

@ -4,6 +4,8 @@ import QtQuick.Window
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
import FluentUI import FluentUI
import "qrc:///AicsKnowledgeBase/qml/component"
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea { FluArea {
property string url: '' property string url: ''
@ -14,7 +16,79 @@ FluArea {
Layout.topMargin: 20 Layout.topMargin: 20
FluText { FluText {
id: title
Layout.topMargin: 20 Layout.topMargin: 20
text: "Video" 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"
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -10,6 +10,8 @@ FileTransferListModel::FileTransferListModel(QObject *parent)
m_roleName.insert(kTotalSizeRole, "totalSize"); m_roleName.insert(kTotalSizeRole, "totalSize");
m_roleName.insert(kSpeedRole, "speed"); m_roleName.insert(kSpeedRole, "speed");
m_roleName.insert(kPausedRole, "paused"); m_roleName.insert(kPausedRole, "paused");
m_data.append({true, "id", "name", 30, 100, 30});
} }

View File

@ -73,8 +73,8 @@ static int xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ul
fileTrans->completedSize += dlnow; fileTrans->completedSize += dlnow;
fileTrans->speed = speed; fileTrans->speed = speed;
qDebug() << std::format("Downloading: {} / {}, Speed: {}", fileTrans->completedSize, fileTrans->totalSize, //qDebug() << std::format("Downloading: {} / {}, Speed: {}", fileTrans->completedSize, fileTrans->totalSize,
speed).c_str(); // speed).c_str();
auto item = static_cast<FileItem>(*fileTrans); auto item = static_cast<FileItem>(*fileTrans);
QTimer::singleShot(0, qApp, [item]() { QTimer::singleShot(0, qApp, [item]() {
@ -96,8 +96,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); curl_easy_getinfo(fileTrans->curlHandle, CURLINFO_SPEED_UPLOAD_T, &speed);
fileTrans->completedSize += ulnow; fileTrans->completedSize += ulnow;
fileTrans->speed = speed; fileTrans->speed = speed;
qDebug() << std::format("Uploading: {} / {}, Speed: {}", fileTrans->completedSize, fileTrans->totalSize, //qDebug() << std::format("Uploading: {} / {}, Speed: {}", fileTrans->completedSize, fileTrans->totalSize,
speed).c_str(); // speed).c_str();
auto item = static_cast<FileItem>(*fileTrans); auto item = static_cast<FileItem>(*fileTrans);
QTimer::singleShot(0, qApp, [item]() { QTimer::singleShot(0, qApp, [item]() {
@ -359,6 +359,10 @@ 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);
if (QFileInfo(QString::fromLocal8Bit(savePath.c_str())).size() == size)
emit transferComplete(true, fileId, fileName);
qDebug() << "End Get" << res; qDebug() << "End Get" << res;
}); });
} }
@ -398,8 +402,6 @@ QString FileTransferManager::getFileName(const QUrl &fileUrl)
} }
void FileTransferManager::getMarkdown(const QString &fileId) void FileTransferManager::getMarkdown(const QString &fileId)
{ {
QtConcurrent::run([fileId, this] { QtConcurrent::run([fileId, this] {

View File

@ -33,6 +33,7 @@ public:
Q_INVOKABLE void getMarkdown(const QString &fileId); Q_INVOKABLE void getMarkdown(const QString &fileId);
signals: signals:
void transferComplete(bool download, QString fileId, QString fileName);
void markdownData(QString data); void markdownData(QString data);
private: private: