五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

TDesign TreeSelect逐級(jí)加載數(shù)據(jù)逐級(jí)展開(kāi)節(jié)點(diǎn)

2023-03-18 19:51 作者:飛天蝸牛狼  | 我要投稿

后臺(tái)(ASP.NET Core,目標(biāo)框架.net 7,除FreeSql外,用到包WinReal.Base)

前端(TDesign Starter 0.7.2 + vue 3.2.45)

控件(TDesign TreeSelect控件)


對(duì)應(yīng)數(shù)據(jù)結(jié)構(gòu)

public class Dept

{

? ? [Column(IsIdentity = true, IsPrimary = true)]

? ? public int DeptId { get; set; }


? ? public string DeptName { get; set; } = "";


? ? public int ParentId { get; set; } //父級(jí)DeptId


? ? public int OrderId { get; set; } //當(dāng)前節(jié)點(diǎn)完整子樹(shù)起始,本身節(jié)點(diǎn)次序值


? ? public int MaxOrderId { get; set; } //當(dāng)前節(jié)點(diǎn)完整子樹(shù)最后一個(gè)節(jié)點(diǎn)的次序值


? ? public int Depth { get; set; } //當(dāng)前節(jié)點(diǎn)所在深度,TDesign中用不到

}


1.后端傳遞數(shù)據(jù)的模型,結(jié)構(gòu)適用于TDesign的t-tree控件

public class TreeNode

? ? {

? ? ? ? public string Value { get; set; } = "";

? ? ? ? public string Label { get; set; } = "";

? ? ? ? public Boolean Children { get; set; } = false;

? ? ? ? public List<TreeNode>? Kids { get; set; }

? ? }


2.后端每次只返回指定父級(jí)的直隸子級(jí)

public Result<List<TreeNode>> GetDeptKidNodes(int parentId)

? ? ? ? {

? ? ? ? ? ? Result<List<TreeNode>> result = new();

? ? ? ? ? ? List<TreeNode> nodes = new List<TreeNode>();

? ? ? ? ? ? var depts = _fsql.Select<Dept>().Where(a => a.ParentId == parentId).OrderBy(a => a.OrderId).ToList();

? ? ? ? ? ? TestLog(JsonSerializer.Serialize(depts));

? ? ? ? ? ? foreach (Dept dept in depts)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? TestLog(dept.DeptName);

? ? ? ? ? ? ? ? if (dept.OrderId == dept.MaxOrderId)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? nodes.Add(new TreeNode { Value = dept.DeptId.ToString(), Label = dept.DeptName, Children = false });

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? else

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? nodes.Add(new TreeNode { Value = dept.DeptId.ToString(), Label = dept.DeptName, Children = true, Kids = DeptGetKids(dept.DeptId) });

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? if (nodes == null)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? result.Err("沒(méi)有子部門(mén)");

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? result.Data = nodes;

? ? ? ? ? ? }

? ? ? ? ? ? return result;

? ? ? ? }


3.前端逐級(jí)展開(kāi)

①api接口:src\api\model\basicinfoModel.ts

export interface TreeNodeModel {

? value: string;

? label: string;

? // children?: Array<TreeNodeModel>;

? children: boolean;

? kids?: Array<TreeNodeModel>;

}


②api接口:src\api\basicinfo.ts

const Api = {

? DeptKidNodes: '/BasicInfo/GetDeptKidNodes',

};

export function getDeptKidNodes(parentId) {

? return request.get({

? ? url: Api.DeptKidNodes,

? ? params: { parentId },

? });

}


③vue文件template

<t-tree ref="tree" :data="items" checkable hover :load="load" />


④vue文件setup script

import { getDeptKidNodes } from '@/api/basicinfo';

import { TreeNodeModel } from '@/api/model/basicinfoModel';


const items = ref<Array<TreeNodeModel>>([

? {

? ? value: '0',

? ? label: '部門(mén)管理',

? ? children: true,

? },

]);

const load = (node) =>

? new Promise((resolve) => {

? ? setTimeout(async () => {

? ? ? const nodes = await getKids(node.value);

? ? ? resolve(nodes);

? ? }, 1000);

? });

const getKids = async (parentId) => {

? const result = await getDeptKidNodes(parentId);

? return result;

};


TDesign TreeSelect逐級(jí)加載數(shù)據(jù)逐級(jí)展開(kāi)節(jié)點(diǎn)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
上蔡县| 凤庆县| 和林格尔县| 密云县| 伊春市| 略阳县| 尖扎县| 柳河县| 阳春市| 重庆市| 府谷县| 景泰县| 宁强县| 清流县| 上思县| 湘潭市| 潢川县| 合肥市| 卓资县| 大兴区| 虞城县| 郯城县| 伊春市| 钟山县| 明光市| 化隆| 蓬溪县| 原阳县| 根河市| 类乌齐县| 孝感市| 汪清县| 从江县| 龙泉市| 澄城县| 福建省| 灵台县| 山阳县| 靖宇县| 浦东新区| 潼南县|