SplitPanel.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. import "../Global"
  5. Item {
  6. id: splitPanel
  7. property string title: ""
  8. // 左边菜单
  9. FluArea{
  10. id: menuArea
  11. anchors.left: parent.left
  12. height: parent.height
  13. width: 200
  14. FluTreeView{
  15. id: menu_tree
  16. anchors.fill: parent
  17. selectionMode: FluTabView.SizeToContent
  18. onItemClicked:(model)=>{
  19. MainEvent.menuTitle = model.text
  20. splitPanel.title = model.text
  21. showSuccess(model.text)
  22. }
  23. }
  24. }
  25. // 右边内容
  26. Loader{
  27. id: contentDefalut
  28. anchors.right: parent.right
  29. anchors.rightMargin: 12
  30. anchors.left: menuArea.right
  31. anchors.leftMargin: 12
  32. anchors.top: parent.top
  33. anchors.bottom: parent.bottom
  34. anchors.bottomMargin: 12
  35. onLoaded: {
  36. if (!contentDefalut.item)
  37. return
  38. if(typeof contentDefalut.item.splitPanel === "undefined"){
  39. return
  40. }
  41. contentDefalut.item.splitPanel = menuArea.parent
  42. }
  43. }
  44. Loader{
  45. id: contentLoader
  46. anchors.right: parent.right
  47. anchors.rightMargin: 12
  48. anchors.left: menuArea.right
  49. anchors.leftMargin: 12
  50. anchors.top: parent.top
  51. anchors.bottom: parent.bottom
  52. anchors.bottomMargin: 12
  53. }
  54. //创建左边的菜单,最多两级
  55. //['home', 'xxx':['x1', 'x2']] 是英文的
  56. function create(data){
  57. var datas = []
  58. for(var items in data){
  59. if(items.length === 0){
  60. datas.push(menu_tree.createItem(items,false))
  61. }else{
  62. var da = []
  63. for(var item in data[items]){
  64. if (typeof data[items][item] !== "string") {
  65. continue
  66. }
  67. da.push(menu_tree.createItem(data[items][item], false))
  68. }
  69. datas.push(menu_tree.createItem(items, true, da))
  70. }
  71. }
  72. menu_tree.updateData(datas)
  73. }
  74. //右侧的分为两个部分一个部分是contentDefalut表示固定的不动的
  75. //第二个部分是一个加载器动态加载不同的组件
  76. //显示固定的部分
  77. function showDefalut(){
  78. contentDefalut.visible = true
  79. contentLoader.visible = false
  80. contentDefalut.focus = true
  81. }
  82. //显示不固定的
  83. function showLoader(){
  84. contentDefalut.visible = false
  85. contentLoader.visible = true
  86. contentLoader.focus = true
  87. }
  88. //设置固定的部分的具体内容 主要是传一个组件
  89. function setDefalut(component){
  90. contentDefalut.sourceComponent = component
  91. showDefalut()
  92. }
  93. //
  94. function setLoader(component){
  95. contentLoader.sourceComponent = component
  96. showLoader()
  97. }
  98. //获取固定的部分的对象的,方便更改属性
  99. // function getDefalut(){
  100. // return contentDefalut.item
  101. // }
  102. //方便更改属性
  103. // function getDefalut(){
  104. // return contentLoader.item
  105. // }
  106. //设置右边显示的参数项,输入的序列的字符串
  107. function setLoaderData(args, value){
  108. if (!contentLoader.item) {
  109. console.log("SplitPanel: contentLoader.item is null in setLoaderData")
  110. return
  111. }
  112. contentLoader.item.argsData = args
  113. contentLoader.item.valueData = value
  114. contentLoader.item.updataData()
  115. }
  116. //设置上下文
  117. function setLoaderContext(configName, taskName){
  118. if (!contentLoader.item) {
  119. console.log("SplitPanel: contentLoader.item is null in setLoaderContext")
  120. return
  121. }
  122. contentLoader.item.configName = configName
  123. contentLoader.item.taskName = taskName
  124. }
  125. //设置配置的名称
  126. function setDefalutConfig(name){
  127. if (!contentDefalut.item) {
  128. console.log("SplitPanel: contentDefalut.item is null in setDefalutConfig")
  129. return
  130. }
  131. contentDefalut.item.configName = name
  132. }
  133. }