import inspect
import os

from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QIcon
from PyQt5.QtNetwork import QNetworkCookie
from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestInfo
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView, QWebEngineProfile
from PyQt5.QtWebChannel import QWebChannel
import sys
from requests.auth import HTTPBasicAuth
from PyQt5.QtCore import QObject

# 创建一个QWebEngineProfile实例
# profile = QWebEngineProfile.defaultProfile()
# profile = QWebEngineProfile.

# 创建一个QWebEnginePage实例
# page = QWebEnginePage(QWebEngineProfile())
pageURI = 'http://192.168.60.2:8082/index'


def main():
    app = QApplication(sys.argv)
    web_view = QWebEngineView()
    web_view.setWindowTitle("后台管理系统")
    web_view.setMinimumSize(1200, 700)
    current_directory = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    web_view.setWindowIcon(QIcon(os.path.join(current_directory, "manager.png")))
    page = QWebEnginePage()
    # http header
    # 创建拦截器实例
    # interceptor = WebEngineUrlRequestInterceptor()
    # 注册拦截器
    # QWebEngineUrlRequestInterceptor.setInterceptor(interceptor)
    # page.setUrlRequestInterceptor(interceptor)
    # 设置页面加载的URL
    page.load(QUrl(pageURI))
    web_view.setPage(page)
    # Cookie
    # netcookie = QNetworkCookie();
    # netcookie.setName(b"Admin-Token")
    # netcookie.setValue(b"eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6IjNhMjI5ODgyLTgyM2QtNDdmNy1hOGRiLTNhMmJiN2FmYTc5NiIsInVzZXJuYW1lIjoiYWRtaW4ifQ.l0CWG-uKjI12W5VYQWr5wiMvWHZkeUHc2jzgQyzTPBaQmwArgq0oe6dvLV07CZcvnNS196RhncFLIkv9328SYg")
    # page.profile().cookieStore().setCookie(netcookie, QUrl(pageURI))
    web_view.show()

    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
