实现接口部分功能

This commit is contained in:
WUSIJIAN
2025-11-28 17:17:07 +08:00
parent 0ad816cc6d
commit 4c2fb2a189
11 changed files with 317 additions and 686 deletions

View File

@@ -19,11 +19,19 @@
<el-table-column prop="tag" label="标签" show-overflow-tooltip min-width="120" />
<el-table-column prop="creator" label="创建人" show-overflow-tooltip min-width="100" />
<el-table-column prop="modifier" label="修改人" show-overflow-tooltip min-width="100" />
<el-table-column prop="createdAt" label="创建时间" show-overflow-tooltip min-width="140" />
<el-table-column prop="updatedAt" label="修改时间" show-overflow-tooltip min-width="140" />
<el-table-column prop="createdAt" label="创建时间" show-overflow-tooltip min-width="140">
<template #default="{ row }">
{{ formatTime(row.createdAt) }}
</template>
</el-table-column>
<el-table-column prop="updatedAt" label="修改时间" show-overflow-tooltip min-width="140">
<template #default="{ row }">
{{ formatTime(row.updatedAt) }}
</template>
</el-table-column>
<el-table-column label="操作" width="200" align="center" fixed="right">
<template #default="{ row }">
<el-button size="small" text type="primary" @click="handleEdit(row)">
<el-button style="color: deepskyblue" size="small" text type="primary" @click="handleEdit(row)">
<el-icon><EditPen /></el-icon>修改
</el-button>
<el-button size="small" text type="danger" @click="handleDelete(row)">
@@ -49,7 +57,7 @@
</template>
<script setup lang="ts">
import { reactive, ref, onMounted, nextTick } from 'vue';
import { reactive, ref, onMounted } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { FolderAdd, EditPen, DeleteFilled } from '@element-plus/icons-vue';
import EditRole from './component/editRole.vue';
@@ -62,8 +70,8 @@ interface ScriptItem {
tag: string;
creator: string;
modifier: string;
createdAt: string;
updatedAt: string;
createdAt: string; // 保持原字段不变
updatedAt: string; // 保持原字段不变
content?: string;
}
@@ -91,6 +99,47 @@ const tableData = reactive<TableState>({
},
});
// ==================== 时间处理函数 ====================
/**
* 格式化时间显示
* @param time 时间字符串或时间戳
* @returns 格式化后的时间字符串
*/
const formatTime = (time: string | number): string => {
if (!time) return '-';
try {
// 如果是时间戳格式
let timestamp = typeof time === 'string' ? parseInt(time) : time;
// 如果是毫秒时间戳,需要判断是否需要转换
if (timestamp > 1000000000000) {
// 已经是毫秒时间戳
} else if (timestamp > 1000000000) {
// 秒时间戳,转换为毫秒
timestamp = timestamp * 1000;
}
const date = new Date(timestamp);
if (isNaN(date.getTime())) {
return String(time); // 返回原始值
}
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
} catch (error) {
console.error('时间格式化错误:', error);
return String(time); // 返回原始值
}
};
// ==================== 方法定义 ====================
/**
@@ -139,8 +188,8 @@ const handleDelete = async (row: ScriptItem) => {
cancelButtonText: '取消',
type: 'warning',
});
console.log(row, 'row');
await deletescript({ id: row.id }).then((res) => {});
await deletescript({ id: row.id });
ElMessage.success('删除成功');
// 重新加载数据
@@ -160,20 +209,6 @@ const handleSuccess = () => {
loadTableData();
};
/**
* 处理分页变化
*/
const handleSizeChange = (size: number) => {
tableData.param.pageSize = size;
tableData.param.pageNum = 1; // 重置到第一页
loadTableData();
};
const handleCurrentChange = (current: number) => {
tableData.param.pageNum = current;
loadTableData();
};
// ==================== 生命周期 ====================
onMounted(() => {
loadTableData();