Overview.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. property int scriptState: 0 // 0是
  35. FluText{
  36. text: 'Scheduler'
  37. Layout.leftMargin: 16
  38. font: FluTextStyle.Subtitle
  39. Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
  40. }
  41. FluIconButton{
  42. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  43. text: "Restart"
  44. iconSource: FluentIcons.RepeatAll
  45. onClicked: {
  46. showSuccess("Restart"+" "+configName)
  47. process_manager.restart(configName)
  48. setStatus(MainEvent.RunStatus.Free)
  49. }
  50. }
  51. FluToggleButton{
  52. id: startStart
  53. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  54. Layout.rightMargin: 16
  55. text: {if(overStatus.runStatus === MainEvent.RunStatus.Stop){return "Stop"}
  56. else{return "Start"}}
  57. selected: {if(overStatus.runStatus === MainEvent.RunStatus.Free){return true}
  58. else{return false}}
  59. disabled: {if(overStatus.runStatus === MainEvent.RunStatus.Error ||
  60. overStatus.runStatus === MainEvent.RunStatus.Empty){return true}
  61. else{return false}
  62. }
  63. onClicked: {
  64. if(overStatus.runStatus === MainEvent.RunStatus.Free){
  65. //如果这个时候初始化好了但是还没有运行脚本
  66. setStatus(MainEvent.RunStatus.Run)
  67. process_manager.start_script(root.configName)
  68. return
  69. }
  70. if(overStatus.runStatus === MainEvent.RunStatus.Run){
  71. // 如果这个时候运行中
  72. setStatus(MainEvent.RunStatus.Emtpy)
  73. process_manager.stop_script(root.configName)
  74. return
  75. }
  76. }
  77. }
  78. }
  79. }
  80. FluArea{
  81. id: schedulerRunning
  82. anchors.top: schedulerOpen.bottom
  83. anchors.topMargin: 10
  84. width: parent.width
  85. height: 100
  86. ColumnLayout{
  87. width: parent.width
  88. spacing: 8
  89. FluText{
  90. text: 'Running'
  91. Layout.leftMargin: 16
  92. Layout.topMargin: 6
  93. font: FluTextStyle.Subtitle
  94. }
  95. Rectangle{
  96. width: schedulerRunning.width - 20
  97. height: 2
  98. Layout.alignment: Qt.AlignHCenter
  99. color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  100. radius: 2
  101. }
  102. Taskmini{
  103. id: task_running
  104. visible: false
  105. Layout.leftMargin: 16
  106. onClick: {
  107. root.splitPanel.title = task_running.name
  108. }
  109. }
  110. }
  111. }
  112. FluArea{
  113. id: schedulerPending
  114. anchors.top: schedulerRunning.bottom
  115. anchors.topMargin: 10
  116. width: parent.width
  117. height: 240
  118. FluText{
  119. id: pendingText
  120. anchors{
  121. top: parent.top
  122. topMargin: 6
  123. }
  124. width: parent.width
  125. text: 'Pending'
  126. leftPadding: 16
  127. font: FluTextStyle.Subtitle
  128. }
  129. Rectangle{
  130. // 这个是一条横线
  131. id: linePending
  132. anchors{
  133. top: pendingText.bottom
  134. topMargin: 8
  135. horizontalCenter: parent.horizontalCenter
  136. }
  137. width: schedulerRunning.width - 20
  138. height: 2
  139. color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  140. radius: 2
  141. }
  142. ListView{
  143. id: pendingListView
  144. anchors{
  145. top: linePending.bottom
  146. topMargin: 8
  147. bottom: parent.bottom
  148. bottomMargin: 8
  149. horizontalCenter: parent.horizontalCenter
  150. }
  151. width: 225
  152. height: 200
  153. clip: true
  154. spacing: 8
  155. model: ListModel{
  156. id: pendingListModel
  157. }
  158. delegate: Component{
  159. Taskmini{
  160. name: model.name
  161. nextRun: model.next_run
  162. onClick: {
  163. root.splitPanel.title = model.name
  164. }
  165. }
  166. }
  167. }
  168. // ColumnLayout{
  169. // width: parent.width
  170. // spacing: 8
  171. // FluText{
  172. // text: 'Pending'
  173. // Layout.leftMargin: 16
  174. // Layout.topMargin: 6
  175. // font: FluTextStyle.Subtitle
  176. // }
  177. // Rectangle{
  178. // // 这个是一条横线
  179. // width: schedulerRunning.width - 20
  180. // height: 2
  181. // Layout.alignment: Qt.AlignHCenter
  182. // color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  183. // radius: 2
  184. // }
  185. // ListView{
  186. // id: pendingListView
  187. // Layout.alignment: Qt.AlignHCenter
  188. // width: 225
  189. // height: 200
  190. // spacing: 8
  191. // model: ListModel{
  192. // id: pendingListModel
  193. // }
  194. // delegate: Component{
  195. // Taskmini{
  196. // name: model.name
  197. // nextRun: model.next_run
  198. // }
  199. // }
  200. // }
  201. // }
  202. }
  203. FluArea{
  204. id: schedulerWaiting
  205. anchors.top: schedulerPending.bottom
  206. anchors.topMargin: 10
  207. anchors.bottom: parent.bottom
  208. anchors.bottomMargin: 0
  209. width: parent.width
  210. ColumnLayout{
  211. width: parent.width
  212. spacing: 8
  213. FluText{
  214. Layout.fillHeight: false
  215. text: 'Waiting'
  216. Layout.leftMargin: 16
  217. Layout.topMargin: 6
  218. font: FluTextStyle.Subtitle
  219. }
  220. Rectangle{
  221. Layout.fillHeight: false
  222. width: schedulerPending.width - 20
  223. height: 2
  224. Layout.alignment: Qt.AlignHCenter
  225. color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  226. radius: 2
  227. }
  228. ListView{
  229. id: waitingListView
  230. Layout.fillHeight: true
  231. Layout.alignment: Qt.AlignHCenter
  232. width: 225
  233. clip: true
  234. spacing: 8
  235. model: ListModel{
  236. id: waitingListModel
  237. }
  238. delegate: Component{
  239. Taskmini{
  240. name: model.name
  241. nextRun: model.next_run
  242. onClick: {
  243. root.splitPanel.title = model.name
  244. }
  245. }
  246. }
  247. }
  248. }
  249. }
  250. }
  251. FluArea{
  252. id: logHeader
  253. anchors.top: parent.top
  254. anchors.left: leftScheduler.right
  255. anchors.leftMargin: 10
  256. anchors.right: parent.right
  257. height: 50
  258. RowLayout{
  259. anchors.fill: parent
  260. RowLayout.alignment: Qt.AlignRight | Qt.AlignVCenter
  261. FluText{
  262. text: 'Log'
  263. Layout.leftMargin: 16
  264. font: FluTextStyle.Subtitle
  265. Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
  266. }
  267. OverStatus{
  268. id: overStatus
  269. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  270. }
  271. FluToggleButton{
  272. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  273. Layout.rightMargin: 16
  274. text:"Auto Scroll On"
  275. selected: true
  276. onClicked: {
  277. selected = !selected
  278. if(selected){
  279. text = "Auto Scroll On"
  280. }else{
  281. text = "Auto Scroll Off"
  282. }
  283. }
  284. }
  285. }
  286. }
  287. FluArea{
  288. anchors.top: logHeader.bottom
  289. anchors.topMargin: 10
  290. anchors.bottom: parent.bottom
  291. anchors.left: leftScheduler.right
  292. anchors.leftMargin: 10
  293. anchors.right: parent.right
  294. FluScrollablePage{
  295. anchors.fill: parent
  296. FluText{
  297. id: textLog
  298. width: parent.width-10
  299. padding: 10
  300. clip: true
  301. wrapMode: Text.WordWrap // 设置自动换行模式
  302. maximumLineCount: 100
  303. property int currentLine: 0
  304. textFormat: Text.RichText
  305. text: ''
  306. function add_log(config, log){
  307. if(config !== root.configName){
  308. return
  309. }
  310. if(log.includes('ERROR') || log.includes('CRITICAL')){
  311. setStatus(MainEvent.RunStatus.Error)
  312. }
  313. if (currentLine > maximumLineCount) {
  314. var index = textLog.text.indexOf("<br>"); //找到第一个<br>的位置
  315. if (index !== -1) {
  316. textLog.text = textLog.text.substring(index + 4); //从<br>之后开始截取字符串
  317. currentLine -= 1
  318. }
  319. }
  320. currentLine += 1
  321. textLog.text += log
  322. }
  323. Component.onCompleted:{
  324. process_manager.log_signal.connect(textLog.add_log)
  325. }
  326. }}
  327. }
  328. Component.onCompleted:{
  329. process_manager.sig_update_task.connect(update_task)
  330. process_manager.sig_update_pending.connect(update_pending)
  331. process_manager.sig_update_waiting.connect(update_waiting)
  332. startInit.start()
  333. }
  334. function update_task(config, data){
  335. if(typeof data !== "string"){
  336. console.error("Pass an incorrect type")
  337. return
  338. }
  339. if(config !== configName){
  340. return
  341. }
  342. task_running.setData(data)
  343. }
  344. function update_pending(config, data){
  345. if(typeof data !== "string"){
  346. console.error("Pass an incorrect type")
  347. return
  348. }
  349. if(config !== configName){
  350. return
  351. }
  352. if(data === "[]"){
  353. pendingListModel.clear()
  354. return
  355. }
  356. pendingListModel.clear()
  357. const d = JSON.parse(data)
  358. for(var item of d){
  359. pendingListModel.append(item)
  360. }
  361. }
  362. function update_waiting(config, data){
  363. if(typeof data !== "string"){
  364. console.error("Pass an incorrect type")
  365. return
  366. }
  367. if(config !== configName){
  368. return
  369. }
  370. if(data === "[]"){
  371. waitingListModel.clear()
  372. return
  373. }
  374. waitingListModel.clear()
  375. const d = JSON.parse(data)
  376. for(var item of d){
  377. waitingListModel.append(item)
  378. }
  379. }
  380. function setStatus(s){
  381. overStatus.runStatus = s
  382. }
  383. }