feat:【mall】diy editor 的 search-bar 优化

This commit is contained in:
YunaiV
2025-11-01 21:19:05 +08:00
parent c6d6d1c1e8
commit b880043900
3 changed files with 18 additions and 52 deletions

View File

@@ -13,10 +13,10 @@ export interface SearchProperty {
style: ComponentStyle; style: ComponentStyle;
} }
// 文字位置 /** 文字位置 */
export type PlaceholderPosition = 'center' | 'left'; export type PlaceholderPosition = 'center' | 'left';
// 定义组件 /** 定义组件 */
export const component = { export const component = {
id: 'SearchBar', id: 'SearchBar',
name: '搜索框', name: '搜索框',

View File

@@ -5,19 +5,19 @@ import { IconifyIcon } from '@vben/icons';
/** 搜索框 */ /** 搜索框 */
defineOptions({ name: 'SearchBar' }); defineOptions({ name: 'SearchBar' });
defineProps<{ property: SearchProperty }>(); defineProps<{ property: SearchProperty }>();
</script> </script>
<template> <template>
<div <div
class="search-bar"
:style="{ :style="{
color: property.textColor, color: property.textColor,
}" }"
> >
<!-- 搜索框 --> <!-- 搜索框 -->
<div <div
class="inner" class="relative flex min-h-7 items-center text-sm"
:style="{ :style="{
height: `${property.height}px`, height: `${property.height}px`,
background: property.backgroundColor, background: property.backgroundColor,
@@ -25,7 +25,7 @@ defineProps<{ property: SearchProperty }>();
}" }"
> >
<div <div
class="placeholder" class="flex w-full items-center gap-0.5 overflow-hidden text-ellipsis whitespace-nowrap break-all px-2"
:style="{ :style="{
justifyContent: property.placeholderPosition, justifyContent: property.placeholderPosition,
}" }"
@@ -33,11 +33,11 @@ defineProps<{ property: SearchProperty }>();
<IconifyIcon icon="ep:search" /> <IconifyIcon icon="ep:search" />
<span>{{ property.placeholder || '搜索商品' }}</span> <span>{{ property.placeholder || '搜索商品' }}</span>
</div> </div>
<div class="right"> <div class="absolute right-2 flex items-center justify-center gap-2">
<!-- 搜索热词 --> <!-- 搜索热词 -->
<span v-for="(keyword, index) in property.hotKeywords" :key="index">{{ <span v-for="(keyword, index) in property.hotKeywords" :key="index">
keyword {{ keyword }}
}}</span> </span>
<!-- 扫一扫 --> <!-- 扫一扫 -->
<IconifyIcon <IconifyIcon
icon="ant-design:scan-outlined" icon="ant-design:scan-outlined"
@@ -47,37 +47,3 @@ defineProps<{ property: SearchProperty }>();
</div> </div>
</div> </div>
</template> </template>
<style scoped lang="scss">
.search-bar {
/* 搜索框 */
.inner {
position: relative;
display: flex;
align-items: center;
min-height: 28px;
font-size: 14px;
.placeholder {
display: flex;
gap: 2px;
align-items: center;
width: 100%;
padding: 0 8px;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
white-space: nowrap;
}
.right {
position: absolute;
right: 8px;
display: flex;
gap: 8px;
align-items: center;
justify-content: center;
}
}
}
</style>

View File

@@ -11,6 +11,7 @@ import {
ElCard, ElCard,
ElForm, ElForm,
ElFormItem, ElFormItem,
ElInput,
ElRadioButton, ElRadioButton,
ElRadioGroup, ElRadioGroup,
ElSlider, ElSlider,
@@ -18,7 +19,7 @@ import {
ElTooltip, ElTooltip,
} from 'element-plus'; } from 'element-plus';
import { Draggable } from '#/views/mall/promotion/components'; import { ColorInput, Draggable } from '#/views/mall/promotion/components';
import ComponentContainerProperty from '../../component-container-property.vue'; import ComponentContainerProperty from '../../component-container-property.vue';
@@ -26,10 +27,12 @@ import ComponentContainerProperty from '../../component-container-property.vue';
defineOptions({ name: 'SearchProperty' }); defineOptions({ name: 'SearchProperty' });
const props = defineProps<{ modelValue: SearchProperty }>(); const props = defineProps<{ modelValue: SearchProperty }>();
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue']);
const formData = useVModel(props, 'modelValue', emit); const formData = useVModel(props, 'modelValue', emit);
// 监听热词数组变化 /** 监听热词数组变化 */
watch( watch(
() => formData.value.hotKeywords, () => formData.value.hotKeywords,
(newVal) => { (newVal) => {
@@ -45,8 +48,7 @@ watch(
<template> <template>
<ComponentContainerProperty v-model="formData.style"> <ComponentContainerProperty v-model="formData.style">
<!-- 表单 --> <ElForm label-width="80px" :model="formData">
<ElForm label-width="80px" :model="formData" class="mt-2">
<ElCard header="搜索热词" class="property-group" shadow="never"> <ElCard header="搜索热词" class="property-group" shadow="never">
<Draggable <Draggable
v-model="formData.hotKeywords" v-model="formData.hotKeywords"
@@ -56,7 +58,7 @@ watch(
}" }"
> >
<template #default="{ index }"> <template #default="{ index }">
<el-input <ElInput
v-model="formData.hotKeywords[index]" v-model="formData.hotKeywords[index]"
placeholder="请输入热词" placeholder="请输入热词"
/> />
@@ -79,7 +81,7 @@ watch(
</ElRadioGroup> </ElRadioGroup>
</ElFormItem> </ElFormItem>
<ElFormItem label="提示文字" prop="placeholder"> <ElFormItem label="提示文字" prop="placeholder">
<el-input v-model="formData.placeholder" /> <ElInput v-model="formData.placeholder" />
</ElFormItem> </ElFormItem>
<ElFormItem label="文本位置" prop="placeholderPosition"> <ElFormItem label="文本位置" prop="placeholderPosition">
<ElRadioGroup v-model="formData!.placeholderPosition"> <ElRadioGroup v-model="formData!.placeholderPosition">
@@ -110,12 +112,10 @@ watch(
<ElFormItem label="框体颜色" prop="backgroundColor"> <ElFormItem label="框体颜色" prop="backgroundColor">
<ColorInput v-model="formData.backgroundColor" /> <ColorInput v-model="formData.backgroundColor" />
</ElFormItem> </ElFormItem>
<ElFormItem class="lef" label="文本颜色" prop="textColor"> <ElFormItem label="文本颜色" prop="textColor">
<ColorInput v-model="formData.textColor" /> <ColorInput v-model="formData.textColor" />
</ElFormItem> </ElFormItem>
</ElCard> </ElCard>
</ElForm> </ElForm>
</ComponentContainerProperty> </ComponentContainerProperty>
</template> </template>
<style scoped lang="scss"></style>