完成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,4 +1,4 @@
<template>
<template>
<view class="plan-detail">
<view class="header">
<text class="title">订阅方案详情</text>
@@ -6,18 +6,18 @@
<view v-if="loading" class="loading">加载中...</view>
<view v-else-if="plan == null" class="empty">未找到该方案</view>
<view v-else class="card">
<text class="name">{{ plan['name'] }}</text>
<text class="desc">{{ plan['description'] != null && (plan['description'] as string).length > 0 ? plan['description'] : '—' }}</text>
<text class="name">{{ getPlanName() }}</text>
<text class="desc">{{ getPlanDescription() }}</text>
<view class="price-row">
<text class="price">¥{{ plan['price'] }}</text>
<text class="period">/{{ plan['billing_period'] === 'yearly' ? '年' : '月' }}</text>
<text class="price">¥{{ getPlanPrice() }}</text>
<text class="period">/{{ getBillingPeriodText() }}</text>
</view>
<view class="features">
<text class="f-title">包含功能</text>
<view class="f-list">
<text class="f-item" v-for="(v,k) in toFeatureArray(plan['features'])" :key="k">• {{ v }}</text>
<text class="f-item" v-for="(v,k) in toFeatureArray(getPlanFeaturesSource())" :key="k">• {{ v }}</text>
</view>
</view>
@@ -37,22 +37,61 @@ const planId = ref<string>('')
const loading = ref<boolean>(true)
const plan = ref<UTSJSONObject | null>(null)
onLoad((opts: OnLoadOptions) => {
planId.value = (opts['id'] ?? '') as string
function getPlanName(): string {
return plan.value != null ? (plan.value.getString('name') ?? '') : ''
}
function getPlanDescription(): string {
const desc = plan.value != null ? (plan.value.getString('description') ?? '') : ''
return desc !== '' ? desc : '—'
}
function getPlanPrice(): string {
const price = plan.value != null ? (plan.value.getNumber('price') ?? 0) : 0
return price.toString()
}
function getBillingPeriodText(): string {
const period = plan.value != null ? (plan.value.getString('billing_period') ?? 'monthly') : 'monthly'
return period === 'yearly' ? '年' : '月'
}
function getPlanFeatures(): any {
if (plan.value == null) return ''
const features = plan.value.get('features')
return features != null ? features : ''
}
function getPlanFeaturesSource(): any {
const features = getPlanFeatures()
return features != null ? features : ''
}
onLoad((opts) => {
if (opts == null) return
const optObj = opts as UTSJSONObject
planId.value = optObj.getString('id') ?? ''
})
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
}
if (parsed instanceof UTSJSONObject) {
arr.push(JSON.stringify(parsed))
return arr
}
} catch (e) {
arr.push(raw)
}
return arr
}
@@ -87,11 +126,13 @@ const loadPlan = async () => {
const toCheckout = () => {
if (plan.value == null) return
const id = (plan.value['id'] ?? '') as string
const id = plan.value.getString('id') ?? ''
uni.navigateTo({ url: `/pages/mall/consumer/subscription/subscribe-checkout?planId=${id}` })
}
onMounted(loadPlan)
onMounted(() => {
loadPlan()
})
</script>
<style scoped>