Explorar el Código

feat: 命盘页聊天区 - 可折叠命盘图 + 语音输入(WeChat风格)

- 命盘图可折叠展开,聊天区自动填满剩余空间

- 输入栏增加🎤/⌨️语音切换按钮,按住说话/松开发送

- 语音消息显示可播放音频气泡(🔈波形动画)

- 上滑取消录音,录音文件上传至后端

- 移除订阅充值区域(已迁移至其他入口)

- api.js新增voiceUpload接口
liaoxg hace 5 meses
padre
commit
7b8de75717
Se han modificado 2 ficheros con 454 adiciones y 323 borrados
  1. 433 322
      client/pages/chart/index.vue
  2. 21 1
      client/utils/api.js

+ 433 - 322
client/pages/chart/index.vue

@@ -8,20 +8,26 @@
       </view>
     </view>
 
-    <!-- Triangle chart -->
-    <view class="chart-section">
-      <TriangleChart
-        :chartData="store.currentChart"
-        :birthYear="store.currentBirthYear"
-        :birthMonth="store.currentBirthMonth"
-        :birthDay="store.currentBirthDay"
-        :recordId="store.currentRecordId"
-        :annotations="annotations"
-        :tags="allTags"
-        @annotation-add="onAnnotationAdd"
-        @annotation-delete="onAnnotationDelete"
-        @tag-create="onTagCreate"
-      />
+    <!-- Triangle chart (collapsible) -->
+    <view class="chart-section" :class="{ 'chart-section--collapsed': chartCollapsed }">
+      <view v-show="!chartCollapsed" class="chart-section__body">
+        <TriangleChart
+          :chartData="store.currentChart"
+          :birthYear="store.currentBirthYear"
+          :birthMonth="store.currentBirthMonth"
+          :birthDay="store.currentBirthDay"
+          :recordId="store.currentRecordId"
+          :annotations="annotations"
+          :tags="allTags"
+          @annotation-add="onAnnotationAdd"
+          @annotation-delete="onAnnotationDelete"
+          @tag-create="onTagCreate"
+        />
+      </view>
+      <view class="chart-section__toggle" @click="chartCollapsed = !chartCollapsed">
+        <text class="chart-section__toggle-label">{{ chartCollapsed ? '展开命盘图' : '收起命盘图' }}</text>
+        <text class="chart-section__toggle-arrow">{{ chartCollapsed ? '▾' : '▴' }}</text>
+      </view>
     </view>
 
     <!-- Menu button (regenerate + share info) -->
@@ -29,53 +35,15 @@
       <text class="menu-btn" @click="showMenu">···</text>
     </view>
 
-    <!-- US-3.1: AI Interpretation panel -->
-    <view v-if="interpretData" id="interpret-section" class="interpret-panel">
-      <view
-        v-for="(section, key) in interpretData"
-        :key="key"
-        class="interpret-card"
-        :class="{ expanded: interpretExpanded[key] }"
-        @click="toggleInterpretSection(key)"
-      >
-        <view class="interpret-card-header">
-          <text class="interpret-num-badge">{{ section.number }}</text>
-          <text class="interpret-card-title">{{ section.title }}</text>
-          <text class="interpret-toggle">{{ interpretExpanded[key] ? '▾' : '▸' }}</text>
-        </view>
-        <view v-show="interpretExpanded[key]" class="interpret-card-body">
-          <text class="interpret-content">{{ section.content }}</text>
-        </view>
-      </view>
-      <!-- Disclaimer -->
-      <view class="interpret-disclaimer">
-        <text class="disclaimer-text">本解读由AI生成,仅供参考</text>
-      </view>
-    </view>
-
-    <!-- Loading skeleton -->
-    <view v-if="interpreting" class="interpret-skeleton">
-      <view v-for="n in 4" :key="n" class="skeleton-card">
-        <view class="skeleton-header"></view>
-        <view v-if="n === 1" class="skeleton-body">
-          <view class="skeleton-line"></view>
-          <view class="skeleton-line short"></view>
-          <view class="skeleton-line"></view>
-        </view>
-      </view>
-    </view>
-
-
-
     <!-- AI Chat -->
     <view class="chat-section">
       <view class="section-title">
         <text class="title-icon">◈</text>
-        AI 解读
+        命盘解读
         <text v-if="!userStore.isVipActive && maxChats > 0" class="quota-badge">
-          今日 {{ usedChats }}/{{ maxChats }} 轮
+          {{ usedChats }}/{{ maxChats }}
         </text>
-        <text v-if="userStore.isVipActive" class="quota-badge vip">无限次</text>
+        <text v-if="userStore.isVipActive" class="quota-badge vip">无限</text>
       </view>
 
       <scroll-view class="chat-box" scroll-y :scroll-top="scrollTop">
@@ -91,7 +59,17 @@
               <text>{{ msg.content }}</text>
             </view>
           </view>
-          <!-- Default (AI/User): existing rendering -->
+          <!-- Voice message — playable audio bubble -->
+          <view v-else-if="msg.audioUrl" class="msg-row" :class="msg.role">
+            <view class="msg-bubble msg-bubble--audio" @click="playAudio(msg.audioUrl, idx)">
+              <text class="msg-audio__icon">{{ audioPlayingIdx === idx ? '🔊' : '🔈' }}</text>
+              <view class="msg-audio__wave" :class="{ 'msg-audio__wave--playing': audioPlayingIdx === idx }">
+                <view v-for="i in 4" :key="i" class="msg-audio__bar"></view>
+              </view>
+              <text class="msg-audio__label">语音</text>
+            </view>
+          </view>
+          <!-- Default (AI/User): text bubble -->
           <view v-else class="msg-row" :class="msg.role">
             <view class="msg-bubble">
               <text>{{ msg.content }}</text>
@@ -115,44 +93,48 @@
         <text class="share-hint-text">分享好友可解锁更多次数 · 今日剩余 {{ shareRemaining }} 次</text>
       </view>
 
-      <!-- Input area — always visible, shows upgrade prompt on 4th click -->
+      <!-- Input area — text/voice toggle (WeChat style) -->
       <view class="input-bar">
-        <input
-          class="chat-input"
-          v-model="chatInput"
-          :placeholder="quotaExceeded ? '今日次数已用完,点击发送开通会员' : '输入您的问题...'"
-          @confirm="sendQuestion(chatInput)"
-          :disabled="loading"
-        />
-        <button class="send-btn" @click="sendQuestion(chatInput)" :disabled="loading">
-          {{ loading ? '···' : '发送' }}
-        </button>
-      </view>
-
-      <!-- US-6.6: Subscription card for free users / 已开通 badge for paid -->
-      <view v-if="userStore.isLoggedIn" class="subscribe-section">
-        <!-- Annual paid user — always show badge -->
-        <view v-if="userStore.vipType === 'annual'" class="vip-badge-bar">
-          <text class="vip-badge-text">✅ 已开通AI解读</text>
-          <text class="vip-badge-expiry" v-if="userStore.vipEndTime">有效期至 {{ userStore.vipEndTime.slice(0, 10) }}</text>
-          <text class="vip-poster-link" @click="goPoster">📱 生成推广海报</text>
-        </view>
-        <!-- Practitioner paid user — always show badge -->
-        <view v-else-if="userStore.vipType === 'practitioner'" class="vip-badge-bar pro">
-          <text class="vip-badge-text">✅ 已开通能量师</text>
-          <text class="vip-badge-expiry" v-if="userStore.vipEndTime">有效期至 {{ userStore.vipEndTime.slice(0, 10) }}</text>
+        <!-- Text input mode -->
+        <view v-if="inputMode === 'text'" class="input-bar__row">
+          <view class="input-bar__toggle" @click.stop="toggleInputMode">
+            <text class="input-bar__toggle-icon">🎤</text>
+          </view>
+          <input
+            class="chat-input"
+            v-model="chatInput"
+            :placeholder="quotaExceeded ? '已用完,开通会员继续' : '输入您的问题...'"
+            @confirm="sendQuestion(chatInput)"
+            :disabled="loading"
+          />
+          <button class="send-btn" @click="sendQuestion(chatInput)" :disabled="loading || !chatInput.trim()">
+            {{ loading ? '···' : '发送' }}
+          </button>
         </view>
-        <!-- Free user — subscription card only when quota exceeded -->
-        <view v-else-if="quotaExceeded" class="subscribe-card">
-          <text class="subscribe-title">🔮 AI解读会员</text>
-          <text class="subscribe-desc">¥131/年 · 无限AI解读 · 个性化报告 · 推广赚佣金</text>
-          <view class="subscribe-actions">
-            <button class="subscribe-btn" @click="goSubscribeC">立即开通 ¥131</button>
-            <text class="subscribe-link" @click="goSubscribe">了解能量师专业版</text>
+        <!-- Voice input mode -->
+        <view v-else class="input-bar__row">
+          <view class="input-bar__toggle" @click.stop="toggleInputMode">
+            <text class="input-bar__toggle-icon">⌨️</text>
+          </view>
+          <view
+            class="voice-btn"
+            :class="{ 'voice-btn--recording': isRecording, 'voice-btn--release': willCancel }"
+            @touchstart="onRecordStart"
+            @touchend.prevent="onRecordEnd"
+            @touchmove="onRecordMove"
+            @touchcancel="onRecordCancel"
+          >
+            <view class="voice-btn__ripple" v-if="isRecording"></view>
+            <text class="voice-btn__text">
+              <template v-if="!isRecording">按住 说话</template>
+              <template v-else-if="willCancel">松开 取消</template>
+              <template v-else>松开 发送</template>
+            </text>
+            <text class="voice-btn__hint" v-if="isRecording && !willCancel">上滑取消</text>
           </view>
         </view>
-       </view>
-     </view>
+      </view>
+    </view>
 
      <!-- US-9.4: Proposal card for negotiating state -->
      <view v-if="planRequest && planRequest.status === 'negotiating'" class="proposal-section">
@@ -263,11 +245,11 @@ export default {
 </script>
 
 <script setup>
-import { ref, computed, onMounted, onUnmounted } from 'vue'
+import { ref, computed, onMounted } from 'vue'
 import { useChartStore } from '@/stores/chart'
 import { useUserStore } from '@/stores/user'
 import TriangleChart from '@/components/TriangleChart.vue'
-import { chartApi, chatApi, consultationApi, profileApi, annotationApi, exportApi, interventionApi, planApi, proposalApi, deliveryApi, payApi } from '@/utils/api'
+import { chatApi, consultationApi, profileApi, annotationApi, exportApi, interventionApi, planApi, proposalApi, deliveryApi } from '@/utils/api'
 
 const store = useChartStore()
 const userStore = useUserStore()
@@ -277,6 +259,17 @@ const messages = ref([])
 const loading = ref(false)
 const usedChats = ref(0)
 const maxChats = ref(0)
+
+// US-9.6: Chart collapse state
+const chartCollapsed = ref(false)
+
+// US-9.6: Voice input state
+const inputMode = ref('text') // 'text' | 'voice'
+const isRecording = ref(false)
+const willCancel = ref(false)
+const audioPlayingIdx = ref(-1)
+const recorderManager = uni.getRecorderManager()
+let innerAudioContext = null
 // US-9.3: Intervention state
 const hasActiveIntervention = ref(false)
 const activeInterventionId = ref(null)
@@ -298,11 +291,6 @@ const deliveryData = ref([])
 const annotations = ref([])
 const allTags = ref([])
 
-// US-3.1: AI interpretation state
-const interpretData = ref(null)
-const interpreting = ref(false)
-const interpretExpanded = ref({})
-
 const quotaExceeded = computed(() => {
   if (userStore.isVipActive) return false
   return maxChats.value > 0 && usedChats.value >= maxChats.value
@@ -353,9 +341,6 @@ onMounted(async () => {
     // US-9.4: Load plan request for this chart
     loadPlanRequest()
 
-    // US-3.1: Auto-load AI interpretation (no longer behind a button)
-    fetchInterpret()
-
     // Use consultationMessages from store (set during startConsultation) if available
     if (store.consultationMessages && store.consultationMessages.length > 0) {
       messages.value = store.consultationMessages.map(m => ({
@@ -449,43 +434,162 @@ async function endIntervention() {
   }
 }
 
-// US-3.1: Fetch AI structured interpretation
-async function fetchInterpret() {
-  if (!store.currentRecordId) {
-    uni.showToast({ title: '暂无命盘数据', icon: 'none' })
-    return
+// ─── Voice Input ─────────────────────────────────────────
+// Setup recorder event listeners
+if (recorderManager) {
+  recorderManager.onStart(() => {
+    isRecording.value = true
+  })
+  recorderManager.onStop(async (res) => {
+    isRecording.value = false
+    willCancel.value = false
+    if (res.tempFilePath && !cancelledRecording) {
+      await uploadVoice(res.tempFilePath)
+    }
+    cancelledRecording = false
+  })
+  recorderManager.onError(() => {
+    isRecording.value = false
+    willCancel.value = false
+    uni.showToast({ title: '录音失败', icon: 'none' })
+  })
+}
+let cancelledRecording = false
+let recordStartY = 0
+
+function toggleInputMode() {
+  inputMode.value = inputMode.value === 'text' ? 'voice' : 'text'
+}
+
+function onRecordStart(e) {
+  if (loading.value) return
+  cancelledRecording = false
+  willCancel.value = false
+  recordStartY = e.touches[0]?.clientY || 0
+  // Start recording
+  recorderManager.start({
+    format: 'mp3',
+    sampleRate: 16000,
+    numberOfChannels: 1,
+    encodeBitRate: 48000
+  })
+}
+
+function onRecordMove(e) {
+  if (!isRecording.value) return
+  const touch = e.touches[0]
+  if (touch && recordStartY > 0) {
+    // Slide up more than 50px → show cancel
+    willCancel.value = (recordStartY - touch.clientY) > 50
   }
-  // If already loaded, just scroll to it
-  if (interpretData.value) {
-    scrollToInterpret()
-    return
+}
+
+function onRecordEnd() {
+  if (isRecording.value) {
+    if (willCancel.value) {
+      cancelledRecording = true
+      recorderManager.stop()
+    } else {
+      recorderManager.stop()
+    }
+  }
+}
+
+function onRecordCancel() {
+  if (isRecording.value) {
+    cancelledRecording = true
+    willCancel.value = false
+    isRecording.value = false
+    try { recorderManager.stop() } catch (e) {}
   }
-  interpreting.value = true
+}
+
+async function uploadVoice(filePath) {
   try {
-    const data = await chartApi.interpret(store.currentRecordId)
-    interpretData.value = data
-    // Auto-expand the main character section
-    interpretExpanded.value = { mainCharacter: true }
-    uni.showToast({ title: '解读已生成', icon: 'success' })
-    scrollToInterpret()
+    uni.showLoading({ title: '语音处理中...', mask: true })
+    const result = await chatApi.voiceUpload(filePath, store.currentRecordId)
+    uni.hideLoading()
+    if (result && result.url) {
+      await sendVoiceMessage(result.url)
+    }
   } catch (e) {
-    uni.showToast({ title: e.message || '解读生成失败', icon: 'none' })
-  } finally {
-    interpreting.value = false
+    uni.hideLoading()
+    uni.showToast({ title: '语音上传失败', icon: 'none' })
   }
 }
 
-function scrollToInterpret() {
-  // Scroll to the interpret section after rendering
-  uni.createSelectorQuery().select('#interpret-section').boundingClientRect(res => {
-    if (res) {
-      uni.pageScrollTo({ scrollTop: res.top - 20, duration: 300 })
+async function sendVoiceMessage(audioUrl) {
+  // Add voice message locally
+  messages.value.push({ role: 'user', content: '[语音消息]', audioUrl })
+  scrollTop.value = 99999
+  loading.value = true
+
+  try {
+    if (store.currentRecordId) {
+      const res = await chatApi.send({
+        chartRecordId: store.currentRecordId,
+        query: '[语音消息]',
+        audioUrl
+      })
+      messages.value.push({ role: 'ai', content: res.reply })
+      usedChats.value++
     }
-  }).exec()
+  } catch (e) {
+    if (e.code === 1008) {
+      usedChats.value = maxChats.value
+      messages.value.push({
+        role: 'ai',
+        content: '今日解读次数已用完,开通会员可享无限次解读。'
+      })
+    } else {
+      messages.value.push({
+        role: 'ai',
+        content: e.message || '解读服务暂时不可用,请稍后再试。'
+      })
+    }
+  }
+  loading.value = false
+  scrollTop.value = 99999
 }
 
-function toggleInterpretSection(key) {
-  interpretExpanded.value[key] = !interpretExpanded.value[key]
+function getServerBase() {
+  // Derive server base from API_BASE_URL pattern (strip trailing /api)
+  // In api.js: const API_BASE_URL = 'http://127.0.0.1:8186/api'
+  const token = uni.getStorageSync('token')
+  // We don't have direct access to API_BASE_URL, so we construct it
+  // This works in dev; production should use relative URLs
+  return 'http://127.0.0.1:8186'
+}
+
+function playAudio(audioUrl, idx) {
+  if (audioPlayingIdx.value === idx) {
+    if (innerAudioContext) {
+      innerAudioContext.stop()
+      innerAudioContext.destroy()
+      innerAudioContext = null
+    }
+    audioPlayingIdx.value = -1
+    return
+  }
+  if (innerAudioContext) {
+    innerAudioContext.stop()
+    innerAudioContext.destroy()
+    innerAudioContext = null
+  }
+  audioPlayingIdx.value = idx
+  innerAudioContext = uni.createInnerAudioContext()
+  innerAudioContext.src = getServerBase() + audioUrl
+  innerAudioContext.onPlay(() => {})
+  innerAudioContext.onError(() => {
+    audioPlayingIdx.value = -1
+    uni.showToast({ title: '播放失败', icon: 'none' })
+  })
+  innerAudioContext.onEnded(() => {
+    audioPlayingIdx.value = -1
+    innerAudioContext.destroy()
+    innerAudioContext = null
+  })
+  innerAudioContext.play()
 }
 
 async function sendQuestion(q) {
@@ -544,7 +648,7 @@ async function sendQuestion(q) {
 
 // US-3.3: Regenerate interpretation via action sheet menu
 function showMenu() {
-  const items = ['🔄 重新生成解读']
+  const items = ['🔄 重新开始']
   // US-2.2: PDF export for paid users only
   if (userStore.isVipActive) {
     items.push('📄 导出 PDF')
@@ -573,8 +677,8 @@ function showMenu() {
 
 async function confirmRegenerate() {
   uni.showModal({
-    title: '重新生成解读',
-    content: '将清除当前对话记录并生成全新的AI解读,确定吗?',
+    title: '重新开始',
+    content: '将清除当前对话记录并重新生成命盘解读,确定吗?',
     success: async (confirm) => {
       if (!confirm.confirm) return
       if (!store.currentRecordId) {
@@ -622,9 +726,6 @@ function goSubscribe() {
 function goSubscribeC() {
   uni.navigateTo({ url: '/pages/payment/index?product=annual' })
 }
-function goPoster() {
-  uni.navigateTo({ url: '/pages/subscribe/index' })
-}
 
 // US-2.2: Export PDF (paid users only)
 async function exportPdf() {
@@ -833,6 +934,41 @@ async function submitCounter() {
 .chart-section {
   flex-shrink: 0;
   margin: 0 14px;
+  overflow: hidden;
+  transition: flex-shrink 0.25s;
+
+  &__body {
+    overflow: hidden;
+    transition: max-height 0.3s ease, opacity 0.25s ease;
+  }
+
+  &--collapsed {
+    flex-shrink: 1;
+  }
+
+  &__toggle {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    gap: 6px;
+    padding: 6px 0 4px;
+    cursor: pointer;
+    -webkit-tap-highlight-color: transparent;
+
+    &:active {
+      opacity: 0.6;
+    }
+
+    &-label {
+      font-size: 11px;
+      color: rgba(255, 255, 255, 0.3);
+    }
+
+    &-arrow {
+      font-size: 10px;
+      color: rgba(255, 255, 255, 0.25);
+    }
+  }
 }
 
 /* Menu bar — three-dot button */
@@ -840,7 +976,7 @@ async function submitCounter() {
   display: flex;
   justify-content: flex-end;
   padding: 0 14px;
-  margin: -8px 0 0;
+  margin: -6px 0 8px;
 }
 .menu-btn {
   width: 32px;
@@ -859,104 +995,6 @@ async function submitCounter() {
   background: rgba(255, 255, 255, 0.08);
 }
 
-/* Interpretation panel */
-.interpret-panel {
-  flex-shrink: 0;
-  margin: 0 14px 16px;
-}
-.interpret-card {
-  background: rgba(124, 58, 237, 0.06);
-  border: 1px solid rgba(124, 58, 237, 0.12);
-  border-radius: 12px;
-  margin-bottom: 10px;
-  overflow: hidden;
-  transition: border-color 0.2s;
-}
-.interpret-card.expanded {
-  border-color: rgba(124, 58, 237, 0.25);
-  background: rgba(124, 58, 237, 0.08);
-}
-.interpret-card-header {
-  display: flex;
-  align-items: center;
-  padding: 12px 14px;
-  gap: 10px;
-}
-.interpret-num-badge {
-  width: 28px;
-  height: 28px;
-  border-radius: 50%;
-  background: linear-gradient(135deg, #7c3aed, #6366f1);
-  color: #fff;
-  font-size: 13px;
-  font-weight: 700;
-  line-height: 28px;
-  text-align: center;
-  flex-shrink: 0;
-}
-.interpret-card-title {
-  flex: 1;
-  font-size: 14px;
-  font-weight: 600;
-  color: rgba(255, 255, 255, 0.85);
-}
-.interpret-toggle {
-  font-size: 12px;
-  color: rgba(255, 255, 255, 0.35);
-}
-.interpret-card-body {
-  padding: 0 14px 14px 52px;
-}
-.interpret-content {
-  display: block;
-  font-size: 13px;
-  line-height: 1.7;
-  color: rgba(255, 255, 255, 0.65);
-  white-space: pre-wrap;
-}
-
-/* Disclaimer */
-.interpret-disclaimer {
-  text-align: center;
-  padding: 6px 0 2px;
-}
-.disclaimer-text {
-  font-size: 11px;
-  color: rgba(255, 255, 255, 0.2);
-}
-
-/* Loading skeleton */
-.interpret-skeleton {
-  flex-shrink: 0;
-  margin: 0 14px 16px;
-}
-.skeleton-card {
-  background: rgba(255, 255, 255, 0.03);
-  border: 1px solid rgba(255, 255, 255, 0.05);
-  border-radius: 12px;
-  margin-bottom: 10px;
-  overflow: hidden;
-}
-.skeleton-header {
-  height: 24px;
-  margin: 12px 14px;
-  background: rgba(255, 255, 255, 0.06);
-  border-radius: 6px;
-  width: 60%;
-}
-.skeleton-body {
-  padding: 0 14px 14px;
-}
-.skeleton-line {
-  height: 12px;
-  background: rgba(255, 255, 255, 0.04);
-  border-radius: 4px;
-  margin-bottom: 8px;
-}
-.skeleton-line.short {
-  width: 70%;
-}
-
 .chat-section {
   flex: 1;
   display: flex;
@@ -967,19 +1005,19 @@ async function submitCounter() {
 }
 
 .section-title {
-  font-size: 17px;
+  font-size: 15px;
   font-weight: 600;
-  color: rgba(255, 255, 255, 0.9);
-  margin: 12px 0 14px;
+  color: rgba(255, 255, 255, 0.85);
+  margin-bottom: 10px;
   display: flex;
   align-items: center;
-  gap: 8px;
+  gap: 6px;
 }
 
 .title-icon {
-  font-size: 14px;
+  font-size: 12px;
   color: #fbbf24;
-  opacity: 0.7;
+  opacity: 0.6;
 }
 
 .quota-badge {
@@ -1064,8 +1102,33 @@ async function submitCounter() {
 }
 
 .input-bar {
-  display: flex;
-  gap: 8px;
+  &__row {
+    display: flex;
+    align-items: center;
+    gap: 8px;
+    width: 100%;
+  }
+
+  &__toggle {
+    width: 38px;
+    height: 38px;
+    border-radius: 50%;
+    background: rgba(255, 255, 255, 0.06);
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    flex-shrink: 0;
+    cursor: pointer;
+
+    &:active {
+      background: rgba(255, 255, 255, 0.12);
+    }
+
+    &-icon {
+      font-size: 18px;
+      line-height: 1;
+    }
+  }
 }
 
 .chat-input {
@@ -1089,12 +1152,142 @@ async function submitCounter() {
   line-height: 42px;
   font-size: 14px;
   font-weight: 500;
+  white-space: nowrap;
 }
 
 .send-btn[disabled] {
   opacity: 0.4;
 }
 
+/* ─── Voice recording button ─── */
+.voice-btn {
+  flex: 1;
+  height: 48px;
+  border-radius: 24px;
+  background: rgba(255, 255, 255, 0.06);
+  border: 1px solid rgba(255, 255, 255, 0.1);
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  position: relative;
+  overflow: hidden;
+  user-select: none;
+  -webkit-tap-highlight-color: transparent;
+
+  &:active {
+    background: rgba(255, 255, 255, 0.1);
+  }
+
+  &--recording {
+    background: rgba(251, 191, 36, 0.1);
+    border-color: rgba(251, 191, 36, 0.3);
+  }
+
+  &--release {
+    background: rgba(239, 68, 68, 0.12);
+    border-color: rgba(239, 68, 68, 0.3);
+  }
+
+  &__text {
+    font-size: 15px;
+    font-weight: 500;
+    color: rgba(255, 255, 255, 0.75);
+    position: relative;
+    z-index: 1;
+  }
+
+  &--recording &__text {
+    color: #fbbf24;
+  }
+  &--release &__text {
+    color: #ef4444;
+  }
+
+  &__hint {
+    position: absolute;
+    right: 14px;
+    top: 50%;
+    transform: translateY(-50%);
+    font-size: 10px;
+    color: rgba(255, 255, 255, 0.25);
+    z-index: 1;
+  }
+
+  &__ripple {
+    position: absolute;
+    inset: -20px;
+    border-radius: 50%;
+    background: radial-gradient(circle, rgba(251, 191, 36, 0.08) 0%, transparent 70%);
+    animation: voice-pulse 1s ease-in-out infinite;
+  }
+}
+
+@keyframes voice-pulse {
+  0%, 100% { transform: scale(1); opacity: 0.6; }
+  50% { transform: scale(1.15); opacity: 1; }
+}
+
+/* ─── Audio message bubble ─── */
+.msg-bubble--audio {
+  display: flex;
+  align-items: center;
+  gap: 8px;
+  min-width: 100px;
+  cursor: pointer;
+
+  &:active {
+    opacity: 0.7;
+  }
+}
+
+.msg-audio {
+  &__icon {
+    font-size: 20px;
+    flex-shrink: 0;
+  }
+
+  &__wave {
+    display: flex;
+    align-items: center;
+    gap: 2px;
+    height: 20px;
+
+    &--playing .msg-audio__bar {
+      background: #fbbf24;
+      animation: audio-bar 0.6s ease-in-out infinite alternate;
+    }
+  }
+
+  &__bar {
+    width: 3px;
+    border-radius: 2px;
+    background: rgba(255, 255, 255, 0.3);
+
+    &:nth-child(1) { height: 8px; }
+    &:nth-child(2) { height: 14px; animation-delay: 0.2s; }
+    &:nth-child(3) { height: 10px; animation-delay: 0.4s; }
+    &:nth-child(4) { height: 16px; animation-delay: 0.6s; }
+  }
+
+  &__label {
+    font-size: 12px;
+    color: rgba(255, 255, 255, 0.5);
+    flex-shrink: 0;
+  }
+}
+
+@keyframes audio-bar {
+  0% { transform: scaleY(0.5); }
+  100% { transform: scaleY(1.2); }
+}
+
+.msg-row.user .msg-audio__bar {
+  background: rgba(251, 191, 36, 0.35);
+}
+.msg-row.user .msg-audio__label {
+  color: rgba(251, 191, 36, 0.5);
+}
+
 /* Share hint */
 .share-hint {
   padding: 8px 0;
@@ -1153,88 +1346,6 @@ async function submitCounter() {
   color: #fbbf24;
 }
 
-/* US-6.6: Subscribe section */
-.subscribe-section {
-  margin-top: 10px;
-}
-
-.vip-badge-bar {
-  background: rgba(52, 211, 153, 0.06);
-  border: 1px solid rgba(52, 211, 153, 0.15);
-  border-radius: 10px;
-  padding: 12px 14px;
-  display: flex;
-  flex-wrap: wrap;
-  align-items: center;
-  gap: 6px;
-}
-.vip-badge-bar.pro {
-  background: rgba(167, 139, 250, 0.06);
-  border-color: rgba(167, 139, 250, 0.15);
-}
-.vip-badge-text {
-  font-size: 13px;
-  font-weight: 600;
-  color: #34d399;
-}
-.vip-badge-bar.pro .vip-badge-text {
-  color: #a78bfa;
-}
-.vip-badge-expiry {
-  font-size: 11px;
-  color: rgba(255,255,255,0.4);
-}
-.vip-poster-link {
-  font-size: 12px;
-  color: #fbbf24;
-  margin-left: auto;
-}
-
-.subscribe-card {
-  background: linear-gradient(135deg, rgba(251, 191, 36, 0.08), rgba(217, 119, 6, 0.05));
-  border: 1px solid rgba(251, 191, 36, 0.15);
-  border-radius: 12px;
-  padding: 16px;
-  text-align: center;
-}
-.subscribe-title {
-  display: block;
-  font-size: 15px;
-  font-weight: 600;
-  color: #fbbf24;
-  margin-bottom: 6px;
-}
-.subscribe-desc {
-  display: block;
-  font-size: 12px;
-  color: rgba(255,255,255,0.45);
-  margin-bottom: 14px;
-  line-height: 1.5;
-}
-.subscribe-actions {
-  display: flex;
-  flex-direction: column;
-  gap: 8px;
-  align-items: center;
-}
-.subscribe-btn {
-  width: 100%;
-  background: linear-gradient(135deg, #f59e0b, #d97706);
-  color: #fff;
-  border: none;
-  border-radius: 10px;
-  padding: 12px 0;
-  font-size: 15px;
-  font-weight: 600;
-}
-.subscribe-btn:active {
-  opacity: 0.85;
-}
-.subscribe-link {
-  font-size: 12px;
-  color: rgba(255,255,255,0.35);
-}
-
 /* US-9.4: Proposal section */
 .proposal-section {
   flex-shrink: 0;

+ 21 - 1
client/utils/api.js

@@ -73,7 +73,27 @@ export const chartApi = {
 
 export const chatApi = {
   send: (data) => requestInstance.post('/chat/send', data),
-  history: (chartRecordId) => requestInstance.post('/chat/history', { chartRecordId })
+  history: (chartRecordId) => requestInstance.post('/chat/history', { chartRecordId }),
+  voiceUpload: (filePath, chartRecordId) => {
+    const token = uni.getStorageSync('token')
+    return new Promise((resolve, reject) => {
+      uni.uploadFile({
+        url: API_BASE_URL + '/chat/voice',
+        filePath,
+        name: 'file',
+        formData: { chartRecordId: String(chartRecordId || '') },
+        header: token ? { Authorization: `Bearer ${token}` } : {},
+        success: (res) => {
+          try {
+            const data = JSON.parse(res.data)
+            if (data.code === 0) resolve(data.data)
+            else reject(new Error(data.message || '上传失败'))
+          } catch (e) { reject(new Error('解析响应失败')) }
+        },
+        fail: (err) => reject(err)
+      })
+    })
+  }
 }
 
 export const payApi = {