feat: 完成前端业务闭环与后端联调
This commit is contained in:
@@ -1,34 +1,12 @@
|
||||
import { hasRemoteConfig } from '@/utils/runtime-config.js'
|
||||
import {
|
||||
normalizeAppProfile,
|
||||
normalizeProfileUpdatePayload,
|
||||
normalizeRecommendationPreference
|
||||
} from './profile-contract.js'
|
||||
import {
|
||||
createRequestError,
|
||||
requestStrict
|
||||
} from './request-client.js'
|
||||
|
||||
const requireRemoteProfile = (operation) => {
|
||||
if (hasRemoteConfig()) return
|
||||
const isRead = operation === '读取'
|
||||
throw createRequestError(
|
||||
`个人资料${operation}需要真实服务,当前本地预览不伪造${isRead ? '资料' : '保存成功'}`,
|
||||
isRead ? 'REMOTE_READ_REQUIRED' : 'REMOTE_WRITE_REQUIRED'
|
||||
)
|
||||
}
|
||||
|
||||
const requireRemotePreference = (operation) => {
|
||||
if (hasRemoteConfig()) return
|
||||
throw createRequestError(
|
||||
`个性化推荐偏好${operation}需要真实服务,当前本地预览不会伪造结果`,
|
||||
operation === '读取' ? 'REMOTE_READ_REQUIRED' : 'REMOTE_WRITE_REQUIRED'
|
||||
)
|
||||
}
|
||||
import { requestStrict } from './request-client.js'
|
||||
|
||||
export const profileApi = {
|
||||
async getProfile(requestOptions = {}) {
|
||||
requireRemoteProfile('读取')
|
||||
const profile = await requestStrict({
|
||||
url: '/genealogy/app/auth/profile',
|
||||
method: 'GET'
|
||||
@@ -40,7 +18,6 @@ export const profileApi = {
|
||||
|
||||
async updateProfile(payload, requestOptions = {}) {
|
||||
const profileChanges = normalizeProfileUpdatePayload(payload)
|
||||
requireRemoteProfile('更新')
|
||||
const profile = await requestStrict({
|
||||
url: '/genealogy/app/auth/profile',
|
||||
method: 'PUT',
|
||||
@@ -52,7 +29,6 @@ export const profileApi = {
|
||||
},
|
||||
|
||||
async getRecommendationPreference(requestOptions = {}) {
|
||||
requireRemotePreference('读取')
|
||||
const preference = await requestStrict({
|
||||
url: '/genealogy/app/recommendation-preference',
|
||||
method: 'GET'
|
||||
@@ -64,7 +40,6 @@ export const profileApi = {
|
||||
|
||||
async updateRecommendationPreference(enabled, requestOptions = {}) {
|
||||
if (typeof enabled !== 'boolean') throw new TypeError('个性化推荐开关必须是布尔值')
|
||||
requireRemotePreference('写入')
|
||||
const preference = await requestStrict({
|
||||
url: '/genealogy/app/recommendation-preference',
|
||||
method: 'PUT',
|
||||
|
||||
Reference in New Issue
Block a user