去掉协会 WebView 和魔方账密页,微信登录与咨询接口共用同一 token 和拦截器。 Co-authored-by: Cursor <cursoragent@cursor.com>
105 lines
3.5 KiB
Vue
105 lines
3.5 KiB
Vue
<template>
|
|
<yxg-page title="意象卡片">
|
|
<text v-if="loading" class="hint">加载中…</text>
|
|
<text v-else-if="error" class="err">{{ error }}</text>
|
|
<template v-else>
|
|
<view class="quota"><text>今日剩余 {{ quota?.left ?? quota?.remaining ?? '—' }} 次</text></view>
|
|
<view class="scenes">
|
|
<view
|
|
v-for="s in scenes"
|
|
:key="s.key || s.code || s.id"
|
|
class="scene"
|
|
:class="{ on: scene === (s.key || s.code || s.id) }"
|
|
@click="scene = s.key || s.code || s.id"
|
|
>
|
|
<text>{{ s.title || s.name || s.label }}</text>
|
|
</view>
|
|
</view>
|
|
<view class="btn" :class="{ off: drawing }" @click="draw">
|
|
<text>{{ drawing ? '抽取中…' : '抽取一张卡片' }}</text>
|
|
</view>
|
|
<view v-if="drawn" class="card">
|
|
<image v-if="drawn.image_url" class="img" :src="assetURL(drawn.image_url)" mode="aspectFill" />
|
|
<text class="h1">{{ drawn.title || drawn.name || '意象卡片' }}</text>
|
|
<text class="body">{{ drawn.meaning || drawn.interpretation || drawn.text || '' }}</text>
|
|
</view>
|
|
</template>
|
|
</yxg-page>
|
|
</template>
|
|
|
|
<script setup>
|
|
import YxgPage from '@/components/yxg/yxg-page.vue'
|
|
import { assetURL, yxgApi } from '@/util/yxgApi.js'
|
|
import { ensureAccount, findSelfProfile } from '@/util/yxgAuth.js'
|
|
import { yxgGo } from '@/util/yxgNav.js'
|
|
|
|
const loading = ref(true)
|
|
const drawing = ref(false)
|
|
const error = ref('')
|
|
const scenes = ref([])
|
|
const scene = ref('')
|
|
const quota = ref(null)
|
|
const drawn = ref(null)
|
|
|
|
async function load() {
|
|
loading.value = true
|
|
error.value = ''
|
|
if (!(await ensureAccount('/cards'))) {
|
|
loading.value = false
|
|
return
|
|
}
|
|
try {
|
|
const [s, q] = await Promise.all([yxgApi.listImageCardScenes(), yxgApi.getImageCardQuota()])
|
|
scenes.value = s.items || []
|
|
quota.value = q
|
|
scene.value = scenes.value[0]?.key || scenes.value[0]?.code || scenes.value[0]?.id || ''
|
|
} catch (e) {
|
|
error.value = e instanceof Error ? e.message : '加载失败'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function draw() {
|
|
if (drawing.value) return
|
|
drawing.value = true
|
|
error.value = ''
|
|
try {
|
|
const self = await findSelfProfile()
|
|
if (!self) {
|
|
yxgGo('/profile')
|
|
return
|
|
}
|
|
drawn.value = await yxgApi.drawImageCard({ profile_id: self.id, scene: scene.value })
|
|
quota.value = await yxgApi.getImageCardQuota().catch(() => quota.value)
|
|
} catch (e) {
|
|
error.value = e instanceof Error ? e.message : '抽取失败'
|
|
} finally {
|
|
drawing.value = false
|
|
}
|
|
}
|
|
|
|
onShow(load)
|
|
</script>
|
|
|
|
<style>
|
|
page { background-color: #ffd1c7; }
|
|
</style>
|
|
<style scoped>
|
|
.hint, .err { display: block; padding: 12px 16px; font-size: 13px; color: #999; }
|
|
.err { color: #e54d42; }
|
|
.quota { margin: 8px 16px; padding: 10px 12px; background: #fff; border-radius: 12px; font-size: 13px; color: #666; }
|
|
.scenes { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
|
|
.scene { padding: 8px 12px; border-radius: 999px; background: #fff; font-size: 13px; color: #666; }
|
|
.scene.on { background: #ffe4e4; color: #e54d42; }
|
|
.btn {
|
|
margin: 8px 16px; height: 44px; border-radius: 999px; background: #e54d42; color: #fff;
|
|
display: flex; align-items: center; justify-content: center; font-weight: 700;
|
|
}
|
|
.btn.off { opacity: 0.5; }
|
|
.card { margin: 12px 16px; padding: 16px; background: #fff; border-radius: 18px; }
|
|
.img { width: 100%; height: 200px; border-radius: 12px; margin-bottom: 12px; }
|
|
.h1 { display: block; font-size: 18px; font-weight: 700; color: #333; }
|
|
.body { display: block; margin-top: 8px; font-size: 14px; color: #555; line-height: 1.65; }
|
|
</style>
|