SplitPanel.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. Item {
  5. signal clickMessage(string text)
  6. // 左边菜单
  7. FluArea{
  8. id: menuArea
  9. anchors.left: parent.left
  10. height: parent.height
  11. width: 200
  12. FluTreeView{
  13. id: menu_tree
  14. anchors.fill: parent
  15. selectionMode: FluTabView.SizeToContent
  16. onItemClicked:(model)=>{
  17. clickMessage(model.text)
  18. showSuccess(model.text)
  19. }
  20. }
  21. }
  22. // 右边内容
  23. Loader{
  24. id: contentDefalut
  25. anchors.right: parent.right
  26. anchors.rightMargin: 12
  27. anchors.left: menuArea.right
  28. anchors.leftMargin: 12
  29. anchors.top: parent.top
  30. anchors.bottom: parent.bottom
  31. anchors.bottomMargin: 12
  32. }
  33. Loader{
  34. id: contentLoader
  35. anchors.right: parent.right
  36. anchors.rightMargin: 12
  37. anchors.left: menuArea.right
  38. anchors.leftMargin: 12
  39. anchors.top: parent.top
  40. anchors.bottom: parent.bottom
  41. anchors.bottomMargin: 12
  42. }
  43. Component.onCompleted: {
  44. var datas = []
  45. datas.push(menu_tree.createItem("Home",false))
  46. datas.push(menu_tree.createItem("Update",false))
  47. // datas.push(menu_tree.createItem("Node2",true,[createItem("Node2-1",false),createItem("Node2-2",false)]))
  48. menu_tree.updateData(datas)
  49. }
  50. //创建左边的菜单,最多两级
  51. //['home', 'xxx':['x1', 'x2']]
  52. function create(data){
  53. var datas = []
  54. for(var items in data){
  55. if(items.length === 0){
  56. datas.push(menu_tree.createItem(items,false))
  57. }else{
  58. var da = []
  59. for(var item in data[items]){
  60. da.push(menu_tree.createItem(data[items][item], false))
  61. }
  62. datas.push(menu_tree.createItem(items, true, da))
  63. }
  64. }
  65. menu_tree.updateData(datas)
  66. // for(let items of data){
  67. // if(items.length === 'string'){
  68. // datas.push(menu_tree.createItem(items,false))
  69. // }else{
  70. // var da = []
  71. // for(let item of items){
  72. // da.push(menu_tree.createItem(item,false))
  73. // }
  74. // datas.push(menu_tree.createItem(items, true, da))
  75. // }
  76. // }
  77. }
  78. //右侧的分为两个部分一个部分是contentDefalut表示固定的不动的
  79. //第二个部分是一个加载器动态加载不同的组件
  80. //显示固定的部分
  81. function showDefalut(){
  82. contentDefalut.visible = true
  83. contentLoader.visible = false
  84. }
  85. //显示不固定的
  86. function showLoader(){
  87. contentDefalut.visible = false
  88. contentLoader.visible = true
  89. }
  90. //设置固定的部分的具体内容 主要是传一个组件
  91. function setDefalut(component){
  92. contentDefalut.sourceComponent = component
  93. showDefalut()
  94. }
  95. //
  96. function setLoader(component){
  97. contentLoader.sourceComponent = component
  98. showLoader()
  99. }
  100. //获取固定的部分的对象的,方便更改属性
  101. // function getDefalut(){
  102. // return contentDefalut.item
  103. // }
  104. // //方便更改属性
  105. // function getDefalut(){
  106. // return contentLoader.item
  107. // }
  108. }