File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
DiyEditor/components/mobile/SearchBar Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 3
3
<!-- 表单 -->
4
4
<el-form label-width =" 80px" :model =" formData" class =" m-t-8px" >
5
5
<el-card header =" 搜索热词" class =" property-group" shadow =" never" >
6
- <Draggable v-model =" formData.hotKeywords" :empty-item =" ''" >
6
+ <Draggable v-model =" formData.hotKeywords" :empty-item =" ''" :min = " 0 " >
7
7
<template #default =" { index } " >
8
8
<el-input v-model =" formData.hotKeywords[index]" placeholder =" 请输入热词" />
9
9
</template >
61
61
<script setup lang="ts">
62
62
import { useVModel } from ' @vueuse/core'
63
63
import { SearchProperty } from ' @/components/DiyEditor/components/mobile/SearchBar/config'
64
+ import { isString } from ' @/utils/is'
64
65
65
66
/** 搜索框属性面板 */
66
67
defineOptions ({ name: ' SearchProperty' })
67
68
68
69
const props = defineProps <{ modelValue: SearchProperty }>()
69
70
const emit = defineEmits ([' update:modelValue' ])
70
71
const formData = useVModel (props , ' modelValue' , emit )
72
+
73
+ // 监听热词数组变化
74
+ watch (
75
+ () => formData .value .hotKeywords ,
76
+ (newVal ) => {
77
+ // 找到非字符串项的索引
78
+ const nonStringIndex = newVal .findIndex ((item ) => ! isString (item ))
79
+ if (nonStringIndex !== - 1 ) {
80
+ formData .value .hotKeywords [nonStringIndex ] = ' '
81
+ }
82
+ },
83
+ { deep: true , flush: ' post' }
84
+ )
71
85
</script >
72
86
73
87
<style scoped lang="scss"></style >
Original file line number Diff line number Diff line change 28
28
<Icon
29
29
icon =" ep:delete"
30
30
class =" cursor-pointer text-red-5"
31
- v-if =" formData.length > 1 "
31
+ v-if =" formData.length > min "
32
32
@click =" handleDelete(index)"
33
33
/>
34
34
</el-tooltip >
@@ -69,7 +69,9 @@ const props = defineProps({
69
69
// 空的元素:点击添加按钮时,创建元素并添加到列表;默认为空对象
70
70
emptyItem: any <unknown >().def ({}),
71
71
// 数量限制:默认为0,表示不限制
72
- limit: propTypes .number .def (0 )
72
+ limit: propTypes .number .def (0 ),
73
+ // 最小数量:默认为1
74
+ min: propTypes .number .def (1 )
73
75
})
74
76
// 定义事件
75
77
const emit = defineEmits ([' update:modelValue' ])
You can’t perform that action at this time.
0 commit comments