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

歡迎光臨散文網(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é)點的評論 (共 條)

分享到微博請遵守國家法律
遂溪县| 新疆| 怀远县| 阿合奇县| 南川市| 济宁市| 正阳县| 松潘县| 廊坊市| 英德市| 自治县| 静乐县| 民丰县| 句容市| 天峨县| 临清市| 巴彦县| 庄河市| 安溪县| 大庆市| 南投市| 龙里县| 江安县| 积石山| 资讯 | 佛坪县| 青神县| 郸城县| 若尔盖县| 广德县| 孟州市| 翼城县| 平原县| 灵宝市| 广元市| 寿光市| 阳曲县| 桐乡市| 克拉玛依市| 温宿县| 南投县|