AicsKnowledgeBase_client/AicsKnowledgeBase/qml/page/CreateNotePage.qml

179 lines
6.1 KiB
QML
Raw Normal View History

2023-07-06 19:43:57 +08:00
import QtQuick
import QtQuick.Layouts
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtWebEngine 1.2
import FluentUI
import AicsKB.FileTransferManager
import SignalFileOperation 1.0
2023-07-06 20:26:47 +08:00
import "qrc:///AicsKnowledgeBase/qml/page"
import "qrc:///AicsKnowledgeBase/qml/component"
import "qrc:///AicsKnowledgeBase/qml/global"
2023-07-06 19:43:57 +08:00
2023-07-06 20:26:47 +08:00
FluArea {
id: edit_area
paddings: 0
backgroundColor: "#f9f9f9"
2023-07-07 02:38:52 +08:00
property string knowledgeFileId
2023-07-07 01:45:03 +08:00
property string fileType: "OTHER"
property string fileTitle: "dgfgf"
2023-07-07 02:38:52 +08:00
property string noteFileId
property string noteTitle: ""
property string noteContent: ""
property var tags: []
2023-07-07 01:45:03 +08:00
property bool isModifying: false
2023-07-06 20:26:47 +08:00
2023-07-06 21:21:15 +08:00
Component.onCompleted: {
2023-07-07 03:21:43 +08:00
console.log(knowledgeFileId)
isModifying = false
2023-07-07 01:45:03 +08:00
if (isModifying) {
2023-07-07 02:38:52 +08:00
Request.getSearch("/search/note/" + noteFileId + "/content",
function (response, data) {
noteTitle = data.title
noteContent = data.content
input_title.text = noteTitle
input_md.contentMd = noteContent
tags = data.tags
})
2023-07-07 01:45:03 +08:00
}
2023-07-06 22:13:13 +08:00
noteTitle = Qt.binding(function () {
2023-07-06 21:21:15 +08:00
return input_title.text
})
2023-07-06 22:13:13 +08:00
noteContent = Qt.binding(function () {
2023-07-06 21:36:58 +08:00
return input_md.contentMd
})
2023-07-06 21:21:15 +08:00
}
2023-07-06 20:26:47 +08:00
FluScrollablePage {
id: edit_page
anchors.fill: parent
leftPadding: 5
topPadding: 5
rightPadding: 5
bottomPadding: 0
2023-07-07 01:45:03 +08:00
Item {
Layout.fillWidth: true
implicitHeight: 30
Layout.leftMargin: 5
Layout.bottomMargin: 10
MouseArea {
anchors.fill: parent
onDoubleClicked: {
2023-07-07 02:38:52 +08:00
emit: SignalFileOperation.open(note_page.knowledgeFileId)
2023-07-07 01:45:03 +08:00
}
}
RowLayout {
id: titleRow
RowLayout {
FluIconButton {
iconSize: 12
iconSource: FluentIcons.Back
onClicked: {
emit: SignalFileOperation.back()
}
}
}
Image {
id: icon
source: edit_area.fileType ? "qrc:/AicsKnowledgeBase/res/"
+ edit_area.fileType + ".png" : ""
Layout.preferredHeight: 24
Layout.preferredWidth: 24
}
FluText {
id: title
font.bold: true
font.pointSize: 12
text: edit_area.fileTitle
2023-07-06 21:21:15 +08:00
}
2023-07-06 20:26:47 +08:00
}
}
Item {
Layout.fillWidth: true
implicitHeight: 50
RowLayout {
Layout.fillWidth: true
FluText {
padding: 10
text: "标题"
font {
pointSize: 15
bold: true
}
}
FluTextBox {
2023-07-06 21:21:15 +08:00
id: input_title
2023-07-06 20:26:47 +08:00
padding: 10
2023-07-06 22:13:13 +08:00
placeholderText: "单行输入框"
2023-07-06 20:26:47 +08:00
implicitWidth: parent.width
2023-07-07 02:38:52 +08:00
font.pointSize: 12
2023-07-06 20:26:47 +08:00
}
}
}
2023-07-06 21:21:15 +08:00
FluText {
padding: 10
text: "内容"
font {
pointSize: 15
bold: true
}
}
NoteEditPage {
2023-07-06 21:36:58 +08:00
id: input_md
2023-07-06 21:21:15 +08:00
noteId: "255454"
width: parent.width
2023-07-06 22:13:13 +08:00
height: width * 9 / 16
2023-07-06 21:36:58 +08:00
isEditable: true
2023-07-06 22:13:13 +08:00
isEditing: true
2023-07-06 21:21:15 +08:00
}
RowLayout {
Layout.alignment: Qt.AlignCenter
Layout.topMargin: 10
FluFilledButton {
text: "上传"
onClicked: {
2023-07-07 02:38:52 +08:00
if (noteTitle.trim() !== "" && noteContent !== "") {
2023-07-07 03:21:43 +08:00
console.log(noteTitle)
console.log(noteContent)
console.log(knowledgeFileId)
if (!isModifying) {
2023-07-07 04:48:06 +08:00
Request.post("note", JSON.stringify({
"title": noteTitle,
"content": noteContent,
"tags": [],
"linkingKnowledgeFiles": [knowledgeFileId]
}),
response => {
console.log(response)
}, response => {
console.log(response)
2023-07-07 02:38:52 +08:00
})
2023-07-07 04:48:06 +08:00
SignalFileOperation.back()
2023-07-07 02:38:52 +08:00
} else {
2023-07-07 04:48:06 +08:00
Request.put("note/" + noteFileId, JSON.stringify({
"title": noteTitle,
"content": noteContent,
"tags": [],
"linkingKnowledgeFiles": [knowledgeFileId]
}))
SignalFileOperation.back()
2023-07-07 02:38:52 +08:00
}
}
2023-07-06 21:21:15 +08:00
}
}
FluButton {
text: "取消"
2023-07-07 02:38:52 +08:00
onClicked: {
emit: SignalFileOperation.back()
}
2023-07-06 20:26:47 +08:00
}
}
}
}