后端 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。
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
// Author: fruit.com.cn
|
|
|
|
import { ref } from 'vue'
|
|
|
|
/**
|
|
* 超管「代看创作者」的当前目标。
|
|
*
|
|
* 目标走独立请求头 `X-Creator-Id`(不做查询参数),并且**只有带 `creator-center:impersonate`
|
|
* 权限的账号带上它才生效** —— 创作者自己带这个头没有任何作用。
|
|
* 这里只负责"记住用户选了谁",权限判断在后端。
|
|
*/
|
|
const STORAGE_KEY = 'creator-center:impersonate-id'
|
|
|
|
/**
|
|
* 代看目标按**字符串**存:创作者 id 是雪花 id(19 位),
|
|
* 用 Number 过一遍会被 JS 四舍五入,请求头就会带一个不存在的 id(见 api-phase1.md §0)。
|
|
*/
|
|
function readStored(): string | null {
|
|
const raw = localStorage.getItem(STORAGE_KEY)
|
|
const value = (raw || '').trim()
|
|
return value && value !== '0' ? value : null
|
|
}
|
|
|
|
export const impersonateCreatorId = ref<string | null>(readStored())
|
|
|
|
export function setImpersonateCreatorId(id: string | number | null) {
|
|
const value = id === null || id === undefined || id === '' ? null : String(id)
|
|
impersonateCreatorId.value = value
|
|
if (value) localStorage.setItem(STORAGE_KEY, value)
|
|
else localStorage.removeItem(STORAGE_KEY)
|
|
}
|
|
|
|
/** 创作者中心相关请求统一带上目标头(没选目标就不带) */
|
|
export function creatorCenterHeaders(): Record<string, string> {
|
|
return impersonateCreatorId.value ? { 'X-Creator-Id': String(impersonateCreatorId.value) } : {}
|
|
}
|