| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857 |
- import QtQuick 2.15
- import QtQuick.Controls 2.12
- import QtQuick.Layouts 1.12
- import QtQuick.VirtualKeyboard 2.12
- import QtQuick.Window 2.12
- import "."
- import "./components"
- import Loto 1.0
- ApplicationWindow {
- id: appWindow
- visible: true
- width: 1920
- height: 1080
- //visibility: Window.FullScreen // 设置窗口为全屏
- visibility: Window.Windowed // 窗口模式,非全屏
- flags: Qt.FramelessWindowHint // 设置窗口无边框
- property int defaultLogoutSeconds: 120 + 1
- property int startLogoutInterval: 20
- // 访问StackView
- default property alias appStackView: stackView
- property alias appAlertDialog: __alertDialog
- property alias appShowHome: appWindow.showHome
- property alias appBlurItem: contentWrapper
- property string appTitle: qsTr("智能锁控系统")
- property bool appShowLogout: false
- property int appLogoutSeconds: defaultLogoutSeconds
- property bool appControlLogoutSecondsFlag: false
- property string appLogoutText: "退出登录"
- property alias appHttpGetJobTickets: httpGetJobTickets
- property string logoLabelText: "博士能量隔离系统"
- property var advertisementImageModel: [
- "qrc:/resources/png/a.jpeg",
- "qrc:/resources/png/b.jpeg",
- "qrc:/resources/png/c.jpeg"
- ]
- property int currentIndex: 0
- property bool showHome: true
- property int pressX: 0 // 记录鼠标上次位置,目的是模仿onPositionChanged事件
- property int pressY: 0
- // ============ 首页刷卡登录相关属性 ============
- property bool homeCardLoginLoading: false // 首页刷卡登录loading状态
- property bool homeCardLoginSuccess: false // 首页刷卡登录成功标志
- property var homeCardLoginErrorDialog: null // 错误提示对话框对象
- property bool homeCardLoginSkipLoginPage: false // 首页刷卡登录成功后跳过登录页
-
- // ============ 导航栏刷新作业列表相关属性 ============
- property bool navBarRefreshJobTickets: false // 从导航栏刷新作业列表标志
- // ============ API 超时弹窗(408)与 loading ============
- property var homeTimeoutDialog: null
- property int homeTimeoutCountdown: 10
- property var homeTimeoutRefreshCallback: null
- property bool getUserInfoLoading: false // 获取用户信息 loading
- // 首页刷卡登录:关闭错误提示对话框
- function closeHomeCardLoginErrorDialog() {
- console.log("[main.qml] 关闭首页刷卡登录错误提示");
- if (homeCardLoginErrorDialog !== null) {
- homeCardLoginErrorDialog.visible = false;
- homeCardLoginErrorDialog.destroy();
- homeCardLoginErrorDialog = null;
- }
- homeCardLoginErrorAutoCloseTimer.stop();
- }
- // 关闭 API 超时弹窗并执行刷新回调
- function closeHomeTimeoutDialog() {
- homeTimeoutAutoCloseTimer.stop();
- if (homeTimeoutDialog !== null) {
- homeTimeoutDialog.visible = false;
- homeTimeoutDialog.destroy();
- homeTimeoutDialog = null;
- }
- homeTimeoutRefreshCallback = null;
- }
- // 显示 API 超时弹窗:处理超时,请稍后重试。确认(10) 倒计时,关闭后执行 refreshCallback
- function showHomeTimeoutDialog(refreshCallback) {
- closeHomeTimeoutDialog();
- homeTimeoutCountdown = 10;
- homeTimeoutRefreshCallback = refreshCallback || null;
- var component = Qt.createComponent("components/AlertDialog.qml");
- if (component.status === Component.Ready) {
- homeTimeoutDialog = component.createObject(appAlertDialog, {
- messageTypeName: "",
- messageValue: "处理超时,请稍后重试。",
- messageIconCharacter: "\uf071",
- confirmBtnText: "确认(10)"
- });
- homeTimeoutDialog.parent = appAlertDialog;
- homeTimeoutDialog.confirm.connect(function () {
- if (typeof homeTimeoutRefreshCallback === "function")
- homeTimeoutRefreshCallback();
- closeHomeTimeoutDialog();
- });
- homeTimeoutAutoCloseTimer.restart();
- }
- }
- // 首页刷卡登录:显示错误提示对话框
- function showHomeCardLoginErrorDialog(errorMsg) {
- console.log("[main.qml] 显示首页刷卡登录错误提示:", errorMsg);
- closeHomeCardLoginErrorDialog();
- var component = Qt.createComponent("components/AlertDialog.qml");
- if (component.status === Component.Ready) {
- homeCardLoginErrorDialog = component.createObject(appAlertDialog, {
- messageTypeName: "登录失败",
- messageValue: errorMsg,
- messageIconCharacter: "\uf071"
- });
- homeCardLoginErrorDialog.parent = appAlertDialog;
- homeCardLoginErrorDialog.confirm.connect(function () {
- console.log("[main.qml] 用户点击确认按钮");
- closeHomeCardLoginErrorDialog();
- });
- homeCardLoginErrorAutoCloseTimer.restart();
- console.log("[main.qml] 启动3秒自动关闭定时器");
- }
- }
- // 首页刷卡登录:处理键盘输入
- function homeSetCardIDByKey(keyValue) {
- switch(keyValue) {
- case Qt.Key_0: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "0"; break;
- case Qt.Key_1: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "1"; break;
- case Qt.Key_2: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "2"; break;
- case Qt.Key_3: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "3"; break;
- case Qt.Key_4: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "4"; break;
- case Qt.Key_5: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "5"; break;
- case Qt.Key_6: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "6"; break;
- case Qt.Key_7: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "7"; break;
- case Qt.Key_8: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "8"; break;
- case Qt.Key_9: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "9"; break;
- case Qt.Key_A: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "A"; break;
- case Qt.Key_B: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "B"; break;
- case Qt.Key_C: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "C"; break;
- case Qt.Key_D: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "D"; break;
- case Qt.Key_E: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "E"; break;
- case Qt.Key_F: homeHttpCardLogin.cardID = homeHttpCardLogin.cardID + "F"; break;
- case Qt.Key_Return: {
- if (homeHttpCardLogin.cardID.length > 0) {
- console.log("[main.qml] 首页刷卡回车,卡号:", homeHttpCardLogin.cardID);
- closeHomeCardLoginErrorDialog();
- console.log("[main.qml] 显示loading");
- homeCardLoginLoading = true;
- console.log("[main.qml] 启动登录线程");
- homeHttpCardLogin.start();
- }
- return;
- }
- }
- }
- // ============================================
- MTheme {
- id: theme
- }
- FontLoader {
- id: iconFont
- source: "qrc:/resources/fonts/fontawesome-free-5.15.4-desktop/otfs/FontAwesome5Free-Solid-900.otf"
- }
- HttpClient {
- id: httpClientThread
- Component.onCompleted: {
- httpClientThread.start();
- }
- }
- // ============ 首页刷卡登录HTTP组件 ============
- HttpCardLogin {
- id: homeHttpCardLogin
- Component.onCompleted: {
- // 首页刷卡登录信号连接(只在首页时生效)
- connectHomeCardLoginSignals();
- }
- Component.onDestruction: {
- disconnectHomeCardLoginSignals();
- }
- }
- // 连接首页刷卡登录信号
- function connectHomeCardLoginSignals() {
- // 先断开再连接,避免重复连接
- disconnectHomeCardLoginSignals();
- homeHttpCardLogin.signalPostRequestData.connect(httpClientThread.slotPostRequestData);
- httpClientThread.signalResponseCardLoginData.connect(homeHttpCardLogin.slotHttpResponseCardLogin);
- console.log("[main.qml] 首页刷卡登录信号已连接");
- }
- // 断开首页刷卡登录信号
- function disconnectHomeCardLoginSignals() {
- try {
- homeHttpCardLogin.signalPostRequestData.disconnect(httpClientThread.slotPostRequestData);
- } catch(e) {}
- try {
- httpClientThread.signalResponseCardLoginData.disconnect(homeHttpCardLogin.slotHttpResponseCardLogin);
- } catch(e) {}
- console.log("[main.qml] 首页刷卡登录信号已断开");
- }
- Connections {
- target: homeHttpCardLogin
- function onSignalLoginReturnStat(stat, data) {
- homeCardLoginLoading = false;
- if (stat === 0) {
- homeCardLoginSuccess = true;
- } else if (stat === 408) {
- showHomeTimeoutDialog(function () { });
- } else {
- showHomeCardLoginErrorDialog(data);
- }
- }
- }
- // 首页刷卡登录成功后获取作业票
- HttpGetJobTickets {
- id: homeHttpGetJobTickets
- Component.onCompleted: {
- // 首页获取作业票信号连接(只在首页刷卡登录成功时使用)
- connectHomeGetJobTicketsSignals();
- }
- Component.onDestruction: {
- disconnectHomeGetJobTicketsSignals();
- }
- }
- // 连接首页获取作业票信号
- function connectHomeGetJobTicketsSignals() {
- // 先断开再连接,避免重复连接
- disconnectHomeGetJobTicketsSignals();
- homeHttpGetJobTickets.signalGetRequestData.connect(httpClientThread.slotGetRequestData);
- httpClientThread.signalResponseGetJobTickets.connect(homeHttpGetJobTickets.slotHttpResponseGetJobTickets);
- console.log("[main.qml] 首页获取作业票信号已连接");
- }
- // 断开首页获取作业票信号
- function disconnectHomeGetJobTicketsSignals() {
- try {
- homeHttpGetJobTickets.signalGetRequestData.disconnect(httpClientThread.slotGetRequestData);
- } catch(e) {}
- try {
- httpClientThread.signalResponseGetJobTickets.disconnect(homeHttpGetJobTickets.slotHttpResponseGetJobTickets);
- } catch(e) {}
- console.log("[main.qml] 首页获取作业票信号已断开");
- }
- Connections {
- target: homeHttpGetJobTickets
- function onSignalJobTicketsReturnStat(stat, msg) {
- // 408 超时:显示超时弹窗,确认后刷新(重新请求作业票)
- if (stat === 408) {
- showHomeTimeoutDialog(function () {
- connectHomeGetJobTicketsSignals();
- homeHttpGetJobTickets.start();
- });
- return;
- }
- // 从导航栏刷新的情况
- if (navBarRefreshJobTickets) {
- navBarRefreshJobTickets = false;
- // 断开信号
- disconnectHomeGetJobTicketsSignals();
-
- // stackView 结构:[广告页(0)] -> [Login.qml(1)] -> [JobTicketPage.qml(2)] -> [WorkingPage.qml(3)]
- // 我们需要保留 [广告页] 和 [Login.qml],pop 掉后面的页面
- // 使用 pop(item) 直接 pop 到 Login.qml(索引 1)
- if (stackView.depth > 2) {
- // 获取 Login.qml 页面(索引 1),pop 到该页面
- var loginPage = stackView.get(1);
- if (loginPage) {
- stackView.pop(loginPage);
- }
- }
-
- // 然后 push 列表页
- if (stat !== 0 || JobTicketModel.rowCount() === 0) {
- stackView.push("components/NoJobTicketDialog.qml");
- } else {
- stackView.push("JobTicketPage.qml");
- }
- return;
- }
-
- // 首页刷卡登录的情况
- if (stat !== 0 || JobTicketModel.rowCount() === 0) {
- stackView.push("components/NoJobTicketDialog.qml");
- } else {
- stackView.push("JobTicketPage.qml");
- }
- }
- }
- // 首页刷卡登录成功处理
- onHomeCardLoginSuccessChanged: {
- if (homeCardLoginSuccess) {
- console.log("[main.qml] 处理首页刷卡登录成功");
- homeCardLoginLoading = false;
- closeHomeCardLoginErrorDialog();
-
- // 设置标志:跳过登录页面
- homeCardLoginSkipLoginPage = true;
-
- // 关闭首页,进入作业流程
- showHome = false;
- homeMouseArea.visible = false;
- appShowLogout = true;
-
- // 重置标志
- homeCardLoginSuccess = false;
- }
- }
- // ============================================
- Component {
- id: adPage
- Item {
- width: appWindow.width
- height: appWindow.height
- property string adImageSource: ""
- Image {
- id: sourceItem
- anchors.fill: parent
- fillMode: Image.PreserveAspectCrop
- cache: true
- asynchronous: true
- visible: true
- sourceSize.width: appWindow.width
- sourceSize.height: appWindow.height
- source: adImageSource
- }
- }
- }
- function showAlertDialog(msgTypeName, msgValue, msgIconChar, callbackFunc) {
- var component = Qt.createComponent("components/AlertDialog.qml");
- if (component.status === Component.Ready) {
- // 创建实例并添加到场景中
- var alertDialogComp = component.createObject(appAlertDialog, {
- messageTypeName: msgTypeName,
- messageValue: msgValue,
- messageIconCharacter: msgIconChar
- });
- alertDialogComp.parent = appAlertDialog; // 将提示对话框挂载在appAlterDialog Loader加载器上
- // 处理提示对话框的事件
- alertDialogComp.confirm.connect(function () { callbackFunc(alertDialogComp); });
- } else {
- console.log("Error loading component:", component.errorString());
- }
- }
- function negativeAlertDialogCallback(componentObj) {
- componentObj.visible = false;
- appAlertDialog.sourceComponent = null;
- componentObj.destroy();
- }
- HttpGetUserInfo {
- id: httpGetUserInfo
- Component.onCompleted: {
- httpGetUserInfo.signalGetRequestData.connect(httpClientThread.slotGetRequestData);
- httpClientThread.signalResponseGetUserInfoUrl.connect(httpGetUserInfo.slotHttpResponseGetUserInfo);
- }
- Component.onDestruction: {
- httpGetUserInfo.signalGetRequestData.disconnect(httpClientThread.slotGetRequestData);
- httpClientThread.signalResponseGetUserInfoUrl.disconnect(httpGetUserInfo.slotHttpResponseGetUserInfo);
- }
- }
- Connections {
- target: InteractiveData
- function onRequestTimedOut() {
- showHomeTimeoutDialog(function () { });
- }
- }
- Connections {
- target: httpGetUserInfo
- function onSignalUserInfoReturnStat(stat, msg) {
- getUserInfoLoading = false;
- if (stat === 408) {
- showHomeTimeoutDialog(function () {
- getUserInfoLoading = true;
- httpGetUserInfo.start();
- });
- return;
- }
- if (stat !== 0) {
- showAlertDialog("提示", msg, "\uf071", negativeAlertDialogCallback);
- } else {
- stackView.push("SettingPage.qml");
- }
- }
- }
- // 作业票
- HttpGetJobTickets {
- id: httpGetJobTickets
- Component.onCompleted: {
- httpGetJobTickets.signalGetRequestData.connect(httpClientThread.slotGetRequestData);
- httpClientThread.signalResponseGetJobTickets.connect(httpGetJobTickets.slotHttpResponseGetJobTickets);
- }
- Component.onDestruction: {
- httpGetJobTickets.signalGetRequestData.disconnect(httpClientThread.slotGetRequestData);
- httpClientThread.signalResponseGetJobTickets.disconnect(httpGetJobTickets.slotHttpResponseGetJobTickets);
- }
- }
- Item {
- id: contentWrapper
- anchors.fill: parent
- Image {
- id: __backgroundImage
- x: 0
- y: 0
- width: parent.width
- height: parent.height
- source: "qrc:/resources/png/backgroundImage.png"
- fillMode: Image.PreserveAspectFit
- }
- Rectangle {
- id: logoArea
- x: 52
- y: 42
- width: 211
- height: 64
- z: 65535
- color: "transparent"
- Image {
- id: logoImage
- anchors.fill: parent
- fillMode: Image.PreserveAspectFit
- cache: true
- asynchronous: true
- visible: true
- source: "qrc:/resources/png/bozz.png"
- }
- Text {
- id: __logoLabel
- x: 0
- y: 71
- width: 211
- height: 32
- text: qsTr(logoLabelText)
- opacity: 1
- color: "#40a9ff"
- font.pixelSize: 24
- font.bold: true
- verticalAlignment: Text.AlignVCenter
- }
- }
- RowLayout {
- id: logout_settings
- visible: appShowLogout
- x: 1449
- y: 80
- width: 418
- height: 52
- z: 1000
- spacing: 14
- MButton {
- id: jobTicketBtn
- Layout.preferredWidth: 118
- Layout.preferredHeight: 52
- buttonColor: "#CC0F1929"
- text: qsTr("作业")
- textColor: "white"
- iconCharacter: "\uf0ae"
- iconColor: "#40a9ff"
- onClicked: {
- console.log("[main.qml] 导航栏点击作业按钮,跳转到列表页");
- // 直接替换当前页面为列表页,不重新请求数据,禁用自动跳转详情
- if (JobTicketModel.rowCount() === 0) {
- stackView.replace("components/NoJobTicketDialog.qml");
- } else {
- stackView.replace("JobTicketPage.qml", { autoNavigateToDetail: false });
- }
- }
- }
- MButton {
- Layout.preferredWidth: 118
- Layout.preferredHeight: 52
- buttonColor: "#CC0F1929"
- text: qsTr("设置")
- textColor: "white"
- iconCharacter: "\uf013"
- iconColor: "#40a9ff"
- onClicked: {
- getUserInfoLoading = true;
- httpGetUserInfo.start();
- }
- }
- MButton {
- Layout.preferredWidth: 180
- Layout.preferredHeight: 52
- buttonColor: "#33FF4D4F"
- backgroundOpacity: 0.2
- text: appLogoutSeconds % defaultLogoutSeconds === 0 ? qsTr(appLogoutText) :
- qsTr(appLogoutText + "(" + appLogoutSeconds.toString() + "秒)")
- textColor: "white"
- iconCharacter: "\uf2f5"
- iconColor: "red"
- onClicked: {
- showHome = true;
- }
- }
- }
- StackView {
- id: stackView
- anchors.fill: parent
- initialItem: adPage.createObject(appWindow, {adImageSource: advertisementImageModel[0]})
- focus: true
- Component.onCompleted: {
- currentItem.focus = true
- }
- // 定义淡入淡出效果
- pushEnter: Transition {
- PropertyAnimation {
- property: "opacity"
- from: 0
- to:1
- duration: 500
- }
- }
- pushExit: Transition {
- PropertyAnimation {
- property: "opacity"
- from: 1
- to:0
- duration: 500
- }
- }
- popEnter: Transition {
- PropertyAnimation {
- property: "opacity"
- from: 0
- to:1
- duration: 500
- }
- }
- popExit: Transition {
- PropertyAnimation {
- property: "opacity"
- from: 1
- to:0
- duration: 500
- }
- }
- }
- MButton {
- id: homeAreaTip
- height: 82
- visible: showHome
- anchors.bottom: parent.bottom
- anchors.bottomMargin: 160
- anchors.horizontalCenter: parent.horizontalCenter
- buttonColor: "#808080"
- backgroundOpacity: 0.8
- text: "请点击屏幕进行操作"
- btnHoverEanabled: false
- }
- MouseArea {
- id: homeMouseArea
- anchors.fill: parent
- onClicked: {
- // 点击进入登录页面前,清空可能已输入的卡号
- homeHttpCardLogin.cardID = "";
- showHome = false;
- homeMouseArea.visible = false;
- }
- }
- }
- Loader {
- id: __alertDialog
- z: 99999 // 确保弹窗始终置于最上层,不被 loginInput 人脸框等遮挡
- anchors.fill: parent
- }
- Loader {
- id: loginInput
- visible: false
- anchors.fill: parent
- // anchors.verticalCenter: parent.verticalCenter
- // anchors.horizontalCenter: parent.horizontalCenter
- }
- Loader {
- id: __returnKeyLockProcess
- visible: ReturnKeyLockManager.isVisible
- z: 999
- anchors.fill: parent
- asynchronous: true
- }
- Connections {
- target: ReturnKeyLockManager
- function onIsVisibleChanged() {
- if (ReturnKeyLockManager.isVisible) {
- __returnKeyLockProcess.source = "components/ReturnKeyLockProcess.qml";
- } else {
- __returnKeyLockProcess.sourceComponent = null;
- __returnKeyLockProcess.source = "";
- }
- }
- }
-
- Timer {
- id: swipeTimer
- interval: 3000
- repeat: true
- running: true
- onTriggered: {
- stackView.push(adPage.createObject(appWindow, {adImageSource: advertisementImageModel[(++currentIndex)%advertisementImageModel.length]}));
- }
- }
- onShowHomeChanged: {
- if (!showHome) {
- swipeTimer.stop();
- appControlLogoutSecondsFlag = false
- __startLogoutTimer.restart();
- // 离开首页时,重置首页刷卡登录状态
- homeHttpCardLogin.cardID = "";
- homeCardLoginLoading = false;
- closeHomeCardLoginErrorDialog();
-
- // 检查是否是首页刷卡登录成功导致的页面切换
- if (homeCardLoginSkipLoginPage) {
- console.log("[main.qml] 首页刷卡登录成功,跳过登录页,直接获取作业票");
- homeCardLoginSkipLoginPage = false;
- // 首页刷卡登录成功,不 push Login.qml(避免信号冲突)
- // 直接获取作业票
- homeHttpGetJobTickets.start();
- } else {
- // 正常点击屏幕进入登录页,断开首页信号避免冲突
- disconnectHomeCardLoginSignals();
- disconnectHomeGetJobTicketsSignals();
- // 进入登录页
- stackView.push("Login.qml");
- // 确保Login页面获取焦点
- if (stackView.currentItem) {
- stackView.currentItem.forceActiveFocus();
- }
- }
- } else {
- InteractiveData.clearToken();
- stackView.clear();
- stackView.push(adPage.createObject(appWindow, {adImageSource: advertisementImageModel[0]}));
- homeMouseArea.visible = true;
- appShowLogout = false
- swipeTimer.restart();
- // 回到首页登录倒计时停止
- __startLogoutTimer.stop();
- __logoutCountTimer.stop();
- // 回到首页时,重置首页刷卡登录状态并让键盘监听获取焦点
- homeHttpCardLogin.cardID = "";
- homeCardLoginLoading = false;
- homeCardLoginSuccess = false;
- homeCardLoginSkipLoginPage = false;
- closeHomeCardLoginErrorDialog();
- // 重新连接首页信号
- connectHomeCardLoginSignals();
- connectHomeGetJobTicketsSignals();
- homeKeyboardListener.forceActiveFocus();
- }
- }
- onAppLogoutSecondsChanged: {
- if (appLogoutSeconds === 0) {
- showHome = true;
- appLogoutSeconds = defaultLogoutSeconds;
- }
- }
- onAppControlLogoutSecondsFlagChanged: {
- if (appControlLogoutSecondsFlag) {
- appLogoutSeconds = defaultLogoutSeconds;
- __logoutCountTimer.restart();
- } else {
- __logoutCountTimer.stop();
- }
- }
- MouseArea {
- id: __screenArea
- anchors.fill: parent
- visible: !showHome
- acceptedButtons: Qt.AllButtons
- hoverEnabled: true
- onPositionChanged: {
- // 滑动屏幕重新计时
- __startLogoutTimer.restart();
- appControlLogoutSecondsFlag = false
- appLogoutSeconds = defaultLogoutSeconds;
- }
- onClicked: function(mouse) {mouse.accepted = false;}
- onPressed: function(mouse) {
- if (appWindow.pressX !== mouse.x || appWindow.pressY !== mouse.y) {
- // 模仿onPositionChanged事件
- __startLogoutTimer.restart();
- appControlLogoutSecondsFlag = false
- appLogoutSeconds = defaultLogoutSeconds;
- }
- appWindow.pressX = mouse.x;
- appWindow.pressY = mouse.y;
- mouse.accepted = false;
- }
- onReleased: function(mouse) {mouse.accepted = false;}
- onWheel: function(mouse) {mouse.accepted = false;}
- onDoubleClicked: function(mouse) {mouse.accepted = false;}
- onCanceled: function(mouse) {mouse.accepted = false;}
- onPressAndHold: function(mouse) {mouse.accepted = false;}
- }
- Timer {
- id: __startLogoutTimer
- interval: startLogoutInterval * 1000
- repeat: true
- running: false
- onTriggered: {
- // console.log("emit logout timer")
- appControlLogoutSecondsFlag = true && !showHome;
- }
- }
- Timer {
- id: __logoutCountTimer
- interval: 1000
- repeat: true
- running: false
- onTriggered: {
- appLogoutSeconds--;
- }
- }
- // ============ 首页刷卡登录:键盘监听 ============
- // 让窗口获取焦点并监听键盘事件
- Item {
- id: homeKeyboardListener
- focus: showHome // 首页时获取焦点
- Keys.enabled: showHome
- Keys.onPressed: function(event) {
- if (showHome) {
- homeSetCardIDByKey(event.key);
- event.accepted = true; // 防止事件继续传递
- }
- }
- Component.onCompleted: {
- // 启动时让键盘监听获取焦点
- if (showHome) {
- forceActiveFocus();
- }
- }
- }
- // 首页刷卡登录错误提示自动关闭定时器(3秒)
- Timer {
- id: homeCardLoginErrorAutoCloseTimer
- interval: 3000
- running: false
- repeat: false
- onTriggered: {
- closeHomeCardLoginErrorDialog();
- }
- }
- // API 超时弹窗 10 秒倒计时定时器
- Timer {
- id: homeTimeoutAutoCloseTimer
- interval: 1000
- repeat: true
- running: false
- onTriggered: {
- homeTimeoutCountdown--;
- if (homeTimeoutDialog !== null)
- homeTimeoutDialog.confirmBtnText = "确认(" + Math.max(0, homeTimeoutCountdown) + ")";
- if (homeTimeoutCountdown <= 0) {
- if (typeof homeTimeoutRefreshCallback === "function")
- homeTimeoutRefreshCallback();
- closeHomeTimeoutDialog();
- }
- }
- }
- // 首页刷卡登录 Loading
- LoadingDialog {
- id: homeCardLoginLoadingDialog
- loadingText: "登录中,请稍后..."
- showLoading: homeCardLoginLoading
- }
- // 获取用户信息 Loading
- LoadingDialog {
- id: getUserInfoLoadingDialog
- loadingText: "处理中..."
- showLoading: getUserInfoLoading
- }
- // ============================================
- }
|