mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-07-01 23:51:48 +08:00
update
This commit is contained in:
@ -7,152 +7,152 @@ import QtQuick.Dialogs
|
||||
import FluentUI
|
||||
import "qrc:///example/qml/component"
|
||||
|
||||
FluScrollablePage{
|
||||
FluContentPage{
|
||||
|
||||
title:"Http"
|
||||
|
||||
FluHttp{
|
||||
id:http_get
|
||||
url:"https://api.github.com/search/repositories"
|
||||
onStart: {
|
||||
showLoading()
|
||||
}
|
||||
onFinish: {
|
||||
hideLoading()
|
||||
}
|
||||
onError:
|
||||
(status,errorString)=>{
|
||||
console.debug(status+"->"+errorString)
|
||||
showError(errorString)
|
||||
}
|
||||
onSuccess:
|
||||
(result)=>{
|
||||
window_result.result = result
|
||||
window_result.show()
|
||||
}
|
||||
id:http
|
||||
}
|
||||
|
||||
FluHttp{
|
||||
id:http_post
|
||||
url:"https://www.wanandroid.com/article/query/0/json"
|
||||
onStart: {
|
||||
showLoading()
|
||||
}
|
||||
onFinish: {
|
||||
hideLoading()
|
||||
}
|
||||
onError:
|
||||
(status,errorString)=>{
|
||||
console.debug(status+"->"+errorString)
|
||||
showError(errorString)
|
||||
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)
|
||||
}
|
||||
onSuccess:
|
||||
(result)=>{
|
||||
window_result.result = result
|
||||
window_result.show()
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FluHttp{
|
||||
id:http_download
|
||||
url:"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
||||
// url:"https://www.w3school.com.cn/example/html5/mov_bbb.mp4"
|
||||
onStart: {
|
||||
btn_download.disabled = true
|
||||
|
||||
ListView{
|
||||
id:list_view
|
||||
width: 160
|
||||
clip: true
|
||||
anchors{
|
||||
top: parent.top
|
||||
topMargin: 20
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
}
|
||||
onFinish: {
|
||||
btn_download.disabled = false
|
||||
btn_download.text = "下载文件"
|
||||
text_file_size.text = ""
|
||||
model:data_model
|
||||
delegate: FluButton{
|
||||
implicitWidth: ListView.view.width
|
||||
implicitHeight: 30
|
||||
text: model.name
|
||||
onClicked: {
|
||||
model.onClickListener()
|
||||
}
|
||||
}
|
||||
onDownloadProgress:
|
||||
(recv,total)=>{
|
||||
var locale = Qt.locale()
|
||||
var precent = (recv/total * 100).toFixed(0) + "%"
|
||||
console.debug(precent)
|
||||
btn_download.text = "下载中..."+precent
|
||||
text_file_size.text = "%1/%2".arg(locale.formattedDataSize(recv)).arg(locale.formattedDataSize(total))
|
||||
}
|
||||
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: {
|
||||
http_get.get({q:"FluentUI"})
|
||||
}
|
||||
anchors{
|
||||
top: list_view.top
|
||||
bottom: list_view.bottom
|
||||
left: list_view.right
|
||||
right: parent.right
|
||||
}
|
||||
Flickable{
|
||||
clip: true
|
||||
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
|
||||
padding: 14
|
||||
}
|
||||
FluButton{
|
||||
text:"Post请求"
|
||||
onClicked: {
|
||||
http_post.post({k:"jitpack"})
|
||||
}
|
||||
}
|
||||
RowLayout{
|
||||
FluButton{
|
||||
id:btn_download
|
||||
text:disabled ? "下载中..." : "下载文件"
|
||||
onClicked: {
|
||||
file_dialog.open()
|
||||
}
|
||||
}
|
||||
FluText{
|
||||
id:text_file_size
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
FolderDialog {
|
||||
id: file_dialog
|
||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
||||
onAccepted: {
|
||||
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
||||
http_download.download(path)
|
||||
}
|
||||
}
|
||||
|
||||
Window{
|
||||
property string result : ""
|
||||
id:window_result
|
||||
width: 600
|
||||
height: 400
|
||||
color: FluTheme.dark ? Qt.rgba(0,0,0,1) : Qt.rgba(1,1,1,1)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user