From 14125369fe7528a7260784f17bf84054b1754b3b Mon Sep 17 00:00:00 2001 From: wuyize Date: Fri, 30 Jun 2023 18:37:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AE=80=E5=8D=95=E5=B0=81=E8=A3=85?= =?UTF-8?q?=E4=BA=86http=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AicsKnowledgeBase/qml/LoginWindow.qml | 34 +++++++++++---- AicsKnowledgeBase/qml/MainWindow.qml | 27 ++++++++++++ AicsKnowledgeBase/qml/global/NavItems.qml | 8 ++++ AicsKnowledgeBase/qml/global/Request.qml | 52 +++++++++++++++++++++++ AicsKnowledgeBase/qml/global/qmldir | 1 + AicsKnowledgeBase/qml/page/SearchPage.qml | 20 +++++++++ AicsKnowledgeBase/src/main.cpp | 2 +- 7 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 AicsKnowledgeBase/qml/global/Request.qml create mode 100644 AicsKnowledgeBase/qml/page/SearchPage.qml diff --git a/AicsKnowledgeBase/qml/LoginWindow.qml b/AicsKnowledgeBase/qml/LoginWindow.qml index a7dbc86..4863fa1 100644 --- a/AicsKnowledgeBase/qml/LoginWindow.qml +++ b/AicsKnowledgeBase/qml/LoginWindow.qml @@ -5,6 +5,7 @@ import QtQuick.Window import QtQuick.Layouts import org.wangwenx190.FramelessHelper import AicsKB.HttpClient +import "qrc:///AicsKnowledgeBase/qml/global" AppFluWindow { id: window @@ -32,7 +33,7 @@ AppFluWindow { Rectangle{ width: parent.width * 0.5 height: parent.height - color: "#f3f3f3" + color: "#f3f3f3" ColumnLayout { id: loginRect anchors.fill: parent @@ -90,21 +91,36 @@ AppFluWindow { //normalColor: "#ffffff" text: "登录" onClicked: { - FluApp.navigate("/"); - window.close(); + var param ={ + username: account.text, + password: password.text + } + + Request.post("login",JSON.toString(param), function(result, data) { + console.log(result) + console.log(data) + FluApp.navigate("/"); + window.close(); + }, function() { + FluApp.navigate("/"); + window.close(); + }) + + //HttpClient.doGetRequest( // "https://quic.aiortc.org/", // loginItem, "login") } } + } } - // FluPivotItem { - // title: "注册" - // Rectangle{ - // anchors.fill: parent - // color: "blue" - // } + // FluPivotItem { + // title: "注册" + // Rectangle{ + // anchors.fill: parent + // color: "blue" + // } //} } } diff --git a/AicsKnowledgeBase/qml/MainWindow.qml b/AicsKnowledgeBase/qml/MainWindow.qml index 262e2d2..bba7d88 100644 --- a/AicsKnowledgeBase/qml/MainWindow.qml +++ b/AicsKnowledgeBase/qml/MainWindow.qml @@ -24,6 +24,33 @@ FluWindow { } } + RowLayout { + anchors.top: parent.top + anchors.right: parent.right + anchors.rightMargin: 140 + + height: 44 + + layoutDirection: Qt.RightToLeft + +// Rectangle{ +// anchors.fill: parent +// color: "red" +// } + + Rectangle{ + color: FluColors.White + radius: 50 + width: 32 + height: 32 + } + + Text { + Layout.margins: {right: 10} + text: "用户名" + } + } + RowLayout { anchors.fill: parent diff --git a/AicsKnowledgeBase/qml/global/NavItems.qml b/AicsKnowledgeBase/qml/global/NavItems.qml index f56ac79..c8ee738 100644 --- a/AicsKnowledgeBase/qml/global/NavItems.qml +++ b/AicsKnowledgeBase/qml/global/NavItems.qml @@ -47,6 +47,14 @@ FluObject { } } + FluPaneItem { + title: "搜索" + icon: FluentIcons.Search + onTap: { + navigationView.push("qrc:/AicsKnowledgeBase/qml/page/SearchPage.qml") + } + } + function startPageByItem(data) { navigationView.startPageByItem(data) } diff --git a/AicsKnowledgeBase/qml/global/Request.qml b/AicsKnowledgeBase/qml/global/Request.qml new file mode 100644 index 0000000..da07527 --- /dev/null +++ b/AicsKnowledgeBase/qml/global/Request.qml @@ -0,0 +1,52 @@ +pragma Singleton + +import QtQuick + +QtObject { + id: request + + property string baseUrl: "http://127.0.0.1:4523/m1/2914957-0-default/" + + // GET + function get(url, success, failure) { + var xhr = new XMLHttpRequest + xhr.open("GET", baseUrl + url) + xhr.onreadystatechange = function () { + handleResponse(xhr, success, failure) + } + xhr.send() + } + + // POST + function post(url, arg, success, failure) { + var xhr = new XMLHttpRequest + xhr.open("POST", baseUrl + url) + xhr.setRequestHeader("Content-Length", arg.length) + xhr.setRequestHeader( + "Content-Type", + "application/x-www-form-urlencoded;") //用POST的时候一定要有这句 + xhr.onreadystatechange = function () { + handleResponse(xhr, success, failure) + } + xhr.send(arg) + } + + // 处理返回值 + function handleResponse(xhr, success, failure) { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + if (success !== null && success !== undefined) { + var result = xhr.responseText + try { + success(result, JSON.parse(result)) + } catch (e) { + success(result, {}) + } + } + } else { + if (failure !== null && failure !== undefined) + failure(xhr.responseText, xhr.status) + } + } + } +} diff --git a/AicsKnowledgeBase/qml/global/qmldir b/AicsKnowledgeBase/qml/global/qmldir index 5878107..b7fda2e 100644 --- a/AicsKnowledgeBase/qml/global/qmldir +++ b/AicsKnowledgeBase/qml/global/qmldir @@ -1,2 +1,3 @@ singleton NavItems 1.0 NavItems.qml singleton FooterItems 1.0 FooterItems.qml +singleton Request 1.0 Request.qml \ No newline at end of file diff --git a/AicsKnowledgeBase/qml/page/SearchPage.qml b/AicsKnowledgeBase/qml/page/SearchPage.qml new file mode 100644 index 0000000..909ae98 --- /dev/null +++ b/AicsKnowledgeBase/qml/page/SearchPage.qml @@ -0,0 +1,20 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Window +import QtQuick.Controls +import QtQuick.Controls.Basic +import FluentUI + +FluArea { + property string url: '' + + Layout.fillHeight: true + Layout.fillWidth: true + Layout.topMargin: 20 + paddings: 10 + + FluText { + Layout.topMargin: 20 + text: "Search" + } +} diff --git a/AicsKnowledgeBase/src/main.cpp b/AicsKnowledgeBase/src/main.cpp index edc0d6b..676475b 100644 --- a/AicsKnowledgeBase/src/main.cpp +++ b/AicsKnowledgeBase/src/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) qmlRegisterSingletonInstance("AicsKB.HttpClient", 1, 0, "HttpClient", httpClient); - const QUrl url(u"qrc:/AicsKnowledgeBase/qml/component/FileList.qml"_qs); + const QUrl url(u"qrc:/AicsKnowledgeBase/qml/App.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject* obj, const QUrl& objUrl) { if (!obj && url == objUrl) From 24bcce875ae4cc356e8d7fe6c089ed53212ed08c Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Fri, 30 Jun 2023 19:45:04 +0800 Subject: [PATCH 2/2] =?UTF-8?q?FileList=20mock=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AicsKnowledgeBase/qml/component/FileList.qml | 170 +++++++++--------- .../qml/component/FileListItem.qml | 7 +- AicsKnowledgeBase/qml/global/Request.qml | 2 +- AicsKnowledgeBase/src/main.cpp | 2 +- 4 files changed, 94 insertions(+), 87 deletions(-) diff --git a/AicsKnowledgeBase/qml/component/FileList.qml b/AicsKnowledgeBase/qml/component/FileList.qml index 46d02a8..8f7d105 100644 --- a/AicsKnowledgeBase/qml/component/FileList.qml +++ b/AicsKnowledgeBase/qml/component/FileList.qml @@ -1,6 +1,7 @@ import QtQuick 2.15 import QtQuick.Layouts import FluentUI +import "qrc:///AicsKnowledgeBase/qml/global" Window { id: fileListTestWindow @@ -19,6 +20,9 @@ Window { header: fileListItemHeader model: fileListModel delegate: fileListItemDelegate + Component.onCompleted: { + update() + } } Component { id: fileListItemHeader @@ -32,13 +36,7 @@ Window { width: parent.width height: parent.height separator: ">" - items: [{ - "title": "Home" - }, { - "title": "Documents" - }, { - "title": "File List" - }] + items: [] onClickItem: function (model) { if (model.index + 1 !== count()) { items = items.slice(0, model.index + 1) @@ -56,7 +54,7 @@ Window { height: 24 iconSource: FluentIcons.ChromeBack onClicked: { - if (header.count() > 1) { + if (header.count() > 0) { header.items = header.items.slice( 0, header.count() - 1) } @@ -65,46 +63,53 @@ Window { } } - function add(folderName) { - listView.headerItem.children[0].items - = listView.headerItem.children[0].items.concat([{ - "title": folderName - }]) + function add(folderName, uuid) { + console.log(header.items) + header.items = header.items.concat([{ + "title": folderName, + "uuid": uuid + }]) } function update() { - // combine all header items to a path - var path = "" - // for (var i = 0; i < listView.headerItem.children[0].items.length; i++) { - // path += listView.headerItem.children[0].items[i].title + "/" - // } - console.log(path) - var newListModel = [{ - "title": "File 2", - "isDir": false, - "brief": "This is a test file", - "size": 500, - "type": "WORD", - "date": "2020-09-09", - "pageView": 100, - "stars": 10, - "tags": "tag1,tag2,tag3" - }, { - "title": "File 3", - "isDir": false, - "brief": "This is a test file", - "size": 500, - "type": "WORD", - "date": "2020-09-09", - "pageView": 100, - "stars": 10, - "tags"// 15 tags - : "tag1,tag2,tag3,tag4,tag5,tag6,tag7,tag8,tag9,tag10,tag11,tag12,tag13,tag14,tag15" - }] - // http request for new list data - fileListModel.clear() - fileListModel.append(newListModel) - // set ListView currentItem to null - listView.currentIndex = -1 + var uuid = header.items.length + === 0 ? "null" : header.items[header.items.length - 1].uuid + Request.get(uuid, function (response) { + var data = JSON.parse(response) + console.log(data.knowledgeFileAttribute) + fileListModel.clear() + var files = data.children + for (var i = 0; i < files.length; i++) { + var file = files[i] + console.log(file.name) + var modelItem = { + "title": file.name, + "uuid": file.id, + "date": file.createTime + } + if (file.knowledgeFileAttribute === null) { + modelItem.type = "folder" + modelItem.isDir = true + modelItem.size = 0 + } else { + modelItem.isDir = false + modelItem.type = file.knowledgeFileAttribute.suffix + modelItem.size = file.knowledgeFileAttribute.size + modelItem.brief = file.knowledgeFileAttribute.brief + modelItem.pageView = file.knowledgeFileAttribute.pageView + modelItem.stars = 0 + // merge file.knowledgeFileAttribute.tags array to a string + var tagString = "" + for (var j = 0; j < file.knowledgeFileAttribute.tags.length; j++) { + if (j != 0) + tagString = tagString + "," + tagString = tagString + file.knowledgeFileAttribute.tags[j].name + } + modelItem.tags = tagString + } + fileListModel.append(modelItem) + } + listView.currentIndex = -1 + }) } } } @@ -117,18 +122,19 @@ Window { color: !ListView.isCurrentItem ? "lightgray" : "red" FileListItem { id: fileListItem + uuid: model.uuid width: parent.width height: parent.height title: model.title isDir: model.isDir - brief: model.brief - size: model.size - type: model.type date: model.date - pageView: model.pageView - stars: model.stars + brief: isDir ? "" : model.brief + type: isDir ? "FOLDER" : model.type + pageView: isDir ? 0 : model.pageView + size: isDir ? 0 : model.size + stars: isDir ? 0 : model.stars // split string to array - tags: model.tags.split(",") + tags: isDir ? [] : model.tags.split(",") onTagClicked: { emit: search(tag) console.log(tag) @@ -137,43 +143,43 @@ Window { function doubleClicked() { listView.currentIndex = index if (model.isDir) { - listView.headerItem.add(model.title) + listView.headerItem.add(model.title, model.uuid) } else { - emit: open(model.uid) + emit: open(model.uuid) } } } } ListModel { id: fileListModel - ListElement { - title: "File 1" - isDir: true - brief: "This is a test file" - type: "FOLDER" - } - ListElement { - uid: "2" - title: "File 2" - isDir: false - brief: "This is a test file" - size: 500 - type: "WORD" - date: "2020-09-09" - pageView: 100 - stars: 10 - } - ListElement { - uid: "3" - title: "File 3" - isDir: false - brief: "This is a test file" - type: "PPT" - date: "2020-09-09" - pageView: 100 - size: 10200000022 - stars: 10 - } + // ListElement { + // title: "File 1" + // isDir: true + // brief: "This is a test file" + // type: "FOLDER" + // } + // ListElement { + // uid: "2" + // title: "File 2" + // isDir: false + // brief: "This is a test file" + // size: 500 + // type: "WORD" + // date: "2020-09-09" + // pageView: 100 + // stars: 10 + // } + // ListElement { + // uid: "3" + // title: "File 3" + // isDir: false + // brief: "This is a test file" + // type: "PPT" + // date: "2020-09-09" + // pageView: 100 + // size: 10200000022 + // stars: 10 + // } } } } diff --git a/AicsKnowledgeBase/qml/component/FileListItem.qml b/AicsKnowledgeBase/qml/component/FileListItem.qml index 611cf93..19c6e4e 100644 --- a/AicsKnowledgeBase/qml/component/FileListItem.qml +++ b/AicsKnowledgeBase/qml/component/FileListItem.qml @@ -4,7 +4,7 @@ import QtQuick.Layouts Item { id: fileItem - property string id + property string uuid property string title property string brief property string date @@ -37,7 +37,8 @@ Item { id: titleRow Image { id: icon - source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : "" + source: type ? "qrc:/AicsKnowledgeBase/res/" + type.toUpperCase( + ) + ".png" : "" Layout.preferredHeight: 18 Layout.preferredWidth: 18 } @@ -69,7 +70,7 @@ Item { } FluText { id: pageView - text: fileItem.pageView + "浏览" + tags.length + text: fileItem.pageView + "浏览" } FluText { id: stars diff --git a/AicsKnowledgeBase/qml/global/Request.qml b/AicsKnowledgeBase/qml/global/Request.qml index da07527..da84ee3 100644 --- a/AicsKnowledgeBase/qml/global/Request.qml +++ b/AicsKnowledgeBase/qml/global/Request.qml @@ -5,7 +5,7 @@ import QtQuick QtObject { id: request - property string baseUrl: "http://127.0.0.1:4523/m1/2914957-0-default/" + property string baseUrl: "http://127.0.0.1:4523/m1/2914957-0-5604d062/" // GET function get(url, success, failure) { diff --git a/AicsKnowledgeBase/src/main.cpp b/AicsKnowledgeBase/src/main.cpp index 676475b..edc0d6b 100644 --- a/AicsKnowledgeBase/src/main.cpp +++ b/AicsKnowledgeBase/src/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) qmlRegisterSingletonInstance("AicsKB.HttpClient", 1, 0, "HttpClient", httpClient); - const QUrl url(u"qrc:/AicsKnowledgeBase/qml/App.qml"_qs); + const QUrl url(u"qrc:/AicsKnowledgeBase/qml/component/FileList.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject* obj, const QUrl& objUrl) { if (!obj && url == objUrl)