Tree 树形组件封装
整体思路
-
数据结构设计
- 使用递归的数据结构(
TreeNode
)表示树形数据 - 每个节点包含
id
、name
、可选的children
数组和selected
状态
- 使用递归的数据结构(
-
状态管理
- 使用
useState
在组件内部维护树状态的副本 - 通过
deepCopyTreeData
函数进行深拷贝,避免直接修改原始数据
- 使用
-
核心功能实现
checkChildrenStatus
:检查子节点状态,用于确定父节点的选中状态updateNodeStatus
:递归更新节点状态,实现状态联动效果findUpdatedNode
:在更新后的树中查找特定节点
-
状态同步逻辑
- 父节点选中/取消时,所有子节点跟随变化
- 子节点全部选中时,父节点自动选中
- 子节点全部未选中时,父节点自动取消选中
-
组件渲染
- 使用递归的
renderTreeNodes
函数渲染任意深度的树结构 - 每个节点包含复选框和名称,子节点通过缩进展示层级关系
- 使用递归的
-
外部交互
- 通过
onChange
回调将状态变化通知给父组件 - 使用
useEffect
监听外部数据变化,同步更新内部状态
- 通过
组件目录结构
代码实现
example\App.tsx
import React from "react";
import { Tree, type TreeNode } from "../packages";export default function App() {const data: TreeNode[] = [{id: 1,name: "Node 1",children: [{ id: 2, name: "Node 1.1", selected: true },{id: 3,name: "Node 1.2",selected: false,children: [{ id: 4, name: "Node 1.2.1", selected: false },{ id: 5, name: "Node 1.2.2", selected: false },],},],selected: true,},{ id: 6, name: "Node 2", selected: false },];function onChange(node: TreeNode) {console.log(node);}return (<div><Tree data={data} onChange={onChange} /></div>);
};
example\index.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><div id="root"></div><script type="module" src="./main.tsx"></script>
</body>
</html>
example\main.tsx
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(<App />
);
packages\Tree\src\tree.tsx
import React, { useEffect, useState } from "react";
import { TreeNode, TreeProps } from "./types";// 检查所有子节点状态并返回父节点应该的状态
const checkChildrenStatus = (node: TreeNode): boolean => {if (!node.children || node.children.length === 0) {return !!node.selected;}// 检查是否所有子节点都被选中const allSelected = node.children.every((child) =>child.children && child.children.length > 0? checkChildrenStatus(child): !!child.selected);return allSelected;
};// 深度复制树数据
const deepCopyTreeData = (data: TreeNode[]): TreeNode[] => {return data.map((node) => ({...node,children: node.children ? deepCopyTreeData(node.children) : undefined,}));
};// 更新节点状态
const updateNodeStatus = (nodes: TreeNode[],nodeId: string | number,status: boolean
): TreeNode[] => {return nodes.map((node) => {if (node.id === nodeId) {// 更新当前节点const updatedNode = { ...node, selected: status };// 如果有子节点,递归更新所有子节点if (node.children && node.children.length > 0) {updatedNode.children = updateNodeStatus(node.children, nodeId, status);// 再对所有子节点应用相同的状态updatedNode.children = updatedNode.children.map((child) => ({...child,selected: status,children: child.children? child.children.map((grandChild) => ({...grandChild,selected: status,})): undefined,}));}return updatedNode;} else if (node.children && node.children.length > 0) {// 递归检查子节点const updatedChildren = updateNodeStatus(node.children, nodeId, status);// 检查更新后的子节点状态以决定当前节点状态const allChildrenSelected = updatedChildren.every((child) => !!child.selected);const noChildrenSelected = updatedChildren.every((child) => !child.selected);let nodeStatus = node.selected;if (allChildrenSelected) {nodeStatus = true;} else if (noChildrenSelected) {nodeStatus = false;}return {...node,selected: nodeStatus,children: updatedChildren,};}return node;});
};const Tree: React.FC<TreeProps> = ({ data, onChange }) => {const [treeData, setTreeData] = useState<TreeNode[]>(deepCopyTreeData(data));// 处理节点选择状态变化const handleNodeChange = (node: TreeNode, checked: boolean) => {// 创建更新后的树数据const updatedTreeData = updateNodeStatus(deepCopyTreeData(treeData),node.id,checked);// 更新状态setTreeData(updatedTreeData);// 找到更新后的节点并调用onChangeconst findUpdatedNode = (nodes: TreeNode[],id: string | number): TreeNode | undefined => {for (const n of nodes) {if (n.id === id) return n;if (n.children) {const found = findUpdatedNode(n.children, id);if (found) return found;}}return undefined;};const updatedNode = findUpdatedNode(updatedTreeData, node.id);if (updatedNode && onChange) {onChange(updatedNode);}};// 渲染树节点const renderTreeNodes = (nodes: TreeNode[]) => {return nodes.map((node) => (<div key={node.id} className="tree-node"><inputtype="checkbox"checked={!!node.selected}onChange={(e) => handleNodeChange(node, e.target.checked)}/><span>{node.name}</span>{node.children && node.children.length > 0 && (<div className="children-container" style={{ marginLeft: "20px" }}>{renderTreeNodes(node.children)}</div>)}</div>));};// 当外部data props变化时更新内部状态useEffect(() => {setTreeData(deepCopyTreeData(data));}, [data]);return <div className="tree">{renderTreeNodes(treeData)}</div>;
};export default Tree;
packages\Tree\src\types.tsx
export interface TreeNode {id: string | number;name: string;children?: TreeNode[];selected: boolean;
}export interface TreeProps {data: TreeNode[];onChange: (node: TreeNode) => void;
}
packages\Tree\style\index.tsx (暂时无样式编写)
packages\Tree\tree.tsx
import Tree from "./src/tree";export * from "./src/types";
export { Tree };
packages\index.tsx
import { Tree } from "./Tree";export * from "./Tree";
export { Tree };
packages\vite.d.ts
/// <reference types="vite/client" />
package.json (通过 npm init -y 生成)
这样直接启动会有一个警告:The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
原因是 node 项目模块化未指定类型 type: module
{"name": "react-tree","version": "1.0.0","main": "index.js","type": "module","directories": {"example": "example"},"scripts": {"dev": "vite","build": "vite build"},"keywords": [],"author": "","license": "ISC","description": "","devDependencies": {"@types/node": "^22.15.29","@types/react": "^19.1.6","@types/react-dom": "^19.1.5","@vitejs/plugin-react-swc": "^3.10.0", // 编译 react"vite": "^6.3.5", // 构建工具 "vite-plugin-dts": "^4.5.4" // 生成打包后的声明文件(便于代码提示)},"dependencies": {"react": "^19.1.0","react-dom": "^19.1.0"}
}
tsconfig.json(通过 tsc --init 生成)
{"compilerOptions": {/* Visit https://aka.ms/tsconfig to read more about this file *//* Projects */// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. *//* Language and Environment */"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */"jsx": "react-jsx", /* Specify what JSX code is generated. */// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. *//* Modules */"module": "commonjs", /* Specify what module code is generated. */// "rootDir": "./", /* Specify the root folder within your source files. */// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */// "types": [], /* Specify type package names to be included without being referenced in a source file. */// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */// "resolveJsonModule": true, /* Enable importing .json files. */// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. *//* JavaScript Support */// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. *//* Emit */// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */// "declarationMap": true, /* Create sourcemaps for d.ts files. */// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */// "sourceMap": true, /* Create source map files for emitted JavaScript files. */// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */// "outDir": "./", /* Specify an output folder for all emitted files. */// "removeComments": true, /* Disable emitting comments. */// "noEmit": true, /* Disable emitting files from a compilation. */// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */// "newLine": "crlf", /* Set the newline character for emitting files. */// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */// "declarationDir": "./", /* Specify the output directory for generated declaration files. */// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. *//* Interop Constraints */// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. *//* Type Checking */"strict": true, /* Enable all strict type-checking options. */// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. *//* Completeness */// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */"skipLibCheck": true /* Skip type checking all .d.ts files. */}
}
这样直接生成的会有一个问题:无法使用 JSX,除非提供了 "--jsx" 标志。
所以我们需要让 ts 配置(tsconfig.json)为支持 jsx 语法。"jsx": "react-jsx",
vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import path from "node:path";export default defineConfig({plugins: [react()],root: path.resolve(__dirname, "example"), // 如果不配置,默认会从根目录找 index.htmlserver: {port: 3000,open: true,},
});
相关文章:

Tree 树形组件封装
整体思路 数据结构设计 使用递归的数据结构(TreeNode)表示树形数据每个节点包含id、name、可选的children数组和selected状态 状态管理 使用useState在组件内部维护树状态的副本通过deepCopyTreeData函数进行深拷贝,避免直接修改原始数据 核…...

AI书签管理工具开发全记录(五):后端服务搭建与API实现
文章目录 AI书签管理工具开发全记录(四):后端服务搭建与API实现前言 📝1. 后端框架选型 🛠️2. 项目结构优化 📁3. API路由设计 🧭分类管理书签管理 4. 数据模型定义 💾分类模型&…...

netTAP 100:在机器人技术中将 POWERLINK 转换为 EtherNet/IP
工业机器人服务专家 年轻的 More Robots 公司成立仅一年多,但其在许多应用领域的专业技术已受到广泛欢迎。这是因为More Robots提供 360 度全方位服务,包括从高品质工业机器人和协作机器人到咨询和培训。这包括推荐适合特定任务或应用的机器人࿰…...

多模态大语言模型arxiv论文略读(九十八)
Accelerating Pre-training of Multimodal LLMs via Chain-of-Sight ➡️ 论文标题:Accelerating Pre-training of Multimodal LLMs via Chain-of-Sight ➡️ 论文作者:Ziyuan Huang, Kaixiang Ji, Biao Gong, Zhiwu Qing, Qinglong Zhang, Kecheng Zhe…...

EXCEL--累加,获取大于某个值的第一个数
一、函数 LET(data,A1:A5,cumSum,SCAN(0,data,LAMBDA(a,b,ab)),idx,MATCH(TRUE,cumSum>C1,0),INDEX(data,idx)) 二、函数拆解 1、LET函数:LET(name1, value1, [name2, value2, ...], calculation) name1, name2...:自定义的变量名(需以字…...
【vscode】切换英文字母大小写快捷键如何配置
按 ⌘(Command) Shift P 打开命令面板搜索 "Transform to Uppercase" 或 "Transform to Lowercase" 点击Transform to Uppercase 命令后的齿轮图标 进入设置页面 然后就可以进行配置了 比如我是mac电脑, 切换大写可以配置为 shift alt…...
vue笔记-路由
文章目录 createWebHistory的使用router-linkrouter-link颜色是黑色,正常应该是蓝色router-link 跳转了但是不展示 其他 vue这个题目还是太大,路由单独拆出来。 createWebHistory的使用 推荐在vue-router4中使用。 1、导入。 import { createRouter, c…...

本地部署 DeepSeek R1(最新)【从下载、安装、使用和调用一条龙服务】
文章目录 一、安装 Ollama1.1 下载1.2 安装 二、下载 DeepSeek 模型三、使用 DeepSeek3.1 在命令行环境中使用3.2 在第三方软件中使用 一、安装 Ollama 1.1 下载 官方网址:Ollama 官网下载很慢,甚至出现了下载完显示 无法下载,需要授权 目…...
域名解析怎么查询?有哪些域名解析查询方式?
在互联网的世界里,域名就像是我们日常生活中的门牌号,帮助我们快速定位到想要访问的网站。而域名解析则是将这个易记的域名转换为计算机能够识别的IP地址的关键过程。当我们想要了解一个网站的域名解析情况,或者排查网络问题时,掌…...

win主机如何结束正在执行的任务进程并重启
最近遇到一个问题,一个java入库程序经常在运行了几个小时之后消息无法入库,由于已经没有研发人员来维护这个程序了,故此只能每隔一段时间来重启这个程序以保证一直有消息入库。 但是谁也不能保证一直有人去看这个程序,并且晚上也不…...

maven中的maven-resources-plugin插件详解
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站 一、插件定位与核心功能 maven-resources-plugin是Maven构建工具的核心插件之一,主要用于处理项目中的资源文件(如…...

ROS云课基础篇-01-Linux-250529
ROS云课基础篇收到了很多反馈,正面评价比例高,还有很多朋友反馈需要写更具体一点。 ROS云课基础篇极简复习-C、工具、导航、巡逻一次走完-CSDN博客 于是,有了这篇以及之后的案例,案例均已经测试过8年,但没有在博客公…...
通俗易懂解析:@ComponentScan 与 @MapperScan 的异同与用法
在 Spring 和 MyBatis 集成开发中,ComponentScan 和 MapperScan 是两个核心注解,但它们的用途和工作机制截然不同。本文将通过通俗的语言和示例代码,带您轻松掌握它们的区别和使用方法。 一、基础概念 ComponentScan:Spring 的“通…...

深入了解 C# 异步编程库 AsyncEx
在现代应用程序开发中,异步编程已经成为提升性能和响应能力的关键,尤其在处理网络请求、I/O 操作和其他耗时任务时,异步编程可以有效避免阻塞主线程,提升程序的响应速度和并发处理能力。C# 提供了内建的异步编程支持(通…...
NodeJS全栈开发面试题讲解——P1Node.js 基础与核心机制
✅ 1.1 Node.js 的事件循环原理?如何处理异步操作? 面试官您好,我理解事件循环是 Node.js 的异步非阻塞编程核心。 Node.js 构建在 V8 引擎与 libuv 库之上。虽然 Node.js 是单线程模型,但它通过事件循环(event loop&a…...

Vulhub靶场搭建(Ubuntu)
前言:Vulhub 是一个开源的漏洞靶场平台,全称是 Vulhub: Vulnerable Web Application Environments,主要用于学习和复现各类 Web 安全漏洞。它的核心特征是通过 Docker 环境快速搭建出带有特定漏洞的靶场系统,适合渗透测试学习者、…...

C++:参数传递方法(Parameter Passing Methods)
目录 1. 值传递(Pass by Value) 2. 地址传递(Pass by Address) 3. 引用传递(Pass by Reference) 数组作为函数参数(Array as Parameter) 数组作为函数返回值 什么是函数ÿ…...

大语言模型的推理能力
2025年,各种会推理的AI模型如雨后春笋般涌现,比如ChatGPT o1/o3/o4、DeepSeek r1、Gemini 2 Flash Thinking、Claude 3.7 Sonnet (Extended Thinking)。 对于工程上一些问题比如复杂的自然语言转sql,我们可能忍受模型的得到正确答案需要更多…...
基于BERT和GPT2的实现来理解Transformer的结构和原理
Transformer 核心就是编码器和解码器,简单理解:编码器就是特征提取,解码器就是特征还原。 Transformer 完整架构 Transformer最初是一个Encoder-Decoder架构,用于机器翻译任务: 输入序列 → [Encoder] → 编码表示…...
.net consul服务注册与发现
.NET中Consul服务注册与发现的技术实践 在微服务架构中,服务的注册与发现是至关重要的环节,它能帮助各个服务之间实现高效的通信和协作。Consul作为一款功能强大的工具,为我们提供了优秀的服务注册与发现解决方案。今天,我们就来…...
WifiEspNow库函数详解
WifiEspNow库 项目地址https://github.com/yoursunny/WifiEspNow WifiEspNow 是 ESP-NOW 的 Arduino 库,ESP-NOW 是乐鑫定义的无连接 WiFi 通信协议。 有关 ESP-NOW 工作原理及其限制的更多信息,请参阅 ESP-NOW 参考。 WifiEspNow是 ESP-IDF 中 ESP-N…...
rsync使用守护进程启动服务
rsync 本身通常使用 SSH(Secure Shell)协议来进行数据传输,因此它默认使用 SSH 的端口 22。如果使用 rsync 进行通过 SSH 的数据同步,它会通过端口 22 来建立连接。 然而,如果你使用 rsync 作为一个守护进程进行文件同步(即不通过 SSH),则可以配置它使用 TCP 端口 873…...
React 核心概念与生态系统
1. React 简介 React 是由 Facebook 开发并开源的一个用于构建用户界面的 JavaScript 库。它主要用于构建单页应用(SPA),其核心理念是组件化和声明式编程,即 ui render(data)。 2. 核心特点 2.1. 声明式编程 React 使用声明式…...
使用React Native开发新闻资讯类鸿蒙应用的准备工作
以下是一篇关于使用React Native开发新闻资讯类鸿蒙应用的准备工作指南,结合鸿蒙生态特性与React Native技术栈整合要点: 一、环境搭建与工具链配置 基础依赖安装 Node.js 18:需支持ES2020语法(如可选链操…...
node-sass 报错
背景:一些老项目使用"node-sass": “^4.14.1” ,node版本要求 14.x,高版本不兼容 解决方案如下: 方案一:替换安装sass (无须降级Node版本) 卸载node-sass npm uninstall node-sass安装sass(Dart…...

Redis的安装与使用
网址:Spring Data Redis 安装包:Releases tporadowski/redis GitHub 解压后 在安装目录中打开cmd 打开服务(注意:每次客户端连接都有先打开服务!!!) 按ctrlC退出服务 客户端连接…...
Linux服务器运维10个基础命令
结合多篇权威资料,以下是运维工程师必须掌握的10个核心命令,涵盖文件管理、系统监控、网络操作等高频场景 1. "ls" 代码分析 "ls" 用于列出目录内容,通过参数组合可增强展示效果: "-l" 显示文件…...

2024年数维杯国际大学生数学建模挑战赛C题时间信号脉冲定时噪声抑制与大气时延抑制模型解题全过程论文及程序
2024年数维杯国际大学生数学建模挑战赛 C题 时间信号脉冲定时噪声抑制与大气时延抑制模型 原题再现: 脉冲星是一种快速旋转的中子星,具有连续稳定的旋转,因此被称为“宇宙灯塔”。脉冲星的空间观测在深空航天器导航和时间标准维护中发挥着至…...

C# 控制台程序获取用户输入数据验证 不合规返回重新提示输入
在 C# 控制台程序中实现输入验证并循环重试,可以通过以下方式实现高效且用户友好的交互。以下是包含多种验证场景的完整解决方案: 一、通用输入验证框架 public static T GetValidInput<T>(string prompt, Func<string, (bool IsValid, T Val…...
【大模型面试每日一题】Day 31:LoRA微调方法中低秩矩阵的秩r如何选取?
【大模型面试每日一题】Day 31:LoRA微调方法中低秩矩阵的秩r如何选取? 📌 题目重现 🌟🌟 面试官:LoRA微调方法中低秩矩阵的秩r如何选取?: #mermaid-svg-g5hxSxV8epzWyP98 {font-family:"…...