HomePage.qml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. import QtQuick 2.5
  2. import QtQuick.Controls 2.0
  3. import Qt.labs.settings 1.0 as QtLabs
  4. import QtQuick.Controls.Material 2.0
  5. import QtLocation 5.5
  6. import QtPositioning 5.5
  7. import QtMultimedia 5.5
  8. import Qt5Compat.GraphicalEffects
  9. import Felgo 4.0
  10. import "../controls"
  11. import "../common"
  12. import "../model"
  13. AppPage {
  14. id: home_Page
  15. signal updatebv(string bv)
  16. property string originalString: ""
  17. property string collectString: ""
  18. property string gps_state: "定位中..."
  19. property bool connect_board: false
  20. property var tt
  21. property bool isonline: false
  22. property var net_list:[]
  23. navigationBarHidden: true
  24. backgroundColor: app.theme_backgroundColor
  25. Component.onCompleted: {
  26. var theme_m = settings.getValue("theme_mode")
  27. if (theme_m === undefined) {
  28. theme_m = "day"
  29. app.theme_select = "day"
  30. settings.setValue("theme_mode","day")
  31. }else{
  32. theme_md = theme_m
  33. if(theme_m!=="auto"){
  34. app.theme_select = theme_m
  35. }
  36. console.log("读取到配置主题模式:",app.theme_select,theme_m)
  37. Theme.navigationTabBar.titlePressedColor= "green"
  38. Theme.navigationTabBar.backgroundColor= app.cardColor
  39. Theme.navigationTabBar.titleColor = app.fontColor
  40. }
  41. }
  42. // Connections {
  43. // target: app
  44. // onTmChange:{
  45. // console.log("配置主题模式:",md)
  46. // theme_select = md
  47. // }
  48. // }
  49. // 接收并显示日志消息
  50. Connections {
  51. target: mqtt
  52. onConnected: {
  53. console.log("mqtt connect")
  54. }
  55. onDisconnected: {
  56. console.log("mqtt disconnect")
  57. //mqtt_text.detailText="MQTT已断开"
  58. }
  59. }
  60. // Connections{
  61. // target: myClass
  62. // }
  63. //串口
  64. Connections{
  65. target: serial
  66. onDataReceived:{
  67. var jsonData = JSON.parse(data)
  68. console.log("接收到主板数据:",data.toString())
  69. if(jsonData.ext.work_sta==="0"){
  70. text_devicesta.text = qsTr("<b>工作状态:</b> 待机")
  71. if(jsonData.ext.ds==="0"){
  72. }else{
  73. }
  74. }else if(jsonData.ext.work_sta==="1"){
  75. text_devicesta.text = qsTr("<b>工作状态:</b> 采集")
  76. }
  77. if(jsonData.ext.gps==="1"){
  78. gps_state = "成功"
  79. }
  80. if(jsonData.ext.imei){
  81. originalString = jsonData.ext.imei
  82. }
  83. if(jsonData.ext.coll_time){
  84. var sh1Arry = jsonData.ext.coll_time[0].split('-')
  85. var sh2Arry = jsonData.ext.coll_time[1].split('-')
  86. var sh3Arry = jsonData.ext.coll_time[2].split('-')
  87. sh1.text = parseInt(sh1Arry[0])+ ":00 - " + parseInt(sh1Arry[1]) + ":00"
  88. sh2.text = parseInt(sh2Arry[0])+ ":00 - " + parseInt(sh2Arry[1]) + ":00"
  89. sh3.text = parseInt(sh3Arry[0])+ ":00 - " + parseInt(sh3Arry[1]) + ":00"
  90. }
  91. if(jsonData.ext.dat_f){
  92. serial.update_dat_f_main(jsonData.ext.dat_f);
  93. }
  94. text_tempture.text = "温度:" + jsonData.ext.at + "℃"
  95. text_humidity.text = "湿度:" + jsonData.ext.ah + "%RH"
  96. text_vbat.text = "电压:" + jsonData.ext.vbat + "V"
  97. text_current.text = "电流:" + jsonData.ext.current + "mA"
  98. text_lat.text = "lat:" + jsonData.ext.lat
  99. text_lng.text = "lng:" + jsonData.ext.lng
  100. var dvs = jsonData.ext.dver
  101. dvs = dvs.split("-")
  102. app.bvReceived(dvs[0])
  103. app.appReceived(dvs[1])
  104. }
  105. onDisconnect_485:{
  106. text_devicesta.text =qsTr("485未连接,读取数据失败");
  107. }
  108. }
  109. Timer {
  110. interval: 100
  111. running: true
  112. repeat: true
  113. onTriggered: {
  114. text_stamp.text = getCurrentTime()
  115. }
  116. }
  117. function handleThemeChange(mode){
  118. theme_select = mode
  119. console.log("theme_select",theme_select)
  120. }
  121. function getCurrentTime() {
  122. var currentTime = new Date();
  123. var years = currentTime.getFullYear()
  124. var mon = currentTime.getMonth() + 1
  125. var dates = currentTime.getDate()
  126. var hours = currentTime.getHours()
  127. var mins = currentTime.getMinutes()
  128. var secs = currentTime.getSeconds()
  129. if(app.theme_md==="auto"){
  130. if(hours>=6&&hours<=18){
  131. app.theme_select = "day"
  132. }else{
  133. app.theme_select = "night"
  134. }
  135. }
  136. return years + "-" + mon + "-" + dates + " " + hours + ":" + mins + ":" + secs
  137. }
  138. Grid {
  139. anchors.fill: parent
  140. anchors.leftMargin: 5
  141. anchors.topMargin: 5
  142. //anchors.horizontalCenter: parent.horizontalCenter
  143. columns: 1
  144. rows: 3
  145. columnSpacing: 10
  146. rowSpacing: 5
  147. horizontalItemAlignment: Grid.AlignHCenter
  148. Row {
  149. width: parent.width *0.995
  150. height: parent.height*0.1
  151. Rectangle {
  152. anchors.fill: parent
  153. color: app.cardColor
  154. radius: 2
  155. Row {
  156. anchors.fill: parent
  157. spacing: dp(20)
  158. AppText{
  159. id: text_stamp
  160. anchors.verticalCenter: parent.verticalCenter
  161. text: ""
  162. fontSize: 20
  163. color: app.fontColor
  164. }
  165. AppText{
  166. id: text_imei
  167. anchors.verticalCenter: parent.verticalCenter
  168. text:"设备ID:" + originalString.toLowerCase()
  169. fontSize: 20
  170. color: app.fontColor
  171. }
  172. AppText{
  173. id: net_sta
  174. anchors.verticalCenter: parent.verticalCenter
  175. color: app.fontColor
  176. text: "联网状态:"
  177. fontSize: 20
  178. //font.bold: true
  179. }
  180. AppText{
  181. id: text_gps
  182. anchors.verticalCenter: parent.verticalCenter
  183. text: "GPS状态:" + gps_state
  184. color: app.fontColor
  185. font.bold: true
  186. //fontSize: 20
  187. }
  188. }
  189. }
  190. }
  191. Row{
  192. //anchors.fill: parent
  193. width: parent.width
  194. height: parent.height*0.5
  195. spacing:5
  196. Rectangle {
  197. width: parent.width*0.245
  198. height: parent.height
  199. color: app.cardColor
  200. radius: 5
  201. Column{
  202. anchors.fill: parent
  203. spacing: 5
  204. //anchors.leftMargin: 10
  205. AppImage {
  206. id: image_01
  207. // 将元素的顶部锚定到父元素的顶部
  208. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  209. anchors.topMargin: 30
  210. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  211. source: "../../assets/a.svg"
  212. }
  213. AppText{
  214. id: text_devicesta
  215. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  216. text: "工作状态:"
  217. color: app.fontColor
  218. font.bold: true
  219. }
  220. }
  221. }
  222. Rectangle {
  223. radius: 5
  224. width: parent.width*0.245
  225. height: parent.height
  226. color: app.cardColor
  227. Timer {
  228. interval: 500
  229. running: true
  230. repeat: true
  231. onTriggered: {
  232. text_gps.text = "GPS状态:" + gps_state
  233. if(mqtt.checkLink()){
  234. mqtt_text.text="MQTT已连接:" + net_list[5]
  235. }else{
  236. mqtt_text.text="MQTT已断开:" + net_list[5]
  237. }
  238. net_list = mqtt.netMessage()
  239. if(net_list){
  240. if(net_list[0]==="1"){isonline = true}else{isonline = false}
  241. net_sta.text = qsTr("<b>联网状态:</b> %1").arg(isonline? "已联网" : "未联网")
  242. net_sta.color = qsTr("%1").arg(isonline? "green" : "red")
  243. ipv4.text = qsTr("<b>[IPV4] </b> %1").arg(net_list[4])
  244. mac.text = qsTr("<b>[MAC] </b> %1").arg(net_list[3])
  245. datt_text.text = "数据上传间隔:" + net_list[6] + "分钟"
  246. netxd_text.text = "下一次数据上传:" + net_list[7] + "秒"
  247. }
  248. }
  249. }
  250. Column{
  251. anchors.fill: parent
  252. spacing: 5
  253. AppImage {
  254. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  255. anchors.topMargin: 30
  256. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  257. source: "../../assets/net.svg"
  258. }
  259. AppText{
  260. id: text_net_title
  261. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  262. text: "网络信息"
  263. color: app.fontColor
  264. font.bold: true
  265. }
  266. AppText{
  267. id: ipv4
  268. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  269. text:"IPv4:"
  270. fontSize: 10
  271. color: "gray"
  272. }
  273. AppText{
  274. id: mac
  275. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  276. text:"MAC:"
  277. fontSize: 10
  278. color: "gray"
  279. }
  280. AppText{
  281. id: mqtt_text
  282. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  283. text:"MQTT断开连接:"
  284. fontSize: 10
  285. color: "gray"
  286. }
  287. AppText{
  288. id: datt_text
  289. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  290. text:"数据上传间隔:"
  291. fontSize: 10
  292. color: "gray"
  293. }
  294. AppText{
  295. id: netxd_text
  296. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  297. text:"下一次数据传:"
  298. fontSize: 10
  299. color: "gray"
  300. }
  301. }
  302. }
  303. Rectangle {
  304. radius: 5
  305. width: parent.width*0.245
  306. height: parent.height
  307. color: app.cardColor
  308. Column{
  309. anchors.top: parent.top
  310. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  311. spacing: 5
  312. AppImage {
  313. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  314. anchors.topMargin: 30
  315. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  316. source: "../../assets/gps.svg"
  317. }
  318. AppText{
  319. id: text_gps_title
  320. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  321. text: "定位信息"
  322. color: app.fontColor
  323. font.bold: true
  324. }
  325. AppText{
  326. id: text_lat
  327. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  328. text:"lat:"
  329. fontSize: 10
  330. color: "gray"
  331. }
  332. AppText{
  333. id: text_lng
  334. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  335. text:"lng:"
  336. fontSize: 10
  337. color: "gray"
  338. }
  339. }
  340. }
  341. Rectangle {
  342. radius: 5
  343. width: parent.width*0.245
  344. height: parent.height
  345. color: app.cardColor
  346. Rectangle{
  347. id: rec_seting
  348. anchors.fill: parent
  349. visible: false
  350. AppText {
  351. //anchors.top: parent
  352. //anchors.topMargin:10
  353. text:"采集时间设置"
  354. anchors.horizontalCenter: parent.horizontalCenter
  355. font.bold: true
  356. }
  357. Grid {
  358. anchors.centerIn: parent
  359. //anchors.horizontalCenter: parent.horizontalCenter
  360. columns: 2
  361. rows: 3
  362. rowSpacing: 5
  363. columnSpacing: 20
  364. AppTextField {
  365. id: sh1_textfield
  366. width: 60
  367. height: 30
  368. borderWidth: dp(1)
  369. radius: 5
  370. // Displays a number only keyboard on mobiles
  371. inputMethodHints: Qt.ImhDigitsOnly
  372. validator: IntValidator {
  373. bottom: 0
  374. top: 23
  375. }
  376. }
  377. AppTextField {
  378. id: sh2_textfield
  379. width: 60
  380. height: 30
  381. borderWidth: dp(1)
  382. radius: 5
  383. // Displays a number only keyboard on mobiles
  384. inputMethodHints: Qt.ImhDigitsOnly
  385. validator: IntValidator {
  386. bottom: 0
  387. top: 23
  388. }
  389. }
  390. AppTextField {
  391. id: sh3_textfield
  392. width: 60
  393. height: 30
  394. borderWidth: dp(1)
  395. radius: 5
  396. // Displays a number only keyboard on mobiles
  397. inputMethodHints: Qt.ImhDigitsOnly
  398. validator: IntValidator {
  399. bottom: 0
  400. top: 23
  401. }
  402. }
  403. AppTextField {
  404. id: sh4_textfield
  405. width: 60
  406. height: 30
  407. borderWidth: dp(1)
  408. radius: 5
  409. // Displays a number only keyboard on mobiles
  410. inputMethodHints: Qt.ImhDigitsOnly
  411. validator: IntValidator {
  412. bottom: 0
  413. top: 23
  414. }
  415. }
  416. AppTextField {
  417. id: sh5_textfield
  418. width: 60
  419. height: 30
  420. borderWidth: dp(1)
  421. radius: 5
  422. // Displays a number only keyboard on mobiles
  423. inputMethodHints: Qt.ImhDigitsOnly
  424. validator: IntValidator {
  425. bottom: 0
  426. top: 23
  427. }
  428. }
  429. AppTextField {
  430. id: sh6_textfield
  431. width: 60
  432. height: 30
  433. borderWidth: dp(1)
  434. radius: 5
  435. // Displays a number only keyboard on mobiles
  436. inputMethodHints: Qt.ImhDigitsOnly
  437. validator: IntValidator {
  438. bottom: 0
  439. top: 23
  440. }
  441. }
  442. }
  443. Row {
  444. anchors.horizontalCenter: parent.horizontalCenter
  445. anchors.bottom: parent.bottom
  446. anchors.bottomMargin: 5
  447. //spacing: -15
  448. AppButton {
  449. minimumWidth: 30
  450. minimumHeight: 15
  451. textSize: 15
  452. fontBold: false
  453. iconSize: 10
  454. text: "取消"
  455. textColor: "black"
  456. flat: false
  457. backgroundColor: "#e9e9e9"
  458. borderColor: "white"
  459. onClicked: {
  460. rec_seting.visible = false
  461. column_colt.visible = true
  462. appimage_set.visible = true
  463. image_timesvg.visible = true
  464. }
  465. }
  466. AppButton {
  467. minimumWidth: 30
  468. minimumHeight: 15
  469. textSize: 15
  470. text: "保存"
  471. textColor: "white"
  472. flat: false
  473. backgroundColor: "#0aa26b"
  474. borderColor: "white"
  475. onClicked: {
  476. var int_sh1 = parseInt(sh1_textfield.text)
  477. var int_eh1 = parseInt(sh2_textfield.text)
  478. var int_sh2 = parseInt(sh3_textfield.text)
  479. var int_eh2 = parseInt(sh4_textfield.text)
  480. var int_sh3 = parseInt(sh5_textfield.text)
  481. var int_eh3 = parseInt(sh6_textfield.text)
  482. serial.setCollt(int_sh1,int_eh1,int_sh2,int_eh2,int_sh3,int_eh3)
  483. rec_seting.visible = false
  484. column_colt.visible = true
  485. appimage_set.visible = true
  486. image_timesvg.visible = true
  487. }
  488. }
  489. }
  490. }
  491. Column{
  492. id: column_colt
  493. anchors.top: parent.top
  494. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  495. spacing: 5
  496. AppImage {
  497. id: image_timesvg
  498. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  499. anchors.topMargin: 30
  500. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  501. source: "../../assets/time.svg"
  502. }
  503. AppText{
  504. id: text_coll
  505. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  506. text: "采集时间"
  507. color: app.fontColor
  508. font.bold: true
  509. }
  510. AppText{
  511. id: sh1
  512. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  513. text:"09:00-10:00"
  514. fontSize: 10
  515. color: "gray"
  516. }
  517. AppText{
  518. id: sh2
  519. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  520. text:"14:00-16:00"
  521. fontSize: 10
  522. color: "gray"
  523. }
  524. AppText{
  525. id: sh3
  526. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  527. text:"17:00-19:00"
  528. fontSize: 10
  529. color: "gray"
  530. }
  531. AppImage {
  532. id: appimage_set
  533. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  534. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  535. source: "../../assets/set.svg"
  536. AppButton{
  537. id: settime
  538. anchors.fill: parent
  539. //text:" 修改"
  540. textColor: "GRAY"
  541. textSize: 10
  542. flat: true
  543. onClicked: {
  544. var sh1Arry = sh1.text.split('-')
  545. var sh2Arry = sh2.text.split('-')
  546. var sh3Arry = sh3.text.split('-')
  547. sh1_textfield.text = parseInt(sh1Arry[0]);
  548. sh2_textfield.text= parseInt(sh1Arry[1]);
  549. sh3_textfield.text = parseInt(sh2Arry[0]);
  550. sh4_textfield.text = parseInt(sh2Arry[1]);
  551. sh5_textfield.text = parseInt(sh3Arry[0]);
  552. sh6_textfield.text = parseInt(sh3Arry[1]);
  553. column_colt.visible = false
  554. appimage_set.visible = false
  555. image_timesvg.visible = false
  556. rec_seting.visible = true
  557. }
  558. }
  559. }
  560. }
  561. }
  562. }
  563. Row {
  564. width: parent.width
  565. height: parent.height*0.38
  566. spacing: 5
  567. Rectangle {
  568. radius: 5
  569. width: parent.width*0.245
  570. height: parent.height
  571. color: app.cardColor
  572. Column {
  573. anchors.centerIn: parent
  574. spacing: 5
  575. AppImage {
  576. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  577. anchors.topMargin: 30
  578. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  579. source: "../../assets/tempture.svg"
  580. }
  581. AppText{
  582. id: text_tempture
  583. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  584. text: "温度:"
  585. color: app.fontColor
  586. font.bold: true
  587. }
  588. }
  589. }
  590. Rectangle {
  591. radius: 5
  592. width: parent.width*0.245
  593. height: parent.height
  594. color: app.cardColor
  595. Column {
  596. anchors.centerIn: parent
  597. spacing: 5
  598. AppImage {
  599. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  600. anchors.topMargin: 30
  601. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  602. source: "../../assets/humidity.svg"
  603. }
  604. AppText{
  605. id: text_humidity
  606. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  607. text: "湿度:"
  608. color: app.fontColor
  609. font.bold: true
  610. }
  611. }
  612. }
  613. Rectangle {
  614. radius: 5
  615. width: parent.width*0.245
  616. height: parent.height
  617. color: app.cardColor
  618. Column {
  619. anchors.centerIn: parent
  620. spacing: 5
  621. AppImage {
  622. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  623. anchors.topMargin: 30
  624. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  625. source: "../../assets/vbat.svg"
  626. }
  627. AppText{
  628. id: text_vbat
  629. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  630. text: "电压:"
  631. color: app.fontColor
  632. font.bold: true
  633. }
  634. }
  635. }
  636. Rectangle {
  637. radius: 5
  638. width: parent.width*0.245
  639. height: parent.height
  640. color: app.cardColor
  641. Column {
  642. anchors.centerIn: parent
  643. spacing: 5
  644. AppImage {
  645. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  646. anchors.topMargin: 30
  647. fillMode: Image.PreserveAspectFit // 保持纵横比适应
  648. source: "../../assets/current.svg"
  649. }
  650. AppText{
  651. id: text_current
  652. anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示
  653. text: "电流:"
  654. color: app.fontColor
  655. font.bold: true
  656. }
  657. }
  658. }
  659. }
  660. }
  661. } // page