mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 19:20:59 +08:00
43 lines
2.1 KiB
C++
43 lines
2.1 KiB
C++
#ifndef FLUHTTP_H
|
||
#define FLUHTTP_H
|
||
|
||
#include <QObject>
|
||
#include <QtQml/qqml.h>
|
||
#include <QFile>
|
||
#include <QNetworkAccessManager>
|
||
#include "stdafx.h"
|
||
|
||
class FluHttp : public QObject
|
||
{
|
||
Q_OBJECT
|
||
Q_PROPERTY_AUTO(int,retry);
|
||
Q_PROPERTY_AUTO(int,timeout)
|
||
QML_NAMED_ELEMENT(FluHttp)
|
||
private:
|
||
QVariant invokeIntercept(const QVariant& params,const QVariant& headers,const QString& method);
|
||
void handleReply(QNetworkReply* reply);
|
||
void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params);
|
||
void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& params);
|
||
void onStart(const QJSValue& callable);
|
||
void onFinish(const QJSValue& callable);
|
||
void onError(const QJSValue& callable,int status,QString errorString,QString result);
|
||
void onSuccess(const QJSValue& callable,QString result);
|
||
void onDownloadProgress(const QJSValue& callable,qint64 recv, qint64 total);
|
||
void onUploadProgress(const QJSValue& callable,qint64 recv, qint64 total);
|
||
public:
|
||
explicit FluHttp(QObject *parent = nullptr);
|
||
~FluHttp();
|
||
//神坑!!! 如果参数使用QVariantMap会有问题,在6.4.3版本中QML一调用就会编译失败。所以改用QMap<QString, QVariant>
|
||
Q_INVOKABLE void get(QString url,QJSValue callable,QMap<QString, QVariant> params= {},QMap<QString, QVariant> headers = {});
|
||
Q_INVOKABLE void post(QString url,QJSValue callable,QMap<QString, QVariant> params= {},QMap<QString, QVariant> headers = {});
|
||
Q_INVOKABLE void postString(QString url,QJSValue callable,QString params = "",QMap<QString, QVariant> headers = {});
|
||
Q_INVOKABLE void postJson(QString url,QJSValue callable,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {});
|
||
Q_INVOKABLE void download(QString url,QJSValue callable,QString filePath,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {});
|
||
Q_INVOKABLE void upload(QString url,QJSValue callable,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {});
|
||
Q_INVOKABLE void cancel();
|
||
private:
|
||
QList<QPointer<QNetworkReply>> _cache;
|
||
};
|
||
|
||
#endif // FLUHTTP_H
|