TG-PlatformPlus/qml/WebEngines.qml

96 lines
3.5 KiB
QML

import QtQuick
import QtQuick.Controls
import QtWebEngine
import "./common"
// import "./Style"
Item {
id: self
width: 400
height: 300
//![1]
WebEngineView {
id: webengine
focus: true
anchors.fill: parent
property var hasreload: false
property var weburl: ""
url: g_settingInfluxdbHost != "" ? ("http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/orgs/"+g_settingInfluxdbOrgId+"/data-explorer"): ""
onUrlChanged:{
weburl = url.toString()
// if(weburl == "http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/signin" && !hasreload)
// {
// reload()
// timer.start()
// hasreload = true
// nooptimer.start()
// }
}
}
property var hasReload: false
Timer {
id: nooptimer
interval: 500; running: true; repeat: true
property var signinIndex: 0
onTriggered:
{
if(webengine.loadProgress === 100)
{
if(webengine.weburl == "http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/signin")
{
signinIndex ++
if( !hasReload )
{
webengine.reload()
hasReload = true
}
else if ( signinIndex >= 3)
{
signinIndex = 0
hasReload = false
}
}
else
{
signinIndex = 0
}
if(webengine.weburl == "http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/signin" ||
webengine.weburl == "http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/signin?returnTo=/orgs/"+g_settingInfluxdbOrgId+"/data-explorer" )
timer.start()
if(webengine.weburl == "http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/signin?returnTo=/orgs/"+g_settingInfluxdbOrgId+"/data-explorer")
{
hasReload = false
}
}
}
}
Timer {
id: timer
interval: 1000; running: false; repeat: false
onTriggered: autoLogon()
}
function autoLogon()
{
if(webengine.weburl == "http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/signin" ||
webengine.weburl == "http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/signin?returnTo=/orgs/"+g_settingInfluxdbOrgId+"/data-explorer" )
{
var scriptUserName = "const username =document.getElementById(\'login\')
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, \'value\').set.call(username, \'"+g_settingInfluxdbUsername+"\')
username.dispatchEvent(new Event(\'input\', { bubbles: true }))"
var scriptPassword = "const password =document.getElementById(\'password\')
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, \'value\').set.call(password, \'"+g_settingInfluxdbPassword+"\')
password.dispatchEvent(new Event(\'input\', { bubbles: true }))"
var scriptSubmit = "document.getElementById(\'submit-login\').click()"
webengine.runJavaScript(scriptUserName, function(){})
webengine.runJavaScript(scriptPassword, function(){})
webengine.runJavaScript(scriptSubmit, function(){})
}
}
}