Files
shrimp-admin/src/components/ShrimpSearchInput.vue
T
wc24 4cb3bb8d75 feat: shrimp-admin v0.1.0 — 从 hand-admin 抽离的框架前端
Shrimp 框架前端 — 一种消费 ShrimpServer + ShrimpTable 契约的经典 Vue3 +
Element Plus 实现。不是框架本身,只是按 shrimp-server 约定写的一份参考解法。

包含:
- ShrimpClient + VueAdmin(factory:createShrimpAdmin)
- 5 个 Shrimp* 组件 + 10 个内置 Field*.vue + PowerTree + LangSwitch
- 4 个内置模块:user / role / operationLog / FieldRelativeTime
- 完整后台壳 views(layout/login/sideM/topbar/userbar/navMenu/App/404/logo)
- composables/useTableUrlSync, locales(zh-cn/en 框架默认), style 全套

API 改造:
- createShrimpAdmin({ config, moduleSources, customFields, locales }) factory
- vueAdmin 改为 Proxy 单例,createShrimpAdmin 调用前访问会抛错
- import.meta.glob 业务字段/模块由消费侧传入(vite 静态扫描机制限制)
- 框架默认 locales 与消费侧 locales 在 i18n 初始化时合并

源码 ship 不打包,消费侧靠 vite 直接吃 .ts/.vue。
2026-05-23 21:01:33 +08:00

89 lines
1.9 KiB
Vue

<template>
<div class="header-search" :class="{ show: visible }">
<el-icon :size="18" @click.stop="toggleSearch"
:style="{ color: active ? 'var(--el-color-primary)' : '' }"
><el-icon-search /></el-icon>
<el-input ref="searchInput" :model-value="keyword" class="header-search-input" clearable
@update:model-value="$emit('update:keyword', $event)"
@keyup.enter="onSearch" @blur="onSearchBlur" @clear="onSearch" />
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
interface Props {
keyword: string
visible: boolean
active?: boolean
}
const props = defineProps<Props>()
const emit = defineEmits<{
'update:keyword': [value: string]
'update:visible': [value: boolean]
search: []
}>()
const searchInput = ref()
function toggleSearch() {
const next = !props.visible
emit('update:visible', next)
if (next) {
setTimeout(() => searchInput.value?.focus(), 200)
}
}
function onSearchBlur() {
if (!props.keyword) {
emit('update:visible', false)
}
}
function onSearch() {
emit('search')
}
</script>
<style scoped>
.header-search {
font-size: 0 !important;
display: flex;
align-items: center;
}
.header-search .el-icon {
cursor: pointer;
font-size: 18px;
vertical-align: middle;
}
.header-search-input {
font-size: 14px;
transition: width 0.2s;
width: 0;
overflow: hidden;
background: transparent;
border-radius: 0;
display: inline-block;
vertical-align: middle;
}
.header-search-input :deep(.el-input__inner) {
border-radius: 0;
border: 0;
padding-left: 0;
padding-right: 0;
box-shadow: none !important;
border-bottom: 1px solid var(--el-border-color);
vertical-align: middle;
}
.header-search.show .header-search-input {
width: 200px;
margin-left: 10px;
}
</style>