fix: align authorization page with frontend api types #31

Merged
stefanfeng merged 1 commits from codex/fix-frontend-build-20260915 into main 2026-09-15 15:04:55 +08:00
Showing only changes of commit 9ba89ef2d1 - Show all commits
@@ -83,8 +83,6 @@ import { useAvatarStore } from '@/store/avatar'
import { import {
getAuthorizationList, getAuthorizationList,
updateAuthorization, updateAuthorization,
SQUARE_INTERACTION_TARGET_ID,
SQUARE_INTERACTION_PERMISSIONS,
type Authorization type Authorization
} from '@/api' } from '@/api'
import { pickAvatarId, unwrapListData } from '@/utils/avatar-page-data.js' import { pickAvatarId, unwrapListData } from '@/utils/avatar-page-data.js'
@@ -94,6 +92,8 @@ const avatarStore = useAvatarStore()
const authList = ref<Authorization[]>([]) const authList = ref<Authorization[]>([])
const saving = ref(false) const saving = ref(false)
const UNAVAILABLE_MESSAGE = '该功能尚未向公众用户开放,如需使用请联系会会运营团队' const UNAVAILABLE_MESSAGE = '该功能尚未向公众用户开放,如需使用请联系会会运营团队'
const SQUARE_INTERACTION_TARGET_ID = 'huihui-square'
const SQUARE_INTERACTION_PERMISSIONS = ['like', 'collect', 'comment', 'reply'] as const
const unavailableFeatures = [ const unavailableFeatures = [
{ id: 'make-friends', name: '交友与添加好友', description: '暂未开放', icon: '👥' }, { id: 'make-friends', name: '交友与添加好友', description: '暂未开放', icon: '👥' },
@@ -111,6 +111,9 @@ const squareAuthorization = computed<Authorization>(() => {
targetName: '会会广场互动', targetName: '会会广场互动',
permissions: [...SQUARE_INTERACTION_PERMISSIONS], permissions: [...SQUARE_INTERACTION_PERMISSIONS],
status: 'inactive', status: 'inactive',
takeoverEnabled: false,
takeoverMode: 'immediate',
takeoverDelaySeconds: 180,
createdAt: '' createdAt: ''
} }
}) })
@@ -120,7 +123,7 @@ const otherAuthorizations = computed(() =>
) )
const isUnavailableFeature = (name: string) => unavailableFeatures.some((feature) => const isUnavailableFeature = (name: string) => unavailableFeatures.some((feature) =>
name.replaceAll('发布微博内容', '发布微播内容') === feature.name name.replace(/发布微博内容/g, '发布微播内容') === feature.name
) )
const currentAvatarId = async () => { const currentAvatarId = async () => {
@@ -142,14 +145,12 @@ const toggleSquareAuthorization = async () => {
if (!avatarId || saving.value) return if (!avatarId || saving.value) return
saving.value = true saving.value = true
try { try {
authList.value = unwrapListData(await updateAuthorization(avatarId, { if (!squareAuthorization.value.id) return
id: squareAuthorization.value.id || undefined, const updated = await updateAuthorization(avatarId, {
targetId: SQUARE_INTERACTION_TARGET_ID, id: squareAuthorization.value.id,
targetName: '会会广场互动',
targetType: 'application',
permissions: [...SQUARE_INTERACTION_PERMISSIONS],
status: squareAuthorization.value.status === 'active' ? 'inactive' : 'active' status: squareAuthorization.value.status === 'active' ? 'inactive' : 'active'
})) })
authList.value = authList.value.map((item) => item.id === updated.id ? updated : item)
} catch (error) { } catch (error) {
alert('操作失败,请重试') alert('操作失败,请重试')
} finally { } finally {
@@ -162,10 +163,11 @@ const toggleExistingAuthorization = async (auth: Authorization) => {
if (!avatarId || saving.value) return if (!avatarId || saving.value) return
saving.value = true saving.value = true
try { try {
authList.value = unwrapListData(await updateAuthorization(avatarId, { const updated = await updateAuthorization(avatarId, {
id: auth.id, id: auth.id,
status: auth.status === 'active' ? 'inactive' : 'active' status: auth.status === 'active' ? 'inactive' : 'active'
})) })
authList.value = authList.value.map((item) => item.id === updated.id ? updated : item)
} catch (error) { } catch (error) {
alert('操作失败,请重试') alert('操作失败,请重试')
} finally { } finally {
@@ -177,7 +179,7 @@ const showUnavailableNotice = () => alert(UNAVAILABLE_MESSAGE)
const getAuthIcon = (type: string) => ({ user: '👤', organization: '🏢', application: '📱' }[type] || '🔑') const getAuthIcon = (type: string) => ({ user: '👤', organization: '🏢', application: '📱' }[type] || '🔑')
const getAuthTypeText = (type: string) => ({ user: '用户', organization: '组织', application: '应用' }[type] || type) const getAuthTypeText = (type: string) => ({ user: '用户', organization: '组织', application: '应用' }[type] || type)
const getAuthTargetName = (name: string) => name.replaceAll('发布微博内容', '发布微播内容') const getAuthTargetName = (name: string) => name.replace(/发布微博内容/g, '发布微播内容')
const getPermissionText = (permission: string) => ({ const getPermissionText = (permission: string) => ({
read: '读取', write: '写入', reply: '回复', edit: '编辑', read: '读取', write: '写入', reply: '回复', edit: '编辑',
like: '点赞', collect: '收藏', comment: '评论' like: '点赞', collect: '收藏', comment: '评论'