Overview.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. }
  172. FluArea{
  173. id: schedulerWaiting
  174. anchors.top: schedulerPending.bottom
  175. anchors.topMargin: 10
  176. anchors.bottom: parent.bottom
  177. anchors.bottomMargin: 0
  178. width: parent.width
  179. // ColumnLayout{
  180. // width: parent.width
  181. // spacing: 8
  182. FluText{
  183. id: waitingText
  184. anchors{
  185. top: parent.top
  186. topMargin: 6
  187. }
  188. width: parent.width
  189. text: 'Waiting'
  190. leftPadding: 16
  191. font: FluTextStyle.Subtitle
  192. }
  193. Rectangle{
  194. id: lineWaiting
  195. anchors{
  196. top: waitingText.bottom
  197. topMargin: 8
  198. horizontalCenter: parent.horizontalCenter
  199. }
  200. width: schedulerPending.width - 20
  201. height: 2
  202. color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
  203. radius: 2
  204. }
  205. ListView{
  206. id: waitingListView
  207. anchors{
  208. top: lineWaiting.bottom
  209. topMargin: 8
  210. bottom: parent.bottom
  211. bottomMargin: 8
  212. horizontalCenter: parent.horizontalCenter
  213. }
  214. width: 225
  215. clip: true
  216. spacing: 8
  217. model: ListModel{
  218. id: waitingListModel
  219. }
  220. delegate: Component{
  221. Taskmini{
  222. name: model.name
  223. nextRun: model.next_run
  224. onClick: {
  225. root.splitPanel.title = model.name
  226. }
  227. }
  228. }
  229. }
  230. // }
  231. }
  232. }
  233. FluArea{
  234. id: logHeader
  235. anchors.top: parent.top
  236. anchors.left: leftScheduler.right
  237. anchors.leftMargin: 10
  238. anchors.right: parent.right
  239. height: 50
  240. RowLayout{
  241. anchors.fill: parent
  242. RowLayout.alignment: Qt.AlignRight | Qt.AlignVCenter
  243. FluText{
  244. text: 'Log'
  245. Layout.leftMargin: 16
  246. font: FluTextStyle.Subtitle
  247. Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
  248. }
  249. OverStatus{
  250. id: overStatus
  251. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  252. }
  253. FluToggleButton{
  254. Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
  255. Layout.rightMargin: 16
  256. text:"Auto Scroll On"
  257. selected: true
  258. onClicked: {
  259. selected = !selected
  260. if(selected){
  261. text = "Auto Scroll On"
  262. }else{
  263. text = "Auto Scroll Off"
  264. }
  265. }
  266. }
  267. }
  268. }
  269. FluArea{
  270. anchors.top: logHeader.bottom
  271. anchors.topMargin: 10
  272. anchors.bottom: parent.bottom
  273. anchors.left: leftScheduler.right
  274. anchors.leftMargin: 10
  275. anchors.right: parent.right
  276. FluScrollablePage{
  277. anchors.fill: parent
  278. FluText{
  279. id: textLog
  280. width: parent.width-10
  281. padding: 10
  282. clip: true
  283. wrapMode: Text.WordWrap // 设置自动换行模式
  284. maximumLineCount: 100
  285. property int currentLine: 0
  286. textFormat: Text.RichText
  287. text: ''
  288. function add_log(config, log){
  289. if(config !== root.configName){
  290. return
  291. }
  292. if(log.includes('ERROR') || log.includes('CRITICAL')){
  293. setStatus(MainEvent.RunStatus.Error)
  294. }
  295. if (currentLine > maximumLineCount) {
  296. var index = textLog.text.indexOf("<br>"); //找到第一个<br>的位置
  297. if (index !== -1) {
  298. textLog.text = textLog.text.substring(index + 4); //从<br>之后开始截取字符串
  299. currentLine -= 1
  300. }
  301. }
  302. currentLine += 1
  303. textLog.text += log
  304. }
  305. Component.onCompleted:{
  306. process_manager.log_signal.connect(textLog.add_log)
  307. }
  308. }}
  309. }
  310. Component.onCompleted:{
  311. process_manager.sig_update_task.connect(update_task)
  312. process_manager.sig_update_pending.connect(update_pending)
  313. process_manager.sig_update_waiting.connect(update_waiting)
  314. startInit.start()
  315. }
  316. function update_task(config, data){
  317. if(typeof data !== "string"){
  318. console.error("Pass an incorrect type")
  319. return
  320. }
  321. if(config !== configName){
  322. return
  323. }
  324. task_running.setData(data)
  325. }
  326. function update_pending(config, data){
  327. if(typeof data !== "string"){
  328. console.error("Pass an incorrect type")
  329. return
  330. }
  331. if(config !== configName){
  332. return
  333. }
  334. if(data === "[]"){
  335. pendingListModel.clear()
  336. return
  337. }
  338. pendingListModel.clear()
  339. const d = JSON.parse(data)
  340. for(var item of d){
  341. pendingListModel.append(item)
  342. }
  343. }
  344. function update_waiting(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. waitingListModel.clear()
  354. return
  355. }
  356. waitingListModel.clear()
  357. const d = JSON.parse(data)
  358. for(var item of d){
  359. waitingListModel.append(item)
  360. }
  361. }
  362. function setStatus(s){
  363. overStatus.runStatus = s
  364. }
  365. }