5454</template >
5555
5656<script setup>
57- import { ref , computed , toRefs , onMounted , nextTick , watch , onBeforeUnmount } from ' vue' ;
57+ import { ref , computed , onMounted , nextTick , watch , onBeforeUnmount , useSlots } from ' vue' ;
5858import {
5959 SendOutlined ,
6060 ArrowUpOutlined ,
@@ -67,7 +67,6 @@ import {
6767const inputRef = ref (null );
6868const isSingleLine = ref (true );
6969const optionsExpanded = ref (false );
70- const hasOptionsLeft = ref (false );
7170const singleLineHeight = ref (0 ); // Add this
7271// 用于防抖的定时器
7372const debounceTimer = ref (null );
@@ -107,6 +106,15 @@ const props = defineProps({
107106});
108107
109108const emit = defineEmits ([' update:modelValue' , ' send' , ' keydown' ]);
109+ const slots = useSlots ();
110+ const hasOptionsLeft = computed (() => {
111+ const slot = slots[' options-left' ];
112+ if (! slot) {
113+ return false ;
114+ }
115+ const renderedNodes = slot ();
116+ return Boolean (renderedNodes && renderedNodes .length );
117+ });
110118
111119// 图标映射
112120const iconComponents = {
@@ -206,13 +214,6 @@ const focusInput = () => {
206214 }
207215};
208216
209- // 检查是否有左侧选项
210- const checkOptionsLeft = () => {
211- // 这里可以通过检查slot内容来判断是否有选项
212- // 暂时设为true,实际使用时可以根据slot内容动态判断
213- hasOptionsLeft .value = true ;
214- };
215-
216217// 监听输入值变化
217218watch (inputValue, () => {
218219 nextTick (() => {
@@ -242,7 +243,6 @@ watch(inputValue, () => {
242243// Wait for component to mount before setting up onStartTyping
243244onMounted (() => {
244245 // console.log('Component mounted');
245- checkOptionsLeft ();
246246 nextTick (() => {
247247 if (inputRef .value ) {
248248 // 记录单行模式下的高度和宽度基准
@@ -457,4 +457,4 @@ onBeforeUnmount(() => {
457457 padding : 0.625rem 0.875rem ;
458458 }
459459}
460- </style >
460+ </style >
0 commit comments