Main.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. // ========== 全志A133P启动时序控制(增强版)==========
  11. property int startupPhase: 0
  12. property bool startupComplete: false
  13. property bool themeReady: false
  14. property bool navigationReady: false
  15. property bool loginReady: false
  16. property bool heavyPagesReady: false
  17. property int cleanFrameCount: 0
  18. property bool renderReady: false // 渲染就绪标志
  19. property bool windowReady: false // 窗口就绪标志
  20. property int frameCounter: 0 // 帧计数器
  21. // ========== 主题相关 ==========
  22. property string theme_md: "day"
  23. property string theme_select: "day"
  24. property color theme_backgroundColor: theme_select === "day" ? "#d8d8d8" : "#1a1a1a"
  25. property color cardColor: theme_select === "day" ? "#f5f5f5" : "#2b2b2b"
  26. property color fontColor: theme_select === "day" ? "#333333" : "#e0e0e0"
  27. // 初始为纯黑色,强制设置为不透明,防止花屏
  28. color: "#000000"
  29. // ========== 全志A133P花屏修复:使用双层遮罩 ==========
  30. // 第一层:硬件级黑色背景
  31. Rectangle {
  32. id: hardwareMask
  33. anchors.fill: parent
  34. color: "#000000"
  35. z: 9998
  36. visible: true // 始终保持可见作为后备
  37. opacity: renderReady ? 0.0 : 1.0
  38. Behavior on opacity { NumberAnimation { duration: 300 } }
  39. }
  40. // 第二层:应用级遮罩
  41. Rectangle {
  42. id: startupMask
  43. anchors.fill: parent
  44. color: "#000000"
  45. z: 9999 // 最高层级
  46. visible: !renderReady
  47. // 渲染就绪后延迟消失,确保画面稳定
  48. Behavior on opacity {
  49. NumberAnimation {
  50. duration: 500
  51. easing.type: Easing.InOutQuad
  52. }
  53. }
  54. }
  55. property string boardversionText: ""
  56. property string appversionText: ""
  57. property int logoutcnt
  58. property bool log_enable: false
  59. property bool stitch_enable: false
  60. property bool photoclarity: false
  61. signal logoutClicked
  62. signal tmChange(string md)
  63. signal stitchEnable(bool sw)
  64. // ========== 主题初始化(最早执行) ==========
  65. onInitTheme: {
  66. console.log("onInitTheme")
  67. // 1. 先读取保存的主题,再设置任何颜色
  68. var savedMode = "day"
  69. try {
  70. savedMode = settings.getValue("theme_mode")
  71. if (savedMode === undefined || savedMode === "" || savedMode === null) {
  72. savedMode = "day"
  73. settings.setValue("theme_mode", "day")
  74. }
  75. } catch(e) {
  76. savedMode = "day"
  77. }
  78. app.theme_md = savedMode
  79. if (savedMode !== "auto") {
  80. app.theme_select = savedMode
  81. } else {
  82. var h = new Date().getHours()
  83. app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
  84. }
  85. // 2. 根据主题设置颜色(此时颜色属性会自动更新)
  86. // 无需手动赋值,绑定表达式会自动计算
  87. // 3. 设置Felgo主题
  88. Theme.platform = "ios"
  89. // TabBar样式
  90. Theme.navigationTabBar.titlePressedColor = "green"
  91. Theme.navigationTabBar.backgroundColor = app.cardColor
  92. Theme.navigationTabBar.titleColor = app.fontColor
  93. // NavigationBar样式
  94. Theme.navigationBar.backgroundColor = app.cardColor
  95. Theme.navigationBar.titleColor = app.fontColor
  96. if (!Theme.navigationBar.height) {
  97. Theme.navigationBar.height = dp(56)
  98. }
  99. if (!Theme.statusBarHeight) {
  100. Theme.statusBarHeight = dp(24)
  101. }
  102. // 4. 标记主题就绪
  103. themeReady = true
  104. startupPhase = 1
  105. }
  106. // 新增一个函数来接收 HomePage 发送的文本
  107. function bvReceived(datbv){
  108. boardversionText = datbv
  109. }
  110. function appReceived(datbv){
  111. appversionText = datbv
  112. }
  113. onLogoutClicked: {
  114. logic.logout()
  115. // jump to main page after logout
  116. navigation.currentIndex = 0
  117. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  118. }
  119. //business logic}
  120. Logic {
  121. id: logic
  122. }
  123. // model
  124. DataModel {
  125. id: dataModel
  126. dispatcher: logic // data model handles actions sent by logic
  127. }
  128. // view
  129. Navigation {
  130. objectName: "Navigation_main"
  131. id: navigation
  132. enabled: themeReady && renderReady
  133. navigationMode: Theme.isAndroid ? navigationModeTabs : navigationModeDefault
  134. drawerLogoBackgroundColor: "red"
  135. opacity: renderReady ? 1.0 : 0.0
  136. Behavior on opacity { NumberAnimation { duration: 200 } }
  137. Component.onCompleted: {
  138. console.log("Navigation Component.onCompleted")
  139. if (renderReady) {
  140. initializeNavigation()
  141. } else {
  142. var initializeTimer = Qt.createQmlObject('import QtQuick; Timer { interval: 500; repeat: false }', app)
  143. initializeTimer.triggered.connect(function() {
  144. if (renderReady) {
  145. initializeNavigation()
  146. initializeTimer.destroy()
  147. } else {
  148. initializeTimer.start()
  149. }
  150. })
  151. initializeTimer.start()
  152. }
  153. }
  154. function initializeNavigation() {
  155. console.log("Initializing navigation...")
  156. for(var i = 0;i < navigation.count; i++){
  157. navigation.currentIndex = i
  158. }
  159. navigation.currentIndex = 0
  160. navigationReady = true
  161. }
  162. function setCurrentTab(index){
  163. navigation.currentIndex = index
  164. }
  165. // only enable if user is logged in
  166. // login page below overlays navigation then
  167. // first tab
  168. NavigationItem {
  169. id: uiComponentsItem
  170. title: "主界面"
  171. iconType: IconType.home
  172. Loader{
  173. asynchronous: true
  174. active: renderReady
  175. source: "pages/HomePage.qml"
  176. }
  177. }
  178. NavigationItem {
  179. title: "测试维护"
  180. iconType: IconType.gears
  181. objectName: "autofocus_Item"
  182. TestPage {
  183. //id: autofocus_id
  184. }
  185. }
  186. // second tab
  187. NavigationItem {
  188. title: qsTr("图像查看") // use qsTr for strings you want to translate
  189. iconType: IconType.qrcode
  190. NavigationStack {
  191. PhotostitcherPage {
  192. onVisibleChanged: {
  193. if(visible){
  194. console.log("进入图像查看界面,开始初始化加载...")
  195. loadRootDirectory()
  196. }
  197. }
  198. }
  199. }
  200. }
  201. // fourth tab
  202. NavigationItem {
  203. objectName: "systemset_Item"
  204. title: qsTr("系统设置") // use qsTr for strings you want to translate
  205. iconType: IconType.gears
  206. NavigationStack {
  207. initialPage: ProfilePage {
  208. id: page_sys
  209. onThemChange: {
  210. app.theme_select = mode
  211. app.theme_md = mode
  212. Theme.navigationTabBar.backgroundColor= app.cardColor
  213. Theme.navigationTabBar.titleColor = app.fontColor
  214. Theme.navigationTabBar.dividerColor = "green"
  215. console.log("配置主题模式:",app.theme_select)
  216. }
  217. // handle logout
  218. onLogoutClicked: {
  219. //loginpage.pushed()
  220. logic.logout()
  221. // jump to main page after logout
  222. navigation.currentIndex = 0
  223. serial.setLightness(-255)
  224. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  225. }
  226. }
  227. }
  228. }
  229. tabPosition: Navigation.Left
  230. }
  231. // ========== 业务定时器 ==========
  232. Timer{
  233. interval: 1000
  234. running: true
  235. repeat: true
  236. onTriggered: {
  237. if(navigation.currentIndex === 0&&loginpage.logintimeout%5===0){
  238. serial.readBoardData()
  239. }
  240. loginpage.logintimeout--
  241. ProfilePage.boardversion = "123"
  242. console.log("休眠计数:",loginpage.logintimeout)
  243. if(loginpage.logintimeout===0){ //?秒后进入休眠
  244. loginpage.logintimeout = 300
  245. logoutClicked()
  246. //关闭屏幕(亮度设置为0)
  247. serial.setLightness(-255)
  248. }
  249. }
  250. }
  251. Connections{
  252. target: curl
  253. function onDownloadFinished(result) {
  254. if(result && navigationLoader.item){
  255. navigationLoader.item.setCurrentTab(1)
  256. }
  257. }
  258. }
  259. // ========== 通知页(Phase2后延迟加载,优先级最低) ==========
  260. // LocalNotificationPage {
  261. // id: notificationPage
  262. // visible: false
  263. // Component.onCompleted: {
  264. // console.log("LocalNotificationPage Component.onCompleted...")
  265. // }
  266. // }
  267. // ========== 全志A133P启动流程控制(增强版)==========
  268. Component.onCompleted: {
  269. console.log("App Component.onCompleted, starting phased loading...")
  270. windowReady = true
  271. // 启动渲染就绪检测
  272. renderCheckTimer.start()
  273. // 启动帧计数监控
  274. frameCounterTimer.start()
  275. }
  276. // ========== 全志A133P帧计数器(确保稳定渲染)==========
  277. Timer {
  278. id: frameCounterTimer
  279. interval: 16 // 约60fps
  280. repeat: true
  281. running: !renderReady
  282. onTriggered: {
  283. frameCounter++
  284. if (frameCounter % 60 === 0) {
  285. console.log("Frame count:", frameCounter)
  286. }
  287. }
  288. }
  289. // ========== 全志A133P渲染就绪检测定时器(增强版)==========
  290. Timer {
  291. id: renderCheckTimer
  292. interval: 100 // 每100ms检查一次
  293. repeat: true
  294. property int checkCount: 0
  295. onTriggered: {
  296. checkCount++
  297. console.log("Render check", checkCount, "Frame:", frameCounter)
  298. // 双重条件:1. 等待足够时间 2. 确保已渲染足够帧数
  299. if (checkCount >= 10 && frameCounter >= 10) { // 至少等待5秒和100帧
  300. renderReady = true
  301. console.log("Render ready, removing startup mask")
  302. renderCheckTimer.stop()
  303. frameCounterTimer.stop()
  304. // 延迟后切换到主题背景色
  305. Qt.callLater(function() {
  306. app.color = app.theme_backgroundColor
  307. })
  308. }
  309. }
  310. }
  311. // ========== 登录页(Phase2: 导航加载完成后才加载) ==========
  312. LoginPage {
  313. id: loginpage
  314. title: "植物病菌孢子捕捉分析系统"
  315. Connections{
  316. target: serial
  317. }
  318. visible: opacity > 0
  319. enabled: visible
  320. opacity: dataModel.userLoggedIn ? 0 : 1
  321. Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out
  322. }
  323. }