AicsKnowledgeBase_client/AicsKnowledgeBase/qml/component/TreeViewDialog.qml

179 lines
5.6 KiB
QML
Raw Normal View History

2023-07-06 21:50:19 +08:00
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Window
import FluentUI
import "qrc:///AicsKnowledgeBase/qml/global"
FluPopup {
id: popup
property string title: "Title"
property string neutralText: "Neutral"
property string negativeText: "Negative"
property string positiveText: "Positive"
x: (parent.width - width) / 2
y: (parent.height - height) / 2
signal neutralClicked
signal negativeClicked
signal positiveClicked(var text)
enum ButtonFlag {
NegativeButton = 1,
NeutralButton = 2,
PositiveButton = 4
}
property int buttonFlags: FluContentDialog.NegativeButton | FluContentDialog.PositiveButton
property var minWidth: {
if (Window.window == null)
return 400
return Math.min(Window.window.width, 400)
}
focus: true
function load() {
tree_view.updateData(pullFolderLevel())
}
function pullFolderLevel() {
var root = {
"text": "/",
"expanded": true,
"items": getNextLevel("null"),
"data": {
"uuid": null
}
}
return root
}
function getNextLevel(uuid) {
var items = []
var raw = (Request.getAwait("/knowledge/" + uuid))
var data = JSON.parse(raw).children
for (var i = 0; i < data.length; i++) {
if (data[i].knowledgeFileAttribute !== null)
continue
console.log(data[i].name)
var item = {
"text": data[i].name,
"expanded": false,
"items": [],
"data"//getNextLevel(data[i].id),
: {
"uuid": data[i].id
}
}
items.push(item)
}
return items
}
Rectangle {
id: layout_content
anchors.fill: parent
implicitWidth: minWidth
implicitHeight: text_title.height + text_message.height + layout_actions.height
color: 'transparent'
radius: 5
FluText {
id: text_title
font: FluTextStyle.TitleLarge
text: title
topPadding: 20
leftPadding: 20
rightPadding: 20
wrapMode: Text.WrapAnywhere
anchors {
top: parent.top
left: parent.left
right: parent.right
}
}
FluArea {
id: text_message
Layout.fillWidth: true
Layout.topMargin: 10
paddings: 10
height: 300
anchors {
top: text_title.bottom
left: parent.left
right: parent.right
}
FluTreeView {
id: tree_view
width: parent.width - 20
selectionMode: FluTreeView.Single
anchors {
top: parent.top
left: parent.left
bottom: parent.bottom
}
onItemClicked: model => {}
Component.onCompleted: {
createItem()
//updateData(pullFolderLevel())
}
}
}
Rectangle {
id: layout_actions
height: 68
radius: 5
color: FluTheme.dark ? Qt.rgba(
32 / 255, 32 / 255, 32 / 255,
blurBackground ? blurOpacity - 0.4 : 1) : Qt.rgba(
243 / 255, 243 / 255, 243 / 255,
blurBackground ? blurOpacity - 0.4 : 1)
anchors {
top: text_message.bottom
left: parent.left
right: parent.right
}
RowLayout {
anchors {
centerIn: parent
margins: spacing
fill: parent
}
spacing: 15
FluButton {
id: neutral_btn
Layout.fillWidth: true
Layout.fillHeight: true
visible: popup.buttonFlags & FluContentDialog.NeutralButton
text: neutralText
onClicked: {
popup.close()
neutralClicked()
}
}
FluButton {
id: negative_btn
Layout.fillWidth: true
Layout.fillHeight: true
visible: popup.buttonFlags & FluContentDialog.NegativeButton
text: negativeText
onClicked: {
popup.close()
negativeClicked()
}
}
FluFilledButton {
id: positive_btn
Layout.fillWidth: true
Layout.fillHeight: true
visible: popup.buttonFlags & FluContentDialog.PositiveButton
text: positiveText
onClicked: {
if (tree_view.currentElement === null) {
showError("没有选中数据")
return
}
popup.close()
console.log(tree_view.currentElement.data.uuid)
positiveClicked(tree_view.currentElement.data.uuid)
}
}
}
}
}
}