2023-06-30 18:37:17 +08:00
|
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
import QtQuick.Window
|
|
|
|
|
import QtQuick.Controls
|
|
|
|
|
import QtQuick.Controls.Basic
|
|
|
|
|
import FluentUI
|
2023-07-05 15:39:29 +08:00
|
|
|
|
import "qrc:///AicsKnowledgeBase/qml/global"
|
2023-07-03 10:38:59 +08:00
|
|
|
|
import "qrc:///AicsKnowledgeBase/qml/component"
|
2023-06-30 18:37:17 +08:00
|
|
|
|
|
|
|
|
|
FluArea {
|
2023-07-07 00:24:17 +08:00
|
|
|
|
id: searchPage
|
2023-06-30 18:37:17 +08:00
|
|
|
|
property string url: ''
|
2023-07-07 03:26:13 +08:00
|
|
|
|
property var tags: []
|
|
|
|
|
property ListModel listModel: ListModel {}
|
2023-07-02 15:58:02 +08:00
|
|
|
|
backgroundColor: "#f9f9f9"
|
2023-06-30 18:37:17 +08:00
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.topMargin: 20
|
|
|
|
|
paddings: 10
|
|
|
|
|
|
2023-07-03 16:12:26 +08:00
|
|
|
|
// FluText {
|
|
|
|
|
// Layout.topMargin: 20
|
|
|
|
|
// text: "Search"
|
|
|
|
|
// }
|
2023-07-07 00:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
2023-07-03 10:38:59 +08:00
|
|
|
|
/*
|
|
|
|
|
按标题,内容搜索
|
2023-07-05 15:39:29 +08:00
|
|
|
|
*/
|
2023-07-07 00:24:17 +08:00
|
|
|
|
ColumnLayout {
|
2023-07-05 15:39:29 +08:00
|
|
|
|
|
2023-07-05 01:59:35 +08:00
|
|
|
|
width: parent.width
|
2023-07-07 00:24:17 +08:00
|
|
|
|
RowLayout {
|
|
|
|
|
width: parent.width
|
|
|
|
|
FluTextBox {
|
|
|
|
|
placeholderText: "对标题进行搜索……"
|
2023-07-07 03:26:13 +08:00
|
|
|
|
id: search_text
|
2023-07-03 16:12:26 +08:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
}
|
2023-07-07 00:24:17 +08:00
|
|
|
|
FluIconButton {
|
2023-07-03 16:12:26 +08:00
|
|
|
|
Layout.alignment: Qt.AlignRight
|
2023-07-07 00:24:17 +08:00
|
|
|
|
iconSource: FluentIcons.Search
|
|
|
|
|
onClicked: {
|
2023-07-07 03:26:13 +08:00
|
|
|
|
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]
|
2023-07-05 15:39:29 +08:00
|
|
|
|
}
|
2023-07-07 03:26:13 +08:00
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-07-05 15:39:29 +08:00
|
|
|
|
}
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
2023-07-05 15:39:29 +08:00
|
|
|
|
}
|
2023-07-07 00:24:17 +08:00
|
|
|
|
FluCheckBox {
|
|
|
|
|
id: searchTitleAndContent
|
|
|
|
|
text: "同时搜索简介和内容"
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
2023-07-04 12:40:04 +08:00
|
|
|
|
|
2023-07-03 16:12:26 +08:00
|
|
|
|
//按文件类型
|
2023-07-07 00:24:17 +08:00
|
|
|
|
RowLayout {
|
|
|
|
|
id: selectFormat
|
|
|
|
|
width: parent.width
|
|
|
|
|
FluText {
|
2023-07-03 16:12:26 +08:00
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
2023-07-07 00:24:17 +08:00
|
|
|
|
text: "类型: "
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
2023-07-07 00:24:17 +08:00
|
|
|
|
FluCheckBox {
|
|
|
|
|
id: selectAllFormat
|
|
|
|
|
text: "all"
|
|
|
|
|
Component.onCompleted: {
|
2023-07-03 16:12:26 +08:00
|
|
|
|
clicked()
|
|
|
|
|
}
|
2023-07-07 00:24:17 +08:00
|
|
|
|
onClicked: {
|
|
|
|
|
selectVideo.checked = true
|
|
|
|
|
selectDoc.checked = true
|
|
|
|
|
selectAudio.checked = true
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-07 00:24:17 +08:00
|
|
|
|
FluCheckBox {
|
|
|
|
|
id: selectVideo
|
|
|
|
|
text: "Video"
|
|
|
|
|
onClicked: {
|
2023-07-04 12:40:04 +08:00
|
|
|
|
selectFormat.setAllStatus()
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-07 00:24:17 +08:00
|
|
|
|
FluCheckBox {
|
|
|
|
|
id: selectDoc
|
|
|
|
|
text: "Doc"
|
|
|
|
|
onClicked: {
|
2023-07-04 12:40:04 +08:00
|
|
|
|
selectFormat.setAllStatus()
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 10:38:59 +08:00
|
|
|
|
|
2023-07-07 00:24:17 +08:00
|
|
|
|
FluCheckBox {
|
|
|
|
|
id: selectAudio
|
|
|
|
|
text: "Audio"
|
|
|
|
|
onClicked: {
|
2023-07-05 01:59:35 +08:00
|
|
|
|
selectFormat.setAllStatus()
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-04 12:40:04 +08:00
|
|
|
|
|
|
|
|
|
function setAllStatus() {
|
2023-07-07 00:24:17 +08:00
|
|
|
|
selectAllFormat.checked = selectVideo.checked
|
|
|
|
|
&& selectDoc.checked && selectAudio.checked
|
2023-07-04 12:40:04 +08:00
|
|
|
|
}
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
2023-07-03 10:38:59 +08:00
|
|
|
|
|
2023-07-07 00:24:17 +08:00
|
|
|
|
RowLayout {
|
|
|
|
|
id: inputTags
|
|
|
|
|
width: parent.width
|
2023-07-05 01:59:35 +08:00
|
|
|
|
height: 32
|
2023-07-07 00:24:17 +08:00
|
|
|
|
FluText {
|
2023-07-05 01:59:35 +08:00
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
2023-07-07 00:24:17 +08:00
|
|
|
|
text: "标签: "
|
2023-07-05 01:59:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-07 00:24:17 +08:00
|
|
|
|
Tag {
|
|
|
|
|
id: tags
|
2023-07-05 01:59:35 +08:00
|
|
|
|
width: 290
|
|
|
|
|
}
|
2023-07-07 00:24:17 +08:00
|
|
|
|
function getAllTags(tagList) {
|
|
|
|
|
var allTags = []
|
2023-07-05 15:39:29 +08:00
|
|
|
|
for (var i = 0; i < tagList.count; i++) {
|
2023-07-07 00:24:17 +08:00
|
|
|
|
var item = tagList.get(i)
|
2023-07-05 15:39:29 +08:00
|
|
|
|
allTags.push(item.tag)
|
|
|
|
|
}
|
|
|
|
|
return allTags
|
|
|
|
|
//console.log(allTags)
|
|
|
|
|
}
|
2023-07-05 01:59:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-05 13:58:03 +08:00
|
|
|
|
FluArea {
|
2023-07-04 13:38:01 +08:00
|
|
|
|
backgroundColor: "#f9f9f9"
|
|
|
|
|
border.width: 0
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: 500
|
2023-07-03 10:38:59 +08:00
|
|
|
|
|
2023-07-05 13:58:03 +08:00
|
|
|
|
FileList {
|
2023-07-04 13:38:01 +08:00
|
|
|
|
disableHeader: true
|
2023-07-07 03:26:13 +08:00
|
|
|
|
dataModel: listModel
|
2023-07-03 16:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-07 00:24:17 +08:00
|
|
|
|
function getKnowledgeDetail(uuid, title, brief, tags) {
|
2023-07-07 03:26:13 +08:00
|
|
|
|
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)
|
|
|
|
|
})
|
2023-07-07 00:24:17 +08:00
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
|
}
|
2023-06-30 18:37:17 +08:00
|
|
|
|
}
|