完成tag组件

main
shmily744 2023-07-07 00:56:12 +08:00
parent eb09b43ee8
commit ddc67c9f65
2 changed files with 131 additions and 71 deletions

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 QtQml
import "qrc:///AicsKnowledgeBase/qml/global"
Rectangle { Rectangle {
id: input id: input
@ -13,10 +15,32 @@ Rectangle {
radius: 5 radius: 5
clip: true clip: true
border.color: textInput.activeFocus ? "#268CDC":"#979592" //gray100
ListModel { id: tagListModel } ListModel { id: tagListModel }
property ListModel tagList: 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<data.length;i++){
tagMap.push([data[i].id,data[i].name])
presetsTags.push(data[i].name)
presetsTagsItem.push({title:data[i].name})
}
// console.log(tagMap)
// console.log(presetsTags)
},function (p1, p2) {
// console.log("failure")
// console.log(p1)
// console.log(p2)
})
}
Row { Row {
x: 5 x: 5
@ -48,23 +72,23 @@ Rectangle {
width: input.width - rowTag.width width: input.width - rowTag.width
height: parent.height height: parent.height
TextField { FluAutoSuggestBox{
id:textInput id:textInput
placeholderText: qsTr("按回车键Enter创建标签") anchors.verticalCenter: parent.verticalCenter
width: parent.width
placeholderText: "按回车键Enter创建标签"
Layout.preferredWidth: 300
//items:[{title:""},{title:""},{title:""}]
items: presetsTagsItem
onFocusChanged: { onFocusChanged: {
text ="" text =""
} }
anchors.verticalCenter: parent.verticalCenter
width: parent.width - 15
clip: true
background: Rectangle {
}
Keys.onReturnPressed: { Keys.onReturnPressed: {
var presetsTags = ["前端","后端","数据库"]
if (text.length === 0) if (text.length === 0)
return return
@ -72,12 +96,10 @@ Rectangle {
text = "" text = ""
return return
} }
tagListModel.append({"tag": text}) tagListModel.append({"tag": text})
//console.log(tagListModel.get(0)) //console.log(tagListModel.get(0))
text = "" text = ""
} }
Keys.onPressed: { Keys.onPressed: {
if (event.key === Qt.Key_Backspace) { if (event.key === Qt.Key_Backspace) {
if (text.length === 0 && tagListModel.count) { if (text.length === 0 && tagListModel.count) {
@ -86,7 +108,6 @@ Rectangle {
} }
} }
} }
} }
} }

View File

@ -8,6 +8,7 @@ import "qrc:///AicsKnowledgeBase/qml/global"
import "qrc:///AicsKnowledgeBase/qml/component" import "qrc:///AicsKnowledgeBase/qml/component"
FluArea { FluArea {
id: searchPage
property string url: '' property string url: ''
backgroundColor: "#f9f9f9" backgroundColor: "#f9f9f9"
Layout.fillHeight: true Layout.fillHeight: true
@ -19,14 +20,16 @@ FluArea {
// Layout.topMargin: 20 // Layout.topMargin: 20
// text: "Search" // text: "Search"
// } // }
/* /*
*/ */
ColumnLayout{ ColumnLayout {
width: parent.width width: parent.width
RowLayout{ RowLayout {
width:parent.width width: parent.width
// FluDropDownButton{ // FluDropDownButton{
// id:select_model // id:select_model
// Layout.alignment: Qt.AlignLeft // Layout.alignment: Qt.AlignLeft
@ -52,105 +55,100 @@ FluArea {
// } // }
// ] // ]
// } // }
FluTextBox {
FluTextBox{ placeholderText: "对标题进行搜索……"
placeholderText:"对标题进行搜索……"
Layout.fillWidth: true Layout.fillWidth: true
} }
FluIconButton{ FluIconButton {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
iconSource:FluentIcons.Search iconSource: FluentIcons.Search
onClicked:{ onClicked: {
var allTags = inputTags.getAllTags(tags.tagList) var allTags = inputTags.getAllTags(tags.tagList)
var allTagId =[] var allTagId = []
console.log(allTags) console.log(allTags)
for (var i = 0; i < allTags.length; i++) { for (var i = 0; i < allTags.length; i++) {
var url = "?name=" var url = "?name="
url = url + allTags[i] url = url + allTags[i]
console.log(url) console.log(url)
Request.get(url, Request.get(url, function (result, data) {
function(result, data){ allTagId.push()
allTagId.push() })
}
)
} }
} }
} }
} }
FluCheckBox{ FluCheckBox {
id:searchTitleAndContent id: searchTitleAndContent
text:"同时搜索简介和内容" text: "同时搜索简介和内容"
} }
// //
RowLayout{ RowLayout {
id:selectFormat id: selectFormat
width:parent.width width: parent.width
FluText{ FluText {
Layout.alignment: Qt.AlignLeft Layout.alignment: Qt.AlignLeft
text:"类型: " text: "类型: "
} }
FluCheckBox{ FluCheckBox {
id:selectAllFormat id: selectAllFormat
text:"all" text: "all"
Component.onCompleted:{ Component.onCompleted: {
clicked() clicked()
} }
onClicked:{ onClicked: {
selectVideo.checked=true selectVideo.checked = true
selectDoc.checked=true selectDoc.checked = true
selectAudio.checked=true selectAudio.checked = true
} }
} }
FluCheckBox{ FluCheckBox {
id:selectVideo id: selectVideo
text:"Video" text: "Video"
onClicked:{ onClicked: {
selectFormat.setAllStatus() selectFormat.setAllStatus()
} }
} }
FluCheckBox{ FluCheckBox {
id:selectDoc id: selectDoc
text:"Doc" text: "Doc"
onClicked:{ onClicked: {
selectFormat.setAllStatus() selectFormat.setAllStatus()
} }
} }
FluCheckBox{ FluCheckBox {
id:selectAudio id: selectAudio
text:"Audio" text: "Audio"
onClicked:{ onClicked: {
selectFormat.setAllStatus() selectFormat.setAllStatus()
} }
} }
function setAllStatus() { function setAllStatus() {
selectAllFormat.checked = selectVideo.checked && selectDoc.checked && selectAudio.checked selectAllFormat.checked = selectVideo.checked
&& selectDoc.checked && selectAudio.checked
} }
} }
RowLayout{ RowLayout {
id:inputTags id: inputTags
width:parent.width width: parent.width
height: 32 height: 32
FluText{ FluText {
Layout.alignment: Qt.AlignLeft Layout.alignment: Qt.AlignLeft
text:"标签: " text: "标签: "
} }
Tag{ Tag {
id:tags id: tags
width: 290 width: 290
} }
function getAllTags(tagList){ function getAllTags(tagList) {
var allTags=[]; var allTags = []
for (var i = 0; i < tagList.count; i++) { for (var i = 0; i < tagList.count; i++) {
var item = tagList.get(i); var item = tagList.get(i)
allTags.push(item.tag) allTags.push(item.tag)
} }
return allTags return allTags
@ -200,4 +198,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"
}
} }