
<template>
<div class="search">
<div class="searchinput">
<input
placeholder="请输入搜索关健字(譬如:表名、表注释、字段名......)"
class="s-input"
v-model="searchChild"
@change="searchChange"
@keyup="actionkeyboard"
@keyup.enter="enterkey"
@focus="getAction"
@blur="leave"
/>
<CloseCircleOutlined v-if='searchChild!==""&&searchChild!==undefined' @mousedown='closeinput' class='closeicon'/>
</div>
<div class="history" v-if="visible">
<ul class="dataList-top" >
<li
v-for="(item, index) in historylist"
:key="index"
@mousedown="searchkey(item)"
>
<a >
<div class="hint">{{ item }}</div>
</a>
</li>
</ul>
</div>
</div>
</template>
<script>
import { ref, watch } from "vue";
export default {
name: "searchhistory",
props: {
searchvalue: String || undefined,
list: Array,
},
emits: ["update:searchvalue"],
setup(props, { emit }) {
const searchChild = ref();
const visible = ref(false);
const historylist = ref([]);
const updateSearch = () => {
emit("update:searchvalue", searchChild.value);
};
const searchChange = (e) => {
searchChild.value = e.target.value;
updateSearch();
};
const enterkey = (e) => {
visible.value = false;
emit("enterkeys");
};
const getAction = (e) => {
visible.value = true;
historylist.value = props.list;
};
const leave = (e) => {
visible.value = false;
};
const actionkeyboard = (e) => {
if (e.code === "Backspace") {
if (searchChild.value === "") {
updateSearch();
emit("enterkeys");
}
}
};
const searchkey = (e) => {
searchChild.value = e;
visible.value = false;
updateSearch()
emit("enterkeys");
};
const closeinput = (e) => {
searchChild.value = '';
visible.value = false;
updateSearch()
emit("enterkeys");
};
watch(
() => props.list,
(newVal) => {
historylist.value = newVal || [];
}
);
return {
searchChild,
historylist,
searchChange,
enterkey,
getAction,
visible,
leave,
actionkeyboard,
searchkey,
closeinput
};
},
};
</script>
<style lang="less" scoped>
.search {
display: flex;
flex-direction: column;
width: 700px;
position: relative;
}
.searchinput {
width: 100%;
position: relative;
}
.s-input {
width: 100%;
height: 32px;
padding: 4px;
background-color: #fff;
border: 1px solid #d9d9d9;
}
.s-input:focus :hover {
border: solid 1px #1890ff !important;
}
.history {
width: 100%;
background: white;
position: absolute;
z-index: 1000;
top: 40px;
left: 0;
}
.hint {
font-size: 12px;
list-style: none;
padding-left: 10px;
font-size: 14px;
padding-top: 5px;
padding-bottom: 5px;
}
.closeicon{
display: none;
position: absolute;
right:6px;
top:8px;
}
.dataList-top{
cursor: pointer;
}
.searchinput:hover .closeicon{
position: absolute;
right:6px;
top:8px;
display: block;
}
</style>

- 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
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
<div class="search-item">
<SearchHistory v-model:searchvalue="parms.keyword" :list="searchReverseList" @enterkeys='enterkeys'></SearchHistory>
<a-button class='btn-search' type="primary" @click="search()">搜索</a-button>
</div>
const enterkeys= (e)=>{
search()
}