修改Tag组件

main
wuyize 2023-07-07 02:28:21 +08:00
parent e10fddb188
commit b67075a3ba
2 changed files with 73 additions and 45 deletions

View File

@ -16,29 +16,31 @@ Rectangle {
radius: 5 radius: 5
clip: true clip: true
ListModel { id: tagListModel } ListModel {
id: tagListModel
}
property ListModel tagList: tagListModel property ListModel tagList: tagListModel
property var tagMap:[] property var tagMap: []
property var presetsTags:[] property var presetsTags: []
property var presetsTagsItem:[] property var presetsTagsItem: []
Component.onCompleted: { Component.onCompleted: {
Request.get("tag?name", Request.get("tag?name", function (result, data) {
function(result, data){ // console.log("success")
// console.log("success") // console.log(result)
// console.log(result) // console.log(data.length)
// console.log(data.length) for (var i = 0; i < data.length; i++) {
for(var i =0;i<data.length;i++){ tagMap.push(data[i])
tagMap.push([data[i].id,data[i].name])
presetsTags.push(data[i].name) presetsTags.push(data[i].name)
presetsTagsItem.push({title:data[i].name}) presetsTagsItem.push({
"title": data[i].name
})
} }
// console.log(tagMap) // console.log(tagMap)
// console.log(presetsTags) // console.log(presetsTags)
},function (p1, p2) { }, function (p1, p2) {// console.log("failure")
// console.log("failure") // console.log(p1)
// console.log(p1) // console.log(p2)
// console.log(p2)
}) })
} }
@ -58,11 +60,13 @@ Rectangle {
Loader { Loader {
sourceComponent: tagItem sourceComponent: tagItem
Component.onCompleted: { Component.onCompleted: {
item.closeClicked.connect(function(){ item.closeClicked.connect(function () {
tagListModel.remove(index) tagListModel.remove(index)
}) })
item.tag = Qt.binding(function(){return tag}) item.tag = Qt.binding(function () {
return tag
})
} }
} }
} }
@ -72,19 +76,18 @@ Rectangle {
width: input.width - rowTag.width width: input.width - rowTag.width
height: parent.height height: parent.height
FluAutoSuggestBox{ FluAutoSuggestBox {
id:textInput id: textInput
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
width: parent.width width: parent.width
placeholderText: "按回车键Enter创建标签" placeholderText: "按回车键Enter创建标签"
Layout.preferredWidth: 300 Layout.preferredWidth: 300
//items:[{title:""},{title:""},{title:""}] //items:[{title:""},{title:""},{title:""}]
items: presetsTagsItem items: presetsTagsItem
onFocusChanged: { onFocusChanged: {
text ="" text = ""
} }
Keys.onReturnPressed: { Keys.onReturnPressed: {
@ -92,18 +95,22 @@ Rectangle {
if (text.length === 0) if (text.length === 0)
return return
if(presetsTags.indexOf(text) === -1){ var tagId
text = "" for (var i = 0; i < tagMap.length; i++) {
return if (tagMap[i].name === text) {
} tagListModel.append({
tagListModel.append({"tag": text}) "tag": text,
"id": tagMap[i].id
})
//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) {
tagListModel.remove(tagListModel.count-1) tagListModel.remove(tagListModel.count - 1)
} }
} }
} }
@ -111,11 +118,10 @@ Rectangle {
} }
} }
property Component tagItem: property Component tagItem: Rectangle {
Rectangle {
id: rootTagItem id: rootTagItem
property alias tag: tagText.text property alias tag: tagText.text
signal closeClicked() signal closeClicked
width: content.width width: content.width
height: 25 height: 25
@ -136,7 +142,10 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
height: rootTagItem.height height: rootTagItem.height
Item { width: 5; height: 1 } Item {
width: 5
height: 1
}
Text { Text {
id: tagText id: tagText
@ -146,7 +155,11 @@ Rectangle {
color: "white" color: "white"
} }
Item { visible: mouseArea.hovered; width: 5; height: 1 } Item {
visible: mouseArea.hovered
width: 5
height: 1
}
Item { Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -154,11 +167,15 @@ Rectangle {
height: rootTagItem.height height: rootTagItem.height
visible: mouseArea.hovered visible: mouseArea.hovered
Behavior on width { Behavior on width {
NumberAnimation {duration: 100} NumberAnimation {
duration: 100
}
} }
Behavior on visible { Behavior on visible {
NumberAnimation {duration: 100} NumberAnimation {
duration: 100
}
} }
Rectangle { Rectangle {
@ -189,9 +206,11 @@ Rectangle {
} }
} }
Item { width: 5; height: 1 } Item {
width: 5
height: 1
}
} }
} }
} }
} }

View File

@ -69,7 +69,9 @@ FluButton {
width: parent.width - parent.leftPadding - parent.rightPadding width: parent.width - parent.leftPadding - parent.rightPadding
placeholderText: "请输入简介" placeholderText: "请输入简介"
} }
Tag {} Tag {
id: tags
}
} }
Rectangle { Rectangle {
@ -108,6 +110,13 @@ FluButton {
Layout.fillHeight: true Layout.fillHeight: true
text: "上传" text: "上传"
onClicked: { onClicked: {
for (var i = 0; i < tags.tagList.count; i++) {
console.log(tags.tagList.get(i).tag)
console.log(tags.tagList.get(i).id)
}
return
popup.close() popup.close()
let name = FileTransferManager.getFileName( let name = FileTransferManager.getFileName(
currentSelectedFile) currentSelectedFile)