Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/views/operate-log/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function changeFilterHandle(val: string) {
function changeDayHandle(val: number | string) {
if (val !== 'other') {
daterange.value.start_time = beforeDay(val)
daterange.value.end_time = nowDate
daterange.value.end_time = ''
getList()
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code is mostly correct, but there's one small issue that could be improved:

function changeDayHandle(val: number | string) {
  if (val !== 'other') {
    daterange.value.start_time = beforeDay(val);
    // Avoid an error when using `beforeDay` on 'other'
    daterange.value.end_time = typeof val === 'number' ? '' : nowDate;
    getList();
  }
}

Explanation of changes:

  1. Added a type check (typeof) to ensure that the value used in nowDate is a number before performing arithmetic with it, which prevents any errors. If val is not a number ('unknown'), the end time will remain unchanged instead of being set to undefined (undefined), which can lead to unintended behavior.

If you have more specific requirements or optimizations needed for this function, please clarify!

Expand Down