| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- import QtQuick
- import QtQuick.Controls
- import QtQuick.Layouts
- import FluentUI
- import "../Global"
- Item {
- id: root
- property string configName: ""
- property var splitPanel: null // 传入一个主控制的引用
- Timer{
- id: startInit
- interval: 2500 // 定时器间隔为一秒
- repeat: false // 设置为一次性定时器
- onTriggered: {
- // 停止定时器
- setStatus(MainEvent.RunStatus.Free)
- }
- }
- Item{
- id: leftScheduler
- width: 260
- anchors{
- left: parent.left
- top: parent.top
- bottom: parent.bottom
- }
- FluArea{
- id: schedulerOpen
- anchors.top: parent.top
- width: parent.width
- height: 50
- RowLayout{
- anchors.fill: parent
- property int scriptState: 0 // 0是
- FluText{
- text: 'Scheduler'
- Layout.leftMargin: 16
- font: FluTextStyle.Subtitle
- Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
- }
- FluIconButton{
- Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
- text: "Restart"
- iconSource: FluentIcons.RepeatAll
- onClicked: {
- showSuccess("Restart"+" "+configName)
- process_manager.restart(configName)
- setStatus(MainEvent.RunStatus.Free)
- }
- }
- FluToggleButton{
- id: startStart
- Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
- Layout.rightMargin: 16
- text: {if(overStatus.runStatus === MainEvent.RunStatus.Stop){return "Stop"}
- else{return "Start"}}
- selected: {if(overStatus.runStatus === MainEvent.RunStatus.Free){return true}
- else{return false}}
- disabled: {if(overStatus.runStatus === MainEvent.RunStatus.Error ||
- overStatus.runStatus === MainEvent.RunStatus.Empty){return true}
- else{return false}
- }
- onClicked: {
- if(overStatus.runStatus === MainEvent.RunStatus.Free){
- //如果这个时候初始化好了但是还没有运行脚本
- setStatus(MainEvent.RunStatus.Run)
- process_manager.start_script(root.configName)
- return
- }
- if(overStatus.runStatus === MainEvent.RunStatus.Run){
- // 如果这个时候运行中
- setStatus(MainEvent.RunStatus.Emtpy)
- process_manager.stop_script(root.configName)
- return
- }
- }
- }
- }
- }
- FluArea{
- id: schedulerRunning
- anchors.top: schedulerOpen.bottom
- anchors.topMargin: 10
- width: parent.width
- height: 100
- ColumnLayout{
- width: parent.width
- spacing: 8
- FluText{
- text: 'Running'
- Layout.leftMargin: 16
- Layout.topMargin: 6
- font: FluTextStyle.Subtitle
- }
- Rectangle{
- width: schedulerRunning.width - 20
- height: 2
- Layout.alignment: Qt.AlignHCenter
- color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
- radius: 2
- }
- Taskmini{
- id: task_running
- visible: false
- Layout.leftMargin: 16
- onClick: {
- root.splitPanel.title = task_running.name
- }
- }
- }
- }
- FluArea{
- id: schedulerPending
- anchors.top: schedulerRunning.bottom
- anchors.topMargin: 10
- width: parent.width
- height: 240
- FluText{
- id: pendingText
- anchors{
- top: parent.top
- topMargin: 6
- }
- width: parent.width
- text: 'Pending'
- leftPadding: 16
- font: FluTextStyle.Subtitle
- }
- Rectangle{
- // 这个是一条横线
- id: linePending
- anchors{
- top: pendingText.bottom
- topMargin: 8
- horizontalCenter: parent.horizontalCenter
- }
- width: schedulerRunning.width - 20
- height: 2
- color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
- radius: 2
- }
- ListView{
- id: pendingListView
- anchors{
- top: linePending.bottom
- topMargin: 8
- bottom: parent.bottom
- bottomMargin: 8
- horizontalCenter: parent.horizontalCenter
- }
- width: 225
- height: 200
- clip: true
- spacing: 8
- model: ListModel{
- id: pendingListModel
- }
- delegate: Component{
- Taskmini{
- name: model.name
- nextRun: model.next_run
- onClick: {
- root.splitPanel.title = model.name
- }
- }
- }
- }
- // ColumnLayout{
- // width: parent.width
- // spacing: 8
- // FluText{
- // text: 'Pending'
- // Layout.leftMargin: 16
- // Layout.topMargin: 6
- // font: FluTextStyle.Subtitle
- // }
- // Rectangle{
- // // 这个是一条横线
- // width: schedulerRunning.width - 20
- // height: 2
- // Layout.alignment: Qt.AlignHCenter
- // color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
- // radius: 2
- // }
- // ListView{
- // id: pendingListView
- // Layout.alignment: Qt.AlignHCenter
- // width: 225
- // height: 200
- // spacing: 8
- // model: ListModel{
- // id: pendingListModel
- // }
- // delegate: Component{
- // Taskmini{
- // name: model.name
- // nextRun: model.next_run
- // }
- // }
- // }
- // }
- }
- FluArea{
- id: schedulerWaiting
- anchors.top: schedulerPending.bottom
- anchors.topMargin: 10
- anchors.bottom: parent.bottom
- anchors.bottomMargin: 0
- width: parent.width
- ColumnLayout{
- width: parent.width
- spacing: 8
- FluText{
- Layout.fillHeight: false
- text: 'Waiting'
- Layout.leftMargin: 16
- Layout.topMargin: 6
- font: FluTextStyle.Subtitle
- }
- Rectangle{
- Layout.fillHeight: false
- width: schedulerPending.width - 20
- height: 2
- Layout.alignment: Qt.AlignHCenter
- color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
- radius: 2
- }
- ListView{
- id: waitingListView
- Layout.fillHeight: true
- Layout.alignment: Qt.AlignHCenter
- width: 225
- clip: true
- spacing: 8
- model: ListModel{
- id: waitingListModel
- }
- delegate: Component{
- Taskmini{
- name: model.name
- nextRun: model.next_run
- onClick: {
- root.splitPanel.title = model.name
- }
- }
- }
- }
- }
- }
- }
- FluArea{
- id: logHeader
- anchors.top: parent.top
- anchors.left: leftScheduler.right
- anchors.leftMargin: 10
- anchors.right: parent.right
- height: 50
- RowLayout{
- anchors.fill: parent
- RowLayout.alignment: Qt.AlignRight | Qt.AlignVCenter
- FluText{
- text: 'Log'
- Layout.leftMargin: 16
- font: FluTextStyle.Subtitle
- Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
- }
- OverStatus{
- id: overStatus
- Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
- }
- FluToggleButton{
- Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
- Layout.rightMargin: 16
- text:"Auto Scroll On"
- selected: true
- onClicked: {
- selected = !selected
- if(selected){
- text = "Auto Scroll On"
- }else{
- text = "Auto Scroll Off"
- }
- }
- }
- }
- }
- FluArea{
- anchors.top: logHeader.bottom
- anchors.topMargin: 10
- anchors.bottom: parent.bottom
- anchors.left: leftScheduler.right
- anchors.leftMargin: 10
- anchors.right: parent.right
- FluScrollablePage{
- anchors.fill: parent
- FluText{
- id: textLog
- width: parent.width-10
- padding: 10
- clip: true
- wrapMode: Text.WordWrap // 设置自动换行模式
- maximumLineCount: 100
- property int currentLine: 0
- textFormat: Text.RichText
- text: ''
- function add_log(config, log){
- if(config !== root.configName){
- return
- }
- if(log.includes('ERROR') || log.includes('CRITICAL')){
- setStatus(MainEvent.RunStatus.Error)
- }
- if (currentLine > maximumLineCount) {
- var index = textLog.text.indexOf("<br>"); //找到第一个<br>的位置
- if (index !== -1) {
- textLog.text = textLog.text.substring(index + 4); //从<br>之后开始截取字符串
- currentLine -= 1
- }
- }
- currentLine += 1
- textLog.text += log
- }
- Component.onCompleted:{
- process_manager.log_signal.connect(textLog.add_log)
- }
- }}
- }
- Component.onCompleted:{
- process_manager.sig_update_task.connect(update_task)
- process_manager.sig_update_pending.connect(update_pending)
- process_manager.sig_update_waiting.connect(update_waiting)
- startInit.start()
- }
- function update_task(config, data){
- if(typeof data !== "string"){
- console.error("Pass an incorrect type")
- return
- }
- if(config !== configName){
- return
- }
- task_running.setData(data)
- }
- function update_pending(config, data){
- if(typeof data !== "string"){
- console.error("Pass an incorrect type")
- return
- }
- if(config !== configName){
- return
- }
- if(data === "[]"){
- pendingListModel.clear()
- return
- }
- pendingListModel.clear()
- const d = JSON.parse(data)
- for(var item of d){
- pendingListModel.append(item)
- }
- }
- function update_waiting(config, data){
- if(typeof data !== "string"){
- console.error("Pass an incorrect type")
- return
- }
- if(config !== configName){
- return
- }
- if(data === "[]"){
- waitingListModel.clear()
- return
- }
- waitingListModel.clear()
- const d = JSON.parse(data)
- for(var item of d){
- waitingListModel.append(item)
- }
- }
- function setStatus(s){
- overStatus.runStatus = s
- }
- }
|