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

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

TDesign TreeSelect一次性加載所有數(shù)據(jù)并展開所有節(jié)點

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

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

前端(TDesign Starter 0.7.2 + vue 3.2.45)

控件(TDesign TreeSelect控件)


對應(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; } //父級DeptId


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


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


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

}


1.后端傳遞數(shù)據(jù)的模型

public class TreeNode

? ? {

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

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

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

? ? }

2.后端遞歸取整表數(shù)據(jù)

public Result<List<TreeNode>> GetDeptTreeNodes()

? ? ? ? {

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

? ? ? ? ? ? List<TreeNode>? kids = DeptGetKids(0);

? ? ? ? ? ? if (kids == null)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? result.Err("沒有部門數(shù)據(jù)");

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? result.Data = kids;

? ? ? ? ? ? }

? ? ? ? ? ? return result;

? ? ? ? }

? ? ? ? private List<TreeNode>? DeptGetKids(int parentId)

? ? ? ? {

? ? ? ? ? ? TestLog("parentId = " + parentId.ToString());

? ? ? ? ? ? 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 });

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? else

? ? ? ? ? ? ? ? {

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

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? return nodes;

? ? ? ? }



3.前端一次性加載所有數(shù)據(jù)

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

export interface TreeNodeModel {

? value: string;

? label: string;

? children?: Array<TreeNodeModel>;

}


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

const Api = {

? DeptTreeNodes: '/BasicInfo/GetDeptTreeNodes',

};

export function getDeptTreeNodes() {

? return request.get({

? ? url: Api.DeptTreeNodes,

? });

}


③vue文件template

<t-tree ref="tree" :data="items" checkable hover expand-all :lazy="false" />


④vue文件setup script

import { onMounted, ref } from 'vue';

import { MessagePlugin } from 'tdesign-vue-next';

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

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


const depts = ref<Array<TreeNodeModel>>([]);

onMounted(async () => {

? depts.value = await getDept();

});

// 從api取所有部門的數(shù)據(jù)

const getDept = async () => {

? try {

? ? const result = await getDeptTreeNodes();

? ? return result;

? } catch (error) {

? ? MessagePlugin.error(error.message || '獲取部門數(shù)據(jù)失敗,請稍后再試');

? ? return [];

? }

};


TDesign TreeSelect一次性加載所有數(shù)據(jù)并展開所有節(jié)點的評論 (共 條)

分享到微博請遵守國家法律
治多县| 遵义市| 天峨县| 安仁县| 色达县| 顺平县| 当涂县| 积石山| 东源县| 修文县| 高尔夫| 黄梅县| 阿鲁科尔沁旗| 沂水县| 饶阳县| 建湖县| 汝州市| 运城市| 夏邑县| 如皋市| 潼关县| 鸡东县| 高阳县| 防城港市| 油尖旺区| 清苑县| 连山| 邛崃市| 浏阳市| 焦作市| 曲靖市| 奉节县| 五台县| 嘉禾县| 宕昌县| 云南省| 陆良县| 宝兴县| 习水县| 景宁| 广州市|