2b69686795
- 新增404页面,优化未找到页面体验,避免被搜索引擎索引 - 增加文件代理接口,隐藏真实文件服务器地址,支持文件请求代理 - 实现/article、/case、/product及/page动态路由兼容列表与详情展示 - 添加动态CMS页面兼容入口处理旧式路径,统一路由与SEO设置 - 新增模板1、模板7、模板2、模板3关于我们页面,实现多模板支持 - 模板增强支持CMS单页内容加载及SEO信息动态设置 - 配置环境变量及Git忽略文件规则辅助开发和构建环境管理
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import type { SubscriptionStatus } from '~/types'
|
|
|
|
/**
|
|
* 订阅状态校验
|
|
* 通过 /api/subscription/status 查询当前租户应用的订阅状态
|
|
*/
|
|
export function useSubscription() {
|
|
const status = useState<SubscriptionStatus | null>('subscription-status', () => null)
|
|
const loading = useState<boolean>('subscription-loading', () => false)
|
|
const expired = computed(() => {
|
|
if (!status.value) return false
|
|
return status.value.expired === true || status.value.status === 'expired'
|
|
})
|
|
|
|
async function fetchStatus() {
|
|
loading.value = true
|
|
try {
|
|
const res = await $fetch<SubscriptionStatus>('/api/subscription/status')
|
|
status.value = res
|
|
return res
|
|
} catch {
|
|
// 接口异常时默认允许访问
|
|
status.value = { subscribed: true, status: 'active', expired: false }
|
|
return status.value
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
/** 检查是否过期,过期则跳转续费页 */
|
|
async function checkAndRedirect() {
|
|
await fetchStatus()
|
|
if (expired.value) {
|
|
await navigateTo('/renewal')
|
|
}
|
|
}
|
|
|
|
return {
|
|
status,
|
|
loading,
|
|
expired,
|
|
fetchStatus,
|
|
checkAndRedirect
|
|
}
|
|
}
|