vue3 + element-plus + ts el-table封装

vue3 + element-plus + ts el-table封装

博客参考https://blog.csdn.net/weixin_45291937/article/details/125523244
1. 文件位置(根据自己的需求)
在这里插入图片描述

2. 在 custom 文件夹下面 创建 mytable 文件夹
3. 直接上代码

// index.vue<template><div class="el-table-box"><el-table ref="tableRef" check-strictly :class="[_options.showPagination ? 'isActive' : 'active']" :data="tableData" v-loading="fullLoading" v-bind="_options" default-expand-all highlight-current-row @selection-change="handleSelectionChange" @row-click="handleRowClick" @cell-click="handleCellClick" @sort-change="handleSortChange"><el-table-column v-if="_options.showCheckout" :index="indexMethod" v-bind="{ type: 'selection', width: '50' }"></el-table-column><template v-for="(col, index) in  columns " :key="index"><!---复选框, 序号 (START)--><el-table-column v-if="col.type === 'expand' || col.type === 'customCell'" :index="indexMethod" v-bind="col"><!-- 当type等于expand时, 配置通过h函数渲染、tsx语法或者插槽自定义内容 --><template #default="{ row, $index }"><!-- render函数 (START) : 使用内置的component组件可以支持h函数渲染和txs语法 --><component v-if="col.render" :is="col.render" :row="row" :index="$index" /><!-- 自定义slot (START) --><slot v-else-if="col.slot" name="expand" :row="row" :index="$index"></slot></template></el-table-column><el-table-column v-else-if="col.type === 'index' && (col.hideFlag || col.hideFlag == null)" :index="indexMethod" v-bind="{ type: 'index', width: '50', label: $t(col.label + '') }" width="65"><!-- 当type等于expand时, 配置通过h函数渲染、txs语法或者插槽自定义内容 --><template #default="{ row, $index }"><!-- render函数 (START) : 使用内置的component组件可以支持h函数渲染和txs语法 --><component v-if="col.render" :is="col.render" :row="row" :index="$index" /><!-- 自定义slot (START) --><slot v-else-if="col.slot" name="expand" :row="row" :index="$index"></slot></template></el-table-column><!-- 渲染插槽 START --><TableColumn :col="col" v-else-if="col.hideFlag || col.hideFlag == null" @command="handleAction"><template v-for="slot in  Object.keys($slots) " #[slot]="scope: Record<string, any>"><slot :name=" slot " v-bind=" scope " /></template></TableColumn><!-- 渲染插槽 END --></template><template #empty><div class="mp_tatble_nodata"><img class="active-daek" :src=" ImageUrl " alt=""><div>{{$t('message.application.btn.currently')}}</div></div></template></el-table><!-- 分页器 --><div v-if=" _options.showPagination " class="mt20"><el-pagination v-bind=" _paginationConfig " @size-change=" pageSizeChange " @current-change=" currentPageChange " /></div></div>
</template>
<script lang="ts" setup>import { ComputedRef, computed, ref, onMounted, defineAsyncComponent, withDefaults } from 'vue';import type { TableColumnCtx } from 'element-plus/es/components/table/src/table-column/defaults';import { ElTable } from 'element-plus';import ImageUrl from '/@/assets/nodata.png'const TableColumn = defineAsyncComponent(() => import('./TableColumn.vue'));export type SortParams<T> = {column: TableColumnCtx<T | any>;prop: string;order: Table.Order;};interface TableProps {tableData: Array<object>; // table的数据columns: Table.Column[]; // 每列的配置项options?: Table.Options;fullLoading?: boolean;}const props = withDefaults(defineProps<TableProps>(), {fullLoading: false,});const tableRef = ref<InstanceType<typeof ElTable>>();// 设置option默认值,如果传入自定义的配置则合并option配置项const _options: ComputedRef<Table.Options> = computed(() => {const option = {stripe: false,tooltipEffect: 'dark',showHeader: true,showPagination: false,rowStyle: () => 'cursor:pointer', // 行样式};return Object.assign(option, props?.options);});// 合并分页配置const _paginationConfig = computed(() => {const config = {total: 0,currentPage: 1,pageSize: 10,pageSizes: [10, 20, 50],layout: 'total, sizes, prev, pager, next, jumper'}return Object.assign(config, _options.value.paginationConfig)})const emit = defineEmits(['selection-change', // 当选择项发生变化时会触发该事件'row-click', // 当某一行被点击时会触发该事件'cell-click', // 当某个单元格被点击时会触发该事件'command', // 按钮组事件'size-change', // pageSize事件'current-change', // currentPage按钮组事件'pagination-change', // currentPage或者pageSize改变触发'sort-change', // 列排序发生改变触发'row-radio', // 单选]);// 自定义索引const indexMethod = (index: number) => {const tabIndex = index + (_paginationConfig.value.currentPage - 1) * _paginationConfig.value.pageSize + 1;return tabIndex;};// 切换pageSizeconst pageSizeChange = (pageSize: number) => {emit('size-change', pageSize);emit('pagination-change', 1, pageSize);};// 切换currentPageconst currentPageChange = (currentPage: number) => {emit('current-change', currentPage);emit('pagination-change', currentPage, _paginationConfig.value.pageSize);};// 按钮组事件const handleAction = (command: Table.Command, row: any, index: number) => {emit('command', command, row, index);};// 多选事件const handleSelectionChange = (val: any) => {emit('selection-change', val);};//返回当前选中的行const getSelectionRows = () => {return tableRef.value?.getSelectionRows();};// 当某一行被点击时会触发该事件const handleRowClick = (row: any, column: any, event: MouseEvent) => {emit('row-click', row, column, event);};// 当某个单元格被点击时会触发该事件const handleCellClick = (row: any, column: any, cell: any, event: MouseEvent) => {if (column && column.className) {if (column.className == 'mp-highlight') {emit('cell-click', row, column, cell, event);}}if (_options.value.showRadio) {if (tableRef.value && tableRef.value) tableRef.value.setCurrentRow(row)emit('row-radio', row, column, cell, event);}};/***  当表格的排序条件发生变化的时候会触发该事件* 在列中设置 sortable 属性即可实现以该列为基准的排序, 接受一个 Boolean,默认为 false。* 可以通过 Table 的 default-sort 属性设置默认的排序列和排序顺序。* 如果需要后端排序,需将 sortable 设置为 custom,同时在 Table 上监听 sort-change 事件,* 在事件回调中可以获取当前排序的字段名和排序顺序,从而向接口请求排序后的表格数据。*/const handleSortChange = ({ column, prop, order }: SortParams<any>) => {emit('sort-change', { column, prop, order });};// 暴露给父组件参数和方法,如果外部需要更多的参数或者方法,都可以从这里暴露出去。defineExpose({ element: tableRef, fn: getSelectionRows });
</script>
<style lang="scss" scoped>
:deep(.el-image__inner) {transition: all 0.3s;cursor: pointer;&:hover {transform: scale(1.2);}
}.el-table-box {height: 100%;.isActive {height: calc(100% - 45px) !important;}.active {height: 100%;}.mt20 {display: flex;justify-content: end;}
}</style>

4. 安装 cnpm i -S dayjs (可以不安装 ,如果不安装就删除下面的标记部分)

 // TableColumn.vue<script lang="ts" setup>import dayjs from 'dayjs'defineProps<{ col: Table.Column }>()const emit = defineEmits(['command', 'handleClickRow'])// 按钮组事件const handleAction = (command: Table.Command, { row, $index }: { row: any; $index: number }) => {emit('command', command, row, $index)}
</script>
<template><!-- 如果有配置多级表头的数据,则递归该组件 --><template v-if="col.children?.length"><el-table-column :label="col.label" :width="col.width" :align="col.align"><TableColumn v-for="item in     col.children    " :col="item" :key="item.prop"><template v-for="slot in     Object.keys($slots)    " #[slot]="scope: Record<string, any>"><slot :name=" slot " v-bind=" scope " /></template></TableColumn><template #header=" { column, $index } "><component v-if=" col.headerRender " :is="col.headerRender" :column=" column " :index=" $index " /><slot v-else-if=" col.headerSlot " :name=" col.headerSlot " :column=" column " :index=" $index "></slot><span v-else>{{ $t(column.label) }}</span></template></el-table-column></template><el-table-column v-else-if=" col.highlight " v-bind=" col " class-name='mp-highlight'><template #header=" { column, $index } "><component v-if=" col.headerRender " :is="col.headerRender" :column=" column " :index=" $index " /><slot v-else-if=" col.headerSlot " :name=" col.headerSlot " :column=" column " :index=" $index "></slot><span v-else>{{ $t(column.label)}}</span></template><template #default=" { row, $index } "><span>{{ row[col.prop!] }}</span></template></el-table-column><!-- 其他正常列 --><el-table-column v-else v-bind=" col "><!-- 自定义表头 --><template #header=" { column, $index } "><component v-if=" col.headerRender " :is="col.headerRender" :column=" column " :index=" $index " /><slot v-else-if=" col.headerSlot " :name=" col.headerSlot " :column=" column " :index=" $index "></slot><span v-else>{{ $t(column.label)}}</span></template><template #default=" { row, $index } "><!-- 如需更改图片size,可自行配置参数 --><el-image v-if=" col.type === 'image' " preview-teleported :hide-on-click-modal=" true " :preview-src-list=" [row[col.prop!]] " :src=" row[col.prop!] " fit="cover" class="w-9 h-9 rounded-lg" /><!-- day.js开始  (不安装可删除该部分)  --><!--- 格式化日期 (本项目日期是时间戳,这里日期格式化可根据你的项目来更改) (START)--><template v-else-if=" col.type === 'date' "><!---十位数时间戳--><span v-if=" String(row[col.prop!])?.length <= 10 ">{{ dayjs.unix(row[col.prop!]).format(col.dateFormat ?? 'YYYY-MM-DD') }}</span><!---十三位数时间戳--><span v-else>{{ dayjs(row[col.prop!]).format(col.dateFormat ?? 'YYYY-MM-DD') }}</span></template><!-- day.js结束  --><!-- 如果传递按钮数组,就展示按钮组 START--><el-button-group v-else-if=" col.buttons?.length "><el-button v-for="(    btn, index    ) in     col.buttons    " :key=" index " :size=" btn.size " :type=" btn.type " @click="handleAction(btn.command, { row, $index })">{{ btn.name }}</el-button></el-button-group><!-- render函数 (START) 使用内置的component组件可以支持h函数渲染和txs语法--><component v-else-if=" col.render " :is="col.render" :row=" row " :index=" $index " /><!-- 自定义slot (START) --><slot v-else-if=" col.slot " :name=" col.slot " :row=" row " :index=" $index "></slot><!-- 默认渲染 (START)  --><span v-else>{{ row[col.prop!] }}</span></template></el-table-column>
</template>

5. table.d.ts (表格全局接口文件)

// table.d.ts
declare namespace Table {type VNodeChild = import('vue').VNodeChildtype Type = 'selection' | 'index' | 'expand' | 'image' | 'date'type Size = 'large' | 'default' | 'small'type Align = 'center' | 'left' | 'right'type Command = string | numbertype DateFormat = 'YYYY-MM-DD' | 'YYYY-MM-DD HH:mm:ss' | 'YYYY-MM-DD HH:mm' | 'YYYY-MM'type Order = 'ascending' | 'descending'interface ButtonItem {name: string,command: Command,size?: Sizetype?: 'primary' | 'success' | 'warning' | 'danger' | 'info',}interface Sort {prop: stringorder: Orderinit?: anysilent?: any}interface Column {// 对应列的类型。 如果设置了selection则显示多选框; 如果设置了 index 则显示该行的索引(从 1 开始计算); 如果设置了 expand 则显示为一个可展开的按钮type?: Type | 'customCell',label?: string,prop?: string,slot?: stringwidth?: string,align?: Align,hideFlag?:boolean,hide?:boolean,fixed?:string|boolean,highlight?:boolean,//字段高亮dateFormat?: DateFormat // 显示在页面中的日期格式,简单列举了几种格式, 可自行配置showOverflowTooltip?: boolean,buttons?: ButtonItem[],render?: (row?: any, index?: number) => VNodeChild // 渲染函数,渲染这一列的每一行的单元格sortable?: boolean | 'custom', // 对应列是否可以排序, 如果设置为 'custom',则代表用户希望远程排序,需要监听 Table 的 sort-change 事件headerRender?: ({ column, index }) => VNodeChild, // 渲染函数,渲染列表头headerSlot?: string, // 自定义表头插槽名字children?: Column[] // 配置多级表头的数据集合, 具体用法可参考多级表头使用示例。}interface Options {height?: string | number,// Table 的高度, 默认为自动高度。 如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则这个高度会设置为 Table 的 style.height 的值,Table 的高度会受控于外部样式。stripe?: boolean, // 是否为斑马纹 tablemaxHeight?: string | number, // Table 的最大高度。 合法的值为数字或者单位为 px 的高度。size?: Size // Table 的尺寸showHeader?: boolean // 是否显示表头,showRadio?:boolean, //单选showCheckout?:boolean, //多选defaultExpandAll?:booleantooltipEffect?: 'dark' | 'light' // tooltip effect 属性showPagination?: boolean, // 是否展示分页器paginationConfig?: Pagination, // 分页器配置项,详情见下方 paginationConfig 属性,rowStyle?: ({ row, rowIndex }) => stirng | object // 行的 style 的回调方法,也可以使用一个固定的 Object 为所有行设置一样的 Style。headerCellStyle?: import('vue').CSSProperties, // 表头单元格的style样式,是一个object为所有表头单元格设置一样的 Style。注:CSSProperties类型就是一个对象,像正常在style中写css一样 {color: #f00}defaultSort?: Sort // 默认的排序列的 prop 和顺序。 它的 prop 属性指定默认的排序的列,order 指定默认排序的顺序。"row-key"?: string // 行数据的 Key,用来优化 Table 的渲染。treeProps?:{}}interface Pagination {total?: number, // 总条目数currentPage: number, // 当前页数,支持 v-model 双向绑定pageSize: number, // 每页显示条目个数,支持 v-model 双向绑定pageSizes?: number[], // 每页显示个数选择器的选项设置layout?: string, // 组件布局,子组件名用逗号分隔background?: boolean // 是否为分页按钮添加背景色}interface pagination_type {currentPage: number,limit: number,}
}

6. 简单使用 具体的使用方法可以在 table.d.ts (表格全局接口文件) 中查看配置

<template><div class="mp-box-container layout-pd user-news-center"><Table :columns="tableColumn" v-loading="state.fullLoading" :options="state.options":table-data="state.tableData" @pagination-change="paginationChange"@sort-change="handleSortChange"><!-- 操作 --><template #action="{ row, index }"><div class="user-news-center__btns"><el-button type="primary" link @click="editNewsHandler(row)">{{ $t('编辑') }}</el-button><el-button type="primary" link @click="deleteNewsHander(row)">{{ $t('删除') }}</el-button></div></template></Table></div>
</template><script setup lang="ts">
import { defineAsyncComponent, ref, reactive, onMounted, h, watch } from 'vue' // vue实例
const Table = defineAsyncComponent(() => import('/@/custom/myTable/index.vue')) // 引入组件// 分页
const paginationConfig = reactive({total: 0,currentPage: 1,pageSize: 10,
})// 排序
const orderConfig = reactive({prop: '',order: '',
})let state = reactive({options: { showPagination: true,paginationConfig,},tableData: [],tableColumn: [],fullLoading: false
})const tableColumn = ref<Table.Column[]>([// 公司编码{prop: 'F_EnCode',hideFlag: true,label: '公司编码',width: '150px',showOverflowTooltip: true},// 公司名称{prop: 'F_FullName',label: '公司名称',// highlight: true,  //字段高亮hideFlag: true, //显隐},// 上级公司{prop: 'F_ParentName',label: '上级公司',// highlight: true,  //字段高亮hideFlag: true, //显隐},// 备注{prop: 'F_Description',label: '备注',// highlight: true,  //字段高亮hideFlag: true, //显隐},// 按钮使用render函数渲染(操作){width: '120',label: 'message.publicTable.Operation',prop: 'action',slot: 'action',  // 方法一  插槽fixed: "right",// 方法二 按钮组// buttons:[// 	{// 		name:"编辑",// 		command:"edit",// 		type:"danger"// 	},// 	{// 		name:"删除",// 		command:"delete",// 		type:"danger"// 	}// ]/**    * * 方法三 render 函数* */// render: (row: User, index: number) =>// 	// 渲染单个元素// 	h('div', null, [// 		h(// 			ElButton,// 			{// 				type: 'primary',// 				link: true,// 				onClick: () => handleRenderEdit(row, index)// 			},// { default: () => '编辑' }// 		),// 		h(// 			ElButton,// 			{// 				type: 'primary',// 				link: true,// 				onClick: () => handleRenderDelete(row, index)// 			},// 			{ default: () => '删除' }// 		)// 	])}
])/*** 删除*/
const deleteNewsHander = (row: any) => {}/*** 编辑*/
const editNewsHandler = (row: any) => {}/*** 分页改变*/
const paginationChange = (currentPage: number, pageSize: number) => {paginationConfig.currentPage = currentPage;paginationConfig.pageSize = pageSize;}/*** 排序*/
const handleSortChange = ({ prop, order }: any) => {orderConfig.order = order === 'ascending' ? 'asc' : 'desc'orderConfig.prop = prop}</script>

7. 效果
在这里插入图片描述

8. 以上为全部代码! 欢迎各位同学指导!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/176092.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python实现WOA智能鲸鱼优化算法优化XGBoost回归模型(XGBRegressor算法)项目实战

说明&#xff1a;这是一个机器学习实战项目&#xff08;附带数据代码文档视频讲解&#xff09;&#xff0c;如需数据代码文档视频讲解可以直接到文章最后获取。 1.项目背景 鲸鱼优化算法 (whale optimization algorithm,WOA)是 2016 年由澳大利亚格里菲斯大学的Mirjalili 等提…

CloudCompare简单开发

一、概述 CloudCompare如何进行二次开发&#xff1f;_cloudcompare 二次开发-CSDN博客 开发一个功能&#xff0c;在原始CC的基础上添加一个拓展功能&#xff0c;如下&#xff1a; 二、功能开发 1、修改MainWindow.UI 重点是&#xff1a;要编译&#xff0c;不然在mainwindow.…

JAVA进阶之路JVM-2:类加载机制,类的生命周期,类加载过程,类加载时机,类加载器,双亲委派模型,对象创建过程

JVM类加载机制 类加载 ​ 在JVM虚拟机实现规范中&#xff0c;通过ClassLoader类加载把*.class字节码文件&#xff08;文件流&#xff09;加载到内存&#xff0c;并对字节码文件内容进行验证&#xff0c;准备&#xff0c;解析和初始化&#xff0c;最终形成可以被虚拟机直接使用…

点盾云出现“操作失败,错误码1002”如何解决?

在使用点盾云学习看课时&#xff0c;老师会先将视频或者是在线播放链接发给我们&#xff0c;我们通过下载文件的方式或通过直接在线点播的形式来观看&#xff0c;那么在操作的过程中&#xff0c;有时候我们会遇到一些问题&#xff0c;今天以百度网盘中下载的视频文件为例&#…

浙江启用无人机巡山护林模式,火灾扑救效率高

为了保护天然的森林资源&#xff0c;浙江当地林业部门引入了一种创新技术&#xff1a;林业无人机。这些天空中的守护者正在重新定义森林防火和护林工作的方式。 当下正值天气干燥的季节&#xff0c;这些无人机开始了它们的首次大规模任务。它们在指定的林区内自主巡逻&#xff…

B树与B+树的对比

B树&#xff1a; m阶B树的核心特性&#xff1a; 树中每个节点至多有m棵子树&#xff0c;即至多含有m-1个关键字根节点的子树数属于[2, m]&#xff0c;关键字数属于[1, m-1]&#xff0c;其他节点的子树数属于 [ ⌈ m 2 ⌉ , m ] [\lceil \frac{m}{2}\rceil, m] [⌈2m​⌉,m]&am…

excel对号怎么打

对号无论是老师批改作业&#xff0c;还是在标注某些数据的时候都会用到&#xff0c;但这个符号在键盘上是没有的&#xff0c;那么excel对号怎么打出来呢&#xff0c;其实只要使用插入符号功能就可以了。 excel对号怎么打&#xff1a; 第一步&#xff0c;选中想要打出对号的单…

世界共赢电影在行动 ——世界共赢电影签约仪式在京举行

2023年11月23日&#xff0c;秋景冬温的北京&#xff0c;迎来了美国、韩国、俄罗斯、德国、英国、法国、日本、印度、南非、加拿大、巴西、新加坡、印度尼西亚、伊朗、土耳其、马来西亚、越南、意大利、西班牙、波兰、南非、尼日利亚、澳大利亚等23个国家的影视行业代表&#xf…

第二十章总结

创建线程 继承Thread 类 Thread 类时 java.lang 包中的一个类&#xff0c;从类中实例化的对象代表线程&#xff0c;程序员启动一个新线程需要建立 Thread 实例。 Thread 对象需要一个任务来执行&#xff0c;任务是指线程在启动时执行的工作&#xff0c;start() 方法启动线程&am…

C/C++ Zlib实现文件压缩与解压

在软件开发和数据处理中&#xff0c;对数据进行高效的压缩和解压缩是一项重要的任务。这不仅有助于减小数据在网络传输和存储中的占用空间&#xff0c;还能提高系统的性能和响应速度。本文将介绍如何使用 zlib 库进行数据的压缩和解压缩&#xff0c;以及如何保存和读取压缩后的…

【开源】基于Vue和SpringBoot的数字化社区网格管理系统

项目编号&#xff1a; S 042 &#xff0c;文末获取源码。 \color{red}{项目编号&#xff1a;S042&#xff0c;文末获取源码。} 项目编号&#xff1a;S042&#xff0c;文末获取源码。 目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块三、开发背景四、系统展示五、核心源码5…

六、源NAT实验

学习防火墙之前&#xff0c;对路由交换应要有一定的认识 源NAT1.私网用户通过NAT No-PAT访问Internet2.私网用户通过NATP访问Internet3.私网用户通过Easy-IP访问Internet4.私网用户通过三元组NAT访问Internet5.双出口环境下私网用户通过NAPT访问Internet 源NAT ———————…

预览功能实现

需求&#xff1a;将后端返回来的文字或者图片和视频展示在页面上。 <!-- 预览 --><el-dialog title"预览" :visible.sync"dialogPreviewVisible" width"50%" append-to-body :close-on-click-modal"false" close"Previe…

微服务--03--OpenFeign 实现远程调用

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 OpenFeign其作用就是基于SpringMVC的常见注解&#xff0c;帮我们优雅的实现http请求的发送。 RestTemplate实现了服务的远程调用 OpenFeign快速入门1.引入依赖2.启用…

OpenCV快速入门【完结】:总目录——初窥计算机视觉

文章目录 前言目录1. OpenCV快速入门&#xff1a;初探2. OpenCV快速入门&#xff1a;像素操作和图像变换3. OpenCV快速入门&#xff1a;绘制图形、图像金字塔和感兴趣区域4. OpenCV快速入门&#xff1a;图像滤波与边缘检测5. OpenCV快速入门&#xff1a;图像形态学操作6. OpenC…

创建可以离线打包开发的uniapp H5项目

安装node环境 略 安装vue脚手架&#xff0c;在线 npm install -g vue/cli PS&#xff1a;vue-cli已进入维护模式&#xff0c;vue3最新脚手架使用npm init vuelatest安装&#xff0c;安装后使用create-vue替换vue指令&#xff0c;create-vue底层使用vite提升前端开发效率&…

Redis应用的16个场景

常见的16种应用场景: 缓存、数据共享分布式、分布式锁、全局 ID、计数器、限流、位统计、购物车、用户消息时间线 timeline、消息队列、抽奖、点赞、签到、打卡、商品标签、商品筛选、用户关注、推荐模型、排行榜. 1、缓存 String类型 例如&#xff1a;热点数据缓存&#x…

Redis 命令处理过程

我们知道 Redis 是一个基于内存的高性能键值数据库, 它支持多种数据结构, 提供了丰富的命令, 可以用来实现缓存、消息队列、分布式锁等功能。 而在享受 Redis 带来的种种好处时, 是否曾好奇过 Redis 是如何处理我们发往它的命令的呢&#xff1f; 本文将以伪代码的形式简单分析…

centos 显卡驱动安装(chatglm2大模型安装步骤一)

1.服务器配置 服务器系统:Centos7.9 x64 显卡:RTX3090 (24G) 2.安装环境 2.1 检查显卡驱动是否安装 输入命令:nvidia-smi(显示显卡信息) 如果有以下显示说明,已经有显卡驱动。否则需要重装。 2.2 下载显卡驱动 第一步:浏览器输入https://www.nvidia.cn/Downloa…

Python读取Ansible playbooks返回信息

一&#xff0e;背景及概要设计 当公司管理维护的服务器到达一定规模后&#xff0c;就必然借助远程自动化运维工具&#xff0c;而ansible是其中备选之一。Ansible基于Python开发&#xff0c;集合了众多运维工具&#xff08;puppet、chef、func、fabric&#xff09;的优点&#x…