Overview.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. import FluentUI
  5. import "../Global"
  6. Item {
  7. id: root
  8. property string configName: ""
  9. property var splitPanel: null // 传入一个主控制的引用
  10. Timer{
  11. id: startInit
  12. interval: 2500 // 定时器间隔为一秒
  13. repeat: false // 设置为一次性定时器
  14. onTriggered: {
  15. // 停止定时器
  16. setStatus(MainEvent.RunStatus.Free)
  17. }
  18. }
  19. Item{
  20. id: leftScheduler
  21. width: 260
  22. anchors{
  23. left: parent.left
  24. top: parent.top
  25. bottom: parent.bottom
  26. }
  27. FluArea{
  28. id: schedulerOpen
  29. anchors.top: parent.top
  30. width: parent.width
  31. height: 50
  32. RowLayout{
  33. anchors.fill: parent
  34. FluText{
  35. text: 'Scheduler'
  36. Layout.leftMargin: 16
  37. font: FluTextStyle.Subtitle
  38. Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
  39. }
  40. FluIconButton{
  41. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  42. text: "Restart"
  43. iconSource: FluentIcons.RepeatAll
  44. onClicked: {
  45. showSuccess("Restart"+" "+configName)
  46. process_manager.restart(configName)
  47. startStart.selected = true
  48. textLog.text = ""
  49. }
  50. }
  51. FluToggleButton{
  52. id: startStart
  53. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  54. Layout.rightMargin: 16
  55. text:"Start"
  56. selected: true
  57. onClicked: {
  58. selected = !selected
  59. if(selected){
  60. text = "Start"
  61. process_manager.stop_script(root.configName)
  62. }else{
  63. // 如果按键颜色变灰色
  64. text = "Stop"
  65. process_manager.start_script(root.configName)
  66. }
  67. }
  68. }
  69. }
  70. }
  71. FluArea{
  72. id: schedulerRunning
  73. anchors.top: schedulerOpen.bottom
  74. anchors.topMargin: 10
  75. width: parent.width
  76. height: 100
  77. ColumnLayout{
  78. width: parent.width
  79. spacing: 8
  80. FluText{
  81. text: 'Running'
  82. Layout.leftMargin: 16
  83. Layout.topMargin: 6
  84. font: FluTextStyle.Subtitle
  85. }
  86. Rectangle{
  87. width: schedulerRunning.width - 20
  88. height: 2
  89. Layout.alignment: Qt.AlignHCenter
  90. color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  91. radius: 2
  92. }
  93. Taskmini{
  94. id: task_running
  95. visible: false
  96. Layout.leftMargin: 16
  97. onClick: {
  98. root.splitPanel.title = task_running.name
  99. }
  100. }
  101. }
  102. }
  103. FluArea{
  104. id: schedulerPending
  105. anchors.top: schedulerRunning.bottom
  106. anchors.topMargin: 10
  107. width: parent.width
  108. height: 240
  109. FluText{
  110. id: pendingText
  111. anchors{
  112. top: parent.top
  113. topMargin: 6
  114. }
  115. width: parent.width
  116. text: 'Pending'
  117. leftPadding: 16
  118. font: FluTextStyle.Subtitle
  119. }
  120. Rectangle{
  121. // 这个是一条横线
  122. id: linePending
  123. anchors{
  124. top: pendingText.bottom
  125. topMargin: 8
  126. horizontalCenter: parent.horizontalCenter
  127. }
  128. width: schedulerRunning.width - 20
  129. height: 2
  130. color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  131. radius: 2
  132. }
  133. ListView{
  134. id: pendingListView
  135. anchors{
  136. top: linePending.bottom
  137. topMargin: 8
  138. bottom: parent.bottom
  139. bottomMargin: 8
  140. horizontalCenter: parent.horizontalCenter
  141. }
  142. width: 225
  143. height: 200
  144. clip: true
  145. spacing: 8
  146. model: ListModel{
  147. id: pendingListModel
  148. }
  149. delegate: Component{
  150. Taskmini{
  151. name: model.name
  152. nextRun: model.next_run
  153. onClick: {
  154. root.splitPanel.title = model.name
  155. }
  156. }
  157. }
  158. }
  159. // ColumnLayout{
  160. // width: parent.width
  161. // spacing: 8
  162. // FluText{
  163. // text: 'Pending'
  164. // Layout.leftMargin: 16
  165. // Layout.topMargin: 6
  166. // font: FluTextStyle.Subtitle
  167. // }
  168. // Rectangle{
  169. // // 这个是一条横线
  170. // width: schedulerRunning.width - 20
  171. // height: 2
  172. // Layout.alignment: Qt.AlignHCenter
  173. // color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  174. // radius: 2
  175. // }
  176. // ListView{
  177. // id: pendingListView
  178. // Layout.alignment: Qt.AlignHCenter
  179. // width: 225
  180. // height: 200
  181. // spacing: 8
  182. // model: ListModel{
  183. // id: pendingListModel
  184. // }
  185. // delegate: Component{
  186. // Taskmini{
  187. // name: model.name
  188. // nextRun: model.next_run
  189. // }
  190. // }
  191. // }
  192. // }
  193. }
  194. FluArea{
  195. id: schedulerWaiting
  196. anchors.top: schedulerPending.bottom
  197. anchors.topMargin: 10
  198. anchors.bottom: parent.bottom
  199. anchors.bottomMargin: 0
  200. width: parent.width
  201. ColumnLayout{
  202. width: parent.width
  203. spacing: 8
  204. FluText{
  205. Layout.fillHeight: false
  206. text: 'Waiting'
  207. Layout.leftMargin: 16
  208. Layout.topMargin: 6
  209. font: FluTextStyle.Subtitle
  210. }
  211. Rectangle{
  212. Layout.fillHeight: false
  213. width: schedulerPending.width - 20
  214. height: 2
  215. Layout.alignment: Qt.AlignHCenter
  216. color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  217. radius: 2
  218. }
  219. ListView{
  220. id: waitingListView
  221. Layout.fillHeight: true
  222. Layout.alignment: Qt.AlignHCenter
  223. width: 225
  224. clip: true
  225. spacing: 8
  226. model: ListModel{
  227. id: waitingListModel
  228. }
  229. delegate: Component{
  230. Taskmini{
  231. name: model.name
  232. nextRun: model.next_run
  233. onClick: {
  234. root.splitPanel.title = model.name
  235. }
  236. }
  237. }
  238. }
  239. }
  240. }
  241. }
  242. FluArea{
  243. id: logHeader
  244. anchors.top: parent.top
  245. anchors.left: leftScheduler.right
  246. anchors.leftMargin: 10
  247. anchors.right: parent.right
  248. height: 50
  249. RowLayout{
  250. anchors.fill: parent
  251. RowLayout.alignment: Qt.AlignRight | Qt.AlignVCenter
  252. FluText{
  253. text: 'Log'
  254. Layout.leftMargin: 16
  255. font: FluTextStyle.Subtitle
  256. Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
  257. }
  258. OverStatus{
  259. id: overStatus
  260. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  261. }
  262. FluToggleButton{
  263. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  264. Layout.rightMargin: 16
  265. text:"Auto Scroll On"
  266. selected: true
  267. onClicked: {
  268. selected = !selected
  269. if(selected){
  270. text = "Auto Scroll On"
  271. }else{
  272. text = "Auto Scroll Off"
  273. }
  274. }
  275. }
  276. }
  277. }
  278. FluArea{
  279. anchors.top: logHeader.bottom
  280. anchors.topMargin: 10
  281. anchors.bottom: parent.bottom
  282. anchors.left: leftScheduler.right
  283. anchors.leftMargin: 10
  284. anchors.right: parent.right
  285. FluScrollablePage{
  286. anchors.fill: parent
  287. FluText{
  288. id: textLog
  289. width: parent.width-10
  290. padding: 10
  291. clip: true
  292. wrapMode: Text.WordWrap // 设置自动换行模式
  293. textFormat: Text.RichText
  294. text: ''
  295. function add_log(config, log){
  296. if(config !== root.configName){
  297. return
  298. }
  299. textLog.text += log
  300. }
  301. Component.onCompleted:{
  302. process_manager.log_signal.connect(textLog.add_log)
  303. }
  304. }}
  305. }
  306. Component.onCompleted:{
  307. process_manager.sig_update_task.connect(update_task)
  308. process_manager.sig_update_pending.connect(update_pending)
  309. process_manager.sig_update_waiting.connect(update_waiting)
  310. startInit.start()
  311. }
  312. function update_task(config, data){
  313. if(typeof data !== "string"){
  314. console.error("Pass an incorrect type")
  315. return
  316. }
  317. if(config !== configName){
  318. return
  319. }
  320. task_running.setData(data)
  321. }
  322. function update_pending(config, data){
  323. if(typeof data !== "string"){
  324. console.error("Pass an incorrect type")
  325. return
  326. }
  327. if(config !== configName){
  328. return
  329. }
  330. if(data === "[]"){
  331. pendingListModel.clear()
  332. return
  333. }
  334. pendingListModel.clear()
  335. const d = JSON.parse(data)
  336. for(var item of d){
  337. pendingListModel.append(item)
  338. }
  339. }
  340. function update_waiting(config, data){
  341. if(typeof data !== "string"){
  342. console.error("Pass an incorrect type")
  343. return
  344. }
  345. if(config !== configName){
  346. return
  347. }
  348. if(data === "[]"){
  349. waitingListModel.clear()
  350. return
  351. }
  352. waitingListModel.clear()
  353. const d = JSON.parse(data)
  354. for(var item of d){
  355. waitingListModel.append(item)
  356. }
  357. }
  358. function setStatus(s){
  359. overStatus.runStatus = s
  360. }
  361. }