Skip to content

Commit 95e9bf2

Browse files
committed
refactor: 修复 lint 问题,清理未使用代码
- 移除 ContextEditor 组件中未使用的导入和变量 - 删除 ConversationManager 组件中的冗余函数 - 清理 types 组件中的未使用类型定义 - 优化关键 any 类型为具体类型 - 减少 lint 问题数量从 567 到 546 主要修复内容: - 移除 shouldUseVerticalLayout、shallowRef、nextTick 等未使用导入 - 删除 addVariableOverride、getAutosizeConfig 等未使用函数 - 优化 handleTemplateApply 和 setMessageRef 的类型定义 - 合并重复的 quickTemplates 导入
1 parent e898260 commit 95e9bf2

File tree

4 files changed

+11
-72
lines changed

4 files changed

+11
-72
lines changed

packages/ui/src/components/ContextEditor.vue

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,18 +1027,17 @@
10271027
<script setup lang="ts">
10281028
import { ref, computed, watch, shallowRef, nextTick, h } from 'vue'
10291029
import { useI18n } from 'vue-i18n'
1030-
import {
1031-
NModal, NTabs, NTabPane, NCard, NButton, NSpace, NTag, NList, NListItem,
1032-
NEmpty, NScrollbar, NInput, NSelect, NText, NDropdown, NGrid, NGridItem, NAlert,
1030+
import {
1031+
NModal, NTabs, NTabPane, NCard, NButton, NSpace, NTag, NList, NListItem,
1032+
NEmpty, NScrollbar, NInput, NSelect, NText, NGrid, NGridItem, NAlert,
10331033
NDataTable, type DataTableColumns
10341034
} from 'naive-ui'
10351035
import { useResponsive } from '../composables/useResponsive'
10361036
import { usePerformanceMonitor } from '../composables/usePerformanceMonitor'
10371037
import { useDebounceThrottle } from '../composables/useDebounceThrottle'
10381038
import { useAccessibility } from '../composables/useAccessibility'
10391039
import { useContextEditor } from '../composables/useContextEditor'
1040-
import { quickTemplateManager } from '../data/quickTemplates'
1041-
import type { QuickTemplateDefinition } from '../data/quickTemplates'
1040+
import { quickTemplateManager, type QuickTemplateDefinition } from '../data/quickTemplates'
10421041
import type { ContextEditorProps, ContextEditorEvents } from '../types/components'
10431042
import type { ContextEditorState, ConversationMessage, ToolDefinition } from '@prompt-optimizer/core'
10441043
import { PREDEFINED_VARIABLES } from '../types/variable'
@@ -1069,7 +1068,6 @@ const {
10691068
modalWidth,
10701069
buttonSize: responsiveButtonSize,
10711070
inputSize: responsiveInputSize,
1072-
shouldUseVerticalLayout,
10731071
isMobile
10741072
} = useResponsive()
10751073
@@ -1480,7 +1478,7 @@ const handleTemplatePreview = (template: QuickTemplateDefinition) => {
14801478
showTemplatePreview.value = true
14811479
}
14821480
1483-
const handleTemplateApply = (template: any) => {
1481+
const handleTemplateApply = (template: QuickTemplateDefinition) => {
14841482
if (!template.messages || template.messages.length === 0) {
14851483
console.warn('Template has no messages to apply')
14861484
return
@@ -1751,15 +1749,6 @@ const addVariable = () => {
17511749
}
17521750
}
17531751
1754-
const addVariableOverride = (name: string, currentValue: string) => {
1755-
variableEditState.value = {
1756-
show: true,
1757-
isEditing: false,
1758-
editingName: '',
1759-
name,
1760-
value: currentValue
1761-
}
1762-
}
17631752
17641753
const editVariable = (name: string) => {
17651754
const value = localState.value.variables[name] || ''
@@ -1841,8 +1830,9 @@ const handleCreateVariableAndOpenManager = (name: string) => {
18411830
// 消息聚焦(滚动并高亮)
18421831
const focusedIndex = ref<number | null>(null)
18431832
const messageRefs = new Map<number, HTMLElement>()
1844-
const setMessageRef = (index: number, el: any) => {
1845-
const element = el?.$el ? (el.$el as HTMLElement) : (el as HTMLElement)
1833+
const setMessageRef = (index: number, el: HTMLElement | { $el: HTMLElement } | null) => {
1834+
if (!el) return
1835+
const element = el && '$el' in el ? el.$el : el
18461836
if (element) messageRefs.set(index, element)
18471837
}
18481838
const focusMessage = (index: number) => {
@@ -2116,14 +2106,6 @@ const getImportPlaceholder = () => {
21162106
}
21172107
}
21182108
2119-
// 复制变量占位符到剪贴板
2120-
const copyVariableToClipboard = async (name: string) => {
2121-
try {
2122-
await navigator.clipboard.writeText(`{{${name}}}`)
2123-
} catch (e) {
2124-
console.warn('Failed to copy variable placeholder', e)
2125-
}
2126-
}
21272109
</script>
21282110

21292111
<style scoped>

packages/ui/src/components/ConversationManager.vue

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
</template>
251251

252252
<script setup lang="ts">
253-
import { ref, computed, watch, h, shallowRef, nextTick } from 'vue'
253+
import { ref, computed, watch, h } from 'vue'
254254
import { useI18n } from 'vue-i18n'
255255
import {
256256
NCard, NSpace, NText, NTag, NButton, NEmpty, NScrollbar,
@@ -259,7 +259,7 @@ import {
259259
import { usePerformanceMonitor } from '../composables/usePerformanceMonitor'
260260
import { useDebounceThrottle } from '../composables/useDebounceThrottle'
261261
import type { ConversationManagerProps, ConversationManagerEvents } from '../types/components'
262-
import type { ConversationMessage, OptimizationMode } from '@prompt-optimizer/core'
262+
import type { ConversationMessage } from '@prompt-optimizer/core'
263263
264264
const { t } = useI18n()
265265
@@ -423,24 +423,6 @@ const getRoleTagType = (role: string) => {
423423
}
424424
425425
// 动态autosize配置(轻量化版本)
426-
const getAutosizeConfig = (content: string) => {
427-
if (!content || typeof content !== 'string') {
428-
return { minRows: 1, maxRows: 3 }
429-
}
430-
431-
const lineCount = content.split('\n').length
432-
const charLength = content.length
433-
434-
// 基于内容长度和换行数决定行数范围(轻量化算法)
435-
if (charLength <= 50 && lineCount <= 1) {
436-
return { minRows: 1, maxRows: 2 }
437-
}
438-
if (charLength <= 150 && lineCount <= 2) {
439-
return { minRows: 2, maxRows: 4 }
440-
}
441-
442-
return { minRows: 2, maxRows: Math.min(8, Math.max(lineCount, 3)) }
443-
}
444426
445427
// 获取单个消息的变量信息(与ContextEditor统一)
446428
const getMessageVariables = (content: string) => {
@@ -452,30 +434,9 @@ const getMessageVariables = (content: string) => {
452434
return { detected, missing }
453435
}
454436
455-
// 变量处理的节流版本(用于频繁调用场景)
456-
const getMessageVariablesThrottled = throttle(getMessageVariables, 100)
457-
458-
// 安全的变量获取函数,确保始终返回有效结构
459-
const safeGetMessageVariables = (content: string) => {
460-
try {
461-
const result = getMessageVariablesThrottled(content)
462-
return result || { detected: [], missing: [] }
463-
} catch (error) {
464-
console.warn('[ConversationManager] Error in getMessageVariablesThrottled:', error)
465-
return { detected: [], missing: [] }
466-
}
467-
}
468437
469-
// 保持向后兼容的便捷函数
470-
const getMessageMissingVariables = (content: string): string[] => {
471-
return getMessageVariables(content).missing
472-
}
473438
474-
// 处理变量创建 - 统一化接口,传递变量名给父组件
475-
const handleCreateVariable = (name: string) => {
476-
// 发出变量管理器打开事件,传递要创建的变量名
477-
emit('openVariableManager', name)
478-
}
439+
479440
480441
const toggleCollapse = () => {
481442
isCollapsed.value = !isCollapsed.value

packages/ui/src/components/FavoriteButton.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ import {
101101
NInput,
102102
NSelect,
103103
NDynamicTags,
104-
NSwitch,
105104
NText,
106105
useMessage,
107106
type FormInst,

packages/ui/src/types/components.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
*/
55

66
import type {
7-
VariableDefinition,
87
ConversationMessage,
98
ToolDefinition,
109
ToolCallResult,
11-
ApplyToTestData,
1210
AdvancedTestResult,
1311
ContextEditorState,
1412
ComponentVisibility,
15-
AdvancedModuleState,
1613
VariableImportOptions,
1714
VariableExportData
1815
} from '@prompt-optimizer/core'

0 commit comments

Comments
 (0)