| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- import QtQuick
- import Felgo
- import QtQuick.Controls
- import "pages"
- import "common"
- import "logic"
- import "model"
- App {
- id: app
- licenseKey: "6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C6B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397"
- property bool themeReady: false
- // ========== 主题相关 ==========
- property string theme_md: "day"
- property string theme_select: "day"
- property color theme_backgroundColor: theme_select === "day" ? "#d8d8d8" : "#1a1a1a"
- property color cardColor: theme_select == "day" ? "#f5f5f5" :(theme_select == "night" ? "#2b2b2b":"#f5f5f5") //背景色 //前景色
- property color fontColor: theme_select == "day" ? "black" :(theme_select == "night" ? "white":"black")
- property bool floatPanel: false
- property bool showTxData: false
- property bool showRxData: false
- property bool showPubData: false
- property bool showSubData: false
- property string floatPanel_title: "串口数据"
- property string txDataLog: ""
- property string rxDataLog: ""
- // 初始为纯黑色,强制设置为不透明,防止花屏
- color: "#000000"
- property string boardversionText: ""
- property string appversionText: ""
- property bool tempProtectionState: false // 温度保护状态,true表示处于保护状态
- property int logoutcnt
- signal logoutClicked
- // ========== 主题初始化(最早执行) ==========
- onInitTheme: {
- console.log("onInitTheme")
- // 1. 先读取保存的主题,再设置任何颜色
- var savedMode = "day"
- try {
- savedMode = settings.getValue("theme_mode")
- if (savedMode === undefined || savedMode === "" || savedMode === null) {
- savedMode = "day"
- settings.setValue("theme_mode", "day")
- }
- } catch(e) {
- savedMode = "day"
- }
- app.theme_md = savedMode
- if (savedMode !== "auto") {
- app.theme_select = savedMode
- } else {
- var h = new Date().getHours()
- app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
- }
- // 2. 根据主题设置颜色(此时颜色属性会自动更新)
- // 无需手动赋值,绑定表达式会自动计算
- // 3. 设置Felgo主题
- Theme.platform = "ios"
- // TabBar样式
- Theme.navigationTabBar.titlePressedColor = "green"
- Theme.navigationTabBar.backgroundColor = app.cardColor
- Theme.navigationTabBar.titleColor = app.fontColor
- // NavigationBar样式
- Theme.navigationBar.backgroundColor = app.cardColor
- Theme.navigationBar.titleColor = app.fontColor
- if (!Theme.navigationBar.height) {
- Theme.navigationBar.height = dp(56)
- }
- if (!Theme.statusBarHeight) {
- Theme.statusBarHeight = dp(24)
- }
- // 4. 标记主题就绪
- themeReady = true
- }
- // 新增一个函数来接收 HomePage 发送的文本
- function bvReceived(datbv){
- boardversionText = datbv
- }
- function appReceived(datbv){
- appversionText = datbv
- }
- onLogoutClicked: {
- logic.logout()
- // jump to main page after logout
- navigation.currentIndex = 0
- //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
- }
- //business logic}
- Logic {
- id: logic
- }
- // model
- DataModel {
- id: dataModel
- dispatcher: logic // data model handles actions sent by logic
- }
- // view
- Navigation {
- objectName: "Navigation_main"
- id: navigation
- enabled: themeReady
- navigationMode: Theme.isAndroid ? navigationModeTabs : navigationModeDefault
- drawerLogoBackgroundColor: "red"
- opacity: themeReady ? 1.0 : 0.0
- Behavior on opacity { NumberAnimation { duration: 200 } }
- Component.onCompleted: {
- console.log("Navigation Component.onCompleted")
- initializeNavigation()
- }
- function initializeNavigation() {
- console.log("Initializing navigation...")
- for(var i = 0;i < navigation.count; i++){
- navigation.currentIndex = i
- }
- navigation.currentIndex = 0
- }
- function setCurrentTab(index){
- navigation.currentIndex = index
- }
- // only enable if user is logged in
- // login page below overlays navigation then
- // first tab
- NavigationItem {
- id: uiComponentsItem
- title: "主界面"
- iconType: IconType.home
- Loader{
- asynchronous: true
- active: true
- source: "pages/HomePage.qml"
- }
- }
- NavigationItem {
- title: "测试维护"
- iconType: IconType.gears
- objectName: "autofocus_Item"
- TestPage {
- //id: autofocus_id
- }
- }
- // second tab
- NavigationItem {
- title: qsTr("图像查看") // use qsTr for strings you want to translate
- iconType: IconType.qrcode
- NavigationStack {
- PhotostitcherPage {
- onVisibleChanged: {
- if(visible){
- console.log("进入图像查看界面,开始初始化加载...")
- loadRootDirectory()
- }
- }
- }
- }
- }
- // fourth tab
- NavigationItem {
- objectName: "systemset_Item"
- title: qsTr("系统设置") // use qsTr for strings you want to translate
- iconType: IconType.gears
- NavigationStack {
- initialPage: ProfilePage {
- id: page_sys
- onThemChange: function(mode) { console.log("配置主题模式:",mode)
- app.theme_md = mode
- if (mode !== "auto") {
- app.theme_select = mode
- } else {
- var h = new Date().getHours()
- app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
- }
- app.theme_select = mode
- app.theme_md = mode
- Theme.navigationTabBar.backgroundColor= app.cardColor
- Theme.navigationTabBar.titleColor = app.fontColor
- Theme.navigationTabBar.dividerColor = "green"
- console.log("主题已更新:",app.theme_select)
- }
- // handle logout
- onLogoutClicked: {
- //loginpage.pushed()
- logic.logout()
- // jump to main page after logout
- navigation.currentIndex = 0
- serial.setLightness(-255)
- //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
- }
- }
- }
- }
- tabPosition: Navigation.Left
- }
- // ========== 业务定时器 ==========
- Timer{
- interval: 1000
- running: true
- repeat: true
- onTriggered: {
- if(navigation.currentIndex === 0&&loginpage.logintimeout%5===0){
- serial.readBoardData()
- }
- loginpage.logintimeout--
- ProfilePage.boardversion = "123"
- console.log("休眠计数:",loginpage.logintimeout)
- if(loginpage.logintimeout===0){ //?秒后进入休眠
- loginpage.logintimeout = 300
- logoutClicked()
- //关闭屏幕(亮度设置为0)
- serial.setLightness(-255)
- }
- }
- }
- Connections{
- target: curl
- function onDownloadFinished(result) {
- if(result){
- navigation.setCurrentTab(1)
- }
- }
- }
- // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 跳转相机界面(Tab 1 测试维护)
- Connections {
- target: mqtt
- function onSignal_open_camera() {
- console.log("[Main] 收到远程相机开启指令,跳转相机界面!")
- navigation.setCurrentTab(1)
- }
- }
- Component.onCompleted: {
- console.log("App Component.onCompleted, starting phased loading...")
- }
- LocalNotificationPage {
- id: notificationPage
- visible:false
- }
- // ========== 登录页(Phase2: 导航加载完成后才加载) ==========
- LoginPage {
- id: loginpage
- title: "植物病菌孢子捕捉分析系统"
- Connections{
- target: serial
- }
- visible: opacity > 0
- enabled: visible
- opacity: dataModel.userLoggedIn ? 0 : 1
- Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out
- }
- Rectangle {
- id: rxFloatingWindow
- visible: floatPanel
- width: 400
- height: 300
- x: parent.width - 420
- y: 20
- color: "white"
- opacity: 0.8 // 50% 透明度
- radius: 10
- z: 9999
- Column {
- anchors.fill: parent
- anchors.margins: 10
- spacing: 5
- Row {
- width: parent.width
- spacing: 10
- AppText {
- text: floatPanel_title
- color: "#00ffff"
- fontSize: 16
- font.bold: true
- anchors.verticalCenter: appbutton_clear.verticalCenter
- }
- AppButton {
- id: appbutton_clear
- text: "清空"
- textColor: "white"
- backgroundColor: "#ff4444"
- flat: false
- onClicked: {
- rxDataLog = ""
- txDataLog = ""
- }
- }
- // AppButton {
- // text: "X"
- // textColor: "white"
- // backgroundColor: "#ff4444"
- // flat: false
- // onClicked: {
- // rxSwitch.checked = false
- // }
- // }
- }
- Flickable {
- width: parent.width
- height: parent.height - 40
- contentWidth: width
- contentHeight: txt_logdata.implicitHeight
- clip: true
- AppText {
- id: txt_logdata
- width: parent.width
- text: (showRxData ? rxDataLog : (showTxData ? txDataLog : "")) || (showSubData ? rxDataLog : (showPubData ? txDataLog : ""))
- color: "green"
- fontSize: 12
- wrapMode: Text.WrapAtWordBoundaryOrAnywhere
- }
- }
- }
- // 拖拽功能
- MouseArea {
- anchors.fill: parent
- drag.target: rxFloatingWindow
- drag.axis: Drag.XAndYAxis
- }
- }
- }
|