Compare commits
2 Commits
2b0741fdb9
...
107d950771
| Author | SHA1 | Date | |
|---|---|---|---|
| 107d950771 | |||
| 4d153b4149 |
@ -39,10 +39,12 @@
|
||||
</div>
|
||||
<div class="px-6 pt-[85px] pb-[23px]">
|
||||
<Button
|
||||
:disabled="isPaying"
|
||||
@click="$emit('pay', selectedValue)"
|
||||
class="h-[50px] w-full rounded-[32px] border-none bg-black text-[16px] font-black text-white transition-all hover:bg-black/90 active:scale-[0.98]"
|
||||
class="h-[50px] w-full rounded-[32px] border-none bg-black text-[16px] font-black text-white transition-all hover:bg-black/90 active:scale-[0.98] disabled:opacity-50"
|
||||
>
|
||||
立即支付
|
||||
<Loader2 v-if="isPaying" class="mr-2 h-4 w-4 animate-spin" />
|
||||
{{ isPaying ? '正在支付...' : '立即支付' }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@ -51,6 +53,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Loader2 } from 'lucide-vue-next'
|
||||
|
||||
interface PaymentOption {
|
||||
label: string
|
||||
@ -60,6 +63,7 @@ interface PaymentOption {
|
||||
const props = defineProps<{
|
||||
methods: any[]
|
||||
selectedPlan: any
|
||||
isPaying?: boolean
|
||||
}>()
|
||||
|
||||
const list = computed(() =>
|
||||
|
||||
64
src/components/user-center/UserCenterSkeleton.vue
Normal file
64
src/components/user-center/UserCenterSkeleton.vue
Normal file
@ -0,0 +1,64 @@
|
||||
<template>
|
||||
<div class="user-center-skeleton custom-pulse" :class="[layout === 'desktop' ? 'w-full' : '']">
|
||||
<!-- --- Header Part --- -->
|
||||
<template v-if="type === 'header'">
|
||||
<div v-if="layout === 'mobile'" class="mb-3 ml-[31px] flex h-[60px] items-center gap-3">
|
||||
<div class="size-[60px] rounded-full bg-[#A8FF53]/60"></div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="h-5 w-40 rounded bg-[#A8FF53]/60"></div>
|
||||
<div class="h-3 w-24 rounded bg-[#A8FF53]/40"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="mb-3 flex flex-col items-center">
|
||||
<div class="size-[60px] rounded-full bg-[#A8FF53]/60"></div>
|
||||
<div class="mt-2 h-6 w-32 rounded bg-[#A8FF53]/60"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- --- Devices Part --- -->
|
||||
<template v-if="type === 'devices'">
|
||||
<div v-if="layout === 'mobile'" class="h-[76px] w-full rounded-2xl bg-[#A8FF53]/15"></div>
|
||||
<div v-else class="h-[160px] w-full rounded-2xl bg-[#A8FF53]/15"></div>
|
||||
</template>
|
||||
|
||||
<!-- --- Plans Part --- -->
|
||||
<template v-if="type === 'plans'">
|
||||
<div class="space-y-4">
|
||||
<div class="h-[120px] w-full rounded-2xl bg-black/15"></div>
|
||||
<div class="h-[120px] w-full rounded-2xl bg-black/15"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- --- Payments Part --- -->
|
||||
<template v-if="type === 'payments'">
|
||||
<div class="h-[300px] w-full rounded-2xl bg-black/15"></div>
|
||||
</template>
|
||||
|
||||
<!-- --- Full Layouts (Backward Compatibility) --- -->
|
||||
<template v-if="!type">
|
||||
<!-- Old Full Layout implementation if needed, but we'll use type-based now -->
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
type?: 'header' | 'devices' | 'plans' | 'payments'
|
||||
layout?: 'mobile' | 'desktop'
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.custom-pulse {
|
||||
animation: fast-pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
||||
}
|
||||
|
||||
@keyframes fast-pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -1,18 +1,26 @@
|
||||
<template>
|
||||
<!-- Main Neon Green Card -->
|
||||
<div class="flex h-[678px]">
|
||||
<div class="flex h-[678px] justify-center">
|
||||
<div
|
||||
class="flex w-[345px] flex-col justify-between rounded-4xl border-5 border-white py-[32px] pb-[22px]"
|
||||
>
|
||||
<div>
|
||||
<div class="mb-3 flex flex-col items-center">
|
||||
<img src="../avatar.png" class="size-[60px]" alt="" />
|
||||
<div class="flex flex-col justify-center text-white">
|
||||
<div class="text-xl font-semibold">{{ userInfo.email }}</div>
|
||||
</div>
|
||||
<div class="mb-3 flex min-h-[88px] flex-col items-center">
|
||||
<Transition name="fade" mode="out-in">
|
||||
<UserCenterSkeleton v-if="isUserLoading" type="header" layout="desktop" />
|
||||
<div v-else class="flex flex-col items-center">
|
||||
<img src="../avatar.png" class="size-[60px]" alt="" />
|
||||
<div class="flex flex-col justify-center text-white">
|
||||
<div class="text-xl font-semibold">{{ userInfo.email }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
<div class="mb-5 px-[20px] text-white">
|
||||
<DeviceList :devices="devices" @refresh="emit('refresh')" />
|
||||
<Transition name="fade" mode="out-in">
|
||||
<UserCenterSkeleton v-if="isUserLoading" type="devices" layout="desktop" />
|
||||
<DeviceList v-else :devices="devices" @refresh="emit('refresh')" />
|
||||
</Transition>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
@ -43,17 +51,34 @@
|
||||
class="ml-2.5 flex items-center overflow-hidden rounded-4xl bg-[#A8FF53] pt-[32px] pb-[22px]"
|
||||
>
|
||||
<div class="h-full w-[345px]">
|
||||
<PlanCard :plans="plans" :currentPlanIndex="currentPlanIndex" @select="handlePlanSelect" />
|
||||
<Transition name="fade" mode="out-in">
|
||||
<div v-if="isPlansLoading" class="p-8">
|
||||
<UserCenterSkeleton type="plans" layout="desktop" />
|
||||
</div>
|
||||
<PlanCard
|
||||
v-else
|
||||
:plans="plans"
|
||||
:currentPlanIndex="currentPlanIndex"
|
||||
@select="handlePlanSelect"
|
||||
/>
|
||||
</Transition>
|
||||
</div>
|
||||
<div
|
||||
class="mx-[5px] h-[624px] w-[1px] bg-[url(@/pages/userCenter/DesktopLayout/Line-8.png)]"
|
||||
></div>
|
||||
<div class="h-full w-[345px]">
|
||||
<PaymentMethod
|
||||
:methods="payments"
|
||||
:selectedPlan="selectedPlan"
|
||||
@pay="(id: number | string) => $emit('pay', id)"
|
||||
/>
|
||||
<Transition name="fade" mode="out-in">
|
||||
<div v-if="isPaymentsLoading" class="p-8">
|
||||
<UserCenterSkeleton type="payments" layout="desktop" />
|
||||
</div>
|
||||
<PaymentMethod
|
||||
v-else
|
||||
:methods="payments"
|
||||
:selectedPlan="selectedPlan"
|
||||
:is-paying="isPaying"
|
||||
@pay="(id: number | string) => $emit('pay', id)"
|
||||
/>
|
||||
</Transition>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -64,6 +89,7 @@ import { computed } from 'vue'
|
||||
import PlanCard from '@/components/user-center/PlanCard.vue'
|
||||
import DeviceList from '@/components/user-center/DeviceList.vue'
|
||||
import PaymentMethod from '@/components/user-center/PaymentMethod.vue'
|
||||
import UserCenterSkeleton from '@/components/user-center/UserCenterSkeleton.vue'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { useRouter } from 'vue-router'
|
||||
@ -76,6 +102,10 @@ const props = defineProps<{
|
||||
userInfo: { email: string }
|
||||
selectedPlanId: string
|
||||
selectedPlan: any
|
||||
isPaying: boolean
|
||||
isUserLoading: boolean
|
||||
isPlansLoading: boolean
|
||||
isPaymentsLoading: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['select-plan', 'pay', 'refresh'])
|
||||
@ -137,4 +167,14 @@ function logout() {
|
||||
.tracking-tight {
|
||||
font-family: 'Inter', 'PingFang SC', sans-serif;
|
||||
}
|
||||
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -2,28 +2,53 @@
|
||||
<!-- Main Neon Green Card -->
|
||||
<div class="pt-[35px]">
|
||||
<div class="mb-3 ml-[31px] flex h-[60px] items-center gap-3">
|
||||
<img src="../avatar.png" class="size-[60px]" alt="" />
|
||||
<div class="flex h-full flex-col justify-center text-white">
|
||||
<div class="text-xl font-semibold">{{ userInfo.email }}</div>
|
||||
<div class="text-xs" :class="{ 'text-[#FF00B7]': expireDateInfo.highlight }">
|
||||
{{ expireDateInfo.text }}
|
||||
<Transition name="fade" mode="out-in">
|
||||
<UserCenterSkeleton v-if="isUserLoading" type="header" layout="mobile" />
|
||||
<div v-else class="flex items-center gap-3 text-white">
|
||||
<img src="../avatar.png" class="size-[60px]" alt="" />
|
||||
<div class="flex h-full flex-col justify-center text-white">
|
||||
<div class="text-xl font-semibold">{{ userInfo.email }}</div>
|
||||
<div class="text-xs" :class="{ 'text-[#FF00B7]': expireDateInfo.highlight }">
|
||||
{{ expireDateInfo.text }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
|
||||
<div class="mb-5 pr-[25px] pl-[21px] text-white">
|
||||
<DeviceList :devices="devices" @refresh="emit('refresh')" />
|
||||
<Transition name="fade" mode="out-in">
|
||||
<UserCenterSkeleton v-if="isUserLoading" type="devices" layout="mobile" />
|
||||
<DeviceList v-else :devices="devices" @refresh="emit('refresh')" />
|
||||
</Transition>
|
||||
</div>
|
||||
<div class="overflow-hidden rounded-4xl bg-[#A8FF53]">
|
||||
<div class="pt-7">
|
||||
<PlanCard :plans="plans" :currentPlanIndex="currentPlanIndex" @select="handlePlanSelect" />
|
||||
<Transition name="fade" mode="out-in">
|
||||
<div v-if="isPlansLoading" class="px-6">
|
||||
<UserCenterSkeleton type="plans" layout="mobile" />
|
||||
</div>
|
||||
<PlanCard
|
||||
v-else
|
||||
:plans="plans"
|
||||
:currentPlanIndex="currentPlanIndex"
|
||||
@select="handlePlanSelect"
|
||||
/>
|
||||
</Transition>
|
||||
</div>
|
||||
<div class="pt-7">
|
||||
<PaymentMethod
|
||||
:methods="payments"
|
||||
:selectedPlan="selectedPlan"
|
||||
@pay="(id: number | string) => $emit('pay', id)"
|
||||
/>
|
||||
<Transition name="fade" mode="out-in">
|
||||
<div v-if="isPaymentsLoading" class="px-6">
|
||||
<UserCenterSkeleton type="payments" layout="mobile" />
|
||||
</div>
|
||||
<PaymentMethod
|
||||
v-else
|
||||
:methods="payments"
|
||||
:selectedPlan="selectedPlan"
|
||||
:is-paying="isPaying"
|
||||
@pay="(id: number | string) => $emit('pay', id)"
|
||||
/>
|
||||
</Transition>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -51,6 +76,7 @@ import { computed } from 'vue'
|
||||
import PlanCard from '@/components/user-center/PlanCard.vue'
|
||||
import DeviceList from '@/components/user-center/DeviceList.vue'
|
||||
import PaymentMethod from '@/components/user-center/PaymentMethod.vue'
|
||||
import UserCenterSkeleton from '@/components/user-center/UserCenterSkeleton.vue'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { useRouter } from 'vue-router'
|
||||
@ -63,6 +89,10 @@ const props = defineProps<{
|
||||
userInfo: { email: string }
|
||||
selectedPlanId: string
|
||||
selectedPlan: any
|
||||
isPaying: boolean
|
||||
isUserLoading: boolean
|
||||
isPlansLoading: boolean
|
||||
isPaymentsLoading: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['select-plan', 'pay', 'refresh'])
|
||||
@ -124,4 +154,14 @@ function logout() {
|
||||
.tracking-tight {
|
||||
font-family: 'Inter', 'PingFang SC', sans-serif;
|
||||
}
|
||||
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -22,34 +22,46 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Main Neon Green Card -->
|
||||
<div class="container md:hidden">
|
||||
<MobileLayout
|
||||
:already-subscribed="alreadySubscribed"
|
||||
:devices="devices"
|
||||
:plans="plans"
|
||||
:payments="payments"
|
||||
:user-info="userSubInfo"
|
||||
:selected-plan-id="selectedPlanId"
|
||||
:selected-plan="activePlan"
|
||||
@select-plan="handlePlanSelect"
|
||||
@pay="handlePay"
|
||||
@refresh="init"
|
||||
/>
|
||||
</div>
|
||||
<div class="container mx-auto hidden flex-1 items-center justify-center md:flex">
|
||||
<DesktopLayout
|
||||
:already-subscribed="alreadySubscribed"
|
||||
:devices="devices"
|
||||
:plans="plans"
|
||||
:payments="payments"
|
||||
:user-info="userSubInfo"
|
||||
:selected-plan-id="selectedPlanId"
|
||||
:selected-plan="activePlan"
|
||||
@select-plan="handlePlanSelect"
|
||||
@pay="handlePay"
|
||||
@refresh="init"
|
||||
/>
|
||||
<div class="flex flex-1 flex-col">
|
||||
<!-- Main Neon Green Card -->
|
||||
<div class="container md:hidden">
|
||||
<MobileLayout
|
||||
:already-subscribed="alreadySubscribed"
|
||||
:devices="devices"
|
||||
:plans="plans"
|
||||
:payments="payments"
|
||||
:user-info="userSubInfo"
|
||||
:selected-plan-id="selectedPlanId"
|
||||
:selected-plan="activePlan"
|
||||
:is-paying="isPaying"
|
||||
:is-user-loading="isUserLoading"
|
||||
:is-plans-loading="isPlansLoading"
|
||||
:is-payments-loading="isPaymentsLoading"
|
||||
@select-plan="handlePlanSelect"
|
||||
@pay="handlePay"
|
||||
@refresh="init"
|
||||
/>
|
||||
</div>
|
||||
<div class="hidden flex-1 items-center justify-center md:flex md:pb-[50px]">
|
||||
<div class="container mx-auto">
|
||||
<DesktopLayout
|
||||
:already-subscribed="alreadySubscribed"
|
||||
:devices="devices"
|
||||
:plans="plans"
|
||||
:payments="payments"
|
||||
:user-info="userSubInfo"
|
||||
:selected-plan-id="selectedPlanId"
|
||||
:selected-plan="activePlan"
|
||||
:is-paying="isPaying"
|
||||
:is-user-loading="isUserLoading"
|
||||
:is-plans-loading="isPlansLoading"
|
||||
:is-payments-loading="isPaymentsLoading"
|
||||
@select-plan="handlePlanSelect"
|
||||
@pay="handlePay"
|
||||
@refresh="init"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<OrderStatusDialog ref="orderStatusDialogRef" @close="handleStatusClose" @refresh="init" />
|
||||
@ -62,6 +74,7 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
import MobileLayout from './MobileLayout/index.vue'
|
||||
import DesktopLayout from './DesktopLayout/index.vue'
|
||||
import OrderStatusDialog from '@/components/user-center/OrderStatusDialog.vue'
|
||||
import UserCenterSkeleton from '@/components/user-center/UserCenterSkeleton.vue'
|
||||
import Logo from '@/pages/Home/logo.svg?component'
|
||||
import MobileLogo from '@/pages/Home/mobile-logo.svg?component'
|
||||
import request from '@/utils/request'
|
||||
@ -70,6 +83,10 @@ const route = useRoute()
|
||||
const router = useRouter()
|
||||
// --- State ---
|
||||
const selectedPlanId = ref('p2')
|
||||
const isPaying = ref(false)
|
||||
const isUserLoading = ref(true)
|
||||
const isPlansLoading = ref(true)
|
||||
const isPaymentsLoading = ref(true)
|
||||
const orderStatusDialogRef = ref<InstanceType<typeof OrderStatusDialog> | null>(null)
|
||||
const selectedPayment = ref('alipay')
|
||||
|
||||
@ -132,6 +149,7 @@ const handlePlanSelect = (id: string) => {
|
||||
}
|
||||
|
||||
const handlePay = (methodId: number | string) => {
|
||||
if (isPaying.value) return
|
||||
const plan = plans.value.find((p) => p.id === selectedPlanId.value)
|
||||
if (!plan) return
|
||||
|
||||
@ -147,53 +165,78 @@ const handlePay = (methodId: number | string) => {
|
||||
if (isRenewal) {
|
||||
params.user_subscribe_id = already.id
|
||||
}
|
||||
console.log(params)
|
||||
request.post(api, params).then((res: any) => {
|
||||
request
|
||||
.post('/api/v1/public/portal/order/checkout', {
|
||||
orderNo: res.order_no,
|
||||
returnUrl: `${window.location.origin}/user-center?order_no=${res.order_no}`,
|
||||
})
|
||||
.then((checkoutRes: any) => {
|
||||
if (checkoutRes.type === 'url' && checkoutRes.checkout_url) {
|
||||
localStorage.setItem('pending_order_no', res.order_no)
|
||||
console.log('pending_order_no', res.order_no)
|
||||
setTimeout(() => {
|
||||
window.location.href = checkoutRes.checkout_url
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
isPaying.value = true
|
||||
request
|
||||
.post(api, params)
|
||||
.then((res: any) => {
|
||||
request
|
||||
.post('/api/v1/public/portal/order/checkout', {
|
||||
orderNo: res.order_no,
|
||||
returnUrl: `${window.location.origin}/user-center?order_no=${res.order_no}`,
|
||||
})
|
||||
.then((checkoutRes: any) => {
|
||||
if (checkoutRes.type === 'url' && checkoutRes.checkout_url) {
|
||||
localStorage.setItem('pending_order_no', res.order_no)
|
||||
console.log('pending_order_no', res.order_no)
|
||||
setTimeout(() => {
|
||||
window.location.href = checkoutRes.checkout_url
|
||||
})
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
isPaying.value = false
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
isPaying.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function init() {
|
||||
// 用户信息 & 设备列表
|
||||
request.get('/api/v1/public/user/info').then((res: any) => {
|
||||
devices.value = res.user_devices
|
||||
const emailInfo = res.auth_methods?.find((item: any) => item.auth_type === 'email')
|
||||
if (emailInfo) {
|
||||
userSubInfo.value.email = emailInfo.auth_identifier
|
||||
}
|
||||
})
|
||||
async function init() {
|
||||
// 1. 用户信息 & 设备列表
|
||||
isUserLoading.value = true
|
||||
request
|
||||
.get('/api/v1/public/user/info')
|
||||
.then((res: any) => {
|
||||
devices.value = res.user_devices
|
||||
const emailInfo = res.auth_methods?.find((item: any) => item.auth_type === 'email')
|
||||
if (emailInfo) {
|
||||
userSubInfo.value.email = emailInfo.auth_identifier
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
isUserLoading.value = false
|
||||
})
|
||||
|
||||
// 已订阅列表
|
||||
// 2. 已订阅列表 (非阻塞主要展示)
|
||||
request.get('/api/v1/public/user/subscribe').then((res: any) => {
|
||||
alreadySubscribed.value = res.list || []
|
||||
})
|
||||
|
||||
// 订阅套餐列表
|
||||
request.get('/api/v1/public/subscribe/list').then((res: any) => {
|
||||
plans.value = mapPlans(res.list || [])
|
||||
if (plans.value.length > 0) {
|
||||
selectedPlanId.value = plans.value[0].id
|
||||
}
|
||||
})
|
||||
// 3. 订阅套餐列表
|
||||
isPlansLoading.value = true
|
||||
request
|
||||
.get('/api/v1/public/subscribe/list')
|
||||
.then((res: any) => {
|
||||
plans.value = mapPlans(res.list || [])
|
||||
if (plans.value.length > 0) {
|
||||
selectedPlanId.value = plans.value[0].id
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
isPlansLoading.value = false
|
||||
})
|
||||
|
||||
// 获取支付方式
|
||||
request.get('/api/v1/public/payment/methods').then((res: any) => {
|
||||
console.log(res)
|
||||
payments.value = res.list?.filter((p: any) => p.platform !== 'apple_iap') || []
|
||||
})
|
||||
// 4. 获取支付方式
|
||||
isPaymentsLoading.value = true
|
||||
request
|
||||
.get('/api/v1/public/payment/methods')
|
||||
.then((res: any) => {
|
||||
payments.value = res.list?.filter((p: any) => p.platform !== 'apple_iap') || []
|
||||
})
|
||||
.finally(() => {
|
||||
isPaymentsLoading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@ -211,6 +254,18 @@ function handleStatusClose() {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
/* Simplified layout font */
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700;900&display=swap');
|
||||
|
||||
@ -52,6 +52,68 @@ interface ResponseType extends AxiosResponse {
|
||||
config: RequestConfig
|
||||
}
|
||||
|
||||
const ERROR_MESSAGES: Record<number | string, string> = {
|
||||
'200': '成功',
|
||||
'500': '内部服务器错误',
|
||||
'10001': '数据库查询错误',
|
||||
'10002': '数据库更新错误',
|
||||
'10003': '数据库插入错误',
|
||||
'10004': '数据库删除错误',
|
||||
'20001': '用户已存在',
|
||||
'20002': '用户不存在',
|
||||
'20003': '用户密码错误',
|
||||
'20004': '用户已禁用',
|
||||
'20005': '余额不足',
|
||||
'20006': '停止注册',
|
||||
'20007': '未绑定Telegram',
|
||||
'20008': '用户未绑定OAuth方式',
|
||||
'20009': '邀请码错误',
|
||||
'30001': '节点已存在',
|
||||
'30002': '节点不存在',
|
||||
'30003': '节点组已存在',
|
||||
'30004': '节点组不存在',
|
||||
'30005': '节点组不为空',
|
||||
'400': '参数错误',
|
||||
'40002': '用户令牌为空',
|
||||
'40003': '用户令牌无效',
|
||||
'40004': '用户令牌已过期',
|
||||
'40005': '您还没有登录',
|
||||
'401': '请求过多',
|
||||
'50001': '优惠券不存在',
|
||||
'50002': '优惠券已被使用',
|
||||
'50003': '优惠券不匹配',
|
||||
'60001': '订阅已过期',
|
||||
'60002': '订阅不可用',
|
||||
'60003': '用户已有订阅',
|
||||
'60004': '订阅已被使用',
|
||||
'60005': '单一订阅模式超出限制',
|
||||
'60006': '订阅配额限制',
|
||||
'70001': '验证码错误',
|
||||
'80001': '队列入队错误',
|
||||
'90001': '调试模式已启用',
|
||||
'90002': '发送短信错误',
|
||||
'90003': '短信功能未启用',
|
||||
'90004': '电子邮件功能未启用',
|
||||
'90005': '不支持的登录方式',
|
||||
'90006': '身份验证器不支持此方式',
|
||||
'90007': '电话区号为空',
|
||||
'90008': '密码为空',
|
||||
'90009': '区号为空',
|
||||
'90010': '需要密码或验证码',
|
||||
'90011': '电子邮件已存在',
|
||||
'90012': '电话号码已存在',
|
||||
'90013': '设备已存在',
|
||||
'90014': '电话号码错误',
|
||||
'90015': '此账户今日已达到发送次数限制',
|
||||
'90017': '设备不存在',
|
||||
'90018': '用户 ID 不匹配',
|
||||
'61001': '订单不存在',
|
||||
'61002': '支付方式未找到',
|
||||
'61003': '订单状态错误',
|
||||
'61004': '重置周期不足',
|
||||
'61005': '存在没用完的流量',
|
||||
}
|
||||
|
||||
export default class Request {
|
||||
public axiosInstance: AxiosInstance
|
||||
|
||||
@ -93,34 +155,26 @@ export default class Request {
|
||||
|
||||
if (config.data && !(config.data instanceof FormData)) {
|
||||
const plainText = JSON.stringify(config.data)
|
||||
// 加密后,config.data 会变成 { data: '...', time: '...' }
|
||||
config.data = HiAesUtil.encryptData(plainText, encryptionKey)
|
||||
}
|
||||
|
||||
if (config.method?.toLowerCase() === 'get' || config.params) {
|
||||
const paramsToEncrypt = config.params || {} // 为空则加密 "{}"
|
||||
const paramsToEncrypt = config.params || {}
|
||||
const plainParamsText = JSON.stringify(paramsToEncrypt)
|
||||
const encryptedParams = HiAesUtil.encryptData(plainParamsText, encryptionKey)
|
||||
|
||||
// 将原参数替换为加密后的 data 和 time 字段
|
||||
config.params = {
|
||||
data: encryptedParams.data,
|
||||
time: encryptedParams.time,
|
||||
}
|
||||
}
|
||||
|
||||
if (config.data?.time) {
|
||||
console.log(
|
||||
'解密',
|
||||
HiAesUtil.decryptData(config.data.data, config.data.time, encryptionKey),
|
||||
)
|
||||
}
|
||||
|
||||
config.headers = mergeExtraConfig.formatHeader({
|
||||
...this.config.headers,
|
||||
...config.headers,
|
||||
lang: 'zh_CN',
|
||||
'login-type': 'device',
|
||||
'user-agent': 'android',
|
||||
...(mergeExtraConfig.withToken && {
|
||||
[mergeExtraConfig.tokenKey]: mergeExtraConfig.getToken(),
|
||||
}),
|
||||
@ -142,7 +196,6 @@ export default class Request {
|
||||
const { data, config } = response
|
||||
let responseData = response.data.data
|
||||
|
||||
// 假设后端返回格式为 { data: "base64...", time: "..." }
|
||||
if (responseData && responseData.data && responseData.time) {
|
||||
try {
|
||||
const decryptedStr = HiAesUtil.decryptData(
|
||||
@ -150,7 +203,6 @@ export default class Request {
|
||||
responseData.time,
|
||||
encryptionKey,
|
||||
)
|
||||
// 解密后转化为 JSON 对象供后续业务使用
|
||||
responseData = JSON.parse(decryptedStr)
|
||||
} catch (e) {
|
||||
console.error('解密失败:', e)
|
||||
@ -158,39 +210,32 @@ export default class Request {
|
||||
}
|
||||
}
|
||||
axiosCanceler.removePending(config)
|
||||
if (data.code == 40004) {
|
||||
toast.error('登录状态已失效, 请重新登录')
|
||||
redirectLogin()
|
||||
return
|
||||
}
|
||||
if (data.code == 70001) {
|
||||
toast.error('验证码错误')
|
||||
redirectLogin()
|
||||
return
|
||||
}
|
||||
const resData = config.extraConfig?.originResponseData ? response : responseData
|
||||
if (config.extraConfig?.handleResponse) {
|
||||
if (data.code === 200) {
|
||||
return resData
|
||||
|
||||
if (data.code !== 200) {
|
||||
const msg = ERROR_MESSAGES[data.code] || response.data?.msg || data?.error || '未知错误'
|
||||
|
||||
if (data.code == 40004 || data.code == 40003 || data.code == 40005) {
|
||||
toast.error(msg)
|
||||
redirectLogin()
|
||||
return
|
||||
}
|
||||
|
||||
if (config.extraConfig?.handleResponse) {
|
||||
this.errorReport(config.extraConfig.errorLevel ?? 2, msg)
|
||||
return Promise.reject({
|
||||
...data,
|
||||
message: msg,
|
||||
})
|
||||
}
|
||||
this.errorReport(
|
||||
config.extraConfig.errorLevel ?? 2,
|
||||
response.data?.msg ?? data?.error ?? '未知错误',
|
||||
)
|
||||
return Promise.reject({
|
||||
...data,
|
||||
message: response.data?.msg ?? data?.error ?? '未知错误',
|
||||
})
|
||||
} else {
|
||||
return resData
|
||||
}
|
||||
|
||||
return config.extraConfig?.originResponseData ? response : responseData
|
||||
},
|
||||
(error) => {
|
||||
const status = error?.response?.status
|
||||
const code = error?.code
|
||||
let message = error?.message
|
||||
if (status === 401) {
|
||||
// message = '未登录或登录状态失效'
|
||||
redirectLogin()
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user