-
-
+
+
-
+
+
+
+
@@ -38,51 +46,16 @@
style="width: 100%"
v-loading="loading"
>
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+ {{ formatDateTime(scope.row.logWritetime) }}
+
+
+
编辑
@@ -108,48 +81,42 @@
v-model="drawerVisible"
:title="drawerTitle"
direction="rtl"
- :size="520"
+ :size="500"
>
-
-
+
+
-
-
+
+
-
+
-
-
-
-
-
-
-
+
@@ -188,17 +155,16 @@ import {
} from '@/api/manage-log'
interface LogItem {
- id?: number | string
- operator?: string
- operationType?: string
- operationContent?: string
- module?: string
- ipAddress?: string
- operationTime?: string
+ id?: string | number
+ logName: string
+ logType: string
+ logContent: string
+ logWritetime?: string
remark?: string
- remarks?: string
+ createId?: string
createTime?: string
updateTime?: string
+ updateId?: string
}
const loading = ref(false)
@@ -207,8 +173,9 @@ const tableData = ref([])
const total = ref(0)
const queryForm = reactive({
- operator: '',
- operationType: '',
+ logName: '',
+ logType: '',
+ createId: '',
})
const pagination = reactive({
@@ -223,102 +190,84 @@ const isEdit = ref(false)
const formRef = ref()
const form = reactive({
id: undefined,
- operator: '',
- operationType: '',
- operationContent: '',
- module: '',
- ipAddress: '',
- operationTime: '',
+ logName: '',
+ logType: '',
+ logContent: '',
+ logWritetime: '',
remark: '',
})
const rules: FormRules = {
- operator: [{ required: true, message: '请输入操作人', trigger: 'blur' }],
- operationType: [{ required: true, message: '请输入操作类型', trigger: 'blur' }],
- operationContent: [{ required: true, message: '请输入操作内容', trigger: 'blur' }],
+ logName: [{ required: true, message: '请输入日志名称', trigger: 'blur' }],
+ logType: [{ required: true, message: '请输入日志类型', trigger: 'blur' }],
+ logContent: [{ required: true, message: '请输入日志内容', trigger: 'blur' }],
+ logWritetime: [{ required: true, message: '请选择日志记录时间', trigger: 'change' }],
+}
+
+const formatDateTime = (dateTime?: string) => {
+ if (!dateTime) return '-'
+ try {
+ const date = new Date(dateTime)
+ 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 {
+ return dateTime
+ }
}
const resetForm = () => {
form.id = undefined
- form.operator = ''
- form.operationType = ''
- form.operationContent = ''
- form.module = ''
- form.ipAddress = ''
- form.operationTime = ''
+ form.logName = ''
+ form.logType = ''
+ form.logContent = ''
+ form.logWritetime = ''
form.remark = ''
formRef.value?.clearValidate()
}
-const formatCell = (_row: any, _column: any, value: any) => {
- if (value === 0) return 0
- return value === undefined || value === null || value === '' ? '暂无' : value
-}
-
const loadList = async () => {
loading.value = true
try {
- // 构建查询参数,过滤空字符串
const params: any = {
pageNum: pagination.pageNum,
pageSize: pagination.pageSize,
}
- if (queryForm.operator && queryForm.operator.trim()) {
- params.operator = queryForm.operator.trim()
- }
- if (queryForm.operationType && queryForm.operationType.trim()) {
- params.operationType = queryForm.operationType.trim()
- }
+ // 只添加有值的查询参数
+ if (queryForm.logName) params.logName = queryForm.logName
+ if (queryForm.logType) params.logType = queryForm.logType
+ if (queryForm.createId) params.createId = queryForm.createId
+
const res: any = await manageloglist(params)
-
- console.log('操作日志列表API返回数据:', res)
-
- // 根据返回格式处理数据
- let pageData = res?.data
-
- // 如果res.data不存在,可能是直接返回了分页数据
- if (!pageData && (res?.records || res?.total !== undefined)) {
- pageData = res
- }
-
- // 兼容多种返回格式
+ const data = res?.data ?? res ?? {}
+
+ // 兼容多种返回格式:{data:{records,total}} | {records,total} | {data:[]} | []
const recordsFromData =
- pageData?.records ||
- pageData?.list ||
- pageData?.rows ||
- pageData?.items ||
- (Array.isArray(pageData?.data) ? pageData.data : undefined)
+ data.records ||
+ data.list ||
+ data.rows ||
+ data.items ||
+ (Array.isArray(data.data) ? data.data : undefined)
const records = Array.isArray(recordsFromData)
? recordsFromData
- : Array.isArray(pageData)
- ? pageData
- : Array.isArray(res?.data)
- ? res.data
- : []
+ : Array.isArray(data)
+ ? data
+ : []
const totalValue =
- pageData?.total ??
- pageData?.count ??
- pageData?.totalCount ??
- res?.total ??
- (Array.isArray(records) ? records.length : 0)
+ data.total ?? data.count ?? data.totalCount ?? records.length ?? 0
tableData.value = records
total.value = Number(totalValue) || 0
-
- console.log('解析后的数据:', {
- records: records.length,
- total: total.value,
- firstRecord: records[0]
- })
- } catch (error: any) {
+ } catch (error) {
console.error('load log list error', error)
- const errorMsg = error?.message || error?.msg || '加载操作日志列表失败'
- ElMessage.error(errorMsg)
- tableData.value = []
- total.value = 0
+ ElMessage.error('获取日志列表失败')
} finally {
loading.value = false
}
@@ -330,8 +279,9 @@ const handleSearch = () => {
}
const resetSearch = () => {
- queryForm.operator = ''
- queryForm.operationType = ''
+ queryForm.logName = ''
+ queryForm.logType = ''
+ queryForm.createId = ''
handleSearch()
}
@@ -356,18 +306,11 @@ const openDrawer = async (mode: 'create' | 'edit', row?: LogItem) => {
const res: any = await managelogbyid(row.id)
const data = res?.data || res || {}
form.id = data.id ?? row.id
- form.operator = data.operator ?? row.operator ?? ''
- form.operationType = data.operationType ?? row.operationType ?? ''
- form.operationContent = data.operationContent ?? row.operationContent ?? ''
- form.module = data.module ?? row.module ?? ''
- form.ipAddress = data.ipAddress ?? row.ipAddress ?? ''
- form.operationTime = data.operationTime ?? row.operationTime ?? ''
- form.remark =
- data.remark ??
- data.remarks ??
- row.remark ??
- (row as any)?.remarks ??
- ''
+ form.logName = data.logName ?? row.logName ?? ''
+ form.logType = data.logType ?? row.logType ?? ''
+ form.logContent = data.logContent ?? row.logContent ?? ''
+ form.logWritetime = data.logWritetime ?? row.logWritetime ?? ''
+ form.remark = data.remark ?? row.remark ?? ''
} catch (error) {
ElMessage.error('获取日志详情失败')
drawerVisible.value = false
@@ -375,28 +318,67 @@ const openDrawer = async (mode: 'create' | 'edit', row?: LogItem) => {
}
}
+// 将时间格式转换为ISO 8601格式
+const formatToISO = (dateTime?: string) => {
+ if (!dateTime) return new Date().toISOString()
+ try {
+ // 如果已经是ISO格式,直接返回
+ if (dateTime.includes('T') && dateTime.includes('Z')) {
+ return dateTime
+ }
+ // 如果是其他格式,转换为ISO格式
+ const date = new Date(dateTime)
+ return date.toISOString()
+ } catch {
+ return new Date().toISOString()
+ }
+}
+
const submitForm = () => {
formRef.value?.validate(async (valid) => {
if (!valid) return
submitLoading.value = true
try {
- const payload: any = {
- ...form,
- remarks: form.remark,
+ // 获取当前时间(ISO 8601格式)
+ const now = new Date().toISOString()
+
+ // 获取用户ID(可以从localStorage或其他地方获取,这里先设为0)
+ const userId = 0 // 可以根据实际情况从用户store或localStorage获取
+
+ // 准备提交数据,按照后端Swagger要求补充所有字段
+ const submitData: any = {
+ logName: form.logName,
+ logType: form.logType,
+ logContent: form.logContent || '',
+ remark: form.remark || '',
+ logWritetime: formatToISO(form.logWritetime),
+ createId: userId,
+ updateId: userId,
+ createTime: now,
+ updateTime: now,
+ delSign: false, // 新增时delSign为false
+ }
+
+ // 如果是编辑,需要包含id
+ if (isEdit.value && form.id) {
+ submitData.id = Number(form.id)
+ } else {
+ // 新增时id设为0
+ submitData.id = 0
}
if (isEdit.value) {
- await managelogupd(payload)
+ await managelogupd(submitData)
ElMessage.success('更新成功')
} else {
- await managelogadd(payload)
+ await managelogadd(submitData)
ElMessage.success('新增成功')
}
drawerVisible.value = false
loadList()
} catch (error: any) {
console.error('submit log error', error)
- const errorMsg = error?.message || error?.msg || (isEdit.value ? '更新失败' : '新增失败')
+ const errorMsg = error?.response?.data?.message || error?.message || (isEdit.value ? '更新失败' : '新增失败')
ElMessage.error(errorMsg)
} finally {
submitLoading.value = false
@@ -409,7 +391,7 @@ const handleDelete = (row: LogItem) => {
ElMessage.warning('缺少日志ID')
return
}
- ElMessageBox.confirm(`确认删除操作日志吗?`, '提示', {
+ ElMessageBox.confirm(`确认删除日志「${row.logName}」吗?`, '提示', {
type: 'warning',
})
.then(async () => {
@@ -421,10 +403,9 @@ const handleDelete = (row: LogItem) => {
await managelogdel(row.id)
ElMessage.success('删除成功')
loadList()
- } catch (error: any) {
+ } catch (error) {
console.error('delete log error', error)
- const errorMsg = error?.message || error?.msg || '删除失败'
- ElMessage.error(errorMsg)
+ ElMessage.error('删除失败')
}
})
.catch(() => {})
@@ -436,7 +417,7 @@ onMounted(() => {