Compare commits

..
5 Commits
Author SHA1 Message Date
wc24 e789f8a1f7 feat(filter): filterableFields 递归收集嵌套 filterable,key=点路径
ShrimpTable 把 filterableFields 从'顶层 filter'改成'递归收集 object/tab 嵌套叶子',
生成 key=点路径的合成字段。抽屉/buildFilter/URL 同步全按 field.key 走即可,无需改。
版本与 shrimp-server 对齐 0.7.5。
2026-06-30 16:01:23 +08:00
wc24 d906603ce3 fix(add): array/object 字段新增初值用 []/{}(原落成 '')
handleAdd 里 array/object 类型字段未特判,初值落到 '';虽 FieldArray/FieldObject 能容错,
但语义错。补 array→[]、object→{}。版本与 shrimp-server 对齐 0.7.1。
2026-06-30 14:06:42 +08:00
wc24 c49663e16e feat!: object/array 字段组件 + 去掉 FieldJson + 版本统一 0.7.0
- 新增 FieldObject.vue(嵌套字段组,display/edit 递归渲染)、FieldArray.vue
  (元素列表,增删 + 每项递归渲染 item;第一版从简:无排序拖拽)。靠 glob 自动注册成 object/array。
- 删 FieldJson.vue(json 类型退场,object 取代)。
- 版本与 shrimp-server 统一为 0.7.0。
2026-06-29 22:25:59 +08:00
wc24 c44f2a159e feat(export): 前端生成 xlsx 前把对象/数组单元格 JSON 序列化
后端 export 改为只发原始对象后,前端在 json_to_sheet 前通用地 stringify 非标量单元格
(覆盖 tab 等),避免 [object Object];import 时由后端 reqFilter 还原。
2026-06-29 21:47:10 +08:00
wc24 35abfd831c feat(tab): 显示搬前端,递归渲染子字段组件(替代后端 _label 串)
FieldTab.display 不再吃 displayLabel 字符串,改为渲染选中分支的子字段(各自 display 组件):
relation 子→查 refs 出可点名、number→数字、嵌套 tab→再递归。配 shrimp-server v0.6.9
的 refs 下钻,嵌套关联名自动有。ShrimpTable displayLabel 绑定去掉 tab。
2026-06-29 21:30:48 +08:00
6 changed files with 240 additions and 72 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "shrimp-admin",
"version": "0.3.8",
"version": "0.7.5",
"private": true,
"description": "Shrimp 框架前端 — 消费 ShrimpServer + ShrimpTable 契约的经典 Vue3 + Element Plus 实现",
"main": "src/index.ts",
+30 -4
View File
@@ -29,7 +29,7 @@
<slot :name="`column-${field.key}`" :row="row" :field="field">
<component :is="vueAdmin.getFieldComponent(moduleKey, field.type, field.key)" :field="field"
:model-value="row[field.key]" mode="display"
v-bind="field.type === 'textarea' || field.type === 'tab' ? { displayLabel: row[field.key + '_label'] } : {}" />
v-bind="field.type === 'textarea' ? { displayLabel: row[field.key + '_label'] } : {}" />
</slot>
</template>
</el-table-column>
@@ -212,9 +212,24 @@ const formFields = computed(() => {
return list.filter(f => f.editable !== 'readonly')
})
const searchableFields = computed(() => fields.value.filter(f => f.searchable))
// 递归收集 filterable 字段(含 object/tab 嵌套叶子),生成 key=点路径的"合成字段"。
// 这样筛选抽屉/buildFilter/URL 同步全按 field.key 走即可——key 就是 condition.level 这种路径。
function collectFilterablePaths(list: IFieldConfig[], base: string[], out: any[]) {
for (const f of list) {
const path = [...base, f.key]
if (f.filterable) out.push({ ...f, key: path.join('.') })
if (f.type === 'tab' && Array.isArray((f as any).tabs)) {
for (const t of (f as any).tabs) collectFilterablePaths(t.fields, path, out)
} else if (f.type === 'object' && Array.isArray((f as any).fields)) {
collectFilterablePaths((f as any).fields, path, out)
}
}
}
const filterableFields = computed(() => {
const lockedKeys = new Set(Object.keys(props.baseFilter || {}))
return fields.value.filter(f => f.filterable && !lockedKeys.has(f.key))
const out: any[] = []
collectFilterablePaths(fields.value, [], out)
return out.filter(f => !lockedKeys.has(f.key))
})
const formSlotNames = computed(() => Object.keys(slots).filter(name => name.startsWith('form-')))
@@ -307,8 +322,10 @@ async function handleAdd() {
formData.value[field.key] = false
} else if (field.type === 'number') {
formData.value[field.key] = 0
} else if (field.multiple) {
} else if (field.type === 'array' || field.multiple) {
formData.value[field.key] = []
} else if (field.type === 'object') {
formData.value[field.key] = {}
} else {
formData.value[field.key] = ''
}
@@ -442,7 +459,16 @@ async function handleExport() {
}
if (ownerId.value) query.ownerId = ownerId.value
const list = await api.export(query)
const ws = XLSX.utils.json_to_sheet(list)
// 后端只发原始对象;xlsx 单元格放不下对象/数组(会变 [object Object]),这里通用地 JSON 序列化
// (覆盖 tab 等结构化字段)。import 时这些字符串由后端各类型 reqFilter 还原。
const rows = list.map((row: Record<string, any>) => {
const out: Record<string, any> = {}
for (const [k, v] of Object.entries(row)) {
out[k] = (v !== null && typeof v === 'object') ? JSON.stringify(v) : v
}
return out
})
const ws = XLSX.utils.json_to_sheet(rows)
const wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, props.moduleKey)
XLSX.writeFile(wb, `${props.moduleKey}_export_${Date.now()}.xlsx`)
+107
View File
@@ -0,0 +1,107 @@
<template>
<!-- 显示:逐元素递归渲染 item 的 display 组件 -->
<template v-if="mode === 'display'">
<span v-if="!items.length">-</span>
<span v-else class="arr-display">
<span v-for="(el, i) in items" :key="i" class="arr-chip">
<component :is="vueAdmin.getFieldComponent(moduleKey, field.item.type, '')"
:field="field.item" :model-value="el" mode="display" />
</span>
</span>
</template>
<!-- 编辑:每项一行(标题 + item 编辑组件 + 删除),底部添加。第一版从简:无排序拖拽 -->
<div v-else class="field-array">
<div v-for="(el, i) in items" :key="i" class="arr-row">
<div class="arr-head">
<span class="arr-idx">{{ itemTitle }} #{{ i + 1 }}</span>
<el-button type="danger" text size="small" @click="removeAt(i)">删除</el-button>
</div>
<component :is="vueAdmin.getFieldComponent(moduleKey, field.item.type, '')"
:field="field.item" :model-value="el"
@update:model-value="setAt(i, $event)" mode="edit" :disabled="disabled" />
</div>
<el-button type="primary" text @click="addOne" :disabled="disabled">+ 添加{{ itemTitle }}</el-button>
</div>
</template>
<script lang="ts" setup>
import { computed, inject } from 'vue'
import { vueAdmin } from '../../VueAdmin'
const props = defineProps<{
field: any
modelValue: any
mode: 'display' | 'edit' | 'filter'
disabled?: boolean
}>()
const emit = defineEmits<{ 'update:modelValue': [value: any] }>()
const moduleKey = inject('shrimpModuleKey', '')
const items = computed<any[]>(() => Array.isArray(props.modelValue) ? props.modelValue : [])
const itemTitle = computed(() => vueAdmin.t(props.field.item?.label) || '项')
function setAt(i: number, value: any) {
const arr = items.value.slice()
arr[i] = value
emit('update:modelValue', arr)
}
function removeAt(i: number) {
const arr = items.value.slice()
arr.splice(i, 1)
emit('update:modelValue', arr)
}
function addOne() {
emit('update:modelValue', [...items.value, defaultOf(props.field.item)])
}
/** 按 item schema 递归生成一个默认元素 */
function defaultOf(schema: any): any {
if (!schema) return null
if (schema.defaultValue !== undefined) return schema.defaultValue
if (schema.type === 'object') {
const obj: any = {}
for (const f of schema.fields || []) obj[f.key] = defaultOf(f)
return obj
}
if (schema.type === 'array') return []
if (schema.type === 'number') return 0
if (schema.type === 'boolean') return false
return null
}
</script>
<style scoped>
.arr-display {
display: inline-flex;
flex-wrap: wrap;
align-items: center;
gap: 4px 12px;
}
.field-array {
display: flex;
flex-direction: column;
gap: 8px;
}
.arr-row {
padding: 8px 10px;
border: 1px solid var(--el-border-color-lighter);
border-radius: 6px;
}
.arr-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 6px;
}
.arr-idx {
color: var(--el-text-color-secondary);
font-size: 12px;
font-weight: 600;
}
</style>
-48
View File
@@ -1,48 +0,0 @@
<template>
<template v-if="mode === 'display'">
<el-tooltip v-if="modelValue != null" :content="displayValue" placement="top">
<span class="json-display">{{ displayValue }}</span>
</el-tooltip>
<span v-else>-</span>
</template>
<el-input
v-else
:model-value="modelValue"
@update:model-value="$emit('update:modelValue', $event)"
type="textarea"
:rows="4"
:disabled="disabled"
placeholder="请输入 JSON"
/>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
const props = defineProps<{
field: any
modelValue: any
mode: 'display' | 'edit' | 'filter'
disabled?: boolean
}>()
defineEmits<{
'update:modelValue': [value: any]
}>()
const displayValue = computed(() => {
if (props.modelValue == null) return ''
if (typeof props.modelValue === 'string') return props.modelValue
return JSON.stringify(props.modelValue, null, 2)
})
</script>
<style scoped>
.json-display {
display: inline-block;
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
+69
View File
@@ -0,0 +1,69 @@
<template>
<!-- 显示:递归渲染各子字段的 display 组件(relation 子查 refs) -->
<template v-if="mode === 'display'">
<span v-if="!modelValue || typeof modelValue !== 'object'">-</span>
<span v-else class="obj-display">
<span v-for="f in field.fields || []" :key="f.key" class="obj-child">
<span class="obj-label">{{ vueAdmin.t(f.label) }}:</span>
<component :is="vueAdmin.getFieldComponent(moduleKey, f.type, f.key)"
:field="f" :model-value="(modelValue || {})[f.key]" mode="display" />
</span>
</span>
</template>
<!-- 编辑:每个子字段一行,递归渲染 edit 组件 -->
<div v-else class="field-object">
<el-form-item v-for="f in field.fields || []" :key="f.key" :label="vueAdmin.t(f.label)" :required="f.required">
<component :is="vueAdmin.getFieldComponent(moduleKey, f.type, f.key)"
:field="f" :model-value="(modelValue || {})[f.key]"
@update:model-value="onChild(f.key, $event)" mode="edit" :disabled="disabled" />
</el-form-item>
</div>
</template>
<script lang="ts" setup>
import { inject } from 'vue'
import { vueAdmin } from '../../VueAdmin'
const props = defineProps<{
field: any
modelValue: any
mode: 'display' | 'edit' | 'filter'
disabled?: boolean
}>()
const emit = defineEmits<{ 'update:modelValue': [value: any] }>()
const moduleKey = inject('shrimpModuleKey', '')
function onChild(key: string, value: any) {
emit('update:modelValue', { ...(props.modelValue || {}), [key]: value })
}
</script>
<style scoped>
.obj-display {
display: inline-flex;
flex-wrap: wrap;
align-items: center;
gap: 4px 10px;
}
.obj-child {
display: inline-flex;
align-items: center;
gap: 4px;
}
.obj-label {
color: var(--el-text-color-secondary);
font-size: 12px;
}
.field-object {
display: flex;
flex-direction: column;
gap: 8px;
padding-left: 12px;
border-left: 2px solid var(--el-border-color-lighter);
}
</style>
+33 -19
View File
@@ -1,13 +1,15 @@
<template>
<template v-if="mode === 'display'">
<!-- 表格列展示后端算好的 stringify 文本(displayLabel=${key}_label);本体仍是对象,供编辑/逻辑用 -->
<el-tooltip v-if="displayLabel" :content="String(displayLabel)" placement="top">
<span class="tab-display">{{ displayLabel }}</span>
</el-tooltip>
<span v-else-if="!modelValue || typeof modelValue !== 'object'">-</span>
<el-tooltip v-else :content="JSON.stringify(modelValue, null, 2)" placement="top">
<span class="tab-display">{{ displayText }}</span>
</el-tooltip>
<!-- 显示=前端递归渲染:分支标签 + 选中分支的子字段(各自 display 组件,relation 查 refs/可点、嵌套 tab 再递归) -->
<span v-if="!modelValue || typeof modelValue !== 'object'">-</span>
<span v-else class="tab-display">
<span class="tab-branch">{{ branchLabel }}</span>
<span v-for="childField in selectedTab?.fields || []" :key="childField.key" class="tab-child">
<span class="tab-child-label">{{ vueAdmin.t(childField.label) }}:</span>
<component :is="vueAdmin.getFieldComponent(moduleKey, childField.type, childField.key)"
:field="childField" :model-value="innerValue[childField.key]" mode="display" />
</span>
</span>
</template>
<div v-else class="field-tab">
<el-form-item :label="vueAdmin.t(field.label) + ' - 类型'" :required="field.required">
@@ -39,7 +41,6 @@ const props = defineProps<{
modelValue: any
mode: 'display' | 'edit' | 'filter'
disabled?: boolean
displayLabel?: string
}>()
const emit = defineEmits<{
@@ -48,11 +49,9 @@ const emit = defineEmits<{
const moduleKey = inject('shrimpModuleKey', '')
const displayText = computed(() => {
if (!props.modelValue || typeof props.modelValue !== 'object') return '-'
const type = props.modelValue.type
const tab = props.field.tabs?.find((t: any) => t.key === type)
return tab ? vueAdmin.t(tab.label) : String(type)
const branchLabel = computed(() => {
const tab = selectedTab.value
return tab ? vueAdmin.t(tab.label) : String(props.modelValue?.type ?? '')
})
const selectedTab = computed(() => {
@@ -105,11 +104,26 @@ onMounted(() => {
<style scoped>
.tab-display {
display: inline-block;
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: inline-flex;
flex-wrap: wrap;
align-items: center;
gap: 4px 10px;
}
.tab-branch {
font-weight: 600;
color: var(--el-color-primary);
}
.tab-child {
display: inline-flex;
align-items: center;
gap: 4px;
}
.tab-child-label {
color: var(--el-text-color-secondary);
font-size: 12px;
}
.field-tab {