feat(web-admin): add useRouteEditIdOpen for deep-link edit dialogs

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-12 19:23:23 +08:00
1 parent c0fa3ccfd9
commit 0f1446b5d7
1 file changed
+33
@@ -0,0 +1,33 @@
import { watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
/**
* 监听 route.query.editId,调用 openById;结束后清除 editId,避免刷新重复弹窗。
* openById 应自行处理加载失败提示。
*/
export function useRouteEditIdOpen(openById: (id: string) => void | Promise<void>) {
const route = useRoute()
const router = useRouter()
async function consumeEditId() {
const raw = route.query.editId
const id = Array.isArray(raw) ? String(raw[0] || '') : String(raw || '')
if (!id.trim()) return
try {
await openById(id.trim())
} finally {
if (route.query.editId == null) return
const query = { ...route.query }
delete query.editId
await router.replace({ path: route.path, query })
}
}
watch(
() => route.query.editId,
() => {
void consumeEditId()
},
{ immediate: true }
)
}