AicsKnowledgeBase_client/AicsKnowledgeBase/qml/page/NotePage.qml

290 lines
9.7 KiB
QML
Raw Normal View History

2023-07-06 14:21:01 +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
import "qrc:///AicsKnowledgeBase/qml/page"
2023-07-06 17:16:55 +08:00
import "qrc:///AicsKnowledgeBase/qml/component"
import "qrc:///AicsKnowledgeBase/qml/global"
2023-07-06 14:21:01 +08:00
FluArea {
id: note_area
paddings: 0
backgroundColor: "#f9f9f9"
2023-07-06 23:01:10 +08:00
// visible: false
2023-07-06 14:21:01 +08:00
property string type: ""
2023-07-06 17:16:55 +08:00
property string noteFileId
2023-07-07 03:21:43 +08:00
property string authorId
2023-07-06 14:21:01 +08:00
signal clickTags(string tagName)
// paddings: {
// top: 10
// right: 0
// bottom: 10
// left: 10
// }
FluScrollablePage {
id: note_page
anchors.fill: parent
leftPadding: 10
topPadding: 10
rightPadding: 10
bottomPadding: 0
2023-07-06 17:16:55 +08:00
property string fileId
2023-07-06 14:21:01 +08:00
property int likeCount: 0
property int favoriteCount: 0
property int shareCount: 0
property int browsCount: 555
property bool isLike: false
property bool isFavorite: false
2023-07-06 17:16:55 +08:00
property string title: "文章标题"
property list<string> tags: ["tag 1", "tag 2", "tag 3"]
property string publishTime: "2020-01-01"
2023-07-06 14:21:01 +08:00
property string brief: "这是一个简介"
2023-07-07 01:45:03 +08:00
property string fileTitle: "dfnfgf"
property string fileType: "OTHER"
2023-07-06 14:21:01 +08:00
function getType(suffix) {
2023-07-06 23:01:10 +08:00
if (suffix === "md")
2023-07-06 17:16:55 +08:00
return "MD"
2023-07-06 23:01:10 +08:00
else if (suffix === "mp4" || suffix === "avi" || suffix === "rmvb"
|| suffix === "rm" || suffix === "wmv" || suffix === "mkv")
2023-07-06 17:16:55 +08:00
return "VIDEO"
2023-07-06 23:01:10 +08:00
else
return "OTHER"
2023-07-06 14:21:01 +08:00
}
2023-07-06 20:26:47 +08:00
function loadNote(noteFileId) {
2023-07-06 17:16:55 +08:00
note_area.noteFileId = noteFileId
}
Component.onCompleted: {
2023-07-07 03:21:43 +08:00
Request.getSearch("note/" + noteFileId, function (response, data) {
note_page.fileId = data.id
2023-07-07 02:38:52 +08:00
note_page.fileTitle = data.name
note_page.fileType = getType(data.knowledgeFileAttribute.suffix)
note_page.fileStars = 0
2023-07-06 17:16:55 +08:00
2023-07-07 02:38:52 +08:00
var tagString = ""
2023-07-07 03:21:43 +08:00
for (var j = 0; j < data.tags.length; j++) {
2023-07-07 02:38:52 +08:00
if (j != 0)
tagString = tagString + ","
2023-07-07 03:21:43 +08:00
tagString = tagString + data.tags[j].name
2023-07-07 02:38:52 +08:00
}
note_page.fileTags = tagString
2023-07-07 03:21:43 +08:00
likeCount = data.likers.length
isLike = false
for (var j = 0; j < data.likers.length; j++) {
if (data.likers[j].id === UserData.userId) {
isLike = true
break
}
}
favoriteCount = data.starrers.length
isLike = false
for (var j = 0; j < data.starrers.length; j++) {
if (data.starrers[j].id === UserData.userId) {
isFavorite = true
break
}
}
2023-07-07 02:38:52 +08:00
})
2023-07-06 17:16:55 +08:00
}
FluIconButton {
iconSize: 12
iconSource: FluentIcons.Back
onClicked: {
emit: SignalFileOperation.back()
}
Layout.margins: -5
2023-07-06 14:21:01 +08:00
}
Item {
Layout.fillWidth: true
implicitHeight: 50
FluText {
id: text_title
padding: 10
2023-07-06 17:16:55 +08:00
text: note_page.title
2023-07-06 14:21:01 +08:00
font {
pointSize: 15
bold: true
}
}
2023-07-07 03:21:43 +08:00
FluIconButton {
id: button_edit_note
iconSize: FluentIcons.Edit
visible: authorId === UserData.userId
onClicked: {
emit: SignalFileOperation.modifyNote(note_page.fileId,
note_page.fileType,
note_page.fileTitle,
noteFileId)
}
}
2023-07-06 14:21:01 +08:00
ColumnLayout {
id: layout_share
FluIconButton {
id: button_share
iconSize: 15
iconSource: FluentIcons.Share
2023-07-06 17:16:55 +08:00
text: note_page.shareCount.toString()
2023-07-06 14:21:01 +08:00
}
FluText {
id: text_share
text: note_page.shareCount
font.pointSize: 8
Layout.alignment: button_share.Center
Layout.topMargin: -5
}
anchors {
verticalCenter: text_title.verticalCenter
right: parent.right
}
}
ColumnLayout {
id: layout_favorite
FluIconButton {
id: button_favorite
iconSize: 15
iconSource: note_page.isFavorite ? FluentIcons.FavoriteStarFill : FluentIcons.FavoriteStar
2023-07-07 03:21:43 +08:00
onClicked: {
note_page.isFavorite = !note_page.isFavorite
Request.put("/note/" + noteFileId + "/star", {
"active": note_page.isFavorite
})
}
2023-07-06 14:21:01 +08:00
}
FluText {
id: text_favorite
text: note_page.favoriteCount
font.pointSize: 8
Layout.alignment: button_favorite.Center
Layout.topMargin: -5
}
anchors {
verticalCenter: text_title.verticalCenter
right: layout_share.left
}
}
ColumnLayout {
id: layout_like
FluIconButton {
id: button_like
iconSize: 15
iconSource: note_page.isLike ? FluentIcons.HeartFill : FluentIcons.Heart
2023-07-07 03:21:43 +08:00
onClicked: {
note_page.isLike = !note_page.isLike
Request.put("/note/" + noteFileId + "/like", {
"active": note_page.isLike
})
}
2023-07-06 14:21:01 +08:00
}
FluText {
id: text_like
2023-07-06 17:16:55 +08:00
text: note_page.likeCount
2023-07-06 14:21:01 +08:00
font.pointSize: 8
Layout.alignment: button_like.Center
Layout.topMargin: -5
}
anchors {
verticalCenter: text_title.verticalCenter
right: layout_favorite.left
}
}
}
FluArea {
Layout.fillWidth: true
2023-07-07 01:45:03 +08:00
implicitHeight: 140
2023-07-06 14:21:01 +08:00
ColumnLayout {
RowLayout {
2023-07-06 17:16:55 +08:00
width: parent.width
2023-07-06 14:21:01 +08:00
FluText {
padding: 10
2023-07-06 17:16:55 +08:00
text: note_page.publishTime
2023-07-06 14:21:01 +08:00
}
FluText {
padding: 10
2023-07-06 17:16:55 +08:00
text: note_page.fileSize.toString() + "MB"
2023-07-06 14:21:01 +08:00
}
FluText {
padding: 10
2023-07-06 17:16:55 +08:00
text: note_page.browsCount.toString() + "浏览量"
2023-07-06 14:21:01 +08:00
}
}
FluText {
Layout.topMargin: -2
Layout.leftMargin: 10
2023-07-06 17:16:55 +08:00
text: note_page.brief
2023-07-06 14:21:01 +08:00
}
RowLayout {
Layout.topMargin: 2
Layout.leftMargin: 5
Repeater {
2023-07-06 17:16:55 +08:00
model: note_page.tags
2023-07-06 14:21:01 +08:00
delegate: Button {
Layout.margins: 2
2023-07-06 17:16:55 +08:00
text: "#" + note_page.tags[index]
2023-07-06 14:21:01 +08:00
background: Rectangle {
implicitHeight: 10
implicitWidth: 10
color: FluColors.Grey20
radius: 10
}
onClicked: {
2023-07-06 17:16:55 +08:00
emit: note_area.clickTags(text)
2023-07-06 14:21:01 +08:00
}
}
}
}
2023-07-07 01:45:03 +08:00
Item {
Layout.fillWidth: true
implicitHeight: 30
Layout.leftMargin: 10
MouseArea {
anchors.fill: parent
onDoubleClicked: {
2023-07-07 03:21:43 +08:00
emit: SignalFileOperation.open(note_page.fileId)
2023-07-07 01:45:03 +08:00
}
}
RowLayout {
id: titleRow
Image {
id: icon
source: note_page.fileType ? "qrc:/AicsKnowledgeBase/res/"
+ note_page.fileType + ".png" : ""
Layout.preferredHeight: 24
Layout.preferredWidth: 24
}
FluText {
id: title
font.bold: true
font.pointSize: 12
text: note_page.fileTitle
}
}
}
2023-07-06 14:21:01 +08:00
}
}
2023-07-07 01:45:03 +08:00
2023-07-06 14:21:01 +08:00
NoteEditPage {
2023-07-06 17:16:55 +08:00
id: text_view
2023-07-06 14:21:01 +08:00
noteId: "255454"
2023-07-06 17:16:55 +08:00
width: parent.width
2023-07-07 01:45:03 +08:00
implicitHeight: width * 9 / 16
2023-07-06 14:21:01 +08:00
}
}
}