diff --git a/example/qml-Qt6/page/T_Http.qml b/example/qml-Qt6/page/T_Http.qml index 19ae6d9e..483d7aa7 100644 --- a/example/qml-Qt6/page/T_Http.qml +++ b/example/qml-Qt6/page/T_Http.qml @@ -164,6 +164,14 @@ FluContentPage{ http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param) } } + FluButton{ + implicitWidth: parent.width + implicitHeight: 36 + text: "打开缓存路径" + onClicked: { + Qt.openUrlExternally("file:///"+cacheDirPath) + } + } FluButton{ implicitWidth: parent.width implicitHeight: 36 diff --git a/example/qml-Qt6/window/MainWindow.qml b/example/qml-Qt6/window/MainWindow.qml index a0159a4c..cde74729 100644 --- a/example/qml-Qt6/window/MainWindow.qml +++ b/example/qml-Qt6/window/MainWindow.qml @@ -138,7 +138,7 @@ CustomWindow { id:loader lazy: true anchors.fill: parent - source: "https://zhu-zichu.gitee.io/Qt6_155_LieflatPage.qml" + source: "https://zhu-zichu.gitee.io/Qt6_156_LieflatPage.qml" } } front: Item{ diff --git a/example/qml/page/T_Http.qml b/example/qml/page/T_Http.qml index 88ce5eb7..0722df6c 100644 --- a/example/qml/page/T_Http.qml +++ b/example/qml/page/T_Http.qml @@ -165,6 +165,14 @@ FluContentPage{ http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param) } } + FluButton{ + implicitWidth: parent.width + implicitHeight: 36 + text: "打开缓存路径" + onClicked: { + Qt.openUrlExternally("file:///"+cacheDirPath) + } + } FluButton{ implicitWidth: parent.width implicitHeight: 36 diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index 5db84342..a84a9341 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -139,7 +139,7 @@ CustomWindow { id:loader lazy: true anchors.fill: parent - source: "https://zhu-zichu.gitee.io/Qt5_155_LieflatPage.qml" + source: "https://zhu-zichu.gitee.io/Qt5_156_LieflatPage.qml" } } front: Item{ diff --git a/example/src/main.cpp b/example/src/main.cpp index 1cbe1648..2dcb2d96 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); #ifdef Q_OS_WIN // 此设置仅在Windows下生效 FramelessConfig::instance()->set(Global::Option::ForceHideWindowFrameBorder); - FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow,false); + FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow,true); #endif #ifdef Q_OS_MACOS FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur,false); diff --git a/src/Def.h b/src/Def.h index 812adb82..f11a3ea1 100644 --- a/src/Def.h +++ b/src/Def.h @@ -10,7 +10,7 @@ enum CacheMode { /** 不使用缓存 */ NoCache = 0x0000, - /** 请求网络失败后,读取缓存 */ + /** 请求网络失败后,读取缓存 */ RequestFailedReadCache = 0x0001, /** 如果缓存不存在才请求网络,否则使用缓存 */ diff --git a/src/FluHttp.cpp b/src/FluHttp.cpp index e5e5f99d..6a6d72d7 100644 --- a/src/FluHttp.cpp +++ b/src/FluHttp.cpp @@ -10,7 +10,6 @@ #include #include #include "Def.h" -#include "MainThread.h" #include "FluApp.h" #include "FluTools.h" @@ -54,7 +53,7 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap pa Q_EMIT callable->finish(); return; } - if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest){ + if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){ Q_EMIT callable->cache(readCache(requestMap)); } for (int i = 0; i < retry(); ++i) { @@ -94,7 +93,7 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap pa break; }else{ if(i == retry()-1){ - if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache){ + if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){ Q_EMIT callable->cache(readCache(requestMap)); } Q_EMIT callable->error(status,errorString,result); @@ -102,7 +101,6 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap pa } } Q_EMIT callable->finish(); - // Q_EMIT callable->finish(); }); } @@ -116,7 +114,7 @@ void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap< Q_EMIT callable->finish(); return; } - if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest){ + if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){ Q_EMIT callable->cache(readCache(requestMap)); } for (int i = 0; i < retry(); ++i) { @@ -147,7 +145,7 @@ void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap< break; }else{ if(i == retry()-1){ - if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache){ + if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){ Q_EMIT callable->cache(readCache(requestMap)); } Q_EMIT callable->error(status,errorString,result); @@ -168,7 +166,7 @@ void FluHttp::postJson(QString url,HttpCallable* callable,QMapfinish(); return; } - if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest){ + if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){ Q_EMIT callable->cache(readCache(requestMap)); } for (int i = 0; i < retry(); ++i) { @@ -199,7 +197,7 @@ void FluHttp::postJson(QString url,HttpCallable* callable,QMapcache(readCache(requestMap)); } Q_EMIT callable->error(status,errorString,result); @@ -215,7 +213,7 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap par auto requestMap = toRequest(url,params,headers,"get"); QMap data = invokeIntercept(requestMap).toMap(); Q_EMIT callable->start(); - if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest){ + if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){ Q_EMIT callable->cache(readCache(requestMap)); } if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(requestMap)){ @@ -250,7 +248,7 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap par break; }else{ if(i == retry()-1){ - if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache){ + if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){ Q_EMIT callable->cache(readCache(requestMap)); } Q_EMIT callable->error(status,errorString,result); diff --git a/src/Qt5/imports/FluentUI/plugins.qmltypes b/src/Qt5/imports/FluentUI/plugins.qmltypes index 5f3215d5..b6f83d0e 100644 --- a/src/Qt5/imports/FluentUI/plugins.qmltypes +++ b/src/Qt5/imports/FluentUI/plugins.qmltypes @@ -8,6 +8,21 @@ import QtQuick.tooling 1.2 Module { dependencies: ["QtQuick 2.0"] + Component { + name: "FluHttpType" + exports: ["FluentUI/FluHttpType 1.0"] + isCreatable: false + exportMetaObjectRevisions: [0] + Enum { + name: "CacheMode" + values: { + "NoCache": 0, + "RequestFailedReadCache": 1, + "IfNoneCacheRequest": 2, + "FirstCacheThenRequest": 4 + } + } + } Component { name: "FluCalendarViewType" exports: ["FluentUI/FluCalendarViewType 1.0"] diff --git a/src/fluentuiplugin.cpp b/src/fluentuiplugin.cpp index 986d62f2..307b2f69 100644 --- a/src/fluentuiplugin.cpp +++ b/src/fluentuiplugin.cpp @@ -40,6 +40,7 @@ void FluentUIPlugin::registerTypes(const char *uri) qmlRegisterType(uri,major,minor,"FluHttp"); qmlRegisterType(uri,major,minor,"HttpCallable"); qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluHttpType::staticMetaObject, uri,major,minor,"FluHttpType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluPageType::staticMetaObject, uri,major,minor,"FluPageType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluWindowType::staticMetaObject, uri,major,minor,"FluWindowType", "Access to enums & flags only");