wuyize 2023-07-07 04:48:13 +08:00
commit 8c37bca675
5 changed files with 337 additions and 172 deletions

View File

@ -211,7 +211,9 @@ Item {
Rectangle {
id: fileListItemRect
width: ListView.view.width
height: model.isDir ? 50 : 120
//set the height to fit model.brief
height: model.isDir ? 50 : Math.max(120,
model.brief.length / 3 + 80)
//color: !ListView.isCurrentItem ? "white" : "red"
FileListItem {
id: fileListItem

View File

@ -84,101 +84,98 @@ 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
}
FluText {
id: title
font.bold: true
font.pointSize: 12
text: fileItem.title
textFormat: Text.RichText
}
}
FluText {
id: brief
visible: !fileItem.isDir
text: fileItem.brief
Layout.fillWidth: true
wrapMode: Text.WrapAnywhere
elide: Text.ElideRight
maximumLineCount: 2
textFormat: Text.RichText
}
RowLayout {
id: infoRow
visible: !fileItem.isDir
FluText {
id: date
color: "#5F5F5F"
text: fileItem.date
}
FluText {
id: size
// cast Byte size to right text size
color: "#5F5F5F"
text: fileItem.size > 1024
* 1024 ? (fileItem.size / 1024 / 1024).toFixed(
2) + "MB" : (fileItem.size / 1024).toFixed(
2) + "KB"
}
FluText {
id: pageView
color: "#5F5F5F"
text: fileItem.pageView + "浏览"
}
FluText {
id: stars
color: "#5F5F5F"
text: fileItem.stars + "收藏"
}
}
}
ColumnLayout {
id: row
anchors.fill: parent
anchors.margins: 10
spacing: 10
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)
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()
}
}
}
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
visible: !fileItem.isDir
text: fileItem.brief
Layout.fillWidth: true
wrapMode: Text.WordWrap
elide: Text.ElideRight
maximumLineCount: 4
textFormat: Text.RichText
fontSizeMode: Text.Fit
}
RowLayout {
id: infoRow
visible: !fileItem.isDir
FluText {
id: date
color: "#5F5F5F"
text: fileItem.date
}
FluText {
id: size
// cast Byte size to right text size
color: "#5F5F5F"
text: fileItem.size > 1024
* 1024 ? (fileItem.size / 1024 / 1024).toFixed(
2) + "MB" : (fileItem.size / 1024).toFixed(
2) + "KB"
}
FluText {
id: pageView
color: "#5F5F5F"
text: fileItem.pageView + "浏览"
}
FluText {
id: stars
color: "#5F5F5F"
text: fileItem.stars + "收藏"
}
}
}
}
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)
}
}
}
}
}

View File

@ -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"
}
}

View File

@ -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"
}
}

View File

@ -10,6 +10,8 @@ import "qrc:///AicsKnowledgeBase/qml/component"
FluArea {
id: searchPage
property string url: ''
property var tags: []
property ListModel listModel: ListModel {}
backgroundColor: "#f9f9f9"
Layout.fillHeight: true
Layout.fillWidth: true
@ -30,52 +32,102 @@ FluArea {
width: parent.width
RowLayout {
width: parent.width
// FluDropDownButton{
// id:select_model
// Layout.alignment: Qt.AlignLeft
// text:""
// items:[
// FluMenuItem{
// text:""
// onClicked: {
// select_model.text = text
// }
// },
// FluMenuItem{
// text:""
// onClicked: {
// select_model.text = text
// }
// },
// FluMenuItem{
// text:""
// onClicked: {
// select_model.text = text
// }
// }
// ]
// }
FluTextBox {
placeholderText: "对标题进行搜索……"
id: search_text
Layout.fillWidth: true
}
FluIconButton {
Layout.alignment: Qt.AlignRight
iconSource: FluentIcons.Search
onClicked: {
var allTags = inputTags.getAllTags(tags.tagList)
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()
})
listModel.clear()
var allTags = tags.tagMap
var selectTagName = []
var selectTagId = []
for (var i = 0; i < tags.tagList.count; i++) {
selectTagName.push(tags.tagList.get(i).tag)
console.log(selectTagName[selectTagName.length - 1])
}
for (i = 0; i < selectTagName.length; i++) {
for (var j = 0; j < allTags.length; j++) {
if (selectTagName[i] === allTags[j][1]) {
selectTagId.push(allTags[j][0])
console.log(allTags[j][0])
}
}
}
var params = {
"text": search_text.text,
"applyToBriefAndContent": searchTitleAndContent.checked,
"tags": selectTagId
}
var url = "/search/knowledge?"
// encode params to get url
url += "text=" + params.text
url += "&applyToBriefAndContent=" + params.applyToBriefAndContent
url += "&tags="
for (i = 0; i < params.tags.length; i++) {
url += "&tags=" + params.tags[i]
}
var tagString = ""
// merge all tag to a string split by ','
for (i = 0; i < selectTagName.length; i++) {
if (i !== 0) {
tagString += ","
}
tagString += selectTagName[i]
}
var sName = ""
var sBrief = ""
console.log(url)
Request.getSearch(url, response => {
var dataArray = JSON.parse(response)
for (var i = 0; i < dataArray.length; i++) {
var data = dataArray[i]
if (data.highlightFields.name !== null
&& data.highlightFields.name !== undefined
&& data.highlightFields.name.length > 0) {
for (i = 0; i
< data.highlightFields.name.length; i++) {
if (i !== 0) {
sName += "..."
}
sName += data.highlightFields.name[i]
}
} else {
sName = data.content.name
}
if (data.highlightFields.brief !== null
&& data.highlightFields.brief !== undefined
&& data.highlightFields.brief.length > 0) {
for (i = 0; i
< data.highlightFields.brief.length; i++) {
if (i !== 0) {
sBrief += "..."
}
sBrief += data.highlightFields.brief[i]
}
}
if (data.highlightFields.content !== null
&& data.highlightFields.content !== undefined
&& data.highlightFields.content.length > 0) {
for (i = 0; i
< data.highlightFields.content.length; i++) {
if (i !== 0) {
sBrief += "..."
}
sBrief += data.highlightFields.content[i]
}
}
if (sBrief.length === 0) {
sBrief = data.content.brief
}
getKnowledgeDetail(
data.content.uuid, sName,
sBrief, tagString)
}
})
}
}
}
@ -165,56 +217,28 @@ FluArea {
FileList {
disableHeader: true
dataModel: ListModel {
ListElement {
uuid: "0"
title: "File 1"
isDir: true
brief: "This is a test file"
type: "FOLDER"
}
ListElement {
uuid: "2"
title: "File 2"
isDir: false
brief: "This is a test file"
size: 500
type: "WORD"
date: "2020-09-09"
pageView: 100
stars: 10
}
ListElement {
uuid: "3"
title: "File 3"
isDir: false
brief: "This is a test file"
type: "PPT"
date: "2020-09-09"
pageView: 100
size: 10200000022
stars: 10
}
}
dataModel: listModel
}
}
}
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
}
Request.get("/knowledge/" + uuid, raw => {
var data = JSON.parse(raw)
var item = {
"uuid": uuid,
"title": title,
"brief": brief,
"isDir": false,
"date": data.createTime.substring(0, 10),
"fuuid": "data.parent.id",
"pageView": data.knowledgeFileAttribute.pageView,
"stars": data.knowledgeFileAttribute.stars,
"size": data.knowledgeFileAttribute.size,
"type": getType(data.knowledgeFileAttribute.suffix),
"tags": tags
}
listModel.append(item)
})
}
function getType(suffix) {
if (suffix === "ppt" || suffix === "pptx")