feat(web): 创作者中心「当前创作者」代看下拉 + 未绑定引导页
为什么:超管点进创作者中心原本是一片"未绑定创作者主体"的报错,既没说明原因也没有出路。 这批把两件事做出来:超管能在顶部选一个创作者只读代看;没有创作者身份的账号看到明确的引导页而不是白屏。 - 新增 useCreatorAccess(身份三态:granted / need-target / unbound)+ ImpersonationBar + CreatorAccessGuide, 四个页面用 CreatorCenterPage 统一套壳;身份不满足时不打业务接口,避免一串无意义的报错提示 - 代看目标存 localStorage,由 axios.request 统一给 /admin/creator-center 的请求加 X-Creator-Id 头 (不做查询参数;后端只对具备 impersonate 权限的账号认这个头) - axios 支持 silent 请求:业务码非 0 时不弹全局提示、把 Result 交给调用方判断(引导页据此分流) - 代看只读体验:代看态下「新建作品 / 编辑 / 提交审核 / 撤回」不渲染,编辑页整页禁用并提示原因 - 顶部下拉只在有 impersonate 权限时显示;无权限账号看不到、也不会请求 targets 接口
This commit is contained in:
1 parent
0a2e3e0b81
commit
685c912313
19 files changed
+995
-658
No files matched your search
@@ -41,6 +41,10 @@ const defaultResponseInterceptors = (response: AxiosResponse) => {
|
||||
} else if (response.data.code === SUCCESS_CODE) {
|
||||
return response.data
|
||||
} else {
|
||||
// 静默请求:调用方要自己看业务码(例如创作者中心据此渲染引导页),不弹全局提示
|
||||
if ((response.config as { silent?: boolean })?.silent) {
|
||||
return response.data
|
||||
}
|
||||
ElMessage.error(response?.data?.message)
|
||||
if (response?.data?.code === 401) {
|
||||
const userStore = useUserStoreWithOut()
|
||||
|
||||
+8
-1
@@ -1,23 +1,30 @@
|
||||
import service from './service'
|
||||
import { CONTENT_TYPE } from '@/constants'
|
||||
import { useUserStoreWithOut } from '@/store/modules/user'
|
||||
import { creatorCenterHeaders } from '@/utils/creatorImpersonation'
|
||||
|
||||
const request = (option: AxiosConfig) => {
|
||||
const { url, method, params, data, headers, responseType } = option
|
||||
const { url, method, params, data, headers, responseType, silent } = option
|
||||
const userStore = useUserStoreWithOut()
|
||||
// FormData 不能带 JSON 的 Content-Type,否则 axios 会把表单转成 JSON,浏览器也无法补上 boundary
|
||||
const isFormData = typeof FormData !== 'undefined' && data instanceof FormData
|
||||
// 创作者中心的请求统一带上代看目标头(超管选了代看创作者时才有值;
|
||||
// 后端只对具备 impersonate 权限的账号认这个头,创作者带了也不生效)
|
||||
const impersonationHeaders =
|
||||
typeof url === 'string' && url.startsWith('/admin/creator-center') ? creatorCenterHeaders() : {}
|
||||
return service.request({
|
||||
url: url,
|
||||
method,
|
||||
params,
|
||||
data,
|
||||
responseType: responseType,
|
||||
silent,
|
||||
headers: {
|
||||
...(isFormData ? {} : { 'Content-Type': CONTENT_TYPE }),
|
||||
[userStore.getTokenKey ?? 'Authorization']: userStore.getToken
|
||||
? `Bearer ${userStore.getToken}`
|
||||
: '',
|
||||
...impersonationHeaders,
|
||||
...headers
|
||||
}
|
||||
})
|
||||
|
||||
@@ -18,6 +18,8 @@ interface RequestInterceptors<T> {
|
||||
|
||||
interface RequestConfig<T = AxiosResponse> extends AxiosRequestConfig {
|
||||
interceptors?: RequestInterceptors<T>
|
||||
/** 静默请求:业务码非 0 时由调用方处理,不弹全局提示(见 axios/config.ts) */
|
||||
silent?: boolean
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
Reference in new issue
Block a user