【VUE】element Table指定字段单元格样式及数据格式化

将列表中的指定字段的数据,根据字典值回显,并修改指定状态的显示样式

html 复制代码
	<el-table
				ref="table"
				height="500px"
				:data="dataList"
			>
				<template v-for="(item, index) in columns">
					<el-table-column
						:key="index"
						:index="index"
						:label="item.label"
						align="center"
						:prop="item.code"
						:show-overflow-tooltip="true"
					>
						<template slot-scope="scope">
							<template v-if="item.render">
								<span>
									<RenderDom
										:row="scope.row"
										:index="index"
										:render="item.render"
									/>
								</span>
							</template>

							<template v-else-if="item.code === 'deviceCount'">
								<span
									v-if="
										scope.row[item.code] === null || scope.row[item.code] === ''
									"
									>-</span
								>
								<button
									v-else
									class="deviceCountBtn"
									@click="handleDeviceCountBtn(scope.row)"
								>
									{{ scope.row[item.code] }}
								</button>
							</template>

							<template v-else-if="item.code === 'status'">
								<div class="statusFlex">
									<div
										:class="[
											'statusCircle',
											{ statusCirclePurple: scope.row[item.code] === '2' },
											{
												statusCircleGray:
													scope.row[item.code] === '1' ||
													scope.row[item.code] === '3' ||
													scope.row[item.code] === '4',
											},
										]"
									></div>
									<span>{{
										selectDictLabel(
											dict.type.paas_orderStatus,
											scope.row[item.code]
										)
									}}</span>
								</div>
							</template>
							<template v-else>
								<span>{{ scope.row[item.code] }}</span>
							</template>
						</template>
					</el-table-column>
				</template>
</el-table>
html 复制代码
// 列信息
			columns: [
				{
					label: this.$t('paasOrder.status'),
					code: `status`,
					visible: true,
					width: '250px',
				},
				{
					label: this.$t('common.updatedBy'),
					code: `updatedBy`,
					visible: true,
					width: '220px',
				},
				{
					label: this.$t('common.updatedTime'),
					code: `updatedTime`,
					visible: true,
					width: '220px',
				},
			],
html 复制代码
	// 清除圆形下默认'-'
	.statusCircle::after {
		content: '';
	}
	.statusFlex {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.statusCircleGray {
		width: 13px;
		height: 13px;
		border-radius: 13px;
		background: #d8d8d8;
		margin-right: 6px;
	}
	.statusCirclePurple {
		width: 13px;
		height: 13px;
		border-radius: 13px;
		background: #4d5aa0;
		margin-right: 6px;
	}
相关推荐
云草桑11 分钟前
逆向工程 反编译 C# net core
前端·c#·反编译·逆向工程
布丁椰奶冻16 分钟前
解决使用nvm管理node版本时提示npm下载失败的问题
前端·npm·node.js
Leyla42 分钟前
【代码重构】好的重构与坏的重构
前端
影子落人间1 小时前
已解决npm ERR! request to https://registry.npm.taobao.org/@vant%2farea-data failed
前端·npm·node.js
世俗ˊ1 小时前
CSS入门笔记
前端·css·笔记
子非鱼9211 小时前
【前端】ES6:Set与Map
前端·javascript·es6
6230_1 小时前
git使用“保姆级”教程1——简介及配置项设置
前端·git·学习·html·web3·学习方法·改行学it
想退休的搬砖人1 小时前
vue选项式写法项目案例(购物车)
前端·javascript·vue.js
加勒比海涛2 小时前
HTML 揭秘:HTML 编码快速入门
前端·html
啥子花道2 小时前
Vue3.4 中 v-model 双向数据绑定新玩法详解
前端·javascript·vue.js