feat(role): 跳转带的 ?filter={_id} 在角色列表里自动选中那条
role 是自定义 master-detail 页(非 ShrimpTable、不做服务端过滤),原 onMounted 默认选第一个, 无视 relation 跳转带的 _id。现全量加载后按 URL filter._id 客户端选中目标角色,解析不出走默认。
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "shrimp-admin",
|
||||
"version": "0.3.5",
|
||||
"version": "0.3.6",
|
||||
"private": true,
|
||||
"description": "Shrimp 框架前端 — 消费 ShrimpServer + ShrimpTable 契约的经典 Vue3 + Element Plus 实现",
|
||||
"main": "src/index.ts",
|
||||
|
||||
+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