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。
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<el-drawer class="shrimp-drawer" :model-value="visible" @update:model-value="$emit('update:visible', $event)"
|
||||
:title="title" size="400px">
|
||||
<el-form :model="localFilterData">
|
||||
<template v-for="field in filterableFields" :key="field.key">
|
||||
<el-form-item :label="vueAdmin.t(field.label)">
|
||||
<slot :name="`filter-${field.key}`" :field="field" :data="localFilterData">
|
||||
<component :is="vueAdmin.getFieldComponent(moduleKey, field.type, field.key)" :field="field"
|
||||
:model-value="localFilterData[field.key]"
|
||||
@update:model-value="onFieldChange(field.key, $event)" mode="filter" />
|
||||
</slot>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="handleReset">{{ $t('base.reset') }}</el-button>
|
||||
<el-button type="primary" @click="handleConfirm">{{ $t('base.confirm') }}</el-button>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { IFieldConfig } from 'shrimp-server/types'
|
||||
import { vueAdmin } from '../VueAdmin'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
title: string
|
||||
moduleKey: string
|
||||
filterableFields: IFieldConfig[]
|
||||
filterData: Record<string, any>
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:visible': [value: boolean]
|
||||
confirm: [value: Record<string, any>]
|
||||
reset: []
|
||||
}>()
|
||||
|
||||
const localFilterData = ref<Record<string, any>>({})
|
||||
const closedByReset = ref(false)
|
||||
|
||||
function hasChanged(): boolean {
|
||||
return JSON.stringify(localFilterData.value) !== JSON.stringify(props.filterData)
|
||||
}
|
||||
|
||||
watch(() => props.visible, (val, oldVal) => {
|
||||
if (oldVal === false && val === true) {
|
||||
closedByReset.value = false
|
||||
localFilterData.value = { ...props.filterData }
|
||||
}
|
||||
if (oldVal === true && val === false) {
|
||||
if (closedByReset.value) {
|
||||
closedByReset.value = false
|
||||
emit('reset')
|
||||
return
|
||||
}
|
||||
if (hasChanged()) {
|
||||
emit('confirm', { ...localFilterData.value })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function onFieldChange(key: string, value: any) {
|
||||
localFilterData.value = { ...localFilterData.value, [key]: value }
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
closedByReset.value = true
|
||||
localFilterData.value = {}
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
function handleConfirm() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.shrimp-drawer .el-drawer__header {
|
||||
margin-bottom: 0;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.shrimp-drawer .el-drawer__body {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.shrimp-drawer .el-drawer__footer {
|
||||
padding: 12px 20px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.shrimp-drawer .el-drawer__body .el-form-item {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user