Skip to content

Commit 0dd3b77

Browse files
committed
重构:优化配置管理的 date 格式化
1 parent 72b0ec2 commit 0dd3b77

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/utils/formatTime.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import dayjs from 'dayjs'
2+
13
/**
24
* 时间日期转换
35
* @param date 当前时间,new Date() 格式
@@ -174,3 +176,18 @@ export function formatPast2(ms) {
174176
return 0 + '秒'
175177
}
176178
}
179+
180+
/**
181+
* element plus 的时间 Formatter 实现,使用 YYYY-MM-DD HH:mm:ss 格式
182+
*
183+
* @param row 行数据
184+
* @param column 字段
185+
* @param cellValue 字段值
186+
*/
187+
// @ts-ignore
188+
export const dateFormatter = (row, column, cellValue) => {
189+
if (!cellValue) {
190+
return
191+
}
192+
return dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss')
193+
}

src/views/infra/config/index.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</el-row>
8989

9090
<!-- 列表 -->
91-
<el-table v-loading="loading" :data="list">
91+
<el-table v-loading="loading" :data="list" align="center">
9292
<el-table-column label="参数主键" align="center" prop="id" />
9393
<el-table-column label="参数分类" align="center" prop="category" />
9494
<el-table-column label="参数名称" align="center" prop="name" :show-overflow-tooltip="true" />
@@ -105,13 +105,13 @@
105105
</template>
106106
</el-table-column>
107107
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
108-
<!-- TODO 芋艿:时间写的有点复杂 -->
109-
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
110-
<template #default="scope">
111-
<!-- <span>{{ parseTime(scope.row.createTime) }}</span>-->
112-
<span>{{ dayjs(scope.row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
113-
</template>
114-
</el-table-column>
108+
<el-table-column
109+
label="创建时间"
110+
align="center"
111+
prop="createTime"
112+
width="180"
113+
:formatter="dateFormatter"
114+
/>
115115
<!-- TODO 芋艿:宽度;里面的 css -->
116116
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
117117
<template #default="scope">
@@ -141,10 +141,10 @@
141141
</template>
142142
<script setup lang="ts" name="Config">
143143
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
144+
import { dateFormatter } from '@/utils/formatTime'
145+
import download from '@/utils/download'
144146
import * as ConfigApi from '@/api/infra/config'
145147
import ConfigForm from './form.vue'
146-
import dayjs from 'dayjs'
147-
import download from '@/utils/download'
148148
const message = useMessage() // 消息弹窗
149149
const { t } = useI18n() // 国际化
150150
@@ -206,6 +206,7 @@ const handleDelete = async (id: number) => {
206206
} catch {}
207207
}
208208
209+
/** 导出按钮操作 */
209210
const handleExport = async () => {
210211
try {
211212
// 导出的二次确认

0 commit comments

Comments
 (0)