添加Put和阿巴阿巴

main
karlis 2023-07-06 21:50:19 +08:00
parent afe96c5c2d
commit c3972f4464
4 changed files with 248 additions and 14 deletions

View File

@ -28,7 +28,7 @@ Item {
delegate: fileListItemDelegate
Component.onCompleted: {
if (autoRequest) {
update()
topColumnLayout.update()
} else {
listView.model = dataModel
}
@ -47,14 +47,15 @@ Item {
}])
}
function update() {
console.log("1231231")
var uuid = header.items.length
=== 0 ? "null" : header.items[header.items.length - 1].uuid
Request.get("/knowledge/" + uuid, function (response) {
var data = JSON.parse(response)
console.log(response)
console.log(data.knowledgeFileAttribute)
fileListModel.clear()
var files = data.children
var items = []
for (var i = 0; i < files.length; i++) {
var file = files[i]
console.log(file.name)
@ -86,7 +87,14 @@ Item {
}
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)
listView.currentIndex = -1
@ -120,7 +128,7 @@ Item {
RowLayout {
Layout.preferredWidth: parent.width
Item {
Layout.alignment: Qt.AlignRight
anchors.right: uploadBtn.left
height: 28
width: 28
InputDialog {
@ -134,12 +142,14 @@ Item {
onPositiveClicked: text => {
var param = {
"name": text,
"parentId": header.items[header.items.length
- 1].uuid
"parentId": header.items.length === 0 ? null : header.items[header.items.length - 1].uuid
}
Request.post(
"/knowledge",
JSON.stringify(param))
Request.post("/knowledge",
JSON.stringify(
param)).then(
function (response) {
topColumnLayout.update()
})
}
}
@ -155,6 +165,7 @@ Item {
}
}
FluButton {
id: uploadIcon
Layout.alignment: Qt.AlignRight
text: "上传"
onClicked: function () {
@ -181,7 +192,6 @@ Item {
"parentId": header.items.length !== 0 ? header.items[header.items.length - 1].uuid : null
}
console.log("begin")
console.log(JSON.stringify(body))
Request.post("knowledge/file",
JSON.stringify(body),
function (res, data) {
@ -265,9 +275,15 @@ Item {
console.log(tag)
}
onRefresh: {
console.log("------------" + listView.headerItem)
parent.refresh()
}
}
function refresh() {
console.log("refresh")
listView.headerItem.update()
}
}
function doubleClicked() {
listView.currentIndex = index
if (model.isDir) {

View File

@ -1,11 +1,12 @@
import QtQuick 2.15
import FluentUI
import QtQuick.Layouts
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea {
id: fileItem
property string uuid
property string fuuid: null
property var fuuid: null
property string title
property string brief
property string date
@ -48,7 +49,26 @@ FluArea {
FluMenuItem {
text: "移动至"
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()
})
}
}
}
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()
}
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
function post(url, arg, success, failure) {
var xhr = new XMLHttpRequest
@ -30,6 +38,18 @@ QtObject {
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) {
var xhr = new XMLHttpRequest