index.vue 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  1. <template>
  2. <view class="home-page">
  3. <!-- 顶部状态栏 -->
  4. <view class="top-bar">
  5. <view class="logo">婚恋</view>
  6. <view class="top-right-icons">
  7. <!-- 红娘工作台切换按钮 - 根据数据库查询结果动态显示 -->
  8. <view v-if="showMatchmakerButton"
  9. class="matchmaker-btn" @click="openMatchmakerPopup">
  10. <text class="switch-icon">🔄</text>
  11. <text class="switch-text">切换工作台</text>
  12. </view>
  13. <!-- 消息通知图标 -->
  14. <view class="msg-icon" @click="goToMessages">
  15. <text class="icon">🔔</text>
  16. <view v-if="unreadCount > 0" class="badge">{{ unreadCount }}</view>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 个性化欢迎语 -->
  21. <!-- <view class="welcome-card" v-if="userInfo.nickname">
  22. <view class="welcome-content">
  23. <text class="welcome-text">你好,{{ userInfo.nickname }}!</text>
  24. <text class="match-info">今天有 <text class="highlight">{{ matchCount }}</text> 位新嘉宾和你匹配哦 ❤️</text>
  25. </view>
  26. </view> -->
  27. <!-- 轮播图 -->
  28. <view class="banner-section" v-if="bannerList && bannerList.length > 0">
  29. <swiper class="banner-swiper" :indicator-dots="true" :autoplay="true" :interval="4000" :duration="1000"
  30. :circular="true" indicator-color="rgba(255, 255, 255, 0.5)" indicator-active-color="#E91E63">
  31. <swiper-item v-for="(banner, index) in bannerList" :key="index">
  32. <view class="banner-item" @click="handleBannerClick(banner)">
  33. <image :src="banner.cover_image || banner.coverImage" class="banner-image" mode="aspectFill"
  34. :data-section="'banner'" :data-index="index"
  35. @error="handleImageError" @load="handleImageLoad"></image>
  36. <view class="banner-mask">
  37. <view class="banner-title">{{ banner.name }}</view>
  38. <view class="banner-subtitle" v-if="banner.subtitle">{{ banner.subtitle }}</view>
  39. <view class="banner-btn">查看更多</view>
  40. </view>
  41. </view>
  42. </swiper-item>
  43. </swiper>
  44. </view>
  45. <!-- 小喇叭公告栏 -->
  46. <view class="notice-bar" v-if="noticeList && noticeList.length > 0">
  47. <text class="notice-icon">📢</text>
  48. <swiper class="notice-swiper" vertical :autoplay="true" :interval="3000" :duration="500"
  49. :circular="true">
  50. <swiper-item v-for="(notice, index) in noticeList" :key="index">
  51. <view class="notice-text">{{ notice.content }}</view>
  52. </swiper-item>
  53. </swiper>
  54. </view>
  55. <!-- 核心功能入口 -->
  56. <view class="function-grid">
  57. <view class="grid-item" v-for="(item, index) in functionList" :key="index" @click="handleFunctionClick(item)">
  58. <view class="grid-icon-wrapper" :style="{ background: item.gradient || item.bgColor || '#FFE5F1' }">
  59. <text class="grid-icon" :style="{ color: item.iconColor || '#333333' }">{{ item.icon }}</text>
  60. </view>
  61. <text class="grid-text">{{ item.name }}</text>
  62. </view>
  63. </view>
  64. <!-- 成功案例 -->
  65. <view class="section success-case-section" v-if="successCases && successCases.length > 0">
  66. <view class="section-header">
  67. <text class="section-title">💕 成功案例</text>
  68. <text class="section-more" @click="goToSuccessCaseList">查看更多 ></text>
  69. </view>
  70. <view class="success-case-grid">
  71. <view class="case-card" v-for="(caseItem, index) in successCases.slice(0, 2)" :key="index"
  72. @click="handleSuccessCaseClick(caseItem)">
  73. <view class="case-image-wrapper">
  74. <image :src="caseItem.imageUrl" class="case-image" mode="aspectFill"
  75. :data-section="'successCase'" :data-index="index"
  76. @error="handleImageError" @load="handleImageLoad"></image>
  77. </view>
  78. <view class="case-content">
  79. <view class="couple-names">{{ caseItem.maleUserNickname || '先生' }}&{{ caseItem.femaleUserNickname || '女士' }}</view>
  80. <view class="case-quote">{{ caseItem.quote || '我们通过平台找到了彼此❤️' }}</view>
  81. <view class="case-meta">
  82. <text class="marriage-date">相识于{{ formatMarriageDate(caseItem.marriageDate) }}</text>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <!-- 平台活动 -->
  89. <view class="section activity-recommend-section" v-if="hotActivities && hotActivities.length > 0">
  90. <view class="section-header">
  91. <text class="section-title">🎉 平台活动</text>
  92. <text class="section-more" @click="goToActivityList">查看更多 ></text>
  93. </view>
  94. <view class="activity-scroll-container">
  95. <view class="activity-scroll-wrapper">
  96. <view class="activity-scroll-content">
  97. <!-- 第一组活动 -->
  98. <view class="activity-card-scroll" v-for="(activity, index) in hotActivities" :key="index"
  99. @click="handleActivityClick(activity)">
  100. <view class="activity-image-wrapper">
  101. <image :src="activity.cover_image" class="activity-image" mode="aspectFill"
  102. :data-section="'activity'" :data-index="index"
  103. @error="handleImageError" @load="handleImageLoad"></image>
  104. <view class="activity-status" v-if="activity.status === 1">报名中</view>
  105. </view>
  106. <view class="activity-info-static">
  107. <view class="activity-name-static">{{ activity.name }}</view>
  108. <view class="activity-time-static">{{ formatActivityTime(activity.startTime, activity.endTime) }}</view>
  109. </view>
  110. </view>
  111. <!-- 第二组活动(用于无缝滚动) -->
  112. <view class="activity-card-scroll" v-for="(activity, index) in hotActivities" :key="index + 100"
  113. @click="handleActivityClick(activity)">
  114. <view class="activity-image-wrapper">
  115. <image :src="activity.coverImage" class="activity-image" mode="aspectFill"
  116. :data-section="'activity'" :data-index="index + 100"
  117. @error="handleImageError" @load="handleImageLoad"></image>
  118. <view class="activity-status" v-if="activity.status === 1">报名中</view>
  119. </view>
  120. <view class="activity-info-static">
  121. <view class="activity-name-static">{{ activity.name }}</view>
  122. <view class="activity-time-static">{{ formatActivityTime(activity.startTime, activity.endTime) }}</view>
  123. </view>
  124. </view>
  125. </view>
  126. </view>
  127. </view>
  128. </view>
  129. <!-- 今日缘分推荐 -->
  130. <!-- <view class="section fate-recommend-section" v-if="todayRecommendUsers && todayRecommendUsers.length > 0">
  131. <view class="section-header">
  132. <text class="section-title">🌟 今日缘分</text>
  133. <text class="section-more" @click="goToRecommend">查看更多 ></text>
  134. </view>
  135. <view class="fate-cards">
  136. <view class="fate-card" v-for="(user, index) in todayRecommendUsers" :key="index"
  137. @click="handleUserClick(user)">
  138. <view class="user-avatar-wrapper">
  139. <image :src="user.avatarUrl || user.avatar" class="user-avatar" mode="aspectFill"
  140. :data-section="'todayRecommend'" :data-index="index"
  141. @error="handleImageError" @load="handleImageLoad"></image>
  142. <view class="online-status" v-if="user.isOnline"></view>
  143. </view>
  144. <view class="user-basic-info">
  145. <text class="user-nickname">{{ user.nickname }}</text>
  146. <text class="user-age-location">{{ user.age }}岁 · {{ user.location || user.city }}</text>
  147. </view>
  148. <view class="match-score">
  149. <text class="match-text">匹配度</text>
  150. <text class="match-percentage">{{ formatMatchScore(user.compatibilityScore) }}%</text>
  151. </view>
  152. <view class="user-tags">
  153. <text class="user-tag" v-for="(tag, tagIndex) in parseUserTags(user).slice(0, 2)" :key="tagIndex">
  154. {{ tag }}
  155. </text>
  156. </view>
  157. </view>
  158. </view>
  159. </view> -->
  160. <!-- 个人魅力指数 -->
  161. <view class="section charm-index-section" v-if="userInfo.userId">
  162. <view class="charm-card">
  163. <view class="charm-header">
  164. <text class="charm-title">💖 个人魅力指数</text>
  165. <text class="charm-score">{{ charmIndex.totalScore }}</text>
  166. </view>
  167. <view class="charm-progress">
  168. <view class="progress-bar">
  169. <view class="progress-fill" :style="{ width: charmIndex.totalScore + '%' }"></view>
  170. </view>
  171. <text class="progress-text">超越了{{ charmIndex.beatPercentage }}%的用户</text>
  172. </view>
  173. <view class="charm-items">
  174. <view class="charm-item" v-for="(item, index) in charmIndex.items" :key="index">
  175. <text class="charm-item-label">{{ item.label }}</text>
  176. <view class="charm-item-progress">
  177. <view class="item-progress-bar">
  178. <view class="item-progress-fill" :style="{ width: item.score + '%' }"></view>
  179. </view>
  180. <text class="charm-item-score">{{ item.score }}%</text>
  181. </view>
  182. </view>
  183. </view>
  184. <view class="charm-tip">
  185. <text class="tip-text">💡 {{ charmIndex.tip }}</text>
  186. </view>
  187. </view>
  188. </view>
  189. <!-- 底部占位 -->
  190. <view class="bottom-placeholder"></view>
  191. <!-- 底部导航栏 -->
  192. <view class="tabbar">
  193. <view class="tabbar-item active" @click="switchTab('index')">
  194. <text class="tabbar-icon">🏠</text>
  195. <text class="tabbar-text">首页</text>
  196. </view>
  197. <view class="tabbar-item" @click="switchTab('plaza')">
  198. <text class="tabbar-icon">💕</text>
  199. <text class="tabbar-text">动态</text>
  200. </view>
  201. <view class="tabbar-item" @click="switchTab('recommend')">
  202. <text class="tabbar-icon">👍</text>
  203. <text class="tabbar-text">推荐</text>
  204. </view>
  205. <view class="tabbar-item" @click="switchTab('message')">
  206. <text class="tabbar-icon">💬</text>
  207. <text class="tabbar-text">消息</text>
  208. <view v-if="unreadCount >= 1" class="tabbar-badge">{{ unreadCount }}</view>
  209. </view>
  210. <view class="tabbar-item" @click="switchTab('mine')">
  211. <text class="tabbar-icon">👤</text>
  212. <text class="tabbar-text">我的</text>
  213. </view>
  214. </view>
  215. <!-- 红娘提示弹框 -->
  216. <uni-popup ref="matchmakerPopup" type="dialog">
  217. <uni-popup-dialog
  218. type="confirm"
  219. title="红娘工作台"
  220. content="您是平台认证红娘,是否前往红娘工作台?"
  221. confirmText="前往工作台"
  222. cancelText="取消"
  223. @confirm="goToMatchmakerWorkspace"
  224. @cancel="closeMatchmakerPopup">
  225. </uni-popup-dialog>
  226. </uni-popup>
  227. </view>
  228. </template>
  229. <script>
  230. import api, { request } from '@/utils/api.js'
  231. import { formatTime, formatCountdown, isLoggedIn, goToLogin } from '@/utils/util.js'
  232. import { DEFAULT_IMAGES, ACTIVITY_TYPES } from '@/config/index.js'
  233. import timManager from '@/utils/tim-manager.js'
  234. export default {
  235. data() {
  236. return {
  237. // 用户信息
  238. userInfo: {},
  239. matchCount: 3,
  240. // 是否显示红娘工作台按钮(根据数据库查询结果)
  241. showMatchmakerButton: false,
  242. // 轮播图数据
  243. bannerList: [],
  244. // 公告数据
  245. noticeList: [],
  246. // 功能入口
  247. functionList: [],
  248. // 热门活动
  249. hotActivities: [],
  250. // 成功案例
  251. successCases: [],
  252. // VIP特权(保留但不在首页显示)
  253. vipPrivileges: [
  254. { icon: '💎', text: '专属红娘服务' },
  255. { icon: '⚡', text: '优先匹配推荐' },
  256. { icon: '👑', text: '贵族身份标识' },
  257. { icon: '🔒', text: '隐身访问模式' }
  258. ],
  259. // 今日推荐用户
  260. todayRecommendUsers: [],
  261. // 个人魅力指数
  262. charmIndex: {
  263. totalScore: 75,
  264. beatPercentage: 68,
  265. items: [
  266. { label: '资料完整度', score: 80 },
  267. { label: '活跃度', score: 70 },
  268. { label: '互动质量', score: 75 },
  269. { label: '形象分数', score: 72 }
  270. ],
  271. tip: '完善更多个人信息可提升魅力指数'
  272. },
  273. // 倒计时定时器
  274. countdownTimer: null,
  275. // 图片加载错误计数
  276. imageErrorCount: 0,
  277. // 是否已经显示过红娘弹框(避免重复显示)
  278. hasShownMatchmakerPopup: false
  279. }
  280. },
  281. computed: {
  282. // 从Vuex获取全局未读数
  283. unreadCount() {
  284. return this.$store.getters.getTotalUnread || 0;
  285. }
  286. },
  287. onLoad() {
  288. this.loadUserInfo()
  289. this.loadBannerData()
  290. this.loadNoticeData()
  291. this.loadFunctionGridData()
  292. // this.loadTodayRecommend()
  293. this.loadCharmIndex()
  294. this.loadHotActivities()
  295. this.loadSuccessCases()
  296. // 监听未读消息数更新事件
  297. uni.$on('conversationUnreadUpdate', (totalUnread) => {
  298. console.log('📬 首页收到未读数更新:', totalUnread);
  299. this.$store.dispatch('updateTotalUnread', totalUnread);
  300. });
  301. },
  302. onUnload() {
  303. // 清理资源
  304. uni.$off('conversationUnreadUpdate');
  305. },
  306. onShow() {
  307. console.log('📱 页面onShow触发')
  308. // 页面显示时重新加载用户信息(确保登录后能更新)
  309. this.loadUserInfo()
  310. // 页面显示时查询数据库检查是否为红娘
  311. this.checkMatchmakerStatusFromDB()
  312. },
  313. methods: {
  314. // 从数据库查询用户是否为红娘
  315. async checkMatchmakerStatusFromDB() {
  316. try {
  317. const userId = uni.getStorageSync('userId')
  318. if (!userId) {
  319. console.log('⚠️ 用户未登录,不显示红娘按钮')
  320. this.showMatchmakerButton = false
  321. return
  322. }
  323. console.log('🔍 查询用户红娘状态,userId:', userId)
  324. // 调用API查询用户的is_matchmaker字段
  325. const result = await api.user.getMatchmakerStatus(userId)
  326. if (result && result.isMatchmaker !== undefined) {
  327. const isMatchmaker = parseInt(result.isMatchmaker)
  328. console.log('✅ 查询成功,isMatchmaker:', isMatchmaker)
  329. // 根据查询结果设置按钮显示状态
  330. this.showMatchmakerButton = (isMatchmaker === 1)
  331. // 同时更新本地存储的用户信息
  332. const userInfo = uni.getStorageSync('userInfo') || {}
  333. userInfo.isMatchmaker = isMatchmaker
  334. uni.setStorageSync('userInfo', userInfo)
  335. this.userInfo.isMatchmaker = isMatchmaker
  336. console.log('🎯 红娘按钮显示状态:', this.showMatchmakerButton ? '显示' : '隐藏')
  337. } else {
  338. console.log('⚠️ 查询结果异常,不显示红娘按钮')
  339. this.showMatchmakerButton = false
  340. }
  341. } catch (error) {
  342. console.error('❌ 查询红娘状态失败:', error)
  343. this.showMatchmakerButton = false
  344. }
  345. },
  346. // 前往红娘工作台
  347. async goToMatchmakerWorkspace() {
  348. console.log('🚀 前往红娘工作台')
  349. this.$refs.matchmakerPopup.close()
  350. try {
  351. const userId = uni.getStorageSync('userId')
  352. if (!userId) {
  353. uni.showToast({ title: '请先登录', icon: 'none' })
  354. return
  355. }
  356. if (!timManager.tim) {
  357. try {
  358. timManager.init(1600109674)
  359. console.log('✅ TIM SDK 初始化完成(首页)')
  360. } catch (e) {
  361. console.error('❌ TIM 初始化失败(首页):', e)
  362. }
  363. }
  364. const res = await uni.request({
  365. url: 'http://localhost:8081/api/matchmaker/current',
  366. method: 'GET',
  367. data: { userId }
  368. })
  369. if (!res[1] || res[1].data.code !== 200) {
  370. uni.showToast({ title: '获取红娘信息失败', icon: 'none' })
  371. return
  372. }
  373. const matchmakerInfo = res[1].data.data || {}
  374. const imUserId = matchmakerInfo.imUserId
  375. if (!imUserId) {
  376. uni.showToast({ title: '红娘IM账号缺失', icon: 'none' })
  377. return
  378. }
  379. // 获取UserSig时使用原始imUserId(包含m_前缀)
  380. const sigRes = await uni.request({
  381. url: `http://localhost:8083/api/im/getUserSig?userId=${encodeURIComponent(imUserId)}`,
  382. method: 'GET'
  383. })
  384. if (!sigRes[1] || sigRes[1].data.code !== 200) {
  385. uni.showToast({ title: '获取UserSig失败', icon: 'none' })
  386. return
  387. }
  388. const userSig = sigRes[1].data.data.userSig
  389. console.log('✅ 首页获取 UserSig:', userSig ? '成功' : '失败')
  390. try {
  391. await timManager.logout()
  392. console.log('✅ 已登出之前的IM账号(首页)')
  393. } catch (e) {
  394. console.log('⚠️ 登出失败或未登录(首页):', e.message)
  395. }
  396. await timManager.login(imUserId, userSig)
  397. console.log('✅ 红娘已在首页登录 IM:', imUserId)
  398. uni.$emit('matchmakerIMReady', { imUserId })
  399. } catch (error) {
  400. console.error('❌ 首页初始化红娘IM失败:', error)
  401. uni.showToast({ title: '红娘IM初始化失败', icon: 'none' })
  402. }
  403. uni.navigateTo({
  404. url: '/pages/matchmaker-workbench/index',
  405. fail: (err) => {
  406. console.error('❌ 跳转红娘工作台失败:', err)
  407. uni.showToast({ title: '跳转失败', icon: 'none' })
  408. }
  409. })
  410. },
  411. // 关闭红娘弹框
  412. closeMatchmakerPopup() {
  413. console.log('🚫 用户选择不前往红娘工作台')
  414. this.$refs.matchmakerPopup.close()
  415. },
  416. // 加载用户信息
  417. loadUserInfo() {
  418. // 从本地存储或接口获取用户信息
  419. const userInfo = uni.getStorageSync('userInfo')
  420. if (userInfo) {
  421. this.userInfo = userInfo
  422. this.matchCount = Math.floor(Math.random() * 10) + 1
  423. }
  424. },
  425. // 加载轮播图数据
  426. async loadBannerData() {
  427. try {
  428. // 调用 API 获取轮播图数据
  429. const data = await api.home.getBanners()
  430. if (data && data.length > 0) {
  431. // 处理轮播图数据,确保字段格式正确
  432. this.bannerList = data.map(banner => ({
  433. ...banner,
  434. cover_image: banner.cover_image || banner.coverImage || DEFAULT_IMAGES.banner,
  435. name: banner.name || banner.title || '',
  436. subtitle: banner.subtitle || '',
  437. type: banner.type || 'activity',
  438. targetId: banner.targetId || banner.id
  439. }))
  440. }
  441. } catch (error) {
  442. console.error('获取轮播图失败:', error)
  443. // 使用默认数据
  444. }
  445. },
  446. // 加载金刚区功能列表
  447. async loadFunctionGridData() {
  448. try {
  449. // 调用 API 获取金刚区功能数据
  450. const data = await api.home.getFunctionGrid()
  451. if (data && data.length > 0) {
  452. // 处理金刚区数据,确保字段格式正确
  453. this.functionList = data.map(item => ({
  454. ...item,
  455. // 确保渐变背景色格式正确
  456. gradient: item.gradient || `linear-gradient(135deg, ${item.bgColor} 0%, ${this.lightenColor(item.bgColor, 10)} 100%)`
  457. }))
  458. }
  459. } catch (error) {
  460. console.error('获取金刚区功能列表失败:', error)
  461. // 使用默认数据作为降级方案
  462. this.functionList = [
  463. { id: 1, name: '星命测算', icon: '💖', path: '/pages/astrology/index', bgColor: '#FF6B9D', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF6B9D 0%, #FF8EAB 100%)' },
  464. { id: 2, name: '红娘列表', icon: '👤', path: '/pages/matchmakers/list', bgColor: '#6BC5F8', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #6BC5F8 0%, #87CEEB 100%)' },
  465. { id: 4, name: '精品课程', icon: '📚', path: '/pages/courses/list', bgColor: '#FF8C42', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF8C42 0%, #FFA366 100%)' },
  466. { id: 5, name: '今日缘分', icon: '💝', path: '/pages/recommend/index', bgColor: '#FF69B4', iconColor: '#FFFFFF', gradient: 'linear-gradient(135deg, #FF69B4 0%, #FF8CC8 100%)', needLogin: true }
  467. ]
  468. }
  469. },
  470. // 颜色提亮函数(用于生成渐变背景色)
  471. lightenColor(color, percent) {
  472. // 移除#号
  473. color = color.replace('#', '')
  474. // 转换为RGB
  475. let r = parseInt(color.substring(0, 2), 16)
  476. let g = parseInt(color.substring(2, 4), 16)
  477. let b = parseInt(color.substring(4, 6), 16)
  478. // 提亮颜色
  479. r = Math.min(255, Math.round(r + (255 - r) * percent / 100))
  480. g = Math.min(255, Math.round(g + (255 - g) * percent / 100))
  481. b = Math.min(255, Math.round(b + (255 - b) * percent / 100))
  482. // 转换回十六进制
  483. return '#' + ((r << 16) | (g << 8) | b).toString(16).padStart(6, '0')
  484. },
  485. // 加载公告数据
  486. async loadNoticeData() {
  487. try {
  488. // 调用 API 获取公告数据
  489. const data = await api.home.getNotices()
  490. if (data && data.length > 0) {
  491. this.noticeList = data
  492. }
  493. } catch (error) {
  494. console.error('获取公告失败:', error)
  495. // 使用默认数据
  496. }
  497. },
  498. // 加载今日推荐
  499. async loadTodayRecommend() {
  500. try {
  501. const userId = this.userInfo.userId || parseInt(uni.getStorageSync('userId'))
  502. if (!userId) {
  503. console.log('用户未登录,跳过今日推荐加载')
  504. return
  505. }
  506. // 调用推荐API获取推荐用户列表
  507. const data = await api.recommend.getUsers({
  508. userId: userId,
  509. oppoOnly: 1, // 只推荐异性
  510. limit: 20 // 获取20个用户用于筛选
  511. })
  512. if (data && data.length > 0) {
  513. // 按匹配度降序排序,取前3个匹配度最高的用户
  514. const sortedUsers = data
  515. .filter(user => user.compatibilityScore && user.compatibilityScore > 0)
  516. .sort((a, b) => (b.compatibilityScore || 0) - (a.compatibilityScore || 0))
  517. .slice(0, 3)
  518. // 处理用户数据
  519. this.todayRecommendUsers = sortedUsers.map(user => ({
  520. ...user,
  521. avatarUrl: this.validateImageUrl(user.avatarUrl || DEFAULT_IMAGES.avatar),
  522. age: user.age || 0,
  523. location: this.formatLocation(user),
  524. isOnline: false // 可以根据实际情况设置
  525. }))
  526. console.log('今日缘分推荐加载成功,匹配度最高的用户:', this.todayRecommendUsers)
  527. }
  528. } catch (error) {
  529. console.error('获取推荐用户失败:', error)
  530. this.todayRecommendUsers = []
  531. }
  532. },
  533. // 格式化位置信息
  534. formatLocation(user) {
  535. const parts = []
  536. if (user.provinceName) parts.push(user.provinceName)
  537. if (user.cityName) parts.push(user.cityName)
  538. if (parts.length === 0 && user.location) return user.location
  539. if (parts.length === 0 && user.city) return user.city
  540. return parts.join(' ')
  541. },
  542. // 格式化匹配度分数
  543. formatMatchScore(score) {
  544. if (!score) return '0.0'
  545. return Number(score).toFixed(1)
  546. },
  547. // 解析用户标签
  548. parseUserTags(user) {
  549. const tags = []
  550. if (user.star) tags.push(user.star)
  551. if (user.jobTitle) tags.push(user.jobTitle)
  552. if (user.hobby) {
  553. try {
  554. const hobbies = typeof user.hobby === 'string' ? JSON.parse(user.hobby) : user.hobby
  555. if (Array.isArray(hobbies)) {
  556. tags.push(...hobbies.slice(0, 2))
  557. }
  558. } catch (e) {
  559. console.error('解析兴趣爱好失败:', e)
  560. }
  561. }
  562. return tags
  563. },
  564. // 加载魅力指数
  565. async loadCharmIndex() {
  566. try {
  567. if (this.userInfo.userId) {
  568. // 调用 API 获取魅力指数
  569. // const data = await api.user.getCharmIndex(this.userInfo.userId)
  570. // if (data) {
  571. // this.charmIndex = data
  572. // }
  573. }
  574. } catch (error) {
  575. console.error('获取魅力指数失败:', error)
  576. }
  577. },
  578. // 加载热门活动
  579. async loadHotActivities() {
  580. try {
  581. // 调用 API 获取活动列表(获取所有状态为1的活动,而不是只获取热门活动)
  582. const data = await api.activity.getList({
  583. status: 1,
  584. limit: 10
  585. })
  586. if (data && data.length > 0) {
  587. this.hotActivities = data.map((activity, index) => {
  588. const rawCover = this.validateImageUrl(activity.cover_image || activity.coverImage || activity.imageUrl || activity.image_url)
  589. return {
  590. ...activity,
  591. coverImage: this.ensureRomanticCover(rawCover, index),
  592. name: activity.name || activity.title || '',
  593. startTime: activity.startTime || activity.start_time || activity.startDate || '',
  594. endTime: activity.endTime || activity.end_time || activity.endDate || '',
  595. status: activity.status || 0
  596. }})
  597. }
  598. } catch (error) {
  599. console.error('获取热门活动失败:', error)
  600. }
  601. },
  602. // 格式化活动时间(支持开始和结束时间)
  603. formatActivityTime(startTime, endTime) {
  604. if (!startTime) return '时间待定'
  605. try {
  606. const start = new Date(startTime)
  607. const startMonth = start.getMonth() + 1
  608. const startDay = start.getDate()
  609. const startHour = start.getHours().toString().padStart(2, '0')
  610. const startMinute = start.getMinutes().toString().padStart(2, '0')
  611. let timeStr = `${startMonth}月${startDay}日 ${startHour}:${startMinute}`
  612. // 如果有结束时间,添加结束时间
  613. if (endTime) {
  614. const end = new Date(endTime)
  615. const endMonth = end.getMonth() + 1
  616. const endDay = end.getDate()
  617. const endHour = end.getHours().toString().padStart(2, '0')
  618. const endMinute = end.getMinutes().toString().padStart(2, '0')
  619. timeStr += ` - ${endMonth}月${endDay}日 ${endHour}:${endMinute}`
  620. }
  621. return timeStr
  622. } catch (error) {
  623. return '时间待定'
  624. }
  625. },
  626. // 加载成功案例
  627. async loadSuccessCases() {
  628. try {
  629. // 调用 API 获取成功案例列表
  630. const data = await api.successCase.getList({
  631. pageNum: 1,
  632. pageSize: 5
  633. })
  634. if (data && data.length > 0) {
  635. this.successCases = data.map(caseItem => ({
  636. ...caseItem,
  637. maleUserNickname: caseItem.maleUserNickname || caseItem.male_user_nickname || '先生',
  638. femaleUserNickname: caseItem.femaleUserNickname || caseItem.female_user_nickname || '女士',
  639. imageUrl: this.validateImageUrl(caseItem.imageUrl || caseItem.image_url || DEFAULT_IMAGES.couple),
  640. quote: caseItem.quote || '我们通过平台找到了彼此❤️',
  641. marriageDate: caseItem.marriageDate || caseItem.marriage_date || ''
  642. }))
  643. } else {
  644. // 使用默认数据
  645. this.successCases = []
  646. }
  647. } catch (error) {
  648. console.error('获取成功案例失败:', error)
  649. }
  650. },
  651. // 格式化结婚日期
  652. formatMarriageDate(dateStr) {
  653. if (!dateStr) return '佳音渐近'
  654. try {
  655. const date = new Date(dateStr)
  656. const year = date.getFullYear()
  657. const month = date.getMonth() + 1
  658. const day = date.getDate()
  659. return `${year}年${month}月${day}日`
  660. } catch (error) {
  661. return '佳音渐近'
  662. }
  663. },
  664. // 跳转到VIP页面
  665. goToVip() {
  666. uni.navigateTo({
  667. url: '/pages/vip/index'
  668. })
  669. },
  670. // 跳转到活动列表
  671. goToActivityList() {
  672. uni.navigateTo({
  673. url: '/pages/activities/list'
  674. })
  675. },
  676. // 处理活动点击
  677. handleActivityClick(activity) {
  678. uni.navigateTo({
  679. url: `/pages/activities/detail?id=${activity.id}`
  680. })
  681. },
  682. // 跳转到成功案例列表
  683. goToSuccessCaseList() {
  684. uni.navigateTo({
  685. url: '/pages/success-case/list'
  686. })
  687. },
  688. // 处理成功案例点击
  689. handleSuccessCaseClick(caseItem) {
  690. const caseNo = caseItem.caseNo || caseItem.case_no
  691. uni.navigateTo({
  692. url: `/pages/success-case/detail?caseNo=${caseNo}`
  693. })
  694. },
  695. // 处理图片加载错误并回退到默认图
  696. handleImageError(e) {
  697. const failedSrc = e.detail ? e.detail.errMsg : '未知错误'
  698. const dataset = (e && e.target && e.target.dataset) ? e.target.dataset : {}
  699. const section = dataset.section
  700. const index = dataset.index
  701. console.warn('图片加载失败:', failedSrc, 'section:', section, 'index:', index)
  702. const fallbackMap = {
  703. banner: DEFAULT_IMAGES.banner,
  704. activity: DEFAULT_IMAGES.activity,
  705. successCase: DEFAULT_IMAGES.couple,
  706. todayRecommend: DEFAULT_IMAGES.avatar
  707. }
  708. const setFallback = (list, targetIndex, key, fallback, extraKeys = []) => {
  709. if (!Array.isArray(list) || list.length === 0) return
  710. const numIndex = Number(targetIndex)
  711. if (Number.isNaN(numIndex)) return
  712. const normalizedIndex = ((numIndex % list.length) + list.length) % list.length
  713. if (!list[normalizedIndex]) return
  714. this.$set(list[normalizedIndex], key, fallback)
  715. extraKeys.forEach(extraKey => this.$set(list[normalizedIndex], extraKey, fallback))
  716. }
  717. switch (section) {
  718. case 'banner':
  719. setFallback(this.bannerList, index, 'cover_image', fallbackMap.banner)
  720. setFallback(this.bannerList, index, 'coverImage', fallbackMap.banner)
  721. break
  722. case 'activity':
  723. setFallback(this.hotActivities, index, 'coverImage', this.getRomanticImage(index))
  724. break
  725. case 'successCase':
  726. setFallback(this.successCases, index, 'imageUrl', fallbackMap.successCase)
  727. break
  728. case 'todayRecommend':
  729. setFallback(this.todayRecommendUsers, index, 'avatar', fallbackMap.todayRecommend)
  730. break
  731. default:
  732. break
  733. }
  734. },
  735. // 处理图片加载成功
  736. handleImageLoad(e) {
  737. // 图片加载成功,重置错误计数
  738. this.imageErrorCount = 0
  739. },
  740. // 验证和处理图片URL
  741. validateImageUrl(url) {
  742. if (!url || url === 'null' || url === 'undefined') {
  743. return DEFAULT_IMAGES.activity || DEFAULT_IMAGES.banner || 'http://115.190.125.125:9001/static-images/login-bg.png'
  744. }
  745. let cleanedUrl = String(url).trim()
  746. const httpIndex = cleanedUrl.indexOf('http')
  747. if (httpIndex > 0) {
  748. cleanedUrl = cleanedUrl.slice(httpIndex)
  749. }
  750. if (!cleanedUrl) {
  751. return DEFAULT_IMAGES.activity || DEFAULT_IMAGES.banner || 'http://115.190.125.125:9001/static-images/login-bg.png'
  752. }
  753. // 如果是相对路径,添加协议和域名
  754. if (cleanedUrl.startsWith('/')) {
  755. // 检查是否是完整的服务器路径
  756. if (cleanedUrl.startsWith('/banners/') || cleanedUrl.startsWith('/activities/') || cleanedUrl.startsWith('/images/')) {
  757. return `http://115.190.125.125:9000${cleanedUrl}`
  758. }
  759. return `http://115.190.125.125:9000${cleanedUrl}`
  760. }
  761. // 如果已经是完整URL,直接返回
  762. if (cleanedUrl.startsWith('http://') || cleanedUrl.startsWith('https://')) {
  763. return cleanedUrl
  764. }
  765. // 其他情况返回默认图片
  766. return DEFAULT_IMAGES.activity || DEFAULT_IMAGES.banner || 'http://115.190.125.125:9001/static-images/login-bg.png'
  767. },
  768. getRomanticImage(index = 0) {
  769. if (!this.romanticImages || this.romanticImages.length === 0) {
  770. return DEFAULT_IMAGES.activity || DEFAULT_IMAGES.banner || 'http://115.190.125.125:9001/static-images/login-bg.png'
  771. }
  772. const idx = Math.abs(Number(index) || 0) % this.romanticImages.length
  773. return this.romanticImages[idx]
  774. },
  775. ensureRomanticCover(url, index = 0) {
  776. if (!url || url === DEFAULT_IMAGES.activity || url === DEFAULT_IMAGES.banner || url === 'http://115.190.125.125:9001/static-images/login-bg.png') {
  777. return this.getRomanticImage(index)
  778. }
  779. return url
  780. },
  781. // 跳转到推荐页面
  782. goToRecommend() {
  783. uni.navigateTo({
  784. url: '/pages/recommend/index'
  785. })
  786. },
  787. // 处理用户点击
  788. handleUserClick(user) {
  789. const userId = user.userId || user.id
  790. if (!userId) {
  791. uni.showToast({
  792. title: '用户信息错误',
  793. icon: 'none'
  794. })
  795. return
  796. }
  797. uni.navigateTo({
  798. url: `/pages/recommend/user-detail?userId=${userId}`
  799. })
  800. },
  801. // 格式化时间
  802. formatTime,
  803. // Banner点击
  804. handleBannerClick(banner) {
  805. if (banner.type === 'activity') {
  806. uni.navigateTo({
  807. url: `/pages/activities/detail?id=${banner.targetId}`
  808. })
  809. } else if (banner.type === 'course') {
  810. uni.navigateTo({
  811. url: `/pages/courses/detail?id=${banner.targetId}`
  812. })
  813. } else if (banner.type === 'case') {
  814. uni.navigateTo({
  815. url: '/pages/success-case/list'
  816. })
  817. }
  818. },
  819. // 功能入口点击
  820. handleFunctionClick(item) {
  821. // 今日缘分:直接跳转到专门的推荐页面
  822. if (item && (item.id === 5 || item.name === '今日缘分' || item.name === '今日推荐')) {
  823. console.log('点击今日缘分,跳转到专门页面')
  824. uni.navigateTo({
  825. url: '/pages/today-recommend/index',
  826. success: () => {
  827. console.log('跳转今日缘分页面成功')
  828. },
  829. fail: (err) => {
  830. console.error('跳转今日缘分页面失败:', err)
  831. uni.showToast({
  832. title: '页面跳转失败',
  833. icon: 'none'
  834. })
  835. }
  836. })
  837. return
  838. }
  839. // 检查是否需要登录
  840. if (item.needLogin && !isLoggedIn()) {
  841. uni.navigateTo({
  842. url: '/pages/page3/page3'
  843. })
  844. return
  845. }
  846. if (item.path) {
  847. let url = item.path
  848. if (item.query) {
  849. const queryStr = Object.keys(item.query).map(key => `${key}=${item.query[key]}`).join('&')
  850. url += '?' + queryStr
  851. }
  852. uni.navigateTo({
  853. url: url,
  854. fail: () => {
  855. uni.showToast({
  856. title: '功能开发中',
  857. icon: 'none'
  858. })
  859. }
  860. })
  861. }
  862. },
  863. // 跳转到消息中心
  864. goToMessages() {
  865. uni.navigateTo({
  866. url: '/pages/message/index',
  867. fail: () => {
  868. uni.showToast({
  869. title: '功能开发中',
  870. icon: 'none'
  871. })
  872. }
  873. })
  874. },
  875. // 打开红娘工作台弹框
  876. openMatchmakerPopup() {
  877. // 删除检查处理标记的逻辑,每次点击都显示弹框
  878. if (this.$refs.matchmakerPopup) {
  879. this.$refs.matchmakerPopup.open()
  880. }
  881. },
  882. // 切换Tab
  883. switchTab(tab) {
  884. if (tab === 'index') return
  885. const tabPages = {
  886. plaza: '/pages/plaza/index',
  887. recommend: '/pages/recommend/index',
  888. message: '/pages/message/index',
  889. mine: '/pages/mine/index'
  890. }
  891. if (tabPages[tab]) {
  892. uni.redirectTo({
  893. url: tabPages[tab]
  894. })
  895. }
  896. }
  897. }
  898. }
  899. </script>
  900. <style lang="scss" scoped>
  901. .home-page {
  902. min-height: 100vh;
  903. background: #F5F5F5;
  904. padding-bottom: 120rpx;
  905. }
  906. /* 顶部状态栏 */
  907. .top-bar {
  908. display: flex;
  909. justify-content: space-between;
  910. align-items: center;
  911. padding: 25rpx 35rpx;
  912. background: #FFFFFF;
  913. border-bottom: 2rpx solid #E0E0E0;
  914. .logo {
  915. font-size: 38rpx;
  916. font-weight: 800;
  917. color: #E91E63;
  918. }
  919. .top-right-icons {
  920. display: flex;
  921. align-items: center;
  922. gap: 20rpx;
  923. }
  924. .matchmaker-btn {
  925. position: relative;
  926. width: auto;
  927. height: auto;
  928. display: flex;
  929. align-items: center;
  930. justify-content: center;
  931. background: transparent;
  932. border-radius: 0;
  933. transition: all 0.3s ease;
  934. padding: 10rpx 20rpx;
  935. color: #E91E63;
  936. font-weight: 600;
  937. border: 2rpx solid #E91E63;
  938. border-radius: 25rpx;
  939. &:active {
  940. opacity: 0.8;
  941. transform: scale(0.98);
  942. background: rgba(233, 30, 99, 0.1);
  943. }
  944. .switch-icon {
  945. font-size: 28rpx;
  946. margin-right: 8rpx;
  947. }
  948. .switch-text {
  949. font-size: 26rpx;
  950. color: #E91E63;
  951. font-weight: 600;
  952. }
  953. }
  954. .msg-icon {
  955. position: relative;
  956. width: 68rpx;
  957. height: 68rpx;
  958. display: flex;
  959. align-items: center;
  960. justify-content: center;
  961. background: #FFE5F1;
  962. border-radius: 50%;
  963. transition: all 0.2s ease;
  964. &:active {
  965. opacity: 0.8;
  966. transform: scale(0.95);
  967. }
  968. .icon {
  969. font-size: 44rpx;
  970. }
  971. .badge {
  972. position: absolute;
  973. top: -5rpx;
  974. right: -5rpx;
  975. min-width: 36rpx;
  976. height: 36rpx;
  977. line-height: 36rpx;
  978. padding: 0 8rpx;
  979. background: #FF6B6B;
  980. color: #FFFFFF;
  981. font-size: 20rpx;
  982. font-weight: bold;
  983. border-radius: 18rpx;
  984. text-align: center;
  985. }
  986. }
  987. }
  988. /* 个性化欢迎语 */
  989. .welcome-card {
  990. margin: 25rpx 35rpx;
  991. padding: 35rpx;
  992. background: #FFFFFF;
  993. border-radius: 16rpx;
  994. border: 2rpx solid #E0E0E0;
  995. .welcome-content {
  996. display: flex;
  997. flex-direction: column;
  998. gap: 16rpx;
  999. .welcome-text {
  1000. font-size: 34rpx;
  1001. font-weight: 700;
  1002. color: #333333;
  1003. line-height: 1.3;
  1004. }
  1005. .match-info {
  1006. font-size: 28rpx;
  1007. color: #666666;
  1008. line-height: 1.4;
  1009. .highlight {
  1010. color: #E91E63;
  1011. font-weight: 800;
  1012. font-size: 36rpx;
  1013. }
  1014. }
  1015. }
  1016. }
  1017. /* 轮播图 */
  1018. .banner-section {
  1019. margin: 10rpx 10rpx;
  1020. .banner-swiper {
  1021. height: 480rpx;
  1022. border-radius: 16rpx;
  1023. overflow: hidden;
  1024. border: 2rpx solid #E0E0E0;
  1025. .banner-item {
  1026. position: relative;
  1027. width: 100%;
  1028. height: 100%;
  1029. overflow: hidden;
  1030. .banner-image {
  1031. width: 100%;
  1032. height: 100%;
  1033. }
  1034. .banner-mask {
  1035. position: absolute;
  1036. bottom: 0;
  1037. left: 0;
  1038. right: 0;
  1039. padding: 35rpx;
  1040. background: rgba(0, 0, 0, 0.6);
  1041. color: #FFFFFF;
  1042. .banner-title {
  1043. font-size: 38rpx;
  1044. font-weight: 800;
  1045. margin-bottom: 12rpx;
  1046. line-height: 1.2;
  1047. }
  1048. .banner-subtitle {
  1049. font-size: 26rpx;
  1050. margin-bottom: 24rpx;
  1051. }
  1052. .banner-btn {
  1053. display: inline-block;
  1054. padding: 12rpx 32rpx;
  1055. background: #E91E63;
  1056. border-radius: 8rpx;
  1057. font-size: 26rpx;
  1058. font-weight: 600;
  1059. transition: all 0.2s ease;
  1060. &:active {
  1061. opacity: 0.8;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. }
  1067. }
  1068. /* 公告栏 */
  1069. .notice-bar {
  1070. display: flex;
  1071. align-items: center;
  1072. margin: 25rpx 35rpx;
  1073. padding: 24rpx 30rpx;
  1074. background: #FFF8E1;
  1075. border-radius: 8rpx;
  1076. border: 2rpx solid #FFD54F;
  1077. border-left: 6rpx solid #FFC107;
  1078. .notice-icon {
  1079. font-size: 34rpx;
  1080. margin-right: 24rpx;
  1081. }
  1082. .notice-swiper {
  1083. flex: 1;
  1084. height: 44rpx;
  1085. .notice-text {
  1086. font-size: 28rpx;
  1087. color: #795548;
  1088. line-height: 44rpx;
  1089. white-space: nowrap;
  1090. overflow: hidden;
  1091. text-overflow: ellipsis;
  1092. font-weight: 500;
  1093. }
  1094. }
  1095. }
  1096. /* 功能入口 */
  1097. .function-grid {
  1098. display: flex; /* 核心:改为flex布局 */
  1099. flex-wrap: wrap; /* 自动换行 */
  1100. gap: 25rpx; /* 保留间距(注意:低版本浏览器可能不兼容flex gap,需用margin替代) */
  1101. margin: 20rpx 1rpx;
  1102. padding: 30rpx 20rpx;
  1103. background: #fefeff;
  1104. border-radius: 20rpx;
  1105. border: 2rpx solid #f0f0f5;
  1106. box-shadow: 0 4rpx 16rpx rgba(220, 220, 240, 0.2);
  1107. /* 兼容低版本浏览器(无flex gap时):给子元素加margin,替代gap */
  1108. // > .grid-item {
  1109. // margin: 0 15rpx 30rpx 15rpx;
  1110. // }
  1111. // > .grid-item:nth-child(4n+1) {
  1112. // margin-left: 0;
  1113. // }
  1114. // > .grid-item:nth-child(n+5) {
  1115. // margin-top: 30rpx;
  1116. // }
  1117. }
  1118. .grid-item {
  1119. display: flex;
  1120. flex-direction: column;
  1121. align-items: center;
  1122. justify-content: center;
  1123. gap: 16rpx;
  1124. padding: 24rpx 12rpx;
  1125. transition: all 0.3s ease;
  1126. border-radius: 16rpx;
  1127. background: linear-gradient(180deg, #fff 0%, #fdfdff 100%);
  1128. box-shadow: 0 2rpx 8rpx rgba(220, 220, 240, 0.15);
  1129. /* 核心:保证4列均分,每列最小宽度限制 */
  1130. flex: 1;
  1131. min-width: calc(25% - 22.5rpx); /* 25% - 30rpx/2(gap的一半),适配4列 */
  1132. max-width: calc(25% - 22.5rpx);
  1133. box-sizing: border-box; /* 避免padding撑大宽度 */
  1134. &:hover,
  1135. &:active {
  1136. transform: translateY(-4rpx) scale(0.98);
  1137. background: linear-gradient(180deg, #fff 0%, #f8f8ff 100%);
  1138. box-shadow: 0 6rpx 18rpx rgba(200, 200, 230, 0.25);
  1139. }
  1140. }
  1141. /* 为不同功能定制图标容器底色(贴合功能主题) */
  1142. .grid-item:nth-child(1) .grid-icon-wrapper {
  1143. background: linear-gradient(135deg, #ff85a2 0%, #ff5d8f 100%);
  1144. }
  1145. .grid-item:nth-child(2) .grid-icon-wrapper {
  1146. background: linear-gradient(135deg, #85cfff 0%, #5daaff 100%);
  1147. }
  1148. .grid-item:nth-child(3) .grid-icon-wrapper {
  1149. background: linear-gradient(135deg, #ffc885 0%, #ffaa5d 100%);
  1150. }
  1151. .grid-item:nth-child(4) .grid-icon-wrapper {
  1152. background: linear-gradient(135deg, #ff85d2 0%, #ff5daa 100%);
  1153. }
  1154. .grid-icon-wrapper {
  1155. width: 150rpx;
  1156. height: 150rpx;
  1157. display: flex;
  1158. align-items: center;
  1159. justify-content: center;
  1160. border-radius: 24rpx;
  1161. position: relative;
  1162. overflow: hidden;
  1163. box-shadow: inset 0 3rpx 10rpx rgba(255, 255, 255, 0.4),
  1164. 0 8rpx 24rpx rgba(0, 0, 0, 0.12);
  1165. transition: all 0.3s ease;
  1166. }
  1167. .grid-icon-wrapper::before {
  1168. content: '';
  1169. position: absolute;
  1170. top: -50%;
  1171. left: -50%;
  1172. width: 200%;
  1173. height: 200%;
  1174. background: linear-gradient(135deg,
  1175. rgba(255, 255, 255, 0.7) 0%,
  1176. rgba(255, 255, 255, 0.3) 40%,
  1177. transparent 80%);
  1178. transform: rotate(45deg);
  1179. pointer-events: none;
  1180. z-index: 1;
  1181. }
  1182. .grid-icon {
  1183. font-size: 80rpx;
  1184. color: #fff;
  1185. position: relative;
  1186. z-index: 2;
  1187. filter: drop-shadow(0 4rpx 8rpx rgba(0, 0, 0, 0.15));
  1188. }
  1189. /* 功能图标装饰 */
  1190. .grid-item:nth-child(1) .grid-icon::after {
  1191. content: '⭐';
  1192. position: absolute;
  1193. top: 10rpx;
  1194. right: 10rpx;
  1195. font-size: 30rpx;
  1196. transform: rotate(15deg);
  1197. }
  1198. .grid-item:nth-child(4) .grid-icon::after {
  1199. content: '🎀';
  1200. position: absolute;
  1201. bottom: 10rpx;
  1202. right: 10rpx;
  1203. font-size: 30rpx;
  1204. }
  1205. .grid-text {
  1206. font-size: 26rpx;
  1207. font-weight: 600;
  1208. color: #2d2d46;
  1209. text-align: center;
  1210. line-height: 1.3;
  1211. text-shadow: 0 1rpx 3rpx rgba(0, 0, 0, 0.05);
  1212. }
  1213. /* 响应式适配:小屏自动改为2列 */
  1214. @media (max-width: 600rpx) {
  1215. .grid-item {
  1216. min-width: calc(50% - 15rpx);
  1217. max-width: calc(50% - 15rpx);
  1218. }
  1219. }
  1220. /* 区块样式 */
  1221. .section {
  1222. margin: 40rpx 0;
  1223. .section-header {
  1224. display: flex;
  1225. justify-content: space-between;
  1226. align-items: center;
  1227. padding: 0 35rpx;
  1228. margin-bottom: 25rpx;
  1229. .section-title {
  1230. font-size: 36rpx;
  1231. font-weight: 800;
  1232. color: #333333;
  1233. border-left: 6rpx solid #E91E63;
  1234. padding-left: 16rpx;
  1235. }
  1236. .section-more {
  1237. font-size: 26rpx;
  1238. color: #E91E63;
  1239. font-weight: 600;
  1240. transition: all 0.2s ease;
  1241. &:active {
  1242. opacity: 0.6;
  1243. }
  1244. }
  1245. }
  1246. }
  1247. /* 平台活动展示区 */
  1248. .activity-recommend-section {
  1249. .activity-scroll-container {
  1250. margin: 0 35rpx;
  1251. overflow: hidden;
  1252. position: relative;
  1253. .activity-scroll-wrapper {
  1254. width: 100%;
  1255. overflow: hidden;
  1256. .activity-scroll-content {
  1257. display: flex;
  1258. animation: activityScroll 30s linear infinite;
  1259. gap: 20rpx;
  1260. width: fit-content;
  1261. &:hover {
  1262. animation-play-state: paused;
  1263. }
  1264. .activity-card-scroll {
  1265. flex-shrink: 0;
  1266. width: 500rpx;
  1267. background: #FFFFFF;
  1268. border-radius: 16rpx;
  1269. overflow: hidden;
  1270. border: 2rpx solid #E0E0E0;
  1271. transition: all 0.3s ease;
  1272. &:active {
  1273. transform: scale(0.98);
  1274. opacity: 0.9;
  1275. }
  1276. .activity-image-wrapper {
  1277. position: relative;
  1278. width: 100%;
  1279. height: 280rpx;
  1280. overflow: hidden;
  1281. .activity-image {
  1282. width: 100%;
  1283. height: 100%;
  1284. }
  1285. .activity-status {
  1286. position: absolute;
  1287. top: 15rpx;
  1288. right: 15rpx;
  1289. padding: 6rpx 12rpx;
  1290. background: #4CAF50;
  1291. color: #FFFFFF;
  1292. font-size: 22rpx;
  1293. font-weight: 600;
  1294. border-radius: 8rpx;
  1295. }
  1296. }
  1297. .activity-info-static {
  1298. padding: 20rpx;
  1299. .activity-name-static {
  1300. font-size: 28rpx;
  1301. font-weight: 700;
  1302. color: #333333;
  1303. margin-bottom: 8rpx;
  1304. line-height: 1.3;
  1305. }
  1306. .activity-time-static {
  1307. font-size: 24rpx;
  1308. color: #666666;
  1309. line-height: 1.4;
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. @keyframes activityScroll {
  1318. 0% {
  1319. transform: translateX(0);
  1320. }
  1321. 100% {
  1322. transform: translateX(-50%);
  1323. }
  1324. }
  1325. /* 今日缘分推荐 */
  1326. .fate-recommend-section {
  1327. .fate-cards {
  1328. display: flex;
  1329. gap: 20rpx;
  1330. padding: 0 35rpx;
  1331. overflow-x: auto;
  1332. scrollbar-width: none;
  1333. &::-webkit-scrollbar {
  1334. display: none;
  1335. }
  1336. .fate-card {
  1337. min-width: 320rpx;
  1338. background: #FFFFFF;
  1339. border-radius: 16rpx;
  1340. padding: 25rpx;
  1341. border: 2rpx solid #E0E0E0;
  1342. display: flex;
  1343. flex-direction: column;
  1344. align-items: center;
  1345. gap: 15rpx;
  1346. position: relative;
  1347. transition: all 0.2s ease;
  1348. &:active {
  1349. background: #F5F5F5;
  1350. }
  1351. .user-avatar-wrapper {
  1352. position: relative;
  1353. .user-avatar {
  1354. width: 100rpx;
  1355. height: 100rpx;
  1356. border-radius: 50%;
  1357. border: 3rpx solid #E0E0E0;
  1358. }
  1359. .online-status {
  1360. position: absolute;
  1361. bottom: 5rpx;
  1362. right: 5rpx;
  1363. width: 20rpx;
  1364. height: 20rpx;
  1365. background: #4CAF50;
  1366. border-radius: 50%;
  1367. border: 3rpx solid white;
  1368. }
  1369. }
  1370. .user-basic-info {
  1371. text-align: center;
  1372. .user-nickname {
  1373. font-size: 28rpx;
  1374. font-weight: 700;
  1375. color: #333333;
  1376. display: block;
  1377. margin-bottom: 5rpx;
  1378. }
  1379. .user-age-location {
  1380. font-size: 24rpx;
  1381. color: #666666;
  1382. }
  1383. }
  1384. .match-score {
  1385. display: flex;
  1386. align-items: center;
  1387. gap: 8rpx;
  1388. padding: 8rpx 16rpx;
  1389. background: #FFE5F1;
  1390. border-radius: 8rpx;
  1391. .match-text {
  1392. font-size: 22rpx;
  1393. color: #666666;
  1394. }
  1395. .match-percentage {
  1396. font-size: 26rpx;
  1397. font-weight: 700;
  1398. color: #E91E63;
  1399. }
  1400. }
  1401. .user-tags {
  1402. display: flex;
  1403. gap: 8rpx;
  1404. flex-wrap: wrap;
  1405. justify-content: center;
  1406. .user-tag {
  1407. font-size: 20rpx;
  1408. color: #666666;
  1409. background: #F5F5F5;
  1410. padding: 6rpx 12rpx;
  1411. border-radius: 8rpx;
  1412. border: 1rpx solid #E0E0E0;
  1413. }
  1414. }
  1415. }
  1416. }
  1417. }
  1418. /* 个人魅力指数 */
  1419. .charm-index-section {
  1420. margin: 25rpx 35rpx;
  1421. .charm-card {
  1422. background: #FFFFFF;
  1423. border-radius: 16rpx;
  1424. padding: 35rpx;
  1425. border: 2rpx solid #E0E0E0;
  1426. .charm-header {
  1427. display: flex;
  1428. justify-content: space-between;
  1429. align-items: center;
  1430. margin-bottom: 25rpx;
  1431. .charm-title {
  1432. font-size: 32rpx;
  1433. font-weight: 800;
  1434. color: #333333;
  1435. }
  1436. .charm-score {
  1437. font-size: 48rpx;
  1438. font-weight: 800;
  1439. color: #E91E63;
  1440. }
  1441. }
  1442. .charm-progress {
  1443. margin-bottom: 30rpx;
  1444. .progress-bar {
  1445. width: 100%;
  1446. height: 12rpx;
  1447. background: #FFE5F1;
  1448. border-radius: 6rpx;
  1449. overflow: hidden;
  1450. margin-bottom: 10rpx;
  1451. .progress-fill {
  1452. height: 100%;
  1453. background: #E91E63;
  1454. border-radius: 6rpx;
  1455. transition: width 1s ease;
  1456. }
  1457. }
  1458. .progress-text {
  1459. font-size: 24rpx;
  1460. color: #666666;
  1461. text-align: center;
  1462. display: block;
  1463. }
  1464. }
  1465. .charm-items {
  1466. display: flex;
  1467. flex-direction: column;
  1468. gap: 20rpx;
  1469. margin-bottom: 25rpx;
  1470. .charm-item {
  1471. display: flex;
  1472. justify-content: space-between;
  1473. align-items: center;
  1474. .charm-item-label {
  1475. font-size: 26rpx;
  1476. color: #666666;
  1477. font-weight: 500;
  1478. }
  1479. .charm-item-progress {
  1480. display: flex;
  1481. align-items: center;
  1482. gap: 12rpx;
  1483. flex: 1;
  1484. margin-left: 20rpx;
  1485. .item-progress-bar {
  1486. flex: 1;
  1487. height: 8rpx;
  1488. background: #FFE5F1;
  1489. border-radius: 4rpx;
  1490. overflow: hidden;
  1491. .item-progress-fill {
  1492. height: 100%;
  1493. background: #E91E63;
  1494. border-radius: 4rpx;
  1495. transition: width 1s ease;
  1496. }
  1497. }
  1498. .charm-item-score {
  1499. font-size: 24rpx;
  1500. color: #E91E63;
  1501. font-weight: 600;
  1502. min-width: 60rpx;
  1503. text-align: right;
  1504. }
  1505. }
  1506. }
  1507. }
  1508. .charm-tip {
  1509. padding: 20rpx;
  1510. background: #FFF8E1;
  1511. border-radius: 8rpx;
  1512. border: 2rpx solid #FFD54F;
  1513. .tip-text {
  1514. font-size: 24rpx;
  1515. color: #666666;
  1516. line-height: 1.5;
  1517. }
  1518. }
  1519. }
  1520. }
  1521. /* 底部占位 */
  1522. .bottom-placeholder {
  1523. height: 30rpx;
  1524. }
  1525. /* 底部导航栏 */
  1526. .tabbar {
  1527. position: fixed;
  1528. bottom: 0;
  1529. left: 0;
  1530. right: 0;
  1531. display: flex;
  1532. background-color: #FFFFFF;
  1533. border-top: 1rpx solid #F0F0F0;
  1534. padding-bottom: constant(safe-area-inset-bottom);
  1535. padding-bottom: env(safe-area-inset-bottom);
  1536. z-index: 999;
  1537. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  1538. .tabbar-item {
  1539. flex: 1;
  1540. display: flex;
  1541. flex-direction: column;
  1542. align-items: center;
  1543. justify-content: center;
  1544. padding: 15rpx 0;
  1545. position: relative;
  1546. .tabbar-icon {
  1547. font-size: 44rpx;
  1548. margin-bottom: 5rpx;
  1549. }
  1550. .tabbar-text {
  1551. font-size: 22rpx;
  1552. color: #666666;
  1553. }
  1554. &.active {
  1555. .tabbar-text {
  1556. color: #E91E63;
  1557. font-weight: bold;
  1558. }
  1559. }
  1560. }
  1561. }
  1562. /* 成功案例 */
  1563. .success-case-section {
  1564. .success-case-grid {
  1565. display: grid;
  1566. grid-template-columns: repeat(2, 1fr);
  1567. gap: 20rpx;
  1568. margin: 0 35rpx;
  1569. .case-card {
  1570. background: #FFFFFF;
  1571. border-radius: 16rpx;
  1572. overflow: hidden;
  1573. border: 2rpx solid #E0E0E0;
  1574. transition: all 0.3s ease;
  1575. &:active {
  1576. transform: scale(0.98);
  1577. opacity: 0.9;
  1578. }
  1579. .case-image-wrapper {
  1580. width: 100%;
  1581. height: 320rpx;
  1582. position: relative;
  1583. overflow: hidden;
  1584. .case-image {
  1585. width: 100%;
  1586. height: 100%;
  1587. }
  1588. }
  1589. .case-content {
  1590. padding: 20rpx;
  1591. .couple-names {
  1592. font-size: 28rpx;
  1593. font-weight: 700;
  1594. color: #333333;
  1595. margin-bottom: 10rpx;
  1596. line-height: 1.3;
  1597. }
  1598. .case-quote {
  1599. font-size: 24rpx;
  1600. color: #666666;
  1601. line-height: 1.5;
  1602. margin-bottom: 12rpx;
  1603. display: -webkit-box;
  1604. -webkit-box-orient: vertical;
  1605. -webkit-line-clamp: 2;
  1606. overflow: hidden;
  1607. }
  1608. .case-meta {
  1609. .marriage-date {
  1610. font-size: 22rpx;
  1611. color: #999999;
  1612. line-height: 1.4;
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. @keyframes marquee {
  1620. 0% {
  1621. transform: translateX(0);
  1622. }
  1623. 100% {
  1624. transform: translateX(-50%);
  1625. }
  1626. }
  1627. .tabbar-badge {
  1628. position: absolute;
  1629. top: 8rpx;
  1630. right: 50%;
  1631. margin-right: -40rpx;
  1632. min-width: 32rpx;
  1633. height: 32rpx;
  1634. line-height: 32rpx;
  1635. padding: 0 6rpx;
  1636. background-color: #FA5151;
  1637. border-radius: 16rpx;
  1638. font-size: 20rpx;
  1639. color: #FFFFFF;
  1640. text-align: center;
  1641. }
  1642. </style>