starmusic-mobile
1<template>
2 <view class="search-bar">
3 <view class="search-bar-inner">
4 <lx-icon name="search" :size="32" color="#909399" />
5 <input
6 class="search-input"
7 :value="modelValue"
8 placeholder="搜索歌曲、歌手"
9 confirm-type="search"
10 @input="handleInput"
11 @confirm="handleConfirm"
12 @focus="handleFocus"
13 @blur="handleBlur"
14 />
15 <view v-if="modelValue" class="clear-btn d-press" @click="handleClear">
16 <lx-icon name="close" :size="28" color="#909399" />
17 </view>
18 </view>
19 </view>
20</template>
21
22<script>
23import LxIcon from './lx-icon/lx-icon.vue'
24
25export default {
26 name: 'SearchBar',
27 components: { LxIcon },
28 props: {
29 modelValue: {
30 type: String,
31 default: '',
32 },
33 },
34 emits: ['update:modelValue', 'search', 'focus', 'blur'],
35 methods: {
36 handleInput(e) {
37 this.$emit('update:modelValue', e.detail.value)
38 },
39 handleConfirm() {
40 if (!this.modelValue) return
41 this.$emit('search', this.modelValue)
42 },
43 handleClear() {
44 this.$emit('update:modelValue', '')
45 },
46 handleFocus() {
47 this.$emit('focus')
48 },
49 handleBlur(e) {
50 this.$emit('blur', e)
51 },
52 },
53}
54</script>
55
56<style lang="scss" scoped>
57.search-bar {
58 padding: 16rpx 24rpx;
59 background: var(--card-bg, #fff);
60 /* 半透明底 + 背景模糊:仅背景图开启时生效(变量由 background.js 注入),否则 none 跳过合成 */
61 backdrop-filter: var(--glass-blur, none);
62 -webkit-backdrop-filter: var(--glass-blur, none);
63}
64
65.search-bar-inner {
66 display: flex;
67 align-items: center;
68 height: 72rpx;
69 padding: 0 24rpx;
70 border-radius: 36rpx;
71 background: var(--fill-bg, #f2f3f5);
72 border: 2rpx solid transparent;
73 transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
74}
75
76/* 聚焦态:绿色光晕 */
77.search-bar-inner:focus-within {
78 background: var(--card-bg-strong, #fff);
79 border-color: var(--theme-color, #31c27c);
80 box-shadow: 0 0 0 6rpx rgba(var(--theme-color-rgb, 49, 194, 124), 0.12);
81}
82
83.search-bar-inner > .lx-icon {
84 margin-right: 12rpx;
85}
86
87.search-input {
88 flex: 1;
89 height: 72rpx;
90 font-size: 28rpx;
91 color: #303133;
92}
93
94.clear-btn {
95 display: flex;
96 align-items: center;
97 justify-content: center;
98 padding: 0 8rpx;
99}
100
101</style>