From 4f27ff41b9d0eea242e820f6549dbacad7dc6ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Wed, 26 Jul 2023 22:06:55 +0800 Subject: [PATCH] update --- example/qml/page/T_Http.qml | 271 +++++++++++------- src/FluHttp.cpp | 5 +- .../FluentUI/Controls/FluRectangle.qml | 2 +- 3 files changed, 167 insertions(+), 111 deletions(-) diff --git a/example/qml/page/T_Http.qml b/example/qml/page/T_Http.qml index 4e7ff175..e18dc449 100644 --- a/example/qml/page/T_Http.qml +++ b/example/qml/page/T_Http.qml @@ -15,102 +15,8 @@ FluContentPage{ id:http } - ListModel{ - id:data_model - ListElement{ - name:"Get请求" - onClickListener : function(){ - var callable = {} - callable.onStart = function(){ - showLoading() - } - callable.onFinish = function(){ - hideLoading() - } - callable.onSuccess = function(result){ - text_info.text = result - console.debug(result) - } - callable.onError = function(status,errorString){ - console.debug(status+";"+errorString) - } - http.get("https://httpbingo.org/get",callable) - } - } - ListElement{ - name:"Post表单请求" - onClickListener : function(){ - var callable = {} - callable.onStart = function(){ - showLoading() - } - callable.onFinish = function(){ - hideLoading() - } - callable.onSuccess = function(result){ - text_info.text = result - console.debug(result) - } - callable.onError = function(status,errorString){ - console.debug(status+";"+errorString) - } - var param = {} - param.custname = "朱子楚" - param.custtel = "1234567890" - param.custemail = "zhuzichu520@gmail.com" - http.post("https://httpbingo.org/post",callable,param) - } - } - ListElement{ - name:"Post Json请求" - onClickListener : function(){ - var callable = {} - callable.onStart = function(){ - showLoading() - } - callable.onFinish = function(){ - hideLoading() - } - callable.onSuccess = function(result){ - text_info.text = result - console.debug(result) - } - callable.onError = function(status,errorString){ - console.debug(status+";"+errorString) - } - var param = {} - param.custname = "朱子楚" - param.custtel = "1234567890" - param.custemail = "zhuzichu520@gmail.com" - http.postJson("https://httpbingo.org/post",callable,param) - } - } - ListElement{ - name:"Post String请求" - onClickListener : function(){ - var callable = {} - callable.onStart = function(){ - showLoading() - } - callable.onFinish = function(){ - hideLoading() - } - callable.onSuccess = function(result){ - text_info.text = result - console.debug(result) - } - callable.onError = function(status,errorString){ - console.debug(status+";"+errorString) - } - var param = "我命由我不由天" - http.postString("https://httpbingo.org/post",callable,param) - } - } - } - - - ListView{ - id:list_view + Flickable{ + id:layout_flick width: 160 clip: true anchors{ @@ -119,23 +25,163 @@ FluContentPage{ bottom: parent.bottom left: parent.left } - model:data_model - delegate: FluButton{ - implicitWidth: ListView.view.width - implicitHeight: 30 - text: model.name - onClicked: { - model.onClickListener() + ScrollBar.vertical: FluScrollBar {} + contentHeight:layout_column.height + Column{ + spacing: 2 + id:layout_column + width: parent.width + FluButton{ + implicitWidth: parent.width + implicitHeight: 36 + text: "Get请求" + onClicked: { + var callable = {} + callable.onStart = function(){ + showLoading() + } + callable.onFinish = function(){ + hideLoading() + } + callable.onSuccess = function(result){ + text_info.text = result + console.debug(result) + } + callable.onError = function(status,errorString){ + console.debug(status+";"+errorString) + } + http.get("https://httpbingo.org/get",callable) + } } + FluButton{ + implicitWidth: parent.width + implicitHeight: 36 + text: "Post表单请求" + onClicked: { + var callable = {} + callable.onStart = function(){ + showLoading() + } + callable.onFinish = function(){ + hideLoading() + } + callable.onSuccess = function(result){ + text_info.text = result + console.debug(result) + } + callable.onError = function(status,errorString){ + console.debug(status+";"+errorString) + } + var param = {} + param.custname = "朱子楚" + param.custtel = "1234567890" + param.custemail = "zhuzichu520@gmail.com" + http.post("https://httpbingo.org/post",callable,param) + } + } + FluButton{ + implicitWidth: parent.width + implicitHeight: 36 + text: "Post Json请求" + onClicked: { + var callable = {} + callable.onStart = function(){ + showLoading() + } + callable.onFinish = function(){ + hideLoading() + } + callable.onSuccess = function(result){ + text_info.text = result + console.debug(result) + } + callable.onError = function(status,errorString){ + console.debug(status+";"+errorString) + } + var param = {} + param.custname = "朱子楚" + param.custtel = "1234567890" + param.custemail = "zhuzichu520@gmail.com" + http.postJson("https://httpbingo.org/post",callable,param) + } + } + FluButton{ + implicitWidth: parent.width + implicitHeight: 36 + text: "Post String请求" + onClicked: { + var callable = {} + callable.onStart = function(){ + showLoading() + } + callable.onFinish = function(){ + hideLoading() + } + callable.onSuccess = function(result){ + text_info.text = result + console.debug(result) + } + callable.onError = function(status,errorString){ + console.debug(status+";"+errorString) + } + var param = "我命由我不由天" + http.postString("https://httpbingo.org/post",callable,param) + } + } + FluButton{ + id:btn_download + implicitWidth: parent.width + implicitHeight: 36 + text: "下载文件" + onYChanged: { + console.debug(y) + } + onClicked: { + file_dialog.open() + } + } + } + } + + FolderDialog { + id: file_dialog + currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0] + onAccepted: { + var callable = {} + callable.onStart = function(){ + btn_download.disabled = true + } + callable.onFinish = function(){ + btn_download.disabled = false + btn_download.text = "下载文件" + layout_file_size.visible = false + text_file_size.text = "" + } + callable.onSuccess = function(result){ + showSuccess(result) + } + callable.onError = function(status,errorString){ + showError(errorString) + } + callable.onDownloadProgress = function(recv,total){ + var locale = Qt.locale() + var precent = (recv/total * 100).toFixed(0) + "%" + btn_download.text = "下载中..."+precent + text_file_size.text = "%1/%2".arg(locale.formattedDataSize(recv)).arg(locale.formattedDataSize(total)) + layout_file_size.visible = true + } + var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4" + http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable,path) } } FluArea{ anchors{ - top: list_view.top - bottom: list_view.bottom - left: list_view.right + top: layout_flick.top + bottom: layout_flick.bottom + left: layout_flick.right right: parent.right + leftMargin: 8 } Flickable{ clip: true @@ -154,5 +200,18 @@ FluContentPage{ } } + FluRectangle{ + id:layout_file_size + radius: [4,4,4,4] + height: 36 + width: 160 + visible: false + x:layout_flick.width + y: 173 - layout_flick.contentY + FluText{ + id:text_file_size + anchors.centerIn: parent + } + } } diff --git a/src/FluHttp.cpp b/src/FluHttp.cpp index dfb1ff5a..9831e56d 100644 --- a/src/FluHttp.cpp +++ b/src/FluHttp.cpp @@ -224,17 +224,14 @@ void FluHttp::download(QString url,QJSValue callable,QString filePath,QVariantMa connect(reply,&QNetworkReply::downloadProgress,this,[=](qint64 bytesReceived, qint64 bytesTotal){ onDownloadProgress(callable,bytesReceived,bytesTotal); }); - connect(reply,&QNetworkReply::readyRead,this,[=](){ - file->write(reply->readAll()); - }); loop.exec(); if (reply->error() == QNetworkReply::NoError) { + file->write(reply->readAll()); onSuccess(callable,filePath); }else{ onError(callable,reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(),reply->errorString()); } _cache.removeOne(reply); - file->close(); reply->deleteLater(); reply = nullptr; onFinish(callable); diff --git a/src/imports/FluentUI/Controls/FluRectangle.qml b/src/imports/FluentUI/Controls/FluRectangle.qml index e0450778..9b324204 100644 --- a/src/imports/FluentUI/Controls/FluRectangle.qml +++ b/src/imports/FluentUI/Controls/FluRectangle.qml @@ -5,7 +5,7 @@ import FluentUI Item{ property var radius:[0,0,0,0] - property color color : "#FFFFFF" + property color color : FluTheme.dark ? Qt.rgba(0,0,0,1) : Qt.rgba(1,1,1,1) property bool shadow: true default property alias contentItem: container.data id:control