chat.vue 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. <template>
  2. <view class="container" :class="{ 'panel-active': activePanel !== 'none' }">
  3. <!-- 状态栏占位(微信小程序用 JS 获取真实高度)-->
  4. <view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
  5. <!-- 导航栏 -->
  6. <view class="nav-bar">
  7. <view class="back-btn" @click="goBack">
  8. <text class="back-arrow">‹</text>
  9. </view>
  10. <view class="nav-center">
  11. <text class="nav-title-text">{{ sessionUserName || '在线咨询' }}</text>
  12. <view class="online-dot"></view>
  13. </view>
  14. <view class="nav-right"></view>
  15. </view>
  16. <!-- 聊天内容区域 -->
  17. <scroll-view
  18. class="chat-body"
  19. scroll-y
  20. :scroll-into-view="lastMessageId"
  21. :style="{ height: chatBodyHeight }"
  22. :show-scrollbar="false"
  23. :enhanced="true"
  24. >
  25. <view class="message-list">
  26. <!-- 加载中 -->
  27. <view v-if="loading" class="tip-row">
  28. <text class="tip-text">加载中...</text>
  29. </view>
  30. <!-- 静态初始卡片区(每次进入均显示) -->
  31. <view v-if="!loading" class="init-cards">
  32. <!-- 测评卡片(动态渲染,内容来自 URL 参数)-->
  33. <view v-if="chatType === 'assessment'" class="msg-row left">
  34. <image :src="waiterAvatar" class="avatar" mode="aspectFill"></image>
  35. <view class="msg-content assessment-card-msg">
  36. <view class="card-left">
  37. <image
  38. :src="assessmentCover || '/static/images/assess_cover.svg'"
  39. class="a-cover"
  40. mode="aspectFill"
  41. ></image>
  42. </view>
  43. <view class="card-right">
  44. <text class="a-title">{{ assessmentTitle || '测评咨询' }}</text>
  45. <view class="a-tags">
  46. <text v-if="assessmentLevel" class="a-tag">{{ assessmentLevel }}</text>
  47. <text class="a-tag">职业技能测评</text>
  48. </view>
  49. <text class="a-price">{{ assessmentPrice ? '¥' + assessmentPrice : '咨询获取' }}</text>
  50. </view>
  51. </view>
  52. </view>
  53. <!-- 培训报名卡片 -->
  54. <view v-else-if="chatType === 'training'" class="msg-row left">
  55. <image :src="waiterAvatar" class="avatar" mode="aspectFill"></image>
  56. <view class="msg-content training-reg-card shadow">
  57. <view class="t-card-header">
  58. <text class="t-card-title">{{ trainingTitle || '审计员线下培训' }}</text>
  59. <text class="t-card-subtitle">线下培训 | 职业能力提升</text>
  60. </view>
  61. <view class="t-card-body">
  62. <view class="t-item"><text class="t-label">主办单位:</text><text class="t-val">AAAAA单位</text></view>
  63. <view class="t-item"><text class="t-label">培训时间:</text><text class="t-val">2025-12-12/13/14</text></view>
  64. </view>
  65. <view class="t-card-footer">
  66. <button class="reg-btn" @click="confirmReg">确认报名</button>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 招聘卡片(默认) -->
  71. <view v-else class="msg-row left">
  72. <image :src="waiterAvatar" class="avatar" mode="aspectFill"></image>
  73. <view class="msg-content job-card-msg">
  74. <view class="card-header">
  75. <view class="ch-left">
  76. <text class="card-title">{{ jobName || '审计员' }}</text>
  77. <text class="urgent-tag">急招</text>
  78. </view>
  79. <text class="card-salary">{{ salaryRange || '13K-23K' }}</text>
  80. </view>
  81. <view class="card-tags">
  82. <text class="c-tag">实习</text>
  83. <text class="c-tag">五险一金</text>
  84. <text class="c-tag">985</text>
  85. </view>
  86. <view class="card-meta">
  87. <view class="m-item"><image src="/static/icons/user.svg" class="m-icon"></image><text>招录 1 人</text></view>
  88. <view class="m-item"><image src="/static/icons/time.svg" class="m-icon"></image><text>截止时间:2025-12-12 24:00</text></view>
  89. </view>
  90. <view class="card-company">
  91. <image src="/static/images/logo1.png" class="c-logo" mode="aspectFit"></image>
  92. <view class="c-info">
  93. <text class="c-name">{{ companyName || '华财仁合' }}</text>
  94. <image src="/static/icons/verified.svg" class="v-icon"></image>
  95. </view>
  96. <text class="c-loc">{{ workCity ? '上海市·' + workCity : '上海市·黄浦区' }}</text>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. <!-- 无后续消息提示(不覆盖初始卡片)-->
  102. <view v-if="!loading && messages.length === 0" class="tip-row">
  103. <text class="tip-text">快发一条消息开始吧~</text>
  104. </view>
  105. <!-- 消息列表(全部来自真实API) -->
  106. <block v-for="(msg, index) in messages" :key="msg.id || index">
  107. <!-- 每隔5分钟显示时间戳 -->
  108. <view v-if="shouldShowTime(msg, index)" class="time-stamp-row">
  109. <text class="time-stamp">{{ formatTime(msg.sendTime) }}</text>
  110. </view>
  111. <view
  112. :id="'msg-' + (msg.id || index)"
  113. class="msg-row"
  114. :class="msg.senderType === 1 ? 'right' : 'left'"
  115. >
  116. <image
  117. v-if="msg.senderType !== 1"
  118. :src="resolveAvatarUrl(msg.senderAvatar) || waiterAvatar"
  119. class="avatar"
  120. mode="aspectFill"
  121. ></image>
  122. <!-- 文本消息 -->
  123. <view
  124. v-if="msg.msgType === 'text'"
  125. class="msg-content text-msg"
  126. :class="msg.senderType === 1 ? 'user-bubble' : 'shadow'"
  127. >{{ msg.content }}</view>
  128. <!-- 图片消息 -->
  129. <view v-else-if="msg.msgType === 'image'" class="msg-content img-msg">
  130. <image
  131. :src="msg.fileUrl"
  132. mode="widthFix"
  133. class="chat-img"
  134. @click="previewImg(msg.fileUrl)"
  135. ></image>
  136. </view>
  137. <!-- 文件消息 -->
  138. <view v-else-if="msg.msgType === 'file'" class="msg-content file-msg shadow">
  139. <text class="file-icon-txt">📄</text>
  140. <view class="file-info">
  141. <text class="file-name">{{ msg.fileName || '文件' }}</text>
  142. <text class="file-size">{{ formatFileSize(msg.fileSize) }}</text>
  143. </view>
  144. </view>
  145. <view v-else-if="msg.msgType === 'order_card'" class="msg-content deposit-card">
  146. <view class="deposit-header">
  147. <view class="d-header-left">
  148. <text class="d-title">您有一笔待付款项</text>
  149. <text class="d-subtitle">项目费用及定金支付通知</text>
  150. </view>
  151. <view v-if="!msg.isPaid && msg.countdown > 0" class="d-countdown">
  152. <text class="c-time">{{ msg.countdown }}s</text>
  153. <text class="c-txt">后取消</text>
  154. </view>
  155. <view v-if="msg.isPaid" class="d-paid-tag">已支付</view>
  156. </view>
  157. <view class="deposit-body">
  158. <view class="d-row">
  159. <text class="label">项目名称:</text>
  160. <text class="val">{{ msg.payload && msg.payload.name || '—' }}</text>
  161. </view>
  162. <view class="d-row">
  163. <text class="label">支付金额:</text>
  164. <text class="price">¥{{ formatAmount(msg.payload && msg.payload.amount) }}</text>
  165. </view>
  166. </view>
  167. <view
  168. class="deposit-action"
  169. :class="{ paid: msg.isPaid }"
  170. @click="handlePay(msg)"
  171. >{{ msg.isPaid ? '已支付' : '立即支付' }}</view>
  172. </view>
  173. <!-- 客服推送的岗位卡片 -->
  174. <view v-else-if="msg.msgType === 'job_card'" class="msg-content api-job-card shadow">
  175. <view class="jc-header">
  176. <text class="jc-title">{{ msg.payload && msg.payload.title || '岗位推荐' }}</text>
  177. <text class="jc-salary">{{ msg.payload && msg.payload.salaryRange || '' }}</text>
  178. </view>
  179. <text class="jc-city" v-if="msg.payload && msg.payload.workCity">{{ msg.payload.workCity }}</text>
  180. </view>
  181. <!-- 系统消息 -->
  182. <view v-else-if="msg.senderType === 3" class="system-msg">
  183. <text>{{ msg.content }}</text>
  184. </view>
  185. <!-- 其他未知类型 -->
  186. <view v-else class="msg-content text-msg shadow">{{ msg.content || '[消息]' }}</view>
  187. <image
  188. v-if="msg.senderType === 1"
  189. :src="resolveAvatarUrl(msg.senderAvatar) || userAvatarUrl"
  190. class="avatar"
  191. mode="aspectFill"
  192. ></image>
  193. </view>
  194. </block>
  195. <view id="bottom-anchor" style="height: 40rpx;"></view>
  196. </view>
  197. </scroll-view>
  198. <!-- 底部输入栏 -->
  199. <view class="footer-wrap">
  200. <view class="input-bar">
  201. <image
  202. :src="inputMode === 'text' ? '/static/icons/audio_thin.svg' : '/static/icons/keyboard.svg'"
  203. class="bar-icon"
  204. mode="aspectFit"
  205. @click="toggleInputMode"
  206. ></image>
  207. <view class="center-area">
  208. <input
  209. v-if="inputMode === 'text'"
  210. v-model="inputValue"
  211. class="chat-input"
  212. placeholder="请输入内容..."
  213. confirm-type="send"
  214. @confirm="sendMessage"
  215. @focus="onInputFocus"
  216. />
  217. <view v-else class="voice-press-btn" @touchstart="onVoiceStart" @touchend="onVoiceEnd">按住 说话</view>
  218. </view>
  219. <image
  220. src="/static/icons/emoji_thin.svg"
  221. class="bar-icon"
  222. :class="{ active: activePanel === 'emoji' }"
  223. mode="aspectFit"
  224. @click="togglePanel('emoji')"
  225. ></image>
  226. <image
  227. :src="activePanel === 'plus' ? '/static/icons/plus_active.svg' : '/static/icons/plus_thin.svg'"
  228. class="bar-icon"
  229. mode="aspectFit"
  230. @click="togglePanel('plus')"
  231. ></image>
  232. </view>
  233. <view class="panel-section" :class="{ show: activePanel !== 'none' }">
  234. <view class="emoji-panel" v-if="activePanel === 'emoji'">
  235. <scroll-view scroll-y class="emoji-scroll">
  236. <view class="emoji-grid">
  237. <text v-for="e in emojiList" :key="e" class="emoji-item" @click="addEmoji(e)">{{e}}</text>
  238. </view>
  239. </scroll-view>
  240. </view>
  241. <view class="plus-panel" v-if="activePanel === 'plus'">
  242. <view class="panel-item" @click="chooseImage">
  243. <view class="icon-box shadow-sm">
  244. <image src="/static/icons/album_color.svg" mode="aspectFit"></image>
  245. </view>
  246. <text>相册</text>
  247. </view>
  248. <view class="panel-item" @click="sendMockOrderCard">
  249. <view class="icon-box shadow-sm">
  250. <image src="/static/icons/order_color.svg" mode="aspectFit"></image>
  251. </view>
  252. <text>订单</text>
  253. </view>
  254. </view>
  255. </view>
  256. </view>
  257. </view>
  258. </template>
  259. <script setup lang="js">
  260. import { ref, computed, nextTick } from 'vue';
  261. import { onLoad, onUnload } from '@dcloudio/uni-app';
  262. import { getChatHistory, sendTextMessage, sendImageMessage, markChatRead, payOrderCard, createOrderByOrderCard, createWxPayOrder, autoCreateOrderCard } from '../../api/message.js';
  263. import { getStudent } from '../../api/student.js';
  264. import { connectChat, sendTextByWs, disconnectChat, subscribe, unsubscribe, generateMsgNo, isSocketConnected } from '../../utils/chatSocket.js';
  265. import { BASE_URL } from '../../utils/request.js';
  266. // ---- 状态 ----
  267. const loading = ref(true);
  268. const messages = ref([]);
  269. const inputValue = ref('');
  270. const inputMode = ref('text');
  271. const activePanel = ref('none');
  272. const lastMessageId = ref('bottom-anchor');
  273. const statusBarHeight = ref(20); // 状态栏高度,微信小程序动态获取
  274. // ---- 会话信息(从URL参数传入)----
  275. const sessionId = ref(null);
  276. const fromUserId = ref(null);
  277. const sessionUserName = ref('');
  278. const jobName = ref('');
  279. const chatType = ref('job');
  280. const trainingTitle = ref('');
  281. // ---- 测评信息(咨询时从URL参数传入)----
  282. const assessmentTitle = ref('');
  283. const assessmentCover = ref('');
  284. const assessmentLevel = ref('');
  285. const assessmentId = ref('');
  286. const assessmentPrice = ref('');
  287. // ---- 岗位信息(咨询时从URL参数传入)----
  288. const positionId = ref(null);
  289. const salaryRange = ref('');
  290. const companyName = ref('');
  291. const workCity = ref('');
  292. // ---- 头像 ----
  293. const waiterAvatar = ref('/static/images/hr_avatar.svg');
  294. // 将 OSS ID 或无效头像转为可访问的 URL
  295. function resolveAvatarUrl(url) {
  296. if (!url || url === '' || url === 'undefined') return '';
  297. const str = String(url).trim();
  298. // 已经是有效 HTTP URL(后端 ossService.selectUrlByIds 已转为真实 URL)
  299. if (str.startsWith('http://') || str.startsWith('https://')) return str;
  300. // 纯数字 → OSS 文件 URL(后端接口)
  301. if (/^\d+$/.test(str)) {
  302. return `${BASE_URL}/resource/oss/file/${str}`;
  303. }
  304. // 本地路径 → 空值
  305. if (str.startsWith('/static/')) return '';
  306. return str;
  307. }
  308. // 判断是否为有效的可访问URL
  309. function isValidAvatar(url) {
  310. if (!url || url === '' || url === 'undefined') return false;
  311. const str = String(url).trim();
  312. if (str.startsWith('/static/')) return false;
  313. // 纯数字是 OSS ID,不是可访问的图片 URL
  314. if (/^\d+$/.test(str)) return false;
  315. return true;
  316. }
  317. const userAvatarUrl = ref('/static/images/user_avatar.png');
  318. const emojiList = ['😀','😃','😄','😁','😆','😅','😂','🤣','😊','😇','🙂','🙃','😉','😌','😍','🥰','😘','😗','😙','😚','😋','😛','😝','😜','🤪','🤨','🧐','🤓','😎','🤩','🥳'];
  319. let wsSubId = null; // WebSocket 订阅 ID
  320. // ---- 生命周期 ----
  321. onLoad(async (options) => {
  322. // 获取状态栏高度(微信小程序中 env(safe-area-inset-top) 为0,需要通过 JS 获取)
  323. // #ifdef MP-WEIXIN
  324. try {
  325. const sysInfo = uni.getSystemInfoSync();
  326. statusBarHeight.value = sysInfo.statusBarHeight || 20;
  327. } catch (e) {}
  328. // #endif
  329. if (options.sessionId) sessionId.value = options.sessionId;
  330. if (options.fromUserId) fromUserId.value = options.fromUserId;
  331. if (options.userName) sessionUserName.value = decodeURIComponent(options.userName);
  332. if (options.jobName) jobName.value = decodeURIComponent(options.jobName);
  333. if (options.type) chatType.value = options.type;
  334. // 培训标题
  335. if (options.title) trainingTitle.value = decodeURIComponent(options.title || '');
  336. // 测评参数解析
  337. if (options.title && options.type === 'assessment') {
  338. assessmentTitle.value = decodeURIComponent(options.title || '');
  339. }
  340. if (options.cover) assessmentCover.value = decodeURIComponent(options.cover || '');
  341. if (options.level) assessmentLevel.value = decodeURIComponent(options.level || '');
  342. if (options.assessmentId) assessmentId.value = options.assessmentId;
  343. if (options.price) assessmentPrice.value = options.price;
  344. // 岗位参数解析
  345. if (options.positionId) positionId.value = options.positionId;
  346. if (options.salaryRange) salaryRange.value = decodeURIComponent(options.salaryRange);
  347. if (options.companyName) companyName.value = decodeURIComponent(options.companyName);
  348. if (options.workCity) workCity.value = decodeURIComponent(options.workCity);
  349. const storedInfo = uni.getStorageSync('userInfo') || {};
  350. // 用户头像:优先用存储的 avatarUrl,再尝试 avatar(可能是 OSS ID)
  351. const rawUserAvatar = storedInfo.avatarUrl || storedInfo.avatar || '/static/images/user_avatar.png';
  352. userAvatarUrl.value = resolveAvatarUrl(rawUserAvatar) || '/static/images/user_avatar.png';
  353. if (!fromUserId.value && storedInfo.studentId) fromUserId.value = storedInfo.studentId;
  354. if (!sessionId.value) {
  355. loading.value = false;
  356. uni.showToast({ title: '会话参数缺失', icon: 'none' });
  357. return;
  358. }
  359. await loadHistory();
  360. // 建立 WebSocket 连接,实时接收消息
  361. connectWebSocket();
  362. // 自动创建结算单(不管有没有历史消息,后端会防重复)
  363. if (chatType.value === 'assessment') {
  364. setTimeout(async () => {
  365. try {
  366. const userInfo = uni.getStorageSync('userInfo') || {};
  367. const res = await autoCreateOrderCard({
  368. sessionId: sessionId.value,
  369. studentId: userInfo.studentId || fromUserId.value,
  370. orderName: assessmentTitle.value || (jobName.value + '-测评服务费'),
  371. orderPrice: assessmentPrice.value || '0',
  372. orderType: '测评咨询'
  373. });
  374. if (res.code === 200 && res.data) {
  375. pushOrderCardMsg(res.data);
  376. } else {
  377. console.error('自动创建结算单失败:', res);
  378. }
  379. } catch (err) {
  380. console.error('自动创建结算单异常:', err);
  381. }
  382. }, 800);
  383. } else if (chatType.value === 'job' && positionId.value) {
  384. try {
  385. const { getAssessmentList } = require('../../api/assessment.js');
  386. const evalRes = await getAssessmentList({ positionId: positionId.value, pageNum: 1, pageSize: 1 });
  387. if (evalRes.code === 200 && evalRes.rows && evalRes.rows.length > 0) {
  388. setTimeout(async () => {
  389. try {
  390. const userInfo = uni.getStorageSync('userInfo') || {};
  391. const firstEval = evalRes.rows[0];
  392. const res = await autoCreateOrderCard({
  393. sessionId: sessionId.value,
  394. studentId: userInfo.studentId || fromUserId.value,
  395. orderName: (firstEval.evaluationName || jobName.value) + '-测评服务费',
  396. orderPrice: firstEval.price || assessmentPrice.value || '0',
  397. orderType: '岗位测评'
  398. });
  399. if (res.code === 200 && res.data) {
  400. pushOrderCardMsg(res.data);
  401. }
  402. } catch (err) { console.error('岗位结算单异常:', err); }
  403. }, 800);
  404. } else {
  405. console.log('[Chat] 该岗位无关联测评,不发送结算单');
  406. }
  407. } catch (e) {
  408. console.error('[Chat] 查询关联测评失败:', e);
  409. }
  410. }
  411. });
  412. let orderTimer = null;
  413. function startOrderTimer() {
  414. if (orderTimer) return;
  415. orderTimer = setInterval(() => {
  416. messages.value.forEach(m => {
  417. if (m.msgType === 'order_card' && !m.isPaid && m.countdown > 0) {
  418. m.countdown--;
  419. }
  420. });
  421. }, 1000);
  422. }
  423. onUnload(() => {
  424. if (wsSubId) {
  425. unsubscribe(wsSubId);
  426. wsSubId = null;
  427. }
  428. disconnectChat();
  429. if (orderTimer) clearInterval(orderTimer);
  430. });
  431. // ---- 加载历史消息 ----
  432. async function loadHistory() {
  433. try {
  434. const res = await getChatHistory({ sessionId: sessionId.value, pageNum: 1, pageSize: 50 });
  435. if (res.rows) {
  436. messages.value = res.rows.slice().reverse().map(normalizeMsg);
  437. scrollToBottom();
  438. // 从历史消息中提取客服真实头像(取第一条客服消息的 senderAvatar)
  439. const firstWaiterMsg = res.rows.find(m => m.senderType === 2);
  440. if (firstWaiterMsg && firstWaiterMsg.senderAvatar) {
  441. const resolvedWaiterAvatar = resolveAvatarUrl(firstWaiterMsg.senderAvatar);
  442. if (resolvedWaiterAvatar) {
  443. waiterAvatar.value = resolvedWaiterAvatar;
  444. }
  445. }
  446. // 标记已读
  447. if (messages.value.length > 0) {
  448. const lastMsg = messages.value[messages.value.length - 1];
  449. if (lastMsg.id && !lastMsg.id.toString().startsWith('temp')) {
  450. markChatRead({ sessionId: sessionId.value, lastReadMsgId: lastMsg.id });
  451. }
  452. }
  453. }
  454. } catch (e) {
  455. console.error('[Chat] 加载历史消息失败:', e);
  456. } finally {
  457. loading.value = false;
  458. }
  459. // 异步加载用户真实头像(从学员表获取OSS永久URL)
  460. if (fromUserId.value) {
  461. try {
  462. const stuRes = await getStudent(fromUserId.value);
  463. if (stuRes.code === 200 && stuRes.data) {
  464. const stu = stuRes.data;
  465. // 学员表 avatar/avatarUrl 可能是 OSS URL 或 OSS ID
  466. const resolvedUrl = resolveAvatarUrl(stu.avatarUrl || stu.avatar);
  467. if (resolvedUrl) {
  468. userAvatarUrl.value = resolvedUrl;
  469. }
  470. }
  471. } catch (e) {
  472. console.warn('[Chat] 获取学员头像失败:', e);
  473. }
  474. }
  475. }
  476. // ---- WebSocket 实时消息 ----
  477. function connectWebSocket() {
  478. const token = uni.getStorageSync('token');
  479. connectChat({
  480. token,
  481. onConnect: () => {
  482. console.log('[Chat] WebSocket 已连接,订阅会话消息');
  483. // 订阅当前会话的消息频道
  484. if (sessionId.value) {
  485. wsSubId = subscribe(`/topic/session/${sessionId.value}`, (data) => {
  486. console.log('[Chat] 收到 WebSocket 消息:', data);
  487. onWsMessage(data);
  488. });
  489. }
  490. },
  491. onDisconnect: () => {
  492. console.log('[Chat] WebSocket 已断开');
  493. }
  494. });
  495. }
  496. /**
  497. * 处理 WebSocket 推送的消息
  498. */
  499. function onWsMessage(data) {
  500. if (!data) return;
  501. // 如果是数组(批量消息),逐条处理
  502. const msgList = Array.isArray(data) ? data : [data];
  503. msgList.forEach(msgData => {
  504. const normalized = normalizeMsg(msgData);
  505. // 去重:按 id 判断,同时按 msgNo 判断(解决乐观更新临时消息与服务端回传的重复问题)
  506. const existIdx = messages.value.findIndex(m =>
  507. (m.id && normalized.id && m.id === normalized.id) ||
  508. (m.msgNo && normalized.msgNo && m.msgNo === normalized.msgNo)
  509. );
  510. if (existIdx >= 0) {
  511. // 更新已有消息(临时消息被服务端确认,用真实数据替换)
  512. messages.value[existIdx] = { ...messages.value[existIdx], ...normalized };
  513. } else {
  514. // 追加新消息
  515. messages.value.push(normalized);
  516. }
  517. });
  518. scrollToBottom();
  519. // 标记已读
  520. const lastMsg = messages.value[messages.value.length - 1];
  521. if (lastMsg && lastMsg.id && !String(lastMsg.id).startsWith('temp')) {
  522. markChatRead({ sessionId: sessionId.value, lastReadMsgId: lastMsg.id });
  523. }
  524. }
  525. // ---- 规范化消息(后端字段 → 前端渲染字段)----
  526. function normalizeMsg(msg) {
  527. let payload = null;
  528. if (msg.payload) {
  529. try { payload = typeof msg.payload === 'string' ? JSON.parse(msg.payload) : msg.payload; } catch (e) {}
  530. }
  531. return {
  532. id: msg.msgId,
  533. msgNo: msg.msgNo,
  534. senderType: msg.senderType, // 1=用户 2=客服 3=系统
  535. senderName: msg.senderName,
  536. senderAvatar: msg.senderAvatar,
  537. msgType: msg.msgType || 'text',
  538. content: msg.content,
  539. fileUrl: msg.fileUrl,
  540. fileName: msg.fileName,
  541. fileSize: msg.fileSize,
  542. payload,
  543. sendTime: msg.sendTime,
  544. isPaid: payload && (payload.status === 'paid' || payload.status === '已支付' || payload.paid === true)
  545. };
  546. }
  547. // ---- 发送文本消息 ----
  548. async function sendMessage() {
  549. const content = inputValue.value.trim();
  550. if (!content || !sessionId.value) return;
  551. const msgNo = generateMsgNo();
  552. const tempId = 'temp_' + Date.now();
  553. // 乐观展示
  554. messages.value.push({
  555. id: tempId, msgNo, senderType: 1, msgType: 'text',
  556. content, sendTime: new Date().toISOString(), payload: null
  557. });
  558. inputValue.value = '';
  559. scrollToBottom();
  560. try {
  561. // 优先通过 WebSocket 发送
  562. if (isSocketConnected()) {
  563. const sent = sendTextByWs(sessionId.value, content, 'text', msgNo, fromUserId.value);
  564. if (sent) return; // WebSocket 发送成功,消息会通过订阅回调回来替换临时消息
  565. }
  566. // WebSocket 不可用时,降级为 HTTP 发送
  567. await sendTextMessage({
  568. sessionId: sessionId.value,
  569. msgNo,
  570. content,
  571. msgType: 'text',
  572. senderId: fromUserId.value || undefined
  573. });
  574. } catch (e) {
  575. messages.value = messages.value.filter(m => m.id !== tempId);
  576. uni.showToast({ title: '发送失败,请重试', icon: 'none' });
  577. }
  578. }
  579. // ---- 发送图片 ----
  580. async function chooseImage() {
  581. activePanel.value = 'none';
  582. uni.chooseImage({
  583. count: 1,
  584. success: async (res) => {
  585. const filePath = res.tempFilePaths[0];
  586. const tempId = 'temp_img_' + Date.now();
  587. messages.value.push({
  588. id: tempId, senderType: 1, msgType: 'image',
  589. fileUrl: filePath, sendTime: new Date().toISOString(), payload: null
  590. });
  591. scrollToBottom();
  592. try {
  593. const msgNo = 'MSG_' + Date.now() + '_' + Math.random().toString(36).slice(2, 6);
  594. await sendImageMessage({ sessionId: sessionId.value, msgNo, filePath, senderId: fromUserId.value });
  595. } catch (e) {
  596. messages.value = messages.value.filter(m => m.id !== tempId);
  597. uni.showToast({ title: '图片发送失败', icon: 'none' });
  598. }
  599. }
  600. });
  601. }
  602. // ---- 发送模拟订单卡片 ----
  603. function sendMockOrderCard() {
  604. activePanel.value = 'none';
  605. messages.value.push({
  606. id: 'manual_order_' + Date.now(),
  607. msgNo: 'ORDER_' + Date.now(),
  608. senderType: 2,
  609. msgType: 'order_card',
  610. content: '为您推送测评费用结算单',
  611. payload: {
  612. id: 1,
  613. name: assessmentTitle.value || '测评费用',
  614. amount: assessmentPrice.value || '680.00'
  615. },
  616. sendTime: new Date().toISOString(),
  617. isPaid: false
  618. });
  619. scrollToBottom();
  620. }
  621. // ---- 推送结算单消息(公共方法,先去重再推送)----
  622. function pushOrderCardMsg(card) {
  623. // 去重检查:如果已有同 orderCardId 的结算单消息,不再重复推送
  624. const hasOrderCard = messages.value.some(m =>
  625. m.msgType === 'order_card' && m.payload && m.payload.orderCardId === card.orderCardId
  626. );
  627. if (hasOrderCard) {
  628. console.log('[Chat] 已存在相同结算单消息,跳过推送');
  629. return;
  630. }
  631. messages.value.push({
  632. id: 'order_' + card.orderCardId,
  633. msgNo: 'ORDER_' + Date.now(),
  634. senderType: card.senderType || 3,
  635. msgType: 'order_card',
  636. content: '项目费用结算单',
  637. countdown: Math.floor((card.countdownSeconds || 1800)),
  638. payload: {
  639. orderCardId: card.orderCardId,
  640. id: card.orderCardId,
  641. name: card.orderName || assessmentTitle.value || jobName.value,
  642. // 同时写入amount和price,兼容后端payload字段
  643. amount: card.orderPrice || assessmentPrice.value || '0',
  644. price: card.orderPrice || assessmentPrice.value || '0',
  645. status: 'pending'
  646. },
  647. sendTime: new Date().toISOString(),
  648. isPaid: false
  649. });
  650. scrollToBottom();
  651. startOrderTimer();
  652. }
  653. // ---- 培训报名确认 ----
  654. function confirmReg() {
  655. uni.showLoading({ title: '预约中...' });
  656. setTimeout(() => {
  657. uni.hideLoading();
  658. uni.showToast({ title: '预约成功', icon: 'success' });
  659. }, 1200);
  660. }
  661. // ---- 支付(客服发送 order_card 后用户点击)----
  662. async function handlePay(msg) {
  663. if (msg.isPaid) return;
  664. const orderCardId = msg.payload ? (msg.payload.orderCardId || msg.payload.id) : null;
  665. const userInfo = uni.getStorageSync('userInfo') || {};
  666. console.log('🔥 开始支付流程');
  667. console.log('🔥 orderCardId:', orderCardId, '类型:', typeof orderCardId);
  668. console.log('🔥 fromUserId:', fromUserId.value, '类型:', typeof fromUserId.value);
  669. console.log('🔥 userInfo:', JSON.stringify(userInfo));
  670. console.log('🔥 msg.payload:', JSON.stringify(msg.payload));
  671. // 临时注释掉模拟支付逻辑,测试真实支付
  672. /*
  673. // 如果是模拟 ID (比如上面的 1),我们直接走模拟逻辑
  674. if (orderCardId === 1) {
  675. uni.showLoading({ title: '发起支付...' });
  676. setTimeout(() => {
  677. msg.isPaid = true;
  678. uni.hideLoading();
  679. uni.showToast({ title: '支付成功', icon: 'success' });
  680. uni.setStorageSync('audit_paid', true);
  681. // 支付成功后自动跳转到培训/测评开始页 (参考初始版)
  682. setTimeout(() => {
  683. uni.navigateTo({ url: `/pages/assessment/training?title=${encodeURIComponent(assessmentTitle.value)}` });
  684. }, 1200);
  685. }, 1000);
  686. return;
  687. }
  688. */
  689. if (!orderCardId) {
  690. uni.showToast({ title: '无效的结算单', icon: 'none' });
  691. return;
  692. }
  693. try {
  694. uni.showLoading({ title: '创建支付订单...' });
  695. // 调用新的微信支付接口
  696. console.log('🔥 调用支付接口,参数:', { orderCardId, userId: fromUserId.value });
  697. const payRes = await createWxPayOrder(orderCardId, fromUserId.value);
  698. console.log('🔥 支付接口响应:', payRes);
  699. if (!(payRes.code === 200 || payRes.code === 0)) {
  700. uni.hideLoading();
  701. uni.showToast({ title: payRes.msg || '创建支付订单失败', icon: 'none' });
  702. console.log('🔥 支付接口调用失败:', payRes);
  703. return;
  704. }
  705. // 检查是否返回了微信支付参数
  706. if (payRes.data && payRes.data.wechatPayParams) {
  707. const wxPayParams = payRes.data.wechatPayParams;
  708. uni.hideLoading();
  709. uni.showLoading({ title: '发起微信支付...' });
  710. // 调用微信支付
  711. uni.requestPayment({
  712. provider: 'wxpay',
  713. timeStamp: wxPayParams.timeStamp,
  714. nonceStr: wxPayParams.nonceStr,
  715. package: wxPayParams.package,
  716. signType: wxPayParams.signType || 'RSA',
  717. paySign: wxPayParams.paySign,
  718. success: (res) => {
  719. uni.hideLoading();
  720. console.log('微信支付成功:', res);
  721. // 支付成功,更新UI
  722. msg.isPaid = true;
  723. uni.showToast({ title: '支付成功', icon: 'success' });
  724. // 标记支付状态到storage(供其他页面检测,按positionId区分)
  725. const paidKey = `audit_paid_${assessmentId.value || ''}`;
  726. uni.setStorageSync(paidKey, true);
  727. // 更新消息payload
  728. msg.payload = {
  729. ...(msg.payload || {}),
  730. orderCardId,
  731. orderId: payRes.data.orderId,
  732. orderNo: payRes.data.orderNo || '',
  733. status: 'paid'
  734. };
  735. uni.$emit('payment_done', {
  736. orderCardId,
  737. orderId: payRes.data.orderId,
  738. paid: true
  739. });
  740. // 支付成功后跳转
  741. if (chatType.value === 'assessment') {
  742. setTimeout(() => {
  743. uni.navigateTo({ url: `/pages/assessment/training?title=${encodeURIComponent(assessmentTitle.value)}` });
  744. }, 1200);
  745. }
  746. },
  747. fail: (err) => {
  748. uni.hideLoading();
  749. console.error('微信支付失败:', err);
  750. if (err.errMsg && err.errMsg.includes('cancel')) {
  751. uni.showToast({ title: '支付已取消', icon: 'none' });
  752. } else {
  753. uni.showToast({ title: '支付失败,请重试', icon: 'none' });
  754. }
  755. }
  756. });
  757. } else {
  758. // 没有微信支付参数,可能是免费订单或其他情况
  759. uni.hideLoading();
  760. if (payRes.data && payRes.data.success) {
  761. msg.isPaid = true;
  762. uni.showToast({ title: payRes.data.message || '支付成功', icon: 'success' });
  763. } else {
  764. uni.showToast({ title: '支付处理异常', icon: 'none' });
  765. }
  766. }
  767. } catch (e) {
  768. uni.hideLoading();
  769. console.error('支付失败:', e);
  770. uni.showToast({ title: '支付失败:' + (e.message || '网络错误'), icon: 'none' });
  771. }
  772. }
  773. // ---- 工具 ----
  774. const chatBodyHeight = computed(() => {
  775. const navH = 100;
  776. const footerH = activePanel.value === 'none' ? 120 : 520;
  777. return `calc(100vh - ${navH}rpx - ${footerH}rpx - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;
  778. });
  779. function scrollToBottom() {
  780. nextTick(() => { lastMessageId.value = ''; nextTick(() => { lastMessageId.value = 'bottom-anchor'; }); });
  781. }
  782. function goBack() { uni.navigateBack(); }
  783. function toggleInputMode() {
  784. inputMode.value = inputMode.value === 'text' ? 'voice' : 'text';
  785. activePanel.value = 'none';
  786. }
  787. function togglePanel(panel) {
  788. activePanel.value = activePanel.value === panel ? 'none' : panel;
  789. if (activePanel.value !== 'none') inputMode.value = 'text';
  790. scrollToBottom();
  791. }
  792. function onInputFocus() { activePanel.value = 'none'; scrollToBottom(); }
  793. function addEmoji(e) { inputValue.value += e; }
  794. function previewImg(url) { uni.previewImage({ urls: [url], current: url }); }
  795. function formatFileSize(size) {
  796. if (!size) return '';
  797. if (size < 1024) return size + 'B';
  798. if (size < 1024 * 1024) return (size / 1024).toFixed(1) + 'KB';
  799. return (size / 1024 / 1024).toFixed(1) + 'MB';
  800. }
  801. function formatTime(timeStr) {
  802. if (!timeStr) return '';
  803. const d = new Date(timeStr);
  804. if (isNaN(d)) return timeStr;
  805. const pad = n => n.toString().padStart(2, '0');
  806. return `${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
  807. }
  808. function shouldShowTime(msg, index) {
  809. if (index === 0) return true;
  810. const prev = messages.value[index - 1];
  811. if (!prev.sendTime || !msg.sendTime) return false;
  812. return (new Date(msg.sendTime) - new Date(prev.sendTime)) > 5 * 60 * 1000;
  813. }
  814. // 格式化金额显示
  815. function formatAmount(amount) {
  816. if (!amount && amount !== 0) return '—';
  817. // 如果是字符串,尝试转换为数字
  818. const num = typeof amount === 'string' ? parseFloat(amount) : amount;
  819. if (isNaN(num)) return '—';
  820. // 保留两位小数,去掉不必要的0
  821. return num.toFixed(2).replace(/\.?0+$/, '');
  822. }
  823. const onVoiceStart = () => uni.showToast({ title: '录音中...', icon: 'none' });
  824. const onVoiceEnd = () => uni.showToast({ title: '语音功能暂未开放', icon: 'none' });
  825. </script>
  826. <style lang="scss" scoped>
  827. .container { width: 100%; height: 100vh; background-color: #F4F5F7; display: flex; flex-direction: column; overflow: hidden; }
  828. /* 状态栏占位:高度由 JS 动态注入 */
  829. .status-bar { background: #FFF; flex-shrink: 0; }
  830. /* 导航栏 */
  831. .nav-bar {
  832. height: 100rpx; background: #FFF; display: flex; align-items: center;
  833. padding: 0 30rpx; border-bottom: 1rpx solid #F0F0F0; flex-shrink: 0;
  834. .back-btn { width: 60rpx; display: flex; align-items: center;
  835. .back-arrow { font-size: 56rpx; color: #333; line-height: 1; margin-top: -6rpx; }
  836. }
  837. .nav-center { flex: 1; display: flex; align-items: center; justify-content: center; gap: 12rpx;
  838. .nav-title-text { font-size: 32rpx; font-weight: bold; color: #1A1A1A; }
  839. .online-dot { width: 14rpx; height: 14rpx; border-radius: 50%; background: #10B981; }
  840. }
  841. .nav-right { width: 60rpx; }
  842. }
  843. .chat-body { flex: 1; }
  844. .message-list { padding: 24rpx 30rpx 160rpx; }
  845. .tip-row { padding: 60rpx 0; text-align: center;
  846. .tip-text { font-size: 26rpx; color: #CCC; }
  847. }
  848. .time-stamp-row { display: flex; justify-content: center; margin: 20rpx 0 30rpx; }
  849. .time-stamp { font-size: 22rpx; color: #BBB; background: rgba(0,0,0,0.05); padding: 4rpx 18rpx; border-radius: 8rpx; }
  850. .msg-row {
  851. display: flex; margin-bottom: 44rpx;
  852. .avatar { width: 80rpx; height: 80rpx; border-radius: 50%; flex-shrink: 0; }
  853. &.left { .avatar { margin-right: 18rpx; } }
  854. &.right { justify-content: flex-end; .avatar { margin-left: 18rpx; } }
  855. }
  856. .msg-content { max-width: 520rpx; border-radius: 16rpx; padding: 22rpx 26rpx; font-size: 30rpx; line-height: 1.6; word-break: break-all; }
  857. .text-msg { background: #FFF; color: #333; &.shadow { box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.04); } &.user-bubble { background: #FFB700; color: #FFF; } }
  858. .img-msg { padding: 8rpx; background: #FFF; border-radius: 12rpx; box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.06);
  859. .chat-img { width: 360rpx; border-radius: 8rpx; display: block; }
  860. }
  861. .file-msg { display: flex; align-items: center; gap: 20rpx; background: #FFF; min-width: 300rpx;
  862. .file-icon-txt { font-size: 56rpx; flex-shrink: 0; }
  863. .file-info { flex: 1;
  864. .file-name { display: block; font-size: 28rpx; color: #333; margin-bottom: 6rpx; word-break: break-all; }
  865. .file-size { font-size: 22rpx; color: #999; }
  866. }
  867. }
  868. /* 订单卡片 */
  869. .deposit-card {
  870. background: #FFF; width: 500rpx; border-radius: 20rpx; overflow: hidden; padding: 0; box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  871. .deposit-header { padding: 28rpx 28rpx 16rpx; display: flex; justify-content: space-between; align-items: flex-start;
  872. .d-header-left { flex: 1;
  873. .d-title { font-size: 32rpx; font-weight: bold; color: #333; }
  874. .d-subtitle { font-size: 22rpx; color: #BBB; margin-top: 6rpx; display: block; }
  875. }
  876. .d-countdown {
  877. display: flex; gap: 4rpx; align-items: center; justify-content: flex-end;
  878. .c-time { color: #FF9500; font-size: 26rpx; font-weight: bold; }
  879. .c-txt { color: #999; font-size: 22rpx; }
  880. }
  881. .d-paid-tag { color: #52C41A; font-size: 24rpx; font-weight: bold; }
  882. }
  883. .deposit-body { padding: 8rpx 28rpx 24rpx;
  884. .d-row { margin-bottom: 10rpx; font-size: 26rpx; display: flex;
  885. .label { color: #AAA; width: 140rpx; } .val { color: #333; flex: 1; } .price { color: #FF3B30; font-size: 34rpx; font-weight: bold; }
  886. }
  887. }
  888. .deposit-action { margin: 0 28rpx 28rpx; height: 76rpx; font-size: 28rpx; background: #FFB700; color: #FFF; border-radius: 38rpx; display: flex; align-items: center; justify-content: center; font-weight: bold; &.paid { background: #EEE; color: #999; } }
  889. }
  890. /* 招聘初始卡片(静态展示用) */
  891. .job-card-msg {
  892. background: #FFF; border-radius: 20rpx; width: 500rpx; padding: 30rpx; box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.04);
  893. .card-header { display: flex; justify-content: space-between; margin-bottom: 20rpx;
  894. .ch-left { display: flex; align-items: center; gap: 10rpx;
  895. .card-title { font-weight: bold; font-size: 34rpx; }
  896. .urgent-tag { border: 1rpx solid #FF4D4F; color: #FF4D4F; font-size: 20rpx; padding: 2rpx 10rpx; border-radius: 6rpx; }
  897. }
  898. .card-salary { color: #1F6CFF; font-weight: bold; font-size: 32rpx; }
  899. }
  900. .card-tags { display: flex; gap: 12rpx; margin-bottom: 24rpx;
  901. .c-tag { background: #F5F7FA; color: #888; font-size: 22rpx; padding: 6rpx 16rpx; border-radius: 8rpx; }
  902. }
  903. .card-meta { display: flex; flex-direction: column; gap: 10rpx; margin-bottom: 24rpx;
  904. .m-item { display: flex; align-items: center; gap: 10rpx;
  905. .m-icon { width: 24rpx; height: 24rpx; opacity: 0.4; }
  906. text { font-size: 24rpx; color: #666; }
  907. }
  908. }
  909. .card-company { display: flex; align-items: center; border-top: 1rpx solid #F5F5F5; padding-top: 24rpx;
  910. .c-logo { width: 80rpx; height: 80rpx; border-radius: 12rpx; margin-right: 16rpx; }
  911. .c-info { flex: 1; display: flex; align-items: center; gap: 8rpx;
  912. .c-name { font-size: 28rpx; font-weight: bold; }
  913. .v-icon { width: 28rpx; height: 28rpx; }
  914. }
  915. .c-loc { font-size: 24rpx; color: #999; }
  916. }
  917. }
  918. /* 测评初始卡片 */
  919. .assessment-card-msg {
  920. background: #FFF; width: 480rpx; padding: 24rpx; display: flex; box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.04);
  921. border-radius: 16rpx;
  922. .card-left { width: 140rpx; height: 140rpx; margin-right: 20rpx;
  923. .a-cover { width: 100%; height: 100%; border-radius: 12rpx; }
  924. }
  925. .card-right { flex: 1; display: flex; flex-direction: column; justify-content: space-between;
  926. .a-title { font-weight: bold; font-size: 30rpx; color: #1A1A1A; }
  927. .a-tags { display: flex; gap: 10rpx; flex-wrap: wrap;
  928. .a-tag { font-size: 20rpx; color: #999; background: #F5F7FA; padding: 4rpx 12rpx; border-radius: 6rpx; }
  929. }
  930. .a-price { color: #FF4D4F; font-weight: bold; font-size: 32rpx; }
  931. }
  932. }
  933. /* 培训报名初始卡片 */
  934. .training-reg-card {
  935. background: #FFF; width: 480rpx; padding: 30rpx; border-radius: 20rpx;
  936. .t-card-header { margin-bottom: 24rpx;
  937. .t-card-title { font-weight: bold; font-size: 32rpx; color: #1A1A1A; display: block; margin-bottom: 8rpx; }
  938. .t-card-subtitle { font-size: 24rpx; color: #999; }
  939. }
  940. .t-card-body { margin-bottom: 30rpx;
  941. .t-item { display: flex; font-size: 26rpx; margin-bottom: 10rpx;
  942. .t-label { color: #888; width: 140rpx; } .t-val { color: #333; }
  943. }
  944. }
  945. .t-card-footer {
  946. .reg-btn { width: 100%; height: 72rpx; line-height: 72rpx; background: #1F6CFF; color: #FFF; border-radius: 36rpx; font-size: 28rpx; font-weight: bold; &::after { border: none; } }
  947. }
  948. }
  949. /* API 推送的岗位卡片(客服消息循环中使用)*/
  950. .api-job-card {
  951. background: #FFF; width: 460rpx; padding: 28rpx; border-radius: 16rpx;
  952. .jc-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12rpx;
  953. .jc-title { font-size: 30rpx; font-weight: bold; color: #1A1A1A; flex: 1; }
  954. .jc-salary { font-size: 28rpx; color: #1F6CFF; font-weight: bold; }
  955. }
  956. .jc-city { font-size: 24rpx; color: #888; }
  957. }
  958. /* 系统消息 */
  959. .system-msg { width: 100%; text-align: center; font-size: 24rpx; color: #BBB; padding: 8rpx 20rpx; background: rgba(0,0,0,0.04); border-radius: 8rpx; }
  960. /* 底部输入栏 */
  961. .footer-wrap { position: fixed; bottom: 0; left: 0; right: 0; background: #FFF; border-top: 1rpx solid #EEE; padding-bottom: env(safe-area-inset-bottom); z-index: 1001; }
  962. .input-bar { height: 120rpx; display: flex; align-items: center; padding: 0 24rpx; gap: 20rpx;
  963. .bar-icon { width: 60rpx; height: 60rpx; transition: transform 0.2s; &.active { transform: scale(1.1); } }
  964. .center-area { flex: 1;
  965. .chat-input { background: #F7F8FA; height: 80rpx; border-radius: 12rpx; border: 1rpx solid #EEE; padding: 0 24rpx; font-size: 28rpx; }
  966. .voice-press-btn { height: 80rpx; background: #F7F8FA; border: 1rpx solid #DDD; border-radius: 12rpx; display: flex; align-items: center; justify-content: center; font-size: 28rpx; color: #666; &:active { background: #E0E0E0; } }
  967. }
  968. }
  969. .panel-section { height: 0; overflow: hidden; transition: height 0.3s; &.show { height: 400rpx; border-top: 1rpx solid #F2F2F2; } }
  970. .emoji-panel { height: 100%; .emoji-scroll { height: 100%; } .emoji-grid { display: flex; flex-wrap: wrap; padding: 30rpx; gap: 20rpx; .emoji-item { font-size: 50rpx; width: 84rpx; text-align: center; } } }
  971. .plus-panel { height: 100%; display: flex; padding: 40rpx 60rpx; gap: 80rpx;
  972. .panel-item { display: flex; flex-direction: column; align-items: center;
  973. .icon-box { width: 116rpx; height: 116rpx; background: #FFF; border: 1rpx solid #F0F0F0; border-radius: 28rpx; display: flex; align-items: center; justify-content: center; margin-bottom: 20rpx; box-shadow: 0 4rpx 10rpx rgba(0,0,0,0.03); image { width: 60rpx; height: 60rpx; } }
  974. text { font-size: 26rpx; color: #777; }
  975. }
  976. }
  977. </style>