FluentUI/example/qml/page/T_Network.qml

533 lines
18 KiB
QML
Raw Normal View History

2023-11-23 18:18:28 +08:00
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import FluentUI 1.0
2023-11-29 18:10:56 +08:00
import Qt.labs.platform 1.0
2023-11-23 18:18:28 +08:00
import "qrc:///example/qml/component"
import "../component"
FluContentPage{
2023-11-29 21:35:06 +08:00
id:root
2023-11-23 18:18:28 +08:00
title:"Network"
FluNetworkCallable{
id:callable
onStart: {
showLoading()
}
onFinish: {
hideLoading()
}
onError:
(status,errorString,result)=>{
console.debug(status+";"+errorString+";"+result)
}
2023-11-24 15:35:40 +08:00
onCache:
(result)=>{
text_info.text = result
}
2023-11-23 18:18:28 +08:00
onSuccess:
(result)=>{
text_info.text = result
}
}
Flickable{
id:layout_flick
width: 200
clip: true
anchors{
top: parent.top
topMargin: 20
bottom: parent.bottom
left: parent.left
}
2023-11-24 15:35:40 +08:00
boundsBehavior: Flickable.StopAtBounds
2023-11-23 18:18:28 +08:00
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: {
2023-11-24 15:35:40 +08:00
text_info.text = ""
2023-11-23 18:18:28 +08:00
FluNetwork.get("https://httpbingo.org/get")
.addQuery("name","孙悟空")
.addQuery("age",500)
.addQuery("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-23 18:18:28 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
2023-11-24 15:35:40 +08:00
text: "Post Body"
2023-11-23 18:18:28 +08:00
onClicked: {
2023-11-24 15:35:40 +08:00
text_info.text = ""
FluNetwork.postBody("https://httpbingo.org/post")
.setBody("花果山水帘洞美猴王齐天大圣孙悟空")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-23 18:18:28 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
2023-11-24 15:35:40 +08:00
text: "Post Form"
2023-11-23 18:18:28 +08:00
onClicked: {
2023-11-24 15:35:40 +08:00
text_info.text = ""
FluNetwork.postForm("https://httpbingo.org/post")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-23 18:18:28 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Post JSON"
onClicked: {
2023-11-24 15:35:40 +08:00
text_info.text = ""
2023-11-23 18:18:28 +08:00
FluNetwork.postJson("https://httpbingo.org/post")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-23 18:18:28 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Post JSON Array"
onClicked: {
2023-11-24 15:35:40 +08:00
text_info.text = ""
2023-11-23 18:18:28 +08:00
FluNetwork.postJsonArray("https://httpbingo.org/post")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-23 18:18:28 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
2023-11-24 15:35:40 +08:00
text: "Put Body"
2023-11-23 18:18:28 +08:00
onClicked: {
2023-11-24 15:35:40 +08:00
text_info.text = ""
FluNetwork.putBody("https://httpbingo.org/put")
.setBody("花果山水帘洞美猴王齐天大圣孙悟空")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Put Form"
onClicked: {
text_info.text = ""
FluNetwork.putForm("https://httpbingo.org/put")
2023-11-23 18:18:28 +08:00
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-23 18:18:28 +08:00
.go(callable)
}
}
2023-11-24 15:35:40 +08:00
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Put JSON"
onClicked: {
text_info.text = ""
FluNetwork.putJson("https://httpbingo.org/put")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Put JSON Array"
onClicked: {
text_info.text = ""
FluNetwork.putJsonArray("https://httpbingo.org/put")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Patch Body"
onClicked: {
text_info.text = ""
FluNetwork.patchBody("https://httpbingo.org/patch")
.setBody("花果山水帘洞美猴王齐天大圣孙悟空")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Patch Form"
onClicked: {
text_info.text = ""
FluNetwork.patchForm("https://httpbingo.org/patch")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Patch JSON"
onClicked: {
text_info.text = ""
FluNetwork.patchJson("https://httpbingo.org/patch")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Patch JSON Array"
onClicked: {
text_info.text = ""
FluNetwork.patchJsonArray("https://httpbingo.org/patch")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Delete Body"
onClicked: {
text_info.text = ""
FluNetwork.deleteBody("https://httpbingo.org/delete")
.setBody("花果山水帘洞美猴王齐天大圣孙悟空")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Delete Form"
onClicked: {
text_info.text = ""
FluNetwork.deleteForm("https://httpbingo.org/delete")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Delete JSON"
onClicked: {
text_info.text = ""
FluNetwork.deleteJson("https://httpbingo.org/delete")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Delete JSON Array"
onClicked: {
text_info.text = ""
FluNetwork.deleteJsonArray("https://httpbingo.org/delete")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Custom Header"
onClicked: {
text_info.text = ""
FluNetwork.postJson("https://httpbingo.org/post")
.addHeader("os","PC")
.addHeader("version","1.0.0")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "RequestFailedReadCache"
onClicked: {
text_info.text = ""
FluNetwork.postJson("https://httpbingo.org/post")
.setCacheMode(FluNetworkType.RequestFailedReadCache)
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
.add("cacheMode","RequestFailedReadCache")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "IfNoneCacheRequest"
onClicked: {
text_info.text = ""
FluNetwork.postJson("https://httpbingo.org/post")
.setCacheMode(FluNetworkType.IfNoneCacheRequest)
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
.add("cacheMode","IfNoneCacheRequest")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "FirstCacheThenRequest"
onClicked: {
text_info.text = ""
FluNetwork.postJson("https://httpbingo.org/post")
.setCacheMode(FluNetworkType.FirstCacheThenRequest)
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
.add("cacheMode","FirstCacheThenRequest")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Timeout And Retry"
onClicked: {
text_info.text = ""
FluNetwork.postJson("https://httpbingo.org/post")
.setTimeout(5000)
.setRetry(3)
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
.add("timeout","5000")
.add("retry","3")
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-24 15:35:40 +08:00
.go(callable)
}
}
2023-11-29 18:10:56 +08:00
FluProgressButton{
id:btn_upload
implicitWidth: parent.width
implicitHeight: 36
text: "Upload File"
onClicked: {
file_dialog.open()
}
}
FluProgressButton{
id:btn_download
implicitWidth: parent.width
implicitHeight: 36
text: "Download File"
onClicked: {
2023-11-29 21:35:06 +08:00
folder_dialog.showDialog(function(path){
FluNetwork.get("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
.toDownload(path)
.bind(root)
.go(callable_download_file)
})
}
}
FluProgressButton{
id:btn_download_breakpoint
implicitWidth: parent.width
implicitHeight: 36
text: "Breakpoint Download File"
onClicked: {
folder_dialog.showDialog(function(path){
FluNetwork.get("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
.toDownload(path,true)
.bind(root)
.go(callable_breakpoint_download_file)
})
2023-11-29 18:10:56 +08:00
}
}
}
}
FluNetworkCallable{
id:callable_upload_file
onStart: {
btn_upload.disabled = true
}
onFinish: {
btn_upload.disabled = false
}
onError:
(status,errorString,result)=>{
btn_upload.progress = 0
text_info.text = result
2023-11-30 01:12:57 +08:00
console.debug(status+";"+errorString+";"+result)
2023-11-29 18:10:56 +08:00
}
onSuccess:
(result)=>{
text_info.text = result
}
onUploadProgress:
(sent,total)=>{
btn_upload.progress = sent/total
}
}
FluNetworkCallable{
id:callable_download_file
onStart: {
btn_download.progress = 0
btn_download.disabled = true
}
onFinish: {
btn_download.disabled = false
}
onError:
(status,errorString,result)=>{
btn_download.progress = 0
showError(errorString)
console.debug(status+";"+errorString+";"+result)
}
onSuccess:
(result)=>{
showSuccess(result)
}
onDownloadProgress:
(recv,total)=>{
btn_download.progress = recv/total
}
}
2023-11-29 21:35:06 +08:00
FluNetworkCallable{
id:callable_breakpoint_download_file
onStart: {
btn_download_breakpoint.progress = 0
btn_download_breakpoint.disabled = true
}
onFinish: {
btn_download_breakpoint.disabled = false
}
onError:
(status,errorString,result)=>{
btn_download_breakpoint.progress = 0
showError(errorString)
console.debug(status+";"+errorString+";"+result)
}
onSuccess:
(result)=>{
showSuccess(result)
}
onDownloadProgress:
(recv,total)=>{
btn_download_breakpoint.progress = recv/total
}
}
2023-11-29 18:10:56 +08:00
FileDialog {
id: file_dialog
onAccepted: {
FluNetwork.postForm("https://httpbingo.org/post")
2023-11-30 01:12:57 +08:00
.setRetry(1)//只请求一次
2023-11-29 18:10:56 +08:00
.add("accessToken","12345678")
2023-11-30 01:12:57 +08:00
.addFile("file",FluTools.toLocalPath(file_dialog.currentFile))
2023-11-29 21:35:06 +08:00
.bind(root)
2023-11-29 18:10:56 +08:00
.go(callable_upload_file)
}
}
FileDialog {
2023-11-29 21:35:06 +08:00
property var onSelectListener
2023-11-29 18:10:56 +08:00
id: folder_dialog
2023-11-29 21:35:06 +08:00
folder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
2023-11-29 18:10:56 +08:00
currentFile: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]+"/big_buck_bunny.mp4"
fileMode: FileDialog.SaveFile
onAccepted: {
2023-11-29 21:35:06 +08:00
folder_dialog.onSelectListener(FluTools.toLocalPath(folder_dialog.currentFile))
}
function showDialog(listener){
folder_dialog.onSelectListener = listener
folder_dialog.open()
2023-11-23 18:18:28 +08:00
}
}
FluArea{
anchors{
top: layout_flick.top
bottom: layout_flick.bottom
left: layout_flick.right
right: parent.right
leftMargin: 8
}
Flickable{
clip: true
id:scrollview
boundsBehavior:Flickable.StopAtBounds
width: parent.width
height: parent.height
contentWidth: width
contentHeight: text_info.height
ScrollBar.vertical: FluScrollBar {}
FluText{
id:text_info
width: scrollview.width
wrapMode: Text.WrapAnywhere
padding: 14
}
}
}
}