Main.qml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. color: "#000"
  10. property string theme_md: ""
  11. property string theme_select: "day"
  12. property color theme_backgroundColor: theme_select == "day" ? "#d8d8d8" :(theme_select == "night" ? "#00000":"#d8d8d8")
  13. property color cardColor: theme_select == "day" ? "#f5f5f5" :(theme_select == "night" ? "#2b2b2b":"#f5f5f5") //背景色 //前景色
  14. property color fontColor: theme_select == "day" ? "black" :(theme_select == "night" ? "white":"black")
  15. property string boardversionText: ""
  16. property string appversionText: ""
  17. property int logoutcnt
  18. signal logoutClicked
  19. signal tmChange(string md)
  20. onInitTheme: {
  21. Theme.platform = "ios"
  22. Theme.navigationTabBar.titlePressedColor= "green"
  23. Theme.navigationTabBar.backgroundColor= app.cardColor
  24. Theme.navigationTabBar.titleColor = app.fontColor
  25. }
  26. // 新增一个函数来接收 HomePage 发送的文本
  27. function bvReceived(datbv){
  28. boardversionText = datbv
  29. }
  30. function appReceived(datbv){
  31. appversionText = datbv
  32. }
  33. onLogoutClicked: {
  34. // loginpage.pushed()
  35. logic.logout()
  36. // jump to main page after logout
  37. navigation.currentIndex = 0
  38. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  39. }
  40. // business logic}
  41. Logic {
  42. id: logic
  43. }
  44. // model
  45. DataModel {
  46. id: dataModel
  47. dispatcher: logic // data model handles actions sent by logic
  48. }
  49. // view
  50. Navigation {
  51. objectName: "Navigation_main"
  52. id: navigation
  53. navigationMode: Theme.isAndroid ? navigationModeTabs : navigationModeDefault
  54. drawerLogoBackgroundColor: "red"
  55. Component.onCompleted: {
  56. for(var i = 0;i < navigation.count; i++){
  57. navigation.currentIndex = i
  58. }
  59. navigation.currentIndex = 0
  60. }
  61. function setCurrentTab(index){
  62. navigation.currentIndex = index
  63. }
  64. // only enable if user is logged in
  65. // login page below overlays navigation then
  66. // first tab
  67. NavigationItem {
  68. id: uiComponentsItem
  69. title: "主界面"
  70. iconType: IconType.home
  71. Loader{
  72. asynchronous: true
  73. source: "pages/HomePage.qml"
  74. }
  75. }
  76. NavigationItem {
  77. title: "测试维护"
  78. iconType: IconType.gears
  79. objectName: "autofocus_Item"
  80. TestPage {
  81. //id: autofocus_id
  82. }
  83. }
  84. // second tab
  85. NavigationItem {
  86. title: qsTr("图像拼接") // use qsTr for strings you want to translate
  87. iconType: IconType.qrcode
  88. NavigationStack {
  89. PhotostitcherPage {
  90. }
  91. }
  92. }
  93. // second tab
  94. NavigationItem {
  95. id: sqlite_config
  96. objectName: "autofocus_Item"
  97. title: qsTr("SQLITE") // use qsTr for strings you want to translate
  98. iconType: IconType.square
  99. NavigationStack {
  100. SqlScreen{
  101. }
  102. }
  103. }
  104. // second tab
  105. NavigationItem {
  106. objectName: "systemset_Item"
  107. title: qsTr("系统设置") // use qsTr for strings you want to translate
  108. iconType: IconType.gears
  109. NavigationStack {
  110. initialPage: ProfilePage {
  111. id: page_sys
  112. onThemChange: {
  113. app.theme_select = mode
  114. app.theme_md = mode
  115. Theme.navigationTabBar.backgroundColor= app.cardColor
  116. Theme.navigationTabBar.titleColor = app.fontColor
  117. Theme.navigationTabBar.dividerColor = "green"
  118. console.log("配置主题模式:",app.theme_select)
  119. }
  120. // handle logout
  121. onLogoutClicked: {
  122. //loginpage.pushed()
  123. logic.logout()
  124. // jump to main page after logout
  125. navigation.currentIndex = 0
  126. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  127. }
  128. }
  129. }
  130. }
  131. tabPosition: Navigation.Left
  132. }
  133. Timer{
  134. interval: 5000
  135. running: true
  136. repeat: true
  137. onTriggered: {
  138. if(navigation.currentIndex === 0){
  139. serial.readBoardData()
  140. }
  141. loginpage.logintimeout++
  142. ProfilePage.boardversion = "123"
  143. logger.log("休眠计数:" + loginpage.logintimeout.toString())
  144. if(loginpage.logintimeout===60){ //?秒后进入休眠
  145. loginpage.logintimeout = 0
  146. logoutClicked()
  147. //关闭屏幕(亮度设置为0)
  148. serial.setLightness(-255)
  149. }
  150. }
  151. }
  152. // 接收并显示日志消息
  153. Connections {
  154. target: logger
  155. }
  156. Connections{
  157. target: curl
  158. onDownloadFinished :function(result){
  159. //notificationPage.visible = false
  160. if(result){
  161. navigation.setCurrentTab(1) //升级文件下载成功,跳转到日志界面
  162. }
  163. }
  164. }
  165. LocalNotificationPage {
  166. id: notificationPage
  167. visible:false
  168. }
  169. // login page lies on top of previous items and overlays if user is not logged in
  170. LoginPage {
  171. id: loginpage
  172. Connections{
  173. target: serial
  174. }
  175. visible: opacity > 0
  176. enabled: visible
  177. opacity: dataModel.userLoggedIn ? 0 : 1 // hide if user is logged in
  178. /*
  179. 这段代码的作用是设置页面的透明度,并且添加了一个数值动画(NumberAnimation),动画持续时间为250毫秒。
  180. 具体解释如下:
  181. opacity:表示设置元素的透明度。在这里,可能是应用于页面元素,用于控制页面的可见性。
  182. NumberAnimation:是一个数字动画,用于在一段时间内改变一个数字的值,这里是用来控制透明度的变化。
  183. duration: 250:指定动画的持续时间,这里是250毫秒,表示透明度变化会在250毫秒内完成。
  184. 综合起来,这段代码实现了一个在页面上添加的透明度变化效果,使页面在250毫秒内淡入或淡出,具体效果可能会受到上下文和其他代码的影响。
  185. */
  186. Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out
  187. }
  188. }