Files
yuxingu-Miniprogram-dev/pages/yxg/companion.vue
T
jackyu66gitandCursor b09d82df8d feat: 小程序统一走 Go 后台,咨询与登录切到 /api/v1
去掉协会 WebView 和魔方账密页,微信登录与咨询接口共用同一 token 和拦截器。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-15 00:26:28 +08:00

103 lines
3.4 KiB
Vue

<template>
<yxg-page title="节气陪伴">
<text v-if="loading" class="hint">加载中</text>
<text v-else-if="error" class="err">{{ error }}</text>
<view v-else class="card">
<text class="term">{{ today.name || today.solar_term || '今日节气' }}</text>
<text class="date">{{ today.date || today.as_of || '' }}</text>
<text class="body">{{ today.guidance || today.copy || today.description || '此刻宜慢一点,给身心留一点空间。' }}</text>
</view>
<view class="card">
<text class="h2">今日心情</text>
<view class="scores">
<view v-for="n in 5" :key="n" class="score" :class="{ on: mood === n }" @click="mood = n">
<text>{{ n }}</text>
</view>
</view>
<input class="inp" v-model="note" placeholder="想记一笔也可以(可选)" />
<view class="btn" :class="{ off: saving }" @click="save"><text>{{ saving ? '保存中…' : '记录心情' }}</text></view>
<text v-if="saved" class="ok">已记下今天的心情</text>
</view>
</yxg-page>
</template>
<script setup>
import YxgPage from '@/components/yxg/yxg-page.vue'
import { yxgApi } from '@/util/yxgApi.js'
import { ensureAccount } from '@/util/yxgAuth.js'
const loading = ref(true)
const error = ref('')
const today = ref({})
const mood = ref(0)
const note = ref('')
const saving = ref(false)
const saved = ref(false)
async function load() {
loading.value = true
error.value = ''
if (!(await ensureAccount('/companion'))) {
loading.value = false
return
}
try {
const [t, m] = await Promise.all([
yxgApi.getSolarTermsToday(),
yxgApi.getMoodToday().catch(() => ({ mood: null })),
])
today.value = t || {}
if (m?.mood) {
mood.value = m.mood.score || 0
note.value = m.mood.note || ''
saved.value = true
}
} catch (e) {
error.value = e instanceof Error ? e.message : '加载失败'
} finally {
loading.value = false
}
}
async function save() {
if (!mood.value || saving.value) return
saving.value = true
try {
await yxgApi.saveMood({ score: mood.value, note: note.value })
saved.value = true
} catch (e) {
uni.showToast({ title: e.message || '保存失败', icon: 'none' })
} finally {
saving.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; }
.card { margin: 12px 16px; padding: 18px 16px; background: #fff; border-radius: 18px; }
.term { display: block; font-size: 22px; font-weight: 700; color: #333; }
.date { display: block; margin-top: 4px; font-size: 12px; color: #bbb; }
.body { display: block; margin-top: 12px; font-size: 14px; color: #555; line-height: 1.65; }
.h2 { display: block; font-size: 16px; font-weight: 700; color: #333; margin-bottom: 10px; }
.scores { display: flex; gap: 8px; margin-bottom: 12px; }
.score {
flex: 1; height: 40px; border-radius: 12px; background: #fdfaf8;
display: flex; align-items: center; justify-content: center; color: #666;
}
.score.on { background: #ffe4e4; color: #e54d42; font-weight: 700; }
.inp { width: 100%; height: 42px; background: #fdfaf8; border-radius: 12px; padding: 0 12px; box-sizing: border-box; }
.btn {
margin-top: 12px; height: 42px; border-radius: 999px; background: #e54d42; color: #fff;
display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.btn.off { opacity: 0.5; }
.ok { display: block; margin-top: 8px; font-size: 12px; color: #2fa866; text-align: center; }
</style>