Compare commits

...

2 Commits

Author SHA1 Message Date
karlis 83c05d97c5 merge 2023-07-06 21:50:55 +08:00
karlis c3972f4464 添加Put和阿巴阿巴 2023-07-06 21:50:19 +08:00
4 changed files with 288 additions and 15 deletions

View File

@ -28,7 +28,7 @@ Item {
delegate: fileListItemDelegate delegate: fileListItemDelegate
Component.onCompleted: { Component.onCompleted: {
if (autoRequest) { if (autoRequest) {
update() topColumnLayout.update()
} else { } else {
listView.model = dataModel listView.model = dataModel
} }
@ -47,14 +47,15 @@ Item {
}]) }])
} }
function update() { function update() {
console.log("1231231")
var uuid = header.items.length var uuid = header.items.length
=== 0 ? "null" : header.items[header.items.length - 1].uuid === 0 ? "null" : header.items[header.items.length - 1].uuid
Request.get("/knowledge/" + uuid, function (response) { Request.get("/knowledge/" + uuid, function (response) {
var data = JSON.parse(response) var data = JSON.parse(response)
console.log(response)
console.log(data.knowledgeFileAttribute)
fileListModel.clear() fileListModel.clear()
var files = data.children var files = data.children
var items = []
for (var i = 0; i < files.length; i++) { for (var i = 0; i < files.length; i++) {
var file = files[i] var file = files[i]
console.log(file.name) console.log(file.name)
@ -86,7 +87,14 @@ Item {
} }
modelItem.tags = tagString modelItem.tags = tagString
} }
fileListModel.append(modelItem) items.push(modelItem)
}
fileListModel.clear()
for (i = 0; i < items.length; i++) {
if (items[i].isDir)
fileListModel.insert(0, items[i])
else
fileListModel.append(items[i])
} }
console.log(fileListModel.count) console.log(fileListModel.count)
listView.currentIndex = -1 listView.currentIndex = -1
@ -120,7 +128,7 @@ Item {
RowLayout { RowLayout {
Layout.preferredWidth: parent.width Layout.preferredWidth: parent.width
Item { Item {
Layout.alignment: Qt.AlignRight anchors.right: uploadBtn.left
height: 28 height: 28
width: 28 width: 28
InputDialog { InputDialog {
@ -134,12 +142,14 @@ Item {
onPositiveClicked: text => { onPositiveClicked: text => {
var param = { var param = {
"name": text, "name": text,
"parentId": header.items[header.items.length "parentId": header.items.length === 0 ? null : header.items[header.items.length - 1].uuid
- 1].uuid
} }
Request.post( Request.post("/knowledge",
"/knowledge", JSON.stringify(
JSON.stringify(param)) param)).then(
function (response) {
topColumnLayout.update()
})
} }
} }
@ -154,8 +164,47 @@ Item {
} }
} }
} }
UploadButton { FluButton {
header: header id: uploadIcon
Layout.alignment: Qt.AlignRight
text: "上传"
onClicked: function () {
console.log("click")
fileDialog.open()
}
FileDialog {
id: fileDialog
onAccepted: function () {
let name = FileTransferManager.getFileName(
selectedFile)
const size = FileTransferManager.getFileSize(
selectedFile)
const md5 = FileTransferManager.getFileMd5(
selectedFile)
if (size <= 0 || md5 === '')
return
var body = {
"name": name,
"brief": "brief",
"size": size,
"md5": md5,
"tags": [],
"parentId": header.items.length !== 0 ? header.items[header.items.length - 1].uuid : null
}
console.log("begin")
Request.post("knowledge/file",
JSON.stringify(body),
function (res, data) {
console.log(res)
console.log(data)
FileTransferManager.upload(
selectedFile, data.id,
data.ticket, name)
}, function (res, data) {
console.log(res)
})
}
}
} }
} }
RowLayout { RowLayout {
@ -226,9 +275,15 @@ Item {
console.log(tag) console.log(tag)
} }
onRefresh: { onRefresh: {
console.log("------------" + listView.headerItem)
parent.refresh()
}
}
function refresh() {
console.log("refresh")
listView.headerItem.update() listView.headerItem.update()
} }
}
function doubleClicked() { function doubleClicked() {
listView.currentIndex = index listView.currentIndex = index
if (model.isDir) { if (model.isDir) {

View File

@ -1,11 +1,12 @@
import QtQuick 2.15 import QtQuick 2.15
import FluentUI import FluentUI
import QtQuick.Layouts import QtQuick.Layouts
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea { FluArea {
id: fileItem id: fileItem
property string uuid property string uuid
property string fuuid: null property var fuuid: null
property string title property string title
property string brief property string brief
property string date property string date
@ -48,7 +49,26 @@ FluArea {
FluMenuItem { FluMenuItem {
text: "移动至" text: "移动至"
onClicked: { onClicked: {
moveDialog.load()
moveDialog.open()
}
TreeViewDialog {
id: moveDialog
title: "选择目标文件夹"
buttonFlags: FluContentDialog.PositiveButton | FluContentDialog.NegativeButton
negativeText: "取消"
positiveText: "确定"
onPositiveClicked: uuid => {
var param = {
"parentId": uuid,
"name": fileItem.title
}
Request.put(
"/knowledge/" + fileItem.uuid,
JSON.stringify(param), () => {
refresh() refresh()
})
}
} }
} }
FluMenuItem { FluMenuItem {

View File

@ -0,0 +1,178 @@
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)
}
}
}
}
}
}

View File

@ -18,6 +18,14 @@ QtObject {
xhr.send() xhr.send()
} }
function getAwait(url) {
var xhr = new XMLHttpRequest
xhr.open("GET", baseUrl + url, false)
xhr.send(null)
// wait for response then return response data
return xhr.responseText
}
// POST // POST
function post(url, arg, success, failure) { function post(url, arg, success, failure) {
var xhr = new XMLHttpRequest var xhr = new XMLHttpRequest
@ -30,6 +38,18 @@ QtObject {
xhr.send(arg) xhr.send(arg)
} }
// PUT
function put(url, arg, success, failure) {
var xhr = new XMLHttpRequest
xhr.open("PUT", baseUrl + url, true)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.withCredentials = true
xhr.onreadystatechange = function () {
handleResponse(xhr, success, failure)
}
xhr.send(arg)
}
/* function post(url, arg, success, failure) { /* function post(url, arg, success, failure) {
var xhr = new XMLHttpRequest var xhr = new XMLHttpRequest