杨磊
2 天以前 ac478242e0ecb50b23b2e91c0541f9ceae2dccf6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
  <div class="search-container">
    <el-select
      v-model="selectedType"
      slot="prepend"
      placeholder="请选择"
      class="type-select"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
    <div class="inputBox">
      <input type="text" v-model="searchText" class="search-input" />
      <div class="searchBtn" @click="handleSearch()">搜索</div>
    </div>
  </div>
</template>
 
<script>
export default {
  name: "SearchBox",
  props: {
    // 接收外部传入的选项
    options: {
      type: Array,
      default: () => [
        { value: "all", label: "全部" },
        { value: "name", label: "标题" },
        { value: "author", label: "作者" },
        { value: "year", label: "年份" },
        { value: "keyWords", label: "关键词" },
        { value: "abstract", label: "摘要" },
        { value: "source", label: "来源" },
      ],
      searchFun: {
        type: Function,
        default: () => {},
      },
    },
  },
  data() {
    return {
      searchText: "", // 输入框内容
      selectedType: "all", // 下拉框选中值
    };
  },
  methods: {
    // 搜索处理
    handleSearch() {
    // 找到选中的选项的label
    const selectedOption = this.options.find(option => option.value === this.selectedType);
    const selectedLabel = selectedOption ? selectedOption.label : '';
    console.log(selectedLabel,"001")
      this.$emit("search", {
        text: this.searchText,
        type: this.selectedType,
        label: selectedLabel 
      });
    },
  },
};
</script>
 
<style scoped>
/* 组合样式 */
.search-container {
  max-width: 800px;
  display: flex;
  align-items: center;
  background-color: #fff;
}
 
/* 输入框样式 */
.search-input {
  width: 100%;
 
}
 
.inputBox {
  border: 1px solid #b9a587;
  height: 38px;
  width: 400px;
  display: flex;
  justify-content: space-between;
  background-color: transparent !important;
  align-items: center;
  padding-right: 5px;
  border-radius: 5px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding-left: 10px;
}
 
.searchBtn {
  width: 70px;
  height: 30px;
  background-color: #937950;
  border-radius: 5px;
  margin-left: 10px;
  cursor: pointer;
  font-size: 14px;
  text-align: center;
  line-height: 30px;
  color: #fff;
}
 
/* 下拉框样式 */
.type-select {
  width: 120px;
}
 
/* 调整间距 */
.el-select /deep/ .el-input__inner {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border: 1px solid #b9a587;
  background-color: transparent;
  border-right: none;
}
 
.el-input-group__prepend {
  padding: 0;
  border: none;
}
</style>