TG-PlatformPlus/qml/debug/dataexplorer/main.qml

125 lines
4.6 KiB
QML
Raw Normal View History

2026-03-02 14:29:58 +08:00
import QtQuick
import QtQuick.Controls
import QtWebEngine
Rectangle {
focus: true
property var currentProId: ""
property var type: "应用"
property var name: "AGR"
property var currentEvent: "开始采集"
property var g_settingInfluxdbHost: "127.0.0.1"
property var g_settingInfluxdbPort: "8086"
property var g_settingInfluxdbUsername: "TGZZ"
property var g_settingInfluxdbPassword: "tgzz2023"
property var g_settingInfluxdbOrgId: "47a40b37fe0172c4"
Component.onCompleted: {
setConfigInfo()
}
function setConfigInfo()
{
var config = common.getConfig();
var influxdbInfo = null
for (var i = 0; i < config.influxdbs.length; i++)
{
if(config.influxdbs[i].name == config.influxdbName)
{
influxdbInfo = config.influxdbs[i]
}
}
if (g_settingInfluxdbHost != influxdbInfo.host)
g_settingInfluxdbHost = influxdbInfo.host
if (g_settingInfluxdbPort != influxdbInfo.port)
g_settingInfluxdbPort = influxdbInfo.port
if (g_settingInfluxdbUsername != influxdbInfo.username)
g_settingInfluxdbUsername = influxdbInfo.username
if (g_settingInfluxdbPassword != influxdbInfo.password)
g_settingInfluxdbPassword = influxdbInfo.password
if (g_settingInfluxdbOrgId != influxdbInfo.orgid)
g_settingInfluxdbOrgId = influxdbInfo.orgid
}
//![1]
WebEngineView {
id: webengine
focus: true
anchors.fill: parent
property var weburl: ""
url: g_settingInfluxdbHost != "" ? ("http://"+g_settingInfluxdbHost+":"+ g_settingInfluxdbPort +"/orgs/"+g_settingInfluxdbOrgId+"/data-explorer"): ""
onUrlChanged:{
weburl = url.toString()
}
}
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(){})
}
}
Timer {
id: urltimer
interval: 2000; running: true; repeat: true
onTriggered: setConfigInfo()
}
}