Main.qml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import QtQuick
  2. import Felgo 4.0
  3. import "pages"
  4. import "common"
  5. import "logic"
  6. import "model"
  7. App {
  8. id: app
  9. licenseKey: "6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C6B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397"
  10. property bool themeReady: false
  11. // ========== 主题相关 ==========
  12. property string theme_md: "day"
  13. property string theme_select: "day"
  14. property color theme_backgroundColor: theme_select === "day" ? "#d8d8d8" : "#1a1a1a"
  15. property color cardColor: theme_select === "day" ? "#f5f5f5" : "#2b2b2b"
  16. property color fontColor: theme_select === "day" ? "#333333" : "#e0e0e0"
  17. // 初始为纯黑色,强制设置为不透明,防止花屏
  18. color: "#000000"
  19. property string boardversionText: ""
  20. property string appversionText: ""
  21. property int logoutcnt
  22. signal logoutClicked
  23. signal tmChange(string md)
  24. // ========== 主题初始化(最早执行) ==========
  25. onInitTheme: {
  26. console.log("onInitTheme")
  27. // 1. 先读取保存的主题,再设置任何颜色
  28. var savedMode = "day"
  29. try {
  30. savedMode = settings.getValue("theme_mode")
  31. if (savedMode === undefined || savedMode === "" || savedMode === null) {
  32. savedMode = "day"
  33. settings.setValue("theme_mode", "day")
  34. }
  35. } catch(e) {
  36. savedMode = "day"
  37. }
  38. app.theme_md = savedMode
  39. if (savedMode !== "auto") {
  40. app.theme_select = savedMode
  41. } else {
  42. var h = new Date().getHours()
  43. app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
  44. }
  45. // 2. 根据主题设置颜色(此时颜色属性会自动更新)
  46. // 无需手动赋值,绑定表达式会自动计算
  47. // 3. 设置Felgo主题
  48. Theme.platform = "ios"
  49. // TabBar样式
  50. Theme.navigationTabBar.titlePressedColor = "green"
  51. Theme.navigationTabBar.backgroundColor = app.cardColor
  52. Theme.navigationTabBar.titleColor = app.fontColor
  53. // NavigationBar样式
  54. Theme.navigationBar.backgroundColor = app.cardColor
  55. Theme.navigationBar.titleColor = app.fontColor
  56. if (!Theme.navigationBar.height) {
  57. Theme.navigationBar.height = dp(56)
  58. }
  59. if (!Theme.statusBarHeight) {
  60. Theme.statusBarHeight = dp(24)
  61. }
  62. // 4. 标记主题就绪
  63. themeReady = true
  64. }
  65. // 新增一个函数来接收 HomePage 发送的文本
  66. function bvReceived(datbv){
  67. boardversionText = datbv
  68. }
  69. function appReceived(datbv){
  70. appversionText = datbv
  71. }
  72. onLogoutClicked: {
  73. logic.logout()
  74. // jump to main page after logout
  75. navigation.currentIndex = 0
  76. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  77. }
  78. //business logic}
  79. Logic {
  80. id: logic
  81. }
  82. // model
  83. DataModel {
  84. id: dataModel
  85. dispatcher: logic // data model handles actions sent by logic
  86. }
  87. // view
  88. Navigation {
  89. objectName: "Navigation_main"
  90. id: navigation
  91. enabled: themeReady
  92. navigationMode: Theme.isAndroid ? navigationModeTabs : navigationModeDefault
  93. drawerLogoBackgroundColor: "red"
  94. opacity: themeReady ? 1.0 : 0.0
  95. Behavior on opacity { NumberAnimation { duration: 200 } }
  96. Component.onCompleted: {
  97. console.log("Navigation Component.onCompleted")
  98. initializeNavigation()
  99. }
  100. function initializeNavigation() {
  101. console.log("Initializing navigation...")
  102. for(var i = 0;i < navigation.count; i++){
  103. navigation.currentIndex = i
  104. }
  105. navigation.currentIndex = 0
  106. }
  107. function setCurrentTab(index){
  108. navigation.currentIndex = index
  109. }
  110. // only enable if user is logged in
  111. // login page below overlays navigation then
  112. // first tab
  113. NavigationItem {
  114. id: uiComponentsItem
  115. title: "主界面"
  116. iconType: IconType.home
  117. Loader{
  118. asynchronous: true
  119. active: true
  120. source: "pages/HomePage.qml"
  121. }
  122. }
  123. NavigationItem {
  124. title: "测试维护"
  125. iconType: IconType.gears
  126. objectName: "autofocus_Item"
  127. TestPage {
  128. //id: autofocus_id
  129. }
  130. }
  131. // second tab
  132. NavigationItem {
  133. title: qsTr("图像查看") // use qsTr for strings you want to translate
  134. iconType: IconType.qrcode
  135. NavigationStack {
  136. PhotostitcherPage {
  137. onVisibleChanged: {
  138. if(visible){
  139. console.log("进入图像查看界面,开始初始化加载...")
  140. loadRootDirectory()
  141. }
  142. }
  143. }
  144. }
  145. }
  146. // fourth tab
  147. NavigationItem {
  148. objectName: "systemset_Item"
  149. title: qsTr("系统设置") // use qsTr for strings you want to translate
  150. iconType: IconType.gears
  151. NavigationStack {
  152. initialPage: ProfilePage {
  153. id: page_sys
  154. function onThemChange(mode) {
  155. app.theme_select = mode
  156. app.theme_md = mode
  157. Theme.navigationTabBar.backgroundColor= app.cardColor
  158. Theme.navigationTabBar.titleColor = app.fontColor
  159. Theme.navigationTabBar.dividerColor = "green"
  160. console.log("配置主题模式:",app.theme_select)
  161. }
  162. // handle logout
  163. onLogoutClicked: {
  164. //loginpage.pushed()
  165. logic.logout()
  166. // jump to main page after logout
  167. navigation.currentIndex = 0
  168. serial.setLightness(-255)
  169. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  170. }
  171. }
  172. }
  173. }
  174. tabPosition: Navigation.Left
  175. }
  176. // ========== 业务定时器 ==========
  177. Timer{
  178. interval: 1000
  179. running: true
  180. repeat: true
  181. onTriggered: {
  182. if(navigation.currentIndex === 0&&loginpage.logintimeout%5===0){
  183. serial.readBoardData()
  184. }
  185. loginpage.logintimeout--
  186. ProfilePage.boardversion = "123"
  187. console.log("休眠计数:",loginpage.logintimeout)
  188. if(loginpage.logintimeout===0){ //?秒后进入休眠
  189. loginpage.logintimeout = 300
  190. logoutClicked()
  191. //关闭屏幕(亮度设置为0)
  192. serial.setLightness(-255)
  193. }
  194. }
  195. }
  196. Connections{
  197. target: curl
  198. function onDownloadFinished(result) {
  199. if(result && navigationLoader.item){
  200. navigationLoader.item.setCurrentTab(1)
  201. }
  202. }
  203. }
  204. Component.onCompleted: {
  205. console.log("App Component.onCompleted, starting phased loading...")
  206. }
  207. // ========== 登录页(Phase2: 导航加载完成后才加载) ==========
  208. LoginPage {
  209. id: loginpage
  210. title: "植物病菌孢子捕捉分析系统"
  211. Connections{
  212. target: serial
  213. }
  214. visible: opacity > 0
  215. enabled: visible
  216. opacity: dataModel.userLoggedIn ? 0 : 1
  217. Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out
  218. }
  219. }