huminmin
3 天以前 7b7c1c76def12f1267c23b8c0de7ec085d96694b
src/components/HeaderSearch/index.vue
@@ -5,7 +5,7 @@
      v-model="show"
      width="600"
      @close="close"
      :show-close="false"
      :show-close="true"
      append-to-body
    >
      <el-input
@@ -46,6 +46,13 @@
import { isHttp } from '@/utils/validate'
import usePermissionStore from '@/store/modules/permission'
const props = defineProps({
  keyword: {
    type: String,
    default: ''
  }
})
const search = ref('')
const options = ref([])
const searchPool = ref([])
@@ -58,9 +65,25 @@
function click() {
  show.value = !show.value
  if (show.value) {
    syncSearchFromKeyword()
    nextTick(() => {
    headerSearchSelectRef.value && headerSearchSelectRef.value.focus()
    options.value = searchPool.value
    })
  }
}
function syncSearchFromKeyword() {
  search.value = props.keyword?.trim?.() ?? ''
  querySearch(search.value)
}
function open(keyword = props.keyword) {
  show.value = true
  search.value = keyword?.trim?.() ?? ''
  querySearch(search.value)
  nextTick(() => {
    headerSearchSelectRef.value && headerSearchSelectRef.value.focus()
  })
}
function close() {
@@ -163,6 +186,10 @@
watch(searchPool, (list) => {
  initFuse(list)
})
defineExpose({
  open
})
</script>
<style lang='scss' scoped>