This commit is contained in:
朱子楚\zhuzi 2023-07-26 22:06:55 +08:00
parent 42f058ca69
commit 4f27ff41b9
3 changed files with 167 additions and 111 deletions

View File

@ -15,11 +15,27 @@ FluContentPage{
id:http id:http
} }
ListModel{ Flickable{
id:data_model id:layout_flick
ListElement{ width: 160
name:"Get请求" clip: true
onClickListener : function(){ anchors{
top: parent.top
topMargin: 20
bottom: parent.bottom
left: parent.left
}
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 = {} var callable = {}
callable.onStart = function(){ callable.onStart = function(){
showLoading() showLoading()
@ -37,9 +53,11 @@ FluContentPage{
http.get("https://httpbingo.org/get",callable) http.get("https://httpbingo.org/get",callable)
} }
} }
ListElement{ FluButton{
name:"Post表单请求" implicitWidth: parent.width
onClickListener : function(){ implicitHeight: 36
text: "Post表单请求"
onClicked: {
var callable = {} var callable = {}
callable.onStart = function(){ callable.onStart = function(){
showLoading() showLoading()
@ -61,9 +79,11 @@ FluContentPage{
http.post("https://httpbingo.org/post",callable,param) http.post("https://httpbingo.org/post",callable,param)
} }
} }
ListElement{ FluButton{
name:"Post Json请求" implicitWidth: parent.width
onClickListener : function(){ implicitHeight: 36
text: "Post Json请求"
onClicked: {
var callable = {} var callable = {}
callable.onStart = function(){ callable.onStart = function(){
showLoading() showLoading()
@ -85,9 +105,11 @@ FluContentPage{
http.postJson("https://httpbingo.org/post",callable,param) http.postJson("https://httpbingo.org/post",callable,param)
} }
} }
ListElement{ FluButton{
name:"Post String请求" implicitWidth: parent.width
onClickListener : function(){ implicitHeight: 36
text: "Post String请求"
onClicked: {
var callable = {} var callable = {}
callable.onStart = function(){ callable.onStart = function(){
showLoading() showLoading()
@ -106,36 +128,60 @@ FluContentPage{
http.postString("https://httpbingo.org/post",callable,param) http.postString("https://httpbingo.org/post",callable,param)
} }
} }
FluButton{
id:btn_download
implicitWidth: parent.width
implicitHeight: 36
text: "下载文件"
onYChanged: {
console.debug(y)
} }
ListView{
id:list_view
width: 160
clip: true
anchors{
top: parent.top
topMargin: 20
bottom: parent.bottom
left: parent.left
}
model:data_model
delegate: FluButton{
implicitWidth: ListView.view.width
implicitHeight: 30
text: model.name
onClicked: { onClicked: {
model.onClickListener() 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{ FluArea{
anchors{ anchors{
top: list_view.top top: layout_flick.top
bottom: list_view.bottom bottom: layout_flick.bottom
left: list_view.right left: layout_flick.right
right: parent.right right: parent.right
leftMargin: 8
} }
Flickable{ Flickable{
clip: true 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
}
}
} }

View File

@ -224,17 +224,14 @@ void FluHttp::download(QString url,QJSValue callable,QString filePath,QVariantMa
connect(reply,&QNetworkReply::downloadProgress,this,[=](qint64 bytesReceived, qint64 bytesTotal){ connect(reply,&QNetworkReply::downloadProgress,this,[=](qint64 bytesReceived, qint64 bytesTotal){
onDownloadProgress(callable,bytesReceived,bytesTotal); onDownloadProgress(callable,bytesReceived,bytesTotal);
}); });
connect(reply,&QNetworkReply::readyRead,this,[=](){
file->write(reply->readAll());
});
loop.exec(); loop.exec();
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
file->write(reply->readAll());
onSuccess(callable,filePath); onSuccess(callable,filePath);
}else{ }else{
onError(callable,reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(),reply->errorString()); onError(callable,reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(),reply->errorString());
} }
_cache.removeOne(reply); _cache.removeOne(reply);
file->close();
reply->deleteLater(); reply->deleteLater();
reply = nullptr; reply = nullptr;
onFinish(callable); onFinish(callable);

View File

@ -5,7 +5,7 @@ import FluentUI
Item{ Item{
property var radius:[0,0,0,0] 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 property bool shadow: true
default property alias contentItem: container.data default property alias contentItem: container.data
id:control id:control