2023-03-07 00:05:27 +08:00
|
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
import QtQuick.Window 2.15
|
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
|
import FluentUI 1.0
|
|
|
|
|
|
2023-03-10 18:08:32 +08:00
|
|
|
|
FluContentPage {
|
|
|
|
|
|
|
|
|
|
title:"TreeView"
|
2023-03-07 18:43:03 +08:00
|
|
|
|
|
2023-03-07 23:27:32 +08:00
|
|
|
|
function randomName() {
|
|
|
|
|
var names = ["张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十"]
|
|
|
|
|
return names[Math.floor(Math.random() * names.length)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function randomCompany() {
|
|
|
|
|
var companies = ["阿里巴巴", "腾讯", "百度", "京东", "华为", "小米", "字节跳动", "美团", "滴滴"]
|
|
|
|
|
return companies[Math.floor(Math.random() * companies.length)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function randomDepartment() {
|
|
|
|
|
var departments = ["技术部", "销售部", "市场部", "人事部", "财务部", "客服部", "产品部", "设计部", "运营部"]
|
|
|
|
|
return departments[Math.floor(Math.random() * departments.length)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createEmployee() {
|
|
|
|
|
var name = randomName()
|
|
|
|
|
return tree_view.createItem(name, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createSubtree(numEmployees) {
|
|
|
|
|
var employees = []
|
|
|
|
|
for (var i = 0; i < numEmployees; i++) {
|
|
|
|
|
employees.push(createEmployee())
|
2023-03-07 18:43:03 +08:00
|
|
|
|
}
|
2023-03-07 23:27:32 +08:00
|
|
|
|
return tree_view.createItem(randomDepartment(), true, employees)
|
2023-03-07 18:43:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 23:27:32 +08:00
|
|
|
|
function createOrg(numLevels, numSubtrees, numEmployees) {
|
|
|
|
|
if (numLevels === 0) {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
var subtrees = []
|
|
|
|
|
for (var i = 0; i < numSubtrees; i++) {
|
|
|
|
|
subtrees.push(createSubtree(numEmployees))
|
|
|
|
|
}
|
|
|
|
|
return [tree_view.createItem(randomCompany(), true, subtrees)].concat(createOrg(numLevels - 1, numSubtrees, numEmployees))
|
|
|
|
|
}
|
2023-03-07 18:43:03 +08:00
|
|
|
|
|
|
|
|
|
|
2023-03-07 00:05:27 +08:00
|
|
|
|
FluTreeView{
|
|
|
|
|
id:tree_view
|
2023-03-07 18:43:03 +08:00
|
|
|
|
width:240
|
2023-03-07 00:05:27 +08:00
|
|
|
|
anchors{
|
2023-03-10 18:08:32 +08:00
|
|
|
|
top:parent.top
|
2023-03-07 00:05:27 +08:00
|
|
|
|
left:parent.left
|
|
|
|
|
bottom:parent.bottom
|
|
|
|
|
}
|
2023-03-07 23:27:32 +08:00
|
|
|
|
onItemClicked:
|
|
|
|
|
(model)=>{
|
|
|
|
|
showSuccess(model.text)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2023-03-08 11:46:40 +08:00
|
|
|
|
var org = createOrg(3, 3, 3)
|
2023-03-07 23:27:32 +08:00
|
|
|
|
updateData(org)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 18:43:03 +08:00
|
|
|
|
}
|
2023-03-07 00:05:27 +08:00
|
|
|
|
|
|
|
|
|
|
2023-03-07 18:43:03 +08:00
|
|
|
|
ColumnLayout{
|
|
|
|
|
anchors{
|
|
|
|
|
left: tree_view.right
|
|
|
|
|
right: parent.right
|
|
|
|
|
top: parent.top
|
|
|
|
|
}
|
2023-03-07 23:27:32 +08:00
|
|
|
|
|
|
|
|
|
FluText{
|
|
|
|
|
text:{
|
|
|
|
|
if(tree_view.selectionMode === FluTreeView.None){
|
2023-03-08 11:46:40 +08:00
|
|
|
|
return "selectionMode->FluTreeView.None"
|
2023-03-07 23:27:32 +08:00
|
|
|
|
}
|
|
|
|
|
if(tree_view.selectionMode === FluTreeView.Single){
|
2023-03-08 11:46:40 +08:00
|
|
|
|
return "selectionMode->FluTreeView.Single"
|
2023-03-07 23:27:32 +08:00
|
|
|
|
}
|
|
|
|
|
if(tree_view.selectionMode === FluTreeView.Multiple){
|
2023-03-08 11:46:40 +08:00
|
|
|
|
return "selectionMode->FluTreeView.Multiple"
|
2023-03-07 23:27:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 18:43:03 +08:00
|
|
|
|
FluButton{
|
2023-03-07 23:27:32 +08:00
|
|
|
|
text:"None"
|
2023-03-07 18:43:03 +08:00
|
|
|
|
onClicked: {
|
2023-03-07 23:27:32 +08:00
|
|
|
|
tree_view.selectionMode = FluTreeView.None
|
2023-03-07 18:43:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 23:27:32 +08:00
|
|
|
|
FluButton{
|
|
|
|
|
text:"Single"
|
|
|
|
|
onClicked: {
|
|
|
|
|
tree_view.selectionMode = FluTreeView.Single
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FluButton{
|
|
|
|
|
text:"Multiple"
|
|
|
|
|
onClicked: {
|
|
|
|
|
tree_view.selectionMode = FluTreeView.Multiple
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FluFilledButton{
|
|
|
|
|
text:"获取选中的数据"
|
|
|
|
|
onClicked: {
|
|
|
|
|
if(tree_view.selectionMode === FluTreeView.None){
|
|
|
|
|
showError("当前非选择模式,没有选中的数据")
|
|
|
|
|
}
|
|
|
|
|
if(tree_view.selectionMode === FluTreeView.Single){
|
2023-03-08 13:41:43 +08:00
|
|
|
|
if(!tree_view.signleData()){
|
|
|
|
|
showError("没有选中数据")
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-03-07 23:27:32 +08:00
|
|
|
|
showSuccess(tree_view.signleData().text)
|
|
|
|
|
}
|
|
|
|
|
if(tree_view.selectionMode === FluTreeView.Multiple){
|
|
|
|
|
if(tree_view.multipData().length===0){
|
|
|
|
|
showError("没有选中数据")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var info = []
|
|
|
|
|
tree_view.multipData().map((value)=>info.push(value.text))
|
|
|
|
|
showSuccess(info.join(","))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2023-03-07 00:05:27 +08:00
|
|
|
|
}
|