Main.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. import QtQuick
  2. import Felgo
  3. import QtQuick.Controls
  4. import "pages"
  5. import "common"
  6. import "logic"
  7. import "model"
  8. App {
  9. id: app
  10. licenseKey: "6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C6B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397"
  11. property bool themeReady: false
  12. // ========== 主题相关 ==========
  13. property string theme_md: "day"
  14. property string theme_select: "day"
  15. property color theme_backgroundColor: theme_select === "day" ? "#d8d8d8" : "#1a1a1a"
  16. property color cardColor: theme_select == "day" ? "#f5f5f5" :(theme_select == "night" ? "#2b2b2b":"#f5f5f5") //背景色 //前景色
  17. property color fontColor: theme_select == "day" ? "black" :(theme_select == "night" ? "white":"black")
  18. property bool floatPanel: false
  19. property bool showTxData: false
  20. property bool showRxData: false
  21. property bool showPubData: false
  22. property bool showSubData: false
  23. property string floatPanel_title: "串口数据"
  24. property string txDataLog: ""
  25. property string rxDataLog: ""
  26. // 初始为纯黑色,强制设置为不透明,防止花屏
  27. color: "#000000"
  28. property string boardversionText: ""
  29. property string appversionText: ""
  30. property bool tempProtectionState: false // 温度保护状态,true表示处于保护状态
  31. property int logoutcnt
  32. signal logoutClicked
  33. // ========== 主题初始化(最早执行) ==========
  34. onInitTheme: {
  35. console.log("onInitTheme")
  36. // 1. 先读取保存的主题,再设置任何颜色
  37. var savedMode = "day"
  38. try {
  39. savedMode = settings.getValue("theme_mode")
  40. if (savedMode === undefined || savedMode === "" || savedMode === null) {
  41. savedMode = "day"
  42. settings.setValue("theme_mode", "day")
  43. }
  44. } catch(e) {
  45. savedMode = "day"
  46. }
  47. app.theme_md = savedMode
  48. if (savedMode !== "auto") {
  49. app.theme_select = savedMode
  50. } else {
  51. var h = new Date().getHours()
  52. app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
  53. }
  54. // 2. 根据主题设置颜色(此时颜色属性会自动更新)
  55. // 无需手动赋值,绑定表达式会自动计算
  56. // 3. 设置Felgo主题
  57. Theme.platform = "ios"
  58. // TabBar样式
  59. Theme.navigationTabBar.titlePressedColor = "green"
  60. Theme.navigationTabBar.backgroundColor = app.cardColor
  61. Theme.navigationTabBar.titleColor = app.fontColor
  62. // NavigationBar样式
  63. Theme.navigationBar.backgroundColor = app.cardColor
  64. Theme.navigationBar.titleColor = app.fontColor
  65. if (!Theme.navigationBar.height) {
  66. Theme.navigationBar.height = dp(56)
  67. }
  68. if (!Theme.statusBarHeight) {
  69. Theme.statusBarHeight = dp(24)
  70. }
  71. // 4. 标记主题就绪
  72. themeReady = true
  73. }
  74. // 新增一个函数来接收 HomePage 发送的文本
  75. function bvReceived(datbv){
  76. boardversionText = datbv
  77. }
  78. function appReceived(datbv){
  79. appversionText = datbv
  80. }
  81. onLogoutClicked: {
  82. logic.logout()
  83. // jump to main page after logout
  84. navigation.currentIndex = 0
  85. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  86. }
  87. //business logic}
  88. Logic {
  89. id: logic
  90. }
  91. // model
  92. DataModel {
  93. id: dataModel
  94. dispatcher: logic // data model handles actions sent by logic
  95. }
  96. // view
  97. Navigation {
  98. objectName: "Navigation_main"
  99. id: navigation
  100. enabled: themeReady
  101. navigationMode: Theme.isAndroid ? navigationModeTabs : navigationModeDefault
  102. drawerLogoBackgroundColor: "red"
  103. opacity: themeReady ? 1.0 : 0.0
  104. Behavior on opacity { NumberAnimation { duration: 200 } }
  105. Component.onCompleted: {
  106. console.log("Navigation Component.onCompleted")
  107. initializeNavigation()
  108. }
  109. function initializeNavigation() {
  110. console.log("Initializing navigation...")
  111. for(var i = 0;i < navigation.count; i++){
  112. navigation.currentIndex = i
  113. }
  114. navigation.currentIndex = 0
  115. }
  116. function setCurrentTab(index){
  117. navigation.currentIndex = index
  118. }
  119. // only enable if user is logged in
  120. // login page below overlays navigation then
  121. // first tab
  122. NavigationItem {
  123. id: uiComponentsItem
  124. title: "主界面"
  125. iconType: IconType.home
  126. Loader{
  127. asynchronous: true
  128. active: true
  129. source: "pages/HomePage.qml"
  130. }
  131. }
  132. NavigationItem {
  133. title: "测试维护"
  134. iconType: IconType.gears
  135. objectName: "autofocus_Item"
  136. TestPage {
  137. //id: autofocus_id
  138. }
  139. }
  140. // second tab
  141. NavigationItem {
  142. title: qsTr("图像查看") // use qsTr for strings you want to translate
  143. iconType: IconType.qrcode
  144. NavigationStack {
  145. PhotostitcherPage {
  146. onVisibleChanged: {
  147. if(visible){
  148. console.log("进入图像查看界面,开始初始化加载...")
  149. loadRootDirectory()
  150. }
  151. }
  152. }
  153. }
  154. }
  155. // fourth tab
  156. NavigationItem {
  157. objectName: "systemset_Item"
  158. title: qsTr("系统设置") // use qsTr for strings you want to translate
  159. iconType: IconType.gears
  160. NavigationStack {
  161. initialPage: ProfilePage {
  162. id: page_sys
  163. onThemChange: function(mode) { console.log("配置主题模式:",mode)
  164. app.theme_md = mode
  165. if (mode !== "auto") {
  166. app.theme_select = mode
  167. } else {
  168. var h = new Date().getHours()
  169. app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
  170. }
  171. app.theme_select = mode
  172. app.theme_md = mode
  173. Theme.navigationTabBar.backgroundColor= app.cardColor
  174. Theme.navigationTabBar.titleColor = app.fontColor
  175. Theme.navigationTabBar.dividerColor = "green"
  176. console.log("主题已更新:",app.theme_select)
  177. }
  178. // handle logout
  179. onLogoutClicked: {
  180. //loginpage.pushed()
  181. logic.logout()
  182. // jump to main page after logout
  183. navigation.currentIndex = 0
  184. serial.setLightness(-255)
  185. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  186. }
  187. }
  188. }
  189. }
  190. tabPosition: Navigation.Left
  191. }
  192. // ========== 业务定时器 ==========
  193. Timer{
  194. interval: 1000
  195. running: true
  196. repeat: true
  197. onTriggered: {
  198. if(navigation.currentIndex === 0&&loginpage.logintimeout%5===0){
  199. serial.readBoardData()
  200. }
  201. loginpage.logintimeout--
  202. ProfilePage.boardversion = "123"
  203. console.log("休眠计数:",loginpage.logintimeout)
  204. if(loginpage.logintimeout===0){ //?秒后进入休眠
  205. loginpage.logintimeout = 300
  206. logoutClicked()
  207. //关闭屏幕(亮度设置为0)
  208. serial.setLightness(-255)
  209. }
  210. }
  211. }
  212. Connections{
  213. target: curl
  214. function onDownloadFinished(result) {
  215. if(result){
  216. navigation.setCurrentTab(1)
  217. }
  218. }
  219. }
  220. // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 跳转相机界面(Tab 1 测试维护)
  221. Connections {
  222. target: mqtt
  223. function onSignal_open_camera() {
  224. console.log("[Main] 收到远程相机开启指令,跳转相机界面!")
  225. navigation.setCurrentTab(1)
  226. }
  227. }
  228. Component.onCompleted: {
  229. console.log("App Component.onCompleted, starting phased loading...")
  230. }
  231. LocalNotificationPage {
  232. id: notificationPage
  233. visible:false
  234. }
  235. // ========== 登录页(Phase2: 导航加载完成后才加载) ==========
  236. LoginPage {
  237. id: loginpage
  238. title: "植物病菌孢子捕捉分析系统"
  239. Connections{
  240. target: serial
  241. }
  242. visible: opacity > 0
  243. enabled: visible
  244. opacity: dataModel.userLoggedIn ? 0 : 1
  245. Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out
  246. }
  247. Rectangle {
  248. id: rxFloatingWindow
  249. visible: floatPanel
  250. width: 400
  251. height: 300
  252. x: parent.width - 420
  253. y: 20
  254. color: "white"
  255. opacity: 0.8 // 50% 透明度
  256. radius: 10
  257. z: 9999
  258. Column {
  259. anchors.fill: parent
  260. anchors.margins: 10
  261. spacing: 5
  262. Row {
  263. width: parent.width
  264. spacing: 10
  265. AppText {
  266. text: floatPanel_title
  267. color: "#00ffff"
  268. fontSize: 16
  269. font.bold: true
  270. anchors.verticalCenter: appbutton_clear.verticalCenter
  271. }
  272. AppButton {
  273. id: appbutton_clear
  274. text: "清空"
  275. textColor: "white"
  276. backgroundColor: "#ff4444"
  277. flat: false
  278. onClicked: {
  279. rxDataLog = ""
  280. txDataLog = ""
  281. }
  282. }
  283. // AppButton {
  284. // text: "X"
  285. // textColor: "white"
  286. // backgroundColor: "#ff4444"
  287. // flat: false
  288. // onClicked: {
  289. // rxSwitch.checked = false
  290. // }
  291. // }
  292. }
  293. Flickable {
  294. width: parent.width
  295. height: parent.height - 40
  296. contentWidth: width
  297. contentHeight: txt_logdata.implicitHeight
  298. clip: true
  299. AppText {
  300. id: txt_logdata
  301. width: parent.width
  302. text: (showRxData ? rxDataLog : (showTxData ? txDataLog : "")) || (showSubData ? rxDataLog : (showPubData ? txDataLog : ""))
  303. color: "green"
  304. fontSize: 12
  305. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  306. }
  307. }
  308. }
  309. // 拖拽功能
  310. MouseArea {
  311. anchors.fill: parent
  312. drag.target: rxFloatingWindow
  313. drag.axis: Drag.XAndYAxis
  314. }
  315. }
  316. }