Main.qml 8.3 KB

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