SplitPanel.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. }
  36. Loader{
  37. id: contentLoader
  38. anchors.right: parent.right
  39. anchors.rightMargin: 12
  40. anchors.left: menuArea.right
  41. anchors.leftMargin: 12
  42. anchors.top: parent.top
  43. anchors.bottom: parent.bottom
  44. anchors.bottomMargin: 12
  45. }
  46. //创建左边的菜单,最多两级
  47. //['home', 'xxx':['x1', 'x2']] 是英文的
  48. function create(data){
  49. var datas = []
  50. for(var items in data){
  51. if(items.length === 0){
  52. datas.push(menu_tree.createItem(qsTr(items),false))
  53. }else{
  54. var da = []
  55. for(var item in data[items]){
  56. if (typeof data[items][item] !== "string") {
  57. continue
  58. }
  59. da.push(menu_tree.createItem(qsTr(data[items][item]), false))
  60. }
  61. datas.push(menu_tree.createItem(qsTr(items), true, da))
  62. }
  63. }
  64. menu_tree.updateData(datas)
  65. }
  66. //右侧的分为两个部分一个部分是contentDefalut表示固定的不动的
  67. //第二个部分是一个加载器动态加载不同的组件
  68. //显示固定的部分
  69. function showDefalut(){
  70. contentDefalut.visible = true
  71. contentLoader.visible = false
  72. }
  73. //显示不固定的
  74. function showLoader(){
  75. contentDefalut.visible = false
  76. contentLoader.visible = true
  77. }
  78. //设置固定的部分的具体内容 主要是传一个组件
  79. function setDefalut(component){
  80. contentDefalut.sourceComponent = component
  81. showDefalut()
  82. }
  83. //
  84. function setLoader(component){
  85. contentLoader.sourceComponent = component
  86. showLoader()
  87. }
  88. //获取固定的部分的对象的,方便更改属性
  89. // function getDefalut(){
  90. // return contentDefalut.item
  91. // }
  92. // //方便更改属性
  93. // function getDefalut(){
  94. // return contentLoader.item
  95. // }
  96. }