Main.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. // ========== 启动时序控制 ==========
  11. property int startupPhase: 0
  12. property bool startupComplete: false
  13. property bool themeReady: false
  14. property bool contentReady: false // 所有Loader加载完成后才为true
  15. // ========== 主题相关 ==========
  16. property string theme_md: "day"
  17. property string theme_select: "day"
  18. property color theme_backgroundColor: theme_select === "day" ? "#d8d8d8" : "#1a1a1a"
  19. property color cardColor: theme_select === "day" ? "#f5f5f5" : "#2b2b2b"
  20. property color fontColor: theme_select === "day" ? "#333333" : "#e0e0e0"
  21. // 初始为黑色,等启动完成后再切换到主题颜色
  22. color: startupComplete ? theme_backgroundColor : "#000000"
  23. property string boardversionText: ""
  24. property string appversionText: ""
  25. property int logoutcnt
  26. property bool log_enable: false
  27. property bool stitch_enable: false
  28. property bool photoclarity: false
  29. signal logoutClicked
  30. signal tmChange(string md)
  31. signal stitchEnable(bool sw)
  32. // ========== 主题初始化(最早执行) ==========
  33. onInitTheme: {
  34. console.log("onInitTheme")
  35. // 1. 先读取保存的主题,再设置任何颜色
  36. var savedMode = "day"
  37. try {
  38. savedMode = settings.getValue("theme_mode")
  39. if (savedMode === undefined || savedMode === "" || savedMode === null) {
  40. savedMode = "day"
  41. settings.setValue("theme_mode", "day")
  42. }
  43. } catch(e) {
  44. savedMode = "day"
  45. }
  46. app.theme_md = savedMode
  47. if (savedMode !== "auto") {
  48. app.theme_select = savedMode
  49. } else {
  50. var h = new Date().getHours()
  51. app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
  52. }
  53. // 2. 根据主题设置颜色(此时颜色属性会自动更新)
  54. // 无需手动赋值,绑定表达式会自动计算
  55. // 3. 设置Felgo主题
  56. Theme.platform = "ios"
  57. // TabBar样式
  58. Theme.navigationTabBar.titlePressedColor = "green"
  59. Theme.navigationTabBar.backgroundColor = app.cardColor
  60. Theme.navigationTabBar.titleColor = app.fontColor
  61. // NavigationBar样式
  62. Theme.navigationBar.backgroundColor = app.cardColor
  63. Theme.navigationBar.titleColor = app.fontColor
  64. if (!Theme.navigationBar.height) {
  65. Theme.navigationBar.height = dp(56)
  66. }
  67. if (!Theme.statusBarHeight) {
  68. Theme.statusBarHeight = dp(24)
  69. }
  70. // 4. 标记主题就绪
  71. themeReady = true
  72. startupPhase = 1
  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. if (navigationLoader.item) navigationLoader.item.currentIndex = 0
  84. }
  85. // business logic}
  86. Logic {
  87. id: logic
  88. }
  89. // model
  90. DataModel {
  91. id: dataModel
  92. dispatcher: logic // data model handles actions sent by logic
  93. }
  94. // ========== 启动遮罩层(必须最先声明,确保第一帧就覆盖) ==========
  95. Rectangle {
  96. id: splashMask
  97. anchors.fill: parent
  98. color: "#000000"
  99. z: 9999
  100. opacity: 1
  101. visible: opacity > 0
  102. SequentialAnimation on opacity {
  103. running: false
  104. NumberAnimation { to: 0; duration: 800 }
  105. PropertyAction { value: 0; target: splashMask; property: "visible" }
  106. }
  107. }
  108. // ========== 导航(主题就绪后才加载,防止ARM32花屏) ==========
  109. // 放在splashMask之下,z值低于遮罩,确保加载完之前完全不可见
  110. Loader {
  111. id: navigationLoader
  112. anchors.fill: parent
  113. z: 1
  114. active: themeReady
  115. asynchronous: false
  116. onLoaded: checkContentReady()
  117. sourceComponent: Navigation {
  118. objectName: "Navigation_main"
  119. id: navigation
  120. navigationMode: Theme.isAndroid ? navigationModeTabs : navigationModeDefault
  121. drawerLogoBackgroundColor: app.cardColor
  122. Component.onCompleted: {
  123. navigation.currentIndex = 1
  124. console.log("Navigation completed")
  125. }
  126. function setCurrentTab(index){
  127. navigation.currentIndex = index
  128. }
  129. NavigationItem {
  130. id: uiComponentsItem
  131. title: "主界面"
  132. iconType: IconType.home
  133. Loader{
  134. asynchronous: true
  135. source: "pages/HomePage.qml"
  136. }
  137. }
  138. NavigationItem {
  139. title: "测试维护"
  140. iconType: IconType.gears
  141. objectName: "autofocus_Item"
  142. TestPage {
  143. }
  144. }
  145. NavigationItem {
  146. title: qsTr("图像查看")
  147. iconType: IconType.qrcode
  148. NavigationStack {
  149. PhotostitcherPage {
  150. onVisibleChanged: {
  151. if(visible){
  152. console.log("进入图像查看界面,开始初始化加载...")
  153. loadRootDirectory()
  154. }
  155. }
  156. }
  157. }
  158. }
  159. NavigationItem {
  160. objectName: "systemset_Item"
  161. title: qsTr("系统设置")
  162. iconType: IconType.gears
  163. NavigationStack {
  164. initialPage: ProfilePage {
  165. id: page_sys
  166. function onThemChange(mode) {
  167. app.theme_select = mode
  168. app.theme_md = mode
  169. Theme.navigationTabBar.backgroundColor= app.cardColor
  170. Theme.navigationTabBar.titleColor = app.fontColor
  171. Theme.navigationTabBar.dividerColor = "green"
  172. console.log("配置主题模式:",app.theme_select)
  173. }
  174. onLogoutClicked: {
  175. app.logoutClicked()
  176. serial.setLightness(-255)
  177. }
  178. }
  179. }
  180. }
  181. tabPosition: Navigation.Left
  182. }
  183. }
  184. // ========== 启动完成检测定时器 ==========
  185. // 延迟足够长时间,确保所有组件都渲染完成
  186. Timer {
  187. id: startupCompleteTimer
  188. interval: 2000
  189. running: false
  190. repeat: false
  191. onTriggered: {
  192. // 内容加载完成后才允许淡出遮罩
  193. if (contentReady) {
  194. app.startupComplete = true
  195. app.startupPhase = 4
  196. dismissSplashMask()
  197. console.log("Startup complete, dismissing splash mask")
  198. } else {
  199. // 内容还没加载完,重启定时器继续等待
  200. console.log("Content not ready, waiting...")
  201. startupCompleteTimer.restart()
  202. }
  203. }
  204. }
  205. // 检查所有Loader是否加载完成
  206. function checkContentReady() {
  207. if (navigationLoader.status === Loader.Ready &&
  208. loginPageLoader.status === Loader.Ready) {
  209. contentReady = true
  210. console.log("All content loaded")
  211. // 如果定时器已经在跑,说明2秒已到,直接触发遮罩淡出
  212. if (startupCompleteTimer.running) {
  213. startupCompleteTimer.stop()
  214. app.startupComplete = true
  215. app.startupPhase = 4
  216. dismissSplashMask()
  217. console.log("Content ready + timer fired, dismissing splash mask")
  218. }
  219. }
  220. }
  221. // 显式淡出遮罩(避免Behavior时序竞争)
  222. function dismissSplashMask() {
  223. splashMask.opacity = 0
  224. }
  225. // ========== 业务定时器 ==========
  226. Timer{
  227. interval: 1000
  228. running: startupComplete
  229. repeat: true
  230. onTriggered: {
  231. if(loginPageLoader.item && navigationLoader.item && navigationLoader.item.currentIndex === 0 && loginPageLoader.item.logintimeout % 5 === 0){
  232. serial.readBoardData()
  233. }
  234. if(loginPageLoader.item) {
  235. loginPageLoader.item.logintimeout--
  236. }
  237. ProfilePage.boardversion = "123"
  238. console.log("休眠计数:", loginPageLoader.item ? loginPageLoader.item.logintimeout : 0)
  239. if(loginPageLoader.item && loginPageLoader.item.logintimeout === 0){
  240. loginPageLoader.item.logintimeout = 300
  241. logoutClicked()
  242. serial.setLightness(-255)
  243. }
  244. }
  245. }
  246. Connections{
  247. target: curl
  248. function onDownloadFinished(result) {
  249. if(result && navigationLoader.item){
  250. navigationLoader.item.setCurrentTab(1)
  251. }
  252. }
  253. }
  254. // ========== 通知页(主题就绪后才加载) ==========
  255. Loader {
  256. id: notificationPageLoader
  257. active: themeReady
  258. asynchronous: false
  259. sourceComponent: LocalNotificationPage {
  260. id: notificationPage
  261. visible: false
  262. Component.onCompleted: {
  263. console.log("LocalNotificationPage Component.onCompleted...")
  264. }
  265. }
  266. }
  267. // ========== 启动流程控制 ==========
  268. Component.onCompleted: {
  269. console.log("App Component.onCompleted, starting startup timer...")
  270. // 延迟2秒后认为启动完成,给ARM32平台足够的渲染时间
  271. startupCompleteTimer.start()
  272. }
  273. // ========== 登录页(主题就绪后才加载,防止ARM32花屏) ==========
  274. Loader {
  275. id: loginPageLoader
  276. anchors.fill: parent
  277. z: 2
  278. active: themeReady
  279. asynchronous: false
  280. onLoaded: checkContentReady()
  281. sourceComponent: LoginPage {
  282. title: "植物病菌孢子捕捉分析系统"
  283. Connections{
  284. target: serial
  285. }
  286. visible: !dataModel.userLoggedIn
  287. enabled: !dataModel.userLoggedIn
  288. }
  289. }
  290. }