Overview.qml 13 KB

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