完成consumer端同步

This commit is contained in:
2026-05-14 15:28:09 +08:00
parent 612fb3d360
commit 0ffbc53902
197 changed files with 92657 additions and 7564 deletions

View File

@@ -1,22 +1,22 @@
<template>
<template>
<view class="sub-plan-list">
<view class="header">
<text class="title">软件订阅</text>
</view>
<view class="plan-container" v-if="!loading && plans.length > 0">
<view class="plan-card" v-for="p in plans" :key="p['id']" @click="goPlanDetail(p)">
<view class="plan-card" v-for="p in plans" :key="getPlanId(p)" @click="goPlanDetail(p)">
<view class="plan-header">
<text class="plan-name">{{ p['name'] }}</text>
<text v-if="p['billing_period'] === 'yearly'" class="badge">年付优惠</text>
<text class="plan-name">{{ getPlanName(p) }}</text>
<text v-if="getBillingPeriod(p) === 'yearly'" class="badge">年付优惠</text>
</view>
<text class="plan-desc">{{ p['description'] != null && (p['description'] as string).length > 0 ? p['description'] : '适用于大部分使用场景' }}</text>
<text class="plan-desc">{{ getPlanDescription(p) }}</text>
<view class="price-row">
<text class="price">¥{{ p['price'] }}</text>
<text class="period">/{{ p['billing_period'] === 'yearly' ? '年' : '月' }}</text>
<text class="price">¥{{ getPlanPrice(p) }}</text>
<text class="period">/{{ getBillingPeriod(p) === 'yearly' ? '年' : '月' }}</text>
</view>
<view class="feature-list">
<text class="feature-item" v-for="(v,k) in toFeatureArray(p['features'])" :key="k">• {{ v }}</text>
<text class="feature-item" v-for="(v,k) in toFeatureArray(getPlanFeatures(p))" :key="k">• {{ v }}</text>
</view>
<view class="actions">
<button class="primary" @click.stop="toCheckout(p)">立即订阅</button>
@@ -39,18 +39,60 @@ import supaClient from '@/components/supadb/aksupainstance.uts'
const loading = ref<boolean>(true)
const plans = ref<Array<UTSJSONObject>>([])
function normalizePlanObject(p: any): UTSJSONObject {
if (p instanceof UTSJSONObject) {
return p as UTSJSONObject
}
const raw = JSON.stringify(p)
if (raw == null || raw === '') {
return new UTSJSONObject()
}
return JSON.parse(raw) as UTSJSONObject
}
function getPlanId(p: any): string {
return normalizePlanObject(p).getString('id') ?? ''
}
function getPlanName(p: any): string {
return normalizePlanObject(p).getString('name') ?? ''
}
function getBillingPeriod(p: any): string {
return normalizePlanObject(p).getString('billing_period') ?? 'monthly'
}
function getPlanDescription(p: any): string {
const desc = normalizePlanObject(p).getString('description') ?? ''
return desc !== '' ? desc : '适用于大部分使用场景'
}
function getPlanPrice(p: any): string {
const price = normalizePlanObject(p).getNumber('price') ?? 0
return price.toString()
}
function getPlanFeatures(p: any): any {
const features = normalizePlanObject(p).get('features')
return features != null ? features : ''
}
const toFeatureArray = (features: any): Array<string> => {
const arr: Array<string> = []
if (features == null) return arr
if (features instanceof UTSJSONObject) {
const featureMap = (features as UTSJSONObject).toMap()
const entries = featureMap.entries()
for (let i = 0; i < entries.length; i++) {
const entry = entries[i]
const v = entry.value
const vs = typeof v === 'string' ? v : JSON.stringify(v)
arr.push(vs)
const raw = JSON.stringify(features)
if (raw == null || raw === '') return arr
try {
const parsed = JSON.parse(raw)
if (Array.isArray(parsed)) {
for (let i = 0; i < parsed.length; i++) {
arr.push(JSON.stringify(parsed[i]).replace(/[\[\]\{\}"]/g, ''))
}
return arr
}
arr.push(raw)
} catch (e) {
arr.push(raw)
}
return arr
}
@@ -77,17 +119,21 @@ const loadPlans = async () => {
}
}
const goPlanDetail = (p: UTSJSONObject) => {
const id = (p['id'] ?? '') as string
const goPlanDetail = (p: any) => {
const planObj = normalizePlanObject(p)
const id = planObj.getString('id') ?? ''
uni.navigateTo({ url: `/pages/mall/consumer/subscription/plan-detail?id=${id}` })
}
const toCheckout = (p: UTSJSONObject) => {
const id = (p['id'] ?? '') as string
const toCheckout = (p: any) => {
const planObj = normalizePlanObject(p)
const id = planObj.getString('id') ?? ''
uni.navigateTo({ url: `/pages/mall/consumer/subscription/subscribe-checkout?planId=${id}` })
}
onMounted(loadPlans)
onMounted(() => {
loadPlans()
})
</script>
<style scoped>