TaskList.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. import FluentUI
  5. import '../Global'
  6. Item{
  7. id: taskList
  8. signal click(string title)
  9. onClick: {
  10. }
  11. FluScrollablePage{
  12. id: contentScrollable
  13. width: 800
  14. height: parent.height
  15. spacing: 12
  16. anchors.horizontalCenter: parent.horizontalCenter
  17. }
  18. // 任务组
  19. Component{
  20. id: group_item
  21. FluExpander{
  22. id: expander
  23. property string groupName: ""
  24. property string groupTitle: ""
  25. property var argumentValue: {""}
  26. property alias model: groupModel
  27. expand: true
  28. headerText: qsTr(groupTitle)
  29. width: contentScrollable.width
  30. contentHeight: groupGridView.height + 20
  31. ListModel{
  32. id: groupModel
  33. }
  34. GridLayout{
  35. id: groupGridView
  36. clip: true
  37. columns: 3
  38. anchors{
  39. top: parent.top
  40. topMargin: 12
  41. left: parent.left
  42. leftMargin: 12
  43. right: parent.right
  44. rightMargin: 15
  45. bottomMargin: 12
  46. }
  47. Repeater {
  48. delegate: task_item
  49. model: groupModel
  50. }
  51. }
  52. }
  53. }
  54. // 任务小项
  55. Component{
  56. id: task_item
  57. FluArea{
  58. id: task_root
  59. width: 250
  60. height: 50
  61. visible: true
  62. color: FluTheme.dark ? Window.active ? Qt.rgba(38/255,44/255,54/255,1) : Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1)
  63. property alias name: taskName.text
  64. property alias nextRun: taskTime.text
  65. property alias enable: taskEnable.selected
  66. FluText{
  67. id: taskName
  68. anchors{
  69. left: parent.left
  70. leftMargin: 6
  71. top: parent.top
  72. topMargin: 6
  73. }
  74. text: qsTr( model.task)
  75. font: FluTextStyle.BodyStrong
  76. }
  77. FluText{
  78. id: taskTime
  79. anchors{
  80. left: parent.left
  81. leftMargin: 6
  82. bottom: parent.bottom
  83. bottomMargin: 6
  84. }
  85. text: model.next_run
  86. font: FluTextStyle.Caption
  87. }
  88. FluCheckBox{
  89. id: taskEnable
  90. anchors{
  91. right: settingButton.left
  92. rightMargin: 6
  93. verticalCenter: parent.verticalCenter
  94. }
  95. selected: model.enable
  96. // onSelectedChanged: {
  97. // if(process_manager.gui_set_task_bool(MainEvent.scriptName, task_root.name, 'scheduler', 'enable', selected)){
  98. // showSuccess("Enable")
  99. // return true
  100. // }
  101. // showSuccess('Disenable')
  102. // }
  103. clickFunc: function click_func(){
  104. selected = !selected
  105. if(process_manager.gui_set_task_bool(MainEvent.scriptName, model.task, 'scheduler', 'enable', selected)){
  106. showSuccess("Enable")
  107. return true
  108. }
  109. showSuccess('Disenable')
  110. }
  111. text: ''
  112. }
  113. FluButton{
  114. id: settingButton
  115. anchors{
  116. right: parent.right
  117. rightMargin: 10
  118. verticalCenter: parent.verticalCenter
  119. }
  120. text:"setting"
  121. onClicked: {
  122. showSuccess(name)
  123. taskList.click(name)
  124. taskList.parent.parent.title = model.task
  125. }
  126. }
  127. }
  128. }
  129. Component.onCompleted:{
  130. const data = JSON.parse(process_manager.gui_task_list(MainEvent.scriptName))
  131. const menu = JSON.parse(process_manager.gui_menu())
  132. for(const key in menu){
  133. if(key === "Overview" || key === 'TaskList' || key === 'Script' || key === 'Tools'){
  134. continue
  135. }
  136. const groupData = classify(menu[key], data)
  137. create_group(key, groupData)
  138. }
  139. }
  140. // 分类对每一个任务组,
  141. // 第一个参数是这个菜单组的所有, 如["Script", "Restart", "GlobalGame"]
  142. // 第二个参数是整个的数据
  143. // 会提取data的数据 返回一个dict
  144. function classify(group, data){
  145. const result = {}
  146. for(const item in data){
  147. if(group.includes(item)){
  148. result[item] = data[item]
  149. }
  150. }
  151. return result
  152. }
  153. // 创建一个的任务组
  154. function create_group(groupName, groupData){
  155. const object = group_item.createObject(contentScrollable)
  156. if(object === null){
  157. console.error('Create group item failed!')
  158. }
  159. object.groupName = groupName
  160. object.groupTitle = qsTr(groupName)
  161. object.argumentValue = groupData
  162. for(const key in groupData){
  163. const item ={"task": key,
  164. "enable": groupData[key]["enable"],
  165. "next_run": groupData[key]["next_run"]}
  166. object.model.append(item)
  167. }
  168. contentScrollable.content.push(object)
  169. }
  170. }