最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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ó)家法律
施甸县| 兴和县| 崇左市| 上杭县| 五莲县| 亚东县| 根河市| 临沧市| 邳州市| 锦州市| 塔河县| 神农架林区| 汉源县| 依安县| 淄博市| 澄迈县| 利津县| 阳城县| 咸阳市| 海口市| 蓬莱市| 平湖市| 灌阳县| 正蓝旗| 汝阳县| 独山县| 永新县| 冷水江市| 虎林市| 个旧市| 珠海市| 沙湾县| 壶关县| 深水埗区| 浙江省| 丹巴县| 尚义县| 南雄市| 绵阳市| 拉萨市| 宣武区|