Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e789f8a1f7 | ||
|
|
d906603ce3 | ||
|
|
c49663e16e | ||
|
|
c44f2a159e | ||
|
|
35abfd831c | ||
|
|
3b0887b126 | ||
|
|
bba08dadcc | ||
|
|
701ed957ef | ||
|
|
0b75f8c6f2 | ||
|
|
417318921c | ||
|
|
f7ef29a928 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "shrimp-admin",
|
||||
"version": "0.3.2",
|
||||
"version": "0.7.5",
|
||||
"private": true,
|
||||
"description": "Shrimp 框架前端 — 消费 ShrimpServer + ShrimpTable 契约的经典 Vue3 + Element Plus 实现",
|
||||
"main": "src/index.ts",
|
||||
|
||||
@@ -123,11 +123,19 @@ export class VueAdmin extends ShrimpClient {
|
||||
userName = ''
|
||||
config: ShrimpAdminConfig
|
||||
langList: { lang: string; name: string }[]
|
||||
/** 已注册成功的模块路由(moduleKey → IRouteInfo),供 relation 跳转/单项查看解析路由 */
|
||||
moduleRoutes = new Map<string, IRouteInfo>()
|
||||
|
||||
getFieldComponent(_moduleKey: string, type: string, _fieldKey?: string): Component {
|
||||
return fieldRegistry.get(type) || fieldRegistry.get('string')!
|
||||
}
|
||||
|
||||
/** 目标模块能否作为「单项查看」跳转目标:已按权限注册路由 且 非子模块。返回其路由信息或 undefined(不可跳) */
|
||||
routeForModule(moduleKey: string): IRouteInfo | undefined {
|
||||
if (this.moduleInfo.find(m => m.moduleKey === moduleKey)?.parent) return undefined
|
||||
return this.moduleRoutes.get(moduleKey)
|
||||
}
|
||||
|
||||
state = reactive({ isMobile: false })
|
||||
|
||||
private _token: string | null = null
|
||||
@@ -256,6 +264,7 @@ export class VueAdmin extends ShrimpClient {
|
||||
props: { moduleKey: info.moduleKey, events: info.events },
|
||||
meta: { title: info.label }
|
||||
})
|
||||
this.moduleRoutes.set(info.moduleKey, info)
|
||||
}
|
||||
|
||||
initRouter() {
|
||||
|
||||
@@ -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>
|
||||
@@ -132,8 +132,18 @@ const {
|
||||
|
||||
const searchVisible = ref(false)
|
||||
|
||||
// relation 跳转用 ?filter={_id} 锁定单条;_id 是隐形 pin(不在筛选抽屉里),
|
||||
// 用户一旦搜索/改筛选就清掉它,避免被看不见的 _id 一直 AND 着导致结果莫名为空
|
||||
function stripJumpPin() {
|
||||
if ('_id' in filterData.value) {
|
||||
const { _id, ...rest } = filterData.value
|
||||
filterData.value = rest
|
||||
}
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
searchKeyword.value = keyword.value
|
||||
stripJumpPin()
|
||||
currentPage.value = 1
|
||||
refresh()
|
||||
}
|
||||
@@ -151,7 +161,8 @@ const hasFilter = computed(() => {
|
||||
})
|
||||
|
||||
async function handleFilterConfirm(newFilterData: Record<string, any>) {
|
||||
filterData.value = newFilterData
|
||||
const { _id, ...rest } = newFilterData // 确认筛选 → 丢弃跳转 pin
|
||||
filterData.value = rest
|
||||
currentPage.value = 1
|
||||
await refresh()
|
||||
}
|
||||
@@ -201,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-')))
|
||||
@@ -296,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] = ''
|
||||
}
|
||||
@@ -323,8 +351,10 @@ async function handleSave() {
|
||||
formFields.value.forEach(field => {
|
||||
if (field.editable === 'readonly') return
|
||||
if (field.editable === 'addOnly') return
|
||||
const newValue = formData.value[field.key]
|
||||
const oldValue = originalData.value[field.key]
|
||||
// 清空字段值为 undefined 时,JSON.stringify 会丢键 → 后端收不到、看似"提交无效"。
|
||||
// 归一成 null:既保证清空能提交(后端置空),又让"两边都空"不误判为有改动。
|
||||
const newValue = formData.value[field.key] ?? null
|
||||
const oldValue = originalData.value[field.key] ?? null
|
||||
if (newValue === oldValue) return
|
||||
submitData[field.key] = newValue
|
||||
})
|
||||
@@ -429,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`)
|
||||
|
||||
@@ -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>
|
||||
@@ -42,7 +42,7 @@
|
||||
style="width: 100%"
|
||||
/>
|
||||
<el-date-picker v-else :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled"
|
||||
type="datetime" style="width: 100%" />
|
||||
type="datetime" :clearable="!field.required" style="width: 100%" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -1,7 +1,13 @@
|
||||
<template>
|
||||
<template v-if="mode === 'display'">
|
||||
<template v-if="field.multiple">{{ displayNames.join('、') || '-' }}</template>
|
||||
<template v-else>{{ displayName || '-' }}</template>
|
||||
<template v-if="field.multiple">
|
||||
<span v-if="!displayItems.length">-</span>
|
||||
<template v-for="(it, i) in displayItems" :key="i"><a v-if="jumpable" class="rel-link" @click.stop="goto(it.id)">{{ it.name }}</a><span v-else>{{ it.name }}</span><span v-if="i < displayItems.length - 1">、</span></template>
|
||||
</template>
|
||||
<template v-else>
|
||||
<a v-if="jumpable && modelValue != null" class="rel-link" @click.stop="goto(modelValue)">{{ displayName }}</a>
|
||||
<span v-else>{{ displayName || '-' }}</span>
|
||||
</template>
|
||||
</template>
|
||||
<el-select
|
||||
v-else-if="mode === 'filter'"
|
||||
@@ -12,7 +18,7 @@
|
||||
>
|
||||
<el-option v-for="opt in options" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
</el-select>
|
||||
<el-select v-else :model-value="stringValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled" :multiple="field.multiple" filterable remote :remote-method="onSearch" :loading="loading" style="width: 100%">
|
||||
<el-select v-else :model-value="stringValue" @update:model-value="onEdit" :disabled="disabled" :multiple="field.multiple" :clearable="!field.required" filterable remote :remote-method="onSearch" :loading="loading" style="width: 100%">
|
||||
<el-option v-for="opt in options" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
</el-select>
|
||||
</template>
|
||||
@@ -29,10 +35,16 @@ const props = defineProps<{
|
||||
disabled?: boolean
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: any]
|
||||
}>()
|
||||
|
||||
// 编辑态清空:el-select 单选清空发 '' 或 undefined,relation 是 ObjectId、且 undefined 会被
|
||||
// JSON.stringify 丢键 → 都归一成 null(取消关联)。多选清空是 [],原样。
|
||||
function onEdit(v: any) {
|
||||
emit('update:modelValue', v === '' || v == null ? (props.field.multiple ? [] : null) : v)
|
||||
}
|
||||
|
||||
const options = ref<{ label: string; value: string }[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
@@ -44,12 +56,22 @@ const displayName = computed(() => {
|
||||
if (id == null) return ''
|
||||
return dict.value[String(id)] ?? String(id)
|
||||
})
|
||||
const displayNames = computed(() =>
|
||||
const displayItems = computed(() =>
|
||||
(Array.isArray(props.modelValue) ? props.modelValue : [])
|
||||
.map((id: any) => dict.value[String(id)] ?? String(id))
|
||||
.filter(Boolean)
|
||||
.filter((id: any) => id != null)
|
||||
.map((id: any) => ({ id, name: dict.value[String(id)] ?? String(id) }))
|
||||
)
|
||||
|
||||
// 单项查看跳转:目标模块可达(已注册路由)且非子模块时,名字可点 → 跳目标模块并过滤到该 _id(单行)
|
||||
const jumpable = computed(() =>
|
||||
props.mode === 'display' && !!props.field.relation && !!vueAdmin.routeForModule(props.field.relation.moduleKey)
|
||||
)
|
||||
function goto(id: any) {
|
||||
const r = props.field.relation && vueAdmin.routeForModule(props.field.relation.moduleKey)
|
||||
if (!r || id == null) return
|
||||
vueAdmin.router.push({ name: r.name, query: { filter: JSON.stringify({ _id: String(id) }) } })
|
||||
}
|
||||
|
||||
/** 统一转为字符串值,解决 ObjectId 与 el-select 的匹配问题 */
|
||||
const stringValue = computed(() => {
|
||||
// filter 模式强制 multiple,始终返回数组
|
||||
@@ -105,3 +127,13 @@ onMounted(async () => {
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.rel-link {
|
||||
color: var(--el-color-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
.rel-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
@update:model-value="$emit('update:modelValue', $event)"
|
||||
:disabled="disabled"
|
||||
:multiple="field.multiple"
|
||||
:clearable="!field.required"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option v-for="opt in resolvedOptions" :key="opt.value" :label="vueAdmin.t(opt.label)" :value="opt.value" />
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</el-tag>
|
||||
<el-input v-model="inputValue" @keyup.enter="addTag" @blur="addTag" :placeholder="$t('base.pressEnter')" />
|
||||
</div>
|
||||
<el-input v-else :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled" clearable />
|
||||
<el-input v-else :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" :disabled="disabled" :clearable="!field.required" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
:model-value="modelValue"
|
||||
@update:model-value="$emit('update:modelValue', $event)"
|
||||
:disabled="disabled"
|
||||
clearable
|
||||
:clearable="!field.required"
|
||||
/>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<div v-if="!vueAdmin.state.isMobile && nextMenu.length > 0" class="aminui-side">
|
||||
<div class="adminui-side-scroll">
|
||||
<el-scrollbar>
|
||||
<el-menu :default-active="$route.fullPath" router>
|
||||
<el-menu :default-active="$route.path" router>
|
||||
<navMenu :navMenus="nextMenu"></navMenu>
|
||||
</el-menu>
|
||||
</el-scrollbar>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<el-main>
|
||||
<el-scrollbar>
|
||||
<el-menu
|
||||
:default-active="$route.fullPath"
|
||||
:default-active="$route.path"
|
||||
@select="select"
|
||||
router
|
||||
background-color="#212d3d"
|
||||
|
||||
+17
-1
@@ -50,6 +50,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { vueAdmin } from '../VueAdmin'
|
||||
import { IRole, IRoleProto, WithId, ILabel } from '../IShrimpType'
|
||||
import { ElMessage } from 'element-plus'
|
||||
@@ -61,12 +62,24 @@ interface IPowerItem {
|
||||
}
|
||||
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
|
||||
const props = defineProps<{
|
||||
moduleKey: string
|
||||
events?: string[]
|
||||
}>()
|
||||
|
||||
// relation 跳转落到 role 页时带 ?filter={"_id":...}。role 是自定义 master-detail 页(非 ShrimpTable、
|
||||
// 不做服务端过滤),全量加载后按这个 _id 在列表里选中那条;解析不出就走默认(选第一个)。
|
||||
function jumpTargetId(): string {
|
||||
try {
|
||||
const f = route.query.filter ? JSON.parse(String(route.query.filter)) : null
|
||||
return f && typeof f === 'object' ? String(f._id || '') : ''
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
const roleApi = vueAdmin.getModule<IRoleProto>('role')
|
||||
|
||||
const roleList = ref<WithId<IRole>[]>([])
|
||||
@@ -138,7 +151,10 @@ async function handleDelete() {
|
||||
onMounted(async () => {
|
||||
allPowers.value = await roleApi.allPower()
|
||||
await loadRoles()
|
||||
if (roleList.value.length > 0) {
|
||||
const jumpId = jumpTargetId()
|
||||
if (jumpId && roleList.value.some(r => r._id === jumpId)) {
|
||||
onSelect(jumpId)
|
||||
} else if (roleList.value.length > 0) {
|
||||
onSelect(roleList.value[0]._id)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user