FluentUI/example/qml/page/T_Http.qml

159 lines
4.2 KiB
QML
Raw Normal View History

2023-07-20 18:26:47 +08:00
import QtQuick
import Qt.labs.platform
2023-07-20 18:26:47 +08:00
import QtQuick.Layouts
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Dialogs
import FluentUI
import "qrc:///example/qml/component"
FluScrollablePage{
title:"Http"
FluHttp{
id:http_get
url:"https://api.github.com/search/repositories"
onStart: {
showLoading()
}
onFinish: {
hideLoading()
}
onError:
(status,errorString)=>{
2023-07-23 20:44:43 +08:00
console.debug(status+"->"+errorString)
2023-07-20 18:26:47 +08:00
showError(errorString)
}
onSuccess:
(result)=>{
window_result.result = result
window_result.show()
}
}
FluHttp{
id:http_post
url:"https://www.wanandroid.com/article/query/0/json"
onStart: {
showLoading()
}
onFinish: {
hideLoading()
}
onError:
(status,errorString)=>{
2023-07-21 11:19:30 +08:00
console.debug(status+"->"+errorString)
2023-07-20 18:26:47 +08:00
showError(errorString)
}
onSuccess:
(result)=>{
window_result.result = result
window_result.show()
}
}
FluHttp{
id:http_download
url:"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
2023-07-24 18:23:26 +08:00
// url:"https://www.w3school.com.cn/example/html5/mov_bbb.mp4"
2023-07-20 18:26:47 +08:00
onStart: {
btn_download.disabled = true
}
onFinish: {
btn_download.disabled = false
2023-07-20 21:54:45 +08:00
btn_download.text = "下载文件"
2023-07-25 17:57:37 +08:00
text_file_size.text = ""
2023-07-20 18:26:47 +08:00
}
2023-07-20 21:54:45 +08:00
onDownloadProgress:
2023-07-20 18:26:47 +08:00
(recv,total)=>{
2023-07-25 17:57:37 +08:00
var locale = Qt.locale()
2023-07-20 18:26:47 +08:00
var precent = (recv/total * 100).toFixed(0) + "%"
2023-07-21 18:58:09 +08:00
console.debug(precent)
2023-07-20 18:26:47 +08:00
btn_download.text = "下载中..."+precent
2023-07-25 17:57:37 +08:00
text_file_size.text = "%1/%2".arg(locale.formattedDataSize(recv)).arg(locale.formattedDataSize(total))
2023-07-20 18:26:47 +08:00
}
onError:
(status,errorString)=>{
showError(errorString)
}
onSuccess:
(result)=>{
showSuccess(result)
}
}
FluArea{
Layout.fillWidth: true
Layout.topMargin: 20
height: 160
paddings: 10
ColumnLayout{
spacing: 14
anchors.verticalCenter: parent.verticalCenter
FluButton{
text:"Get请求"
onClicked: {
2023-07-23 20:56:04 +08:00
http_get.get({q:"FluentUI"})
2023-07-20 18:26:47 +08:00
}
}
FluButton{
text:"Post请求"
onClicked: {
http_post.post({k:"jitpack"})
}
}
2023-07-25 17:57:37 +08:00
RowLayout{
FluButton{
id:btn_download
text:disabled ? "下载中..." : "下载文件"
onClicked: {
file_dialog.open()
}
}
FluText{
id:text_file_size
Layout.alignment: Qt.AlignVCenter
2023-07-20 18:26:47 +08:00
}
}
2023-07-25 17:57:37 +08:00
2023-07-20 18:26:47 +08:00
}
}
FolderDialog {
id: file_dialog
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
onAccepted: {
2023-07-24 18:23:26 +08:00
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
2023-07-20 18:26:47 +08:00
http_download.download(path)
}
}
Window{
property string result : ""
id:window_result
width: 600
height: 400
2023-07-25 17:57:37 +08:00
color: FluTheme.dark ? Qt.rgba(0,0,0,1) : Qt.rgba(1,1,1,1)
2023-07-20 18:26:47 +08:00
Item{
anchors.fill: parent
Flickable{
id:scrollview
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
text:window_result.result
padding: 14
}
}
}
}
}