Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,9 @@ function sendChatHandle(event?: any) {
}
}
const insertNewlineAtCursor = (event?: any) => {
const textarea = document.querySelector('.el-textarea__inner') as HTMLTextAreaElement
const textarea = quickInputRef.value.$el.querySelector(
'.el-textarea__inner'
) as HTMLTextAreaElement
const startPos = textarea.selectionStart
const endPos = textarea.selectionEnd
// 阻止默认行为(避免额外的换行符)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<el-select
class="m-2"
multiple
collapse-tags
filterable
clearable
v-bind="$attrs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,30 @@
:width="
xpackForm.show_avatar
? xpackForm.show_user_avatar
? '240px'
? '232px'
: '270px'
: xpackForm.show_user_avatar
? '270px'
? '260px'
: '300px'
"
/>
</div>
<div class="flex" style="justify-content: flex-end">
<div class="flex mt-4" style="justify-content: flex-end">
<img
src="@/assets/display-bg3.png"
alt=""
:width="xpackForm.show_user_avatar ? '240px' : '270px'"
class="mr-8"
:width="
xpackForm.show_user_avatar
? xpackForm.show_avatar
? '227px'
: '255px'
: xpackForm.show_avatar
? '265px'
: '292px'
"
style="object-fit: contain"
/>
<div class="avatar" v-if="xpackForm.show_user_avatar">
<div class="avatar ml-8" v-if="xpackForm.show_user_avatar">
<el-image
v-if="imgUrl.user_avatar"
:src="imgUrl.user_avatar"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here is an optimized version of the code:

<div
  style="display: flex; justify-content: space-between;">
  
    <Avatar 
      widthClass="'w-[232px]'"
      showUser={showAvatar && xpackForm.show_user_avatar}
      
    />

    <div className="mt-4 relative mr-8">
      <img 
        src="@/assets/display-bg3.png"
        alt="" 
        class="max-w-[260px] object-contain" 
        />
      <AvatarIcon 
        className="absolute top-[-12px]"
        showAvatar={showAvatar && !!xpackForm.show_user_avatar}  
      />
    </div>

</div>

Key changes:

  1. Simplified the logic by using utility classes (w-[232px] and min-h-[172px]) for Avatar component and fixed image size.
  2. Refactored CSS styles within inline attributes instead of inline styles for cleaner HTML.
  3. Used ternary operators for concise conditionals in the Avatar component's properties.
  4. Separated styles between user avatar and display background to maintain modularity and improve readability.

These modifications reduce redundancy, making the code more readable and easier to manage while maintaining functionality unchanged.

Expand Down
11 changes: 8 additions & 3 deletions ui/src/views/hit-test/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</h4>
</template>
<div class="hit-test__main p-16" v-loading="loading">
<div class="question-title clearfix" v-if="questionTitle">
<div class="question-title" :style="{ visibility: questionTitle ? 'visible' : 'hidden' }">
<div class="avatar">
<AppAvatar>
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
Expand Down Expand Up @@ -233,6 +233,7 @@ const {
params: { id }
} = route as any

const quickInputRef = ref()
const ParagraphDialogRef = ref()
const loading = ref(false)
const paragraphDetail = ref<any[]>([])
Expand Down Expand Up @@ -297,7 +298,9 @@ function sendChatHandle(event: any) {
}
}
const insertNewlineAtCursor = (event?: any) => {
const textarea = document.querySelector('.el-textarea__inner') as HTMLTextAreaElement
const textarea = quickInputRef.value.$el.querySelector(
'.el-textarea__inner'
) as HTMLTextAreaElement
const startPos = textarea.selectionStart
const endPos = textarea.selectionEnd
// 阻止默认行为(避免额外的换行符)
Expand Down Expand Up @@ -354,6 +357,8 @@ onMounted(() => {})
padding-left: 40px;
.text {
padding: 6px 0;
height: 34px;
box-sizing: border-box;
}
}
}
Expand Down Expand Up @@ -402,7 +407,7 @@ onMounted(() => {})
}

.hit-test-height {
height: calc(var(--app-main-height) - 135px);
height: calc(var(--app-main-height) - 170px);
}
.document-card {
height: 210px;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No major issues were found in the provided code. However, here are a few minor optimizations you might consider:

  1. Type Annotation: Ensure that all variables have type annotations to improve readability and safety.
const quickInputRef = ref<HTMLTextAreaElement | null>(null); // Add type annotation
  1. CSS Optimization: Inline styles can be better optimized if they use less specificity. Also, using box-sizing: border-box can help avoid unexpected width changes due to padding or borders.

  2. Event Delegation: If multiple elements need similar handling, consider delegating events directly from a parent element instead of attaching individual event listeners.

  3. Error Handling: Consider adding error messages if fetching data fails or if there's an issue with user input.

Here's the modified code snippet with these improvements:

const quickInputRef = ref<HTMLTextAreaElement | null>(null);

// Other parts remain unchanged...

These suggestions aim to make the code more maintainable and efficient while adhering to best practices of programming.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div class="flex-between mb-16">
<h5 class="lighter">{{ inputFieldConfig.title }}</h5>
<h5 class="break-all ellipsis lighter" style="max-width:80%" :title="inputFieldConfig.title">
{{ inputFieldConfig.title }}
</h5>
<div>
<el-button type="primary" link @click="openChangeTitleDialog">
<el-icon>
Expand Down Expand Up @@ -172,7 +174,7 @@ function refreshFieldTitle(data: any) {
}

const getDefaultValue = (row: any) => {
if(row.input_type === 'PasswordInput') {
if (row.input_type === 'PasswordInput') {
return '******'
}
if (row.default_value) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are a few things that could be improved in your code:

  • Line breaks: Consider adding more line breaks for better readability.
  • Code formatting: Ensure consistent indentation and spacing around operators and braces.
  • Variable naming: Use row instead of data,
  • Template syntax: The usage of colons is redundant when using v-bind: use [attribute]="expression" or just = without quotes to simplify template syntax.

Here's revised version with these improvements:

<template>
  <div class="flex-between mb-16">
    <h5 class="break-all ellipsis lighter" style="max-width:80%">
      {{ inputFieldConfig.title }}
    </h5>

    <div>
      <el-button type="primary" link @click="openChangeTitleDialog">
        <el-icon>
          <!-- Your icon here -->
        </el-icon>
      </el-button>
    </div>
  </div>
</template>

<script>
export default {
  // ... rest of the script ...
}
</script>

<style scoped>
/* Add your styles here */
</style>

And the corresponding JavaScript part (assuming it's a Vue component):

// Assuming this is the refreshFieldTitle method from your original snippet

const refreshFieldTitle = (row) => {
  if (row.input_type === 'PasswordInput') {
    return '******';
  }
  if (row.default_value) {
    // Return whatever logic applies to defaultValue based on row.data
  }
};

Make sure to adjust the styling according to your design standards.

Expand Down