简单封装了http请求
parent
4f407f42ac
commit
14125369fe
|
@ -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"
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
singleton NavItems 1.0 NavItems.qml
|
||||
singleton FooterItems 1.0 FooterItems.qml
|
||||
singleton Request 1.0 Request.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"
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ int main(int argc, char* argv[])
|
|||
qmlRegisterSingletonInstance<HttpClient>("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)
|
||||
|
|
Loading…
Reference in New Issue