fix(web): 适配后端 ID 字符串化(雪花 id 不能过 Number)
后端 J1 起所有 Long id 以字符串下发,审计出 4 处把 id 当数字用的地方: - utils/creatorImpersonation.ts:代看创作者 id 曾 Number(raw) 存 localStorage, 19 位 id 会被四舍五入导致 X-Creator-Id 头带错 id;改为全程字符串 - contentManagement/EpisodeManagementView.vue:Number(route.query.drama) 与 item.id 比较, 从短剧管理带 ?drama= 跳过来会选不中;改为字符串比较 - creator-center/composables/useDramaEdit.js:Number(route.params.id) 同上,作品编辑打不开 - permission/composables/useMenuManagement.js:顶级菜单哨兵 0 与接口的 "0" 类型不一致, 下拉回显会变裸 0;统一成字符串 '0' 核过不需要改:分页 total 后端保持数字;role.id === selectedRoleId 等两侧都来自接口; formatCount 内部 Number() 吃字符串;全局无 id 算术/下标/a.id-b.id。
This commit is contained in:
1 parent
db313f4aa6
commit
3ec9ea6717
4 files changed
+22
-13
No files matched your search
@@ -55,7 +55,8 @@ const selectedDrama = computed(() => dramas.value.find((item) => item.id === sel
|
||||
async function loadDramas() {
|
||||
const res = await pageDramasApi({ pageIndex: 1, pageSize: 200 })
|
||||
dramas.value = res.data?.list || []
|
||||
const fromQuery = Number(route.query.drama)
|
||||
// 剧 id 是字符串(雪花 id 过 Number 会被四舍五入),这里按字符串比较
|
||||
const fromQuery = route.query.drama ? String(route.query.drama) : ''
|
||||
if (fromQuery && dramas.value.some((item) => item.id === fromQuery)) {
|
||||
selectedDramaId.value = fromQuery
|
||||
} else if (!selectedDramaId.value && dramas.value.length) {
|
||||
|
||||
@@ -42,7 +42,8 @@ function writeSession(key, value) {
|
||||
export function useDramaEdit() {
|
||||
const { ensureAccess, impersonating } = useCreatorAccess()
|
||||
const route = useRoute()
|
||||
const dramaId = Number(route.params.id)
|
||||
// 作品 id 是字符串(雪花 id 过 Number 会被四舍五入),按字符串比对
|
||||
const dramaId = route.params.id ? String(route.params.id) : ''
|
||||
|
||||
const loading = ref(false)
|
||||
const drama = ref(null)
|
||||
|
||||
@@ -47,7 +47,9 @@ export function useMenuManagement() {
|
||||
const treeData = computed(() => mapNodes(menuTree.value))
|
||||
|
||||
const parentOptions = computed(() => {
|
||||
const options = [{ id: 0, label: '顶级菜单' }]
|
||||
// 顶级菜单哨兵跟接口的 parentId 一样用字符串 "0":菜单 id 是字符串,
|
||||
// 数字 0 会在下拉里对不上、回显成裸 "0"
|
||||
const options = [{ id: '0', label: '顶级菜单' }]
|
||||
const walk = (nodes, depth) => {
|
||||
;(nodes || []).forEach((node) => {
|
||||
if (node.type !== 'BUTTON') {
|
||||
@@ -73,7 +75,7 @@ export function useMenuManagement() {
|
||||
}
|
||||
}
|
||||
|
||||
function resetForm(parentId = 0) {
|
||||
function resetForm(parentId = '0') {
|
||||
Object.assign(form, {
|
||||
id: null,
|
||||
parentId,
|
||||
@@ -94,7 +96,7 @@ export function useMenuManagement() {
|
||||
const raw = node.raw || {}
|
||||
Object.assign(form, {
|
||||
id: raw.id,
|
||||
parentId: raw.parentId ?? 0,
|
||||
parentId: raw.parentId ?? '0',
|
||||
title: raw.meta?.title || '',
|
||||
routePath: raw.path || '',
|
||||
routeName: raw.name || '',
|
||||
@@ -114,7 +116,7 @@ export function useMenuManagement() {
|
||||
return ElMessage.warning('请填写对应路由')
|
||||
}
|
||||
const payload = {
|
||||
parentId: form.parentId || 0,
|
||||
parentId: form.parentId || '0',
|
||||
title: form.title.trim(),
|
||||
routePath: form.routePath.trim(),
|
||||
routeName: form.routeName.trim(),
|
||||
|
||||
Reference in new issue
Block a user