FamilyTianpanCard.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <template>
  2. <!-- 家庭天盘卡片 — 心维度专属 (#FF6B9D 火) -->
  3. <view class="tianpan-card" v-if="visible">
  4. <!-- 卡片头部 -->
  5. <view class="tp-header">
  6. <view class="tp-header-left">
  7. <view class="tp-icon-badge">
  8. <text class="tp-icon-text">&#x2637;</text>
  9. </view>
  10. <view class="tp-header-info">
  11. <text class="tp-title">家庭天盘</text>
  12. <text class="tp-subtitle">五行能量 · 每日更新</text>
  13. </view>
  14. </view>
  15. <view class="tp-header-action" @click="goDetail">
  16. <text class="tp-action-text">&#x2192;</text>
  17. </view>
  18. </view>
  19. <!-- 三栏展示 -->
  20. <view class="tp-body">
  21. <!-- 今日运势 -->
  22. <view class="tp-col tp-col-fortune">
  23. <text class="tp-col-icon">&#x2B50;</text>
  24. <text class="tp-col-label">今日运势</text>
  25. <view class="tp-fortune-badge" :class="'fortune-level-' + fortuneLevel">
  26. <text class="tp-fortune-text">{{ fortuneText }}</text>
  27. </view>
  28. <text class="tp-fortune-desc">{{ fortuneDesc }}</text>
  29. </view>
  30. <!-- 今日心情 -->
  31. <view class="tp-col tp-col-mood">
  32. <text class="tp-col-icon">{{ moodEmoji }}</text>
  33. <text class="tp-col-label">今日心情</text>
  34. <text class="tp-mood-value">{{ moodText }}</text>
  35. <view class="tp-mood-bar-track">
  36. <view class="tp-mood-bar-fill" :style="{ width: moodPercent + '%' }"></view>
  37. </view>
  38. </view>
  39. <!-- 吉位 -->
  40. <view class="tp-col tp-col-direction">
  41. <text class="tp-col-icon">&#x1F9ED;</text>
  42. <text class="tp-col-label">今日吉位</text>
  43. <view class="tp-compass-wrap">
  44. <canvas
  45. canvas-id="tianpanCompass"
  46. id="tianpanCompass"
  47. type="2d"
  48. class="tp-compass-canvas"
  49. ></canvas>
  50. </view>
  51. <text class="tp-direction-value">{{ luckyDirection }}</text>
  52. </view>
  53. </view>
  54. <!-- 底部周报提示 -->
  55. <view class="tp-footer" v-if="weeklyTip">
  56. <text class="tp-footer-icon">&#x1F4A1;</text>
  57. <text class="tp-footer-text">{{ weeklyTip }}</text>
  58. </view>
  59. <!-- 今日宜忌提示 -->
  60. <view class="tp-advice-section">
  61. <view class="tp-advice-item">
  62. <text class="tp-advice-icon">♦</text>
  63. <text class="tp-advice-label">宜:</text>
  64. <text class="tp-advice-text">{{ getAdvice(true) }}</text>
  65. </view>
  66. <view class="tp-advice-item">
  67. <text class="tp-advice-icon">✖</text>
  68. <text class="tp-advice-label">忌:</text>
  69. <text class="tp-advice-text">{{ getAdvice(false) }}</text>
  70. </view>
  71. </view>
  72. <!-- 查看详情入口 -->
  73. <view class="tp-detail-btn" @click="goDetail">
  74. <text class="tp-detail-text">查看家庭天盘详情 &#x2192;</text>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. /**
  80. * FamilyTianpanCard — 家庭天盘概览卡片(嵌入心维度页面)
  81. *
  82. * Props:
  83. * fortune — { level: 0-4, text, description }
  84. * mood — { emoji, text, score: 0-100 }
  85. * dominantElement — 'wood'|'fire'|'earth'|'metal'|'water'
  86. * weeklyTip — string 本周提示
  87. * visible — boolean 是否显示
  88. *
  89. * 吉位 Canvas 绘制五元素罗盘,高亮吉位方向。
  90. */
  91. export default {
  92. name: 'FamilyTianpanCard',
  93. props: {
  94. fortune: {
  95. type: Object,
  96. default: function() { return null }
  97. },
  98. mood: {
  99. type: Object,
  100. default: function() { return null }
  101. },
  102. dominantElement: {
  103. type: String,
  104. default: ''
  105. },
  106. weeklyTip: {
  107. type: String,
  108. default: ''
  109. },
  110. visible: {
  111. type: Boolean,
  112. default: true
  113. }
  114. },
  115. data: function() {
  116. return {
  117. canvasCtx: null,
  118. canvasReady: false,
  119. // 五行 → 方位映射
  120. elementDirMap: {
  121. wood: '东',
  122. fire: '南',
  123. earth: '中',
  124. metal: '西',
  125. water: '北'
  126. },
  127. // 方位 → 颜色映射
  128. dirColorMap: {
  129. '东': '#10B981',
  130. '南': '#FF6B9D',
  131. '中': '#FF8C42',
  132. '西': '#6366F1',
  133. '北': '#3B82F6'
  134. },
  135. // 方位 → 角度(从北顺时针,Canvas 默认从右/东开始)
  136. dirAngleMap: {
  137. '东': Math.PI / 2,
  138. '南': Math.PI,
  139. '中': 0,
  140. '西': -Math.PI / 2,
  141. '北': 0
  142. }
  143. }
  144. },
  145. computed: {
  146. fortuneLevel: function() {
  147. if (!this.fortune) return 2
  148. return this.fortune.level !== undefined ? this.fortune.level : 2
  149. },
  150. fortuneText: function() {
  151. if (!this.fortune || !this.fortune.text) return '平'
  152. return this.fortune.text
  153. },
  154. fortuneDesc: function() {
  155. if (!this.fortune || !this.fortune.description) return '今日宜静心养性'
  156. return this.fortune.description
  157. },
  158. moodEmoji: function() {
  159. if (this.mood && this.mood.emoji) return this.mood.emoji
  160. return '\u{1F60A}' // 默认笑脸
  161. },
  162. moodText: function() {
  163. if (this.mood && this.mood.text) return this.mood.text
  164. return '平静'
  165. },
  166. moodPercent: function() {
  167. if (this.mood && this.mood.score !== undefined) return this.mood.score
  168. return 60
  169. },
  170. luckyDirection: function() {
  171. if (this.dominantElement && this.elementDirMap[this.dominantElement]) {
  172. return this.elementDirMap[this.dominantElement] + '方'
  173. }
  174. return '东方'
  175. },
  176. luckyElementColor: function() {
  177. var dir = this.luckyDirection
  178. return this.dirColorMap[dir] || '#FF6B9D'
  179. }
  180. },
  181. watch: {
  182. visible: function(val) {
  183. if (val) {
  184. var self = this
  185. setTimeout(function() {
  186. self.initCanvas()
  187. }, 300)
  188. }
  189. },
  190. dominantElement: function() {
  191. if (this.canvasReady) {
  192. this.drawCompass()
  193. }
  194. }
  195. },
  196. mounted: function() {
  197. if (this.visible) {
  198. var self = this
  199. setTimeout(function() {
  200. self.initCanvas()
  201. }, 500)
  202. }
  203. },
  204. methods: {
  205. goDetail: function() {
  206. uni.navigateTo({
  207. url: '/pages/mind-detail/family-dashboard'
  208. })
  209. },
  210. /**
  211. * 获取当日宜忌建议
  212. * @param {boolean} isGood - 是否获取宜(true)或忌(false)
  213. */
  214. getAdvice: function(isGood) {
  215. const advice = {
  216. 木: {
  217. good: '植树种花、亲近自然,交友聚会增进感情,制定计划规划未来',
  218. bad: '冲动消费、盲目扩张,长期熬夜、透支健康,与人争执失和气'
  219. },
  220. 火: {
  221. good: '社交活动、表达感想,旅行出游、放松心情,运动健身、增强活力',
  222. bad: '过度劳累、身体透支,情绪激动、失去理智,暴饮暴食、饮酒无度'
  223. },
  224. 土: {
  225. good: '规律作息、健康管理,家务整理、创造舒适,学习充电、稳固提升',
  226. bad: '情绪压抑、独自忍耐,忽视身体、健康警讯,盲目保守、错失机会'
  227. },
  228. 金: {
  229. good: '整理环境、创造秩序,专注工作、提升效率,投资理财、稳健收益',
  230. bad: '过度拘谨、缺乏变通,忽略情感、人情冷漠,欲望过多、贪求不满'
  231. },
  232. 水: {
  233. good: '阅读思考、拓展思维,社交活动、增进人脉,创意思考、寻找机遇',
  234. bad: '犹豫不决、错过良机,过度幻想、缺乏行动,沉迷游戏、浪费时光'
  235. }
  236. }
  237. // 默认值(如果五行未知或未提供)
  238. if (!this.fortune || !this.fortune.dominantElement) {
  239. return isGood ? '保持心情愉悦,积极面对每一天' : '避免负面情绪,不过度劳累'
  240. }
  241. const element = this.fortune.dominantElement
  242. return advice[element][isGood ? 'good' : 'bad']
  243. },
  244. initCanvas: function() {
  245. var self = this
  246. var query = uni.createSelectorQuery().in(self)
  247. query.select('#tianpanCompass')
  248. .fields({ node: true, size: true })
  249. .exec(function(res) {
  250. if (!res || !res[0] || !res[0].node) return
  251. var ctx = res[0].node.getContext('2d')
  252. var dpr = uni.getSystemInfoSync().pixelRatio || 2
  253. var w = res[0].width
  254. var h = res[0].height
  255. res[0].node.width = w * dpr
  256. res[0].node.height = h * dpr
  257. ctx.scale(dpr, dpr)
  258. self.canvasCtx = ctx
  259. self.canvasReady = true
  260. self._compassW = w
  261. self._compassH = h
  262. self.drawCompass()
  263. })
  264. },
  265. drawCompass: function() {
  266. var ctx = this.canvasCtx
  267. if (!ctx) return
  268. var w = this._compassW || 100
  269. var h = this._compassH || 100
  270. var cx = w / 2
  271. var cy = h / 2
  272. var outerR = Math.min(cx, cy) - 4
  273. // 清空
  274. ctx.clearRect(0, 0, w, h)
  275. // 五个方位: 北(上), 东(右), 南(下), 西(左), 中(中心)
  276. var directions = [
  277. { label: '北', element: 'water', angle: -Math.PI / 2 },
  278. { label: '东', element: 'wood', angle: 0 },
  279. { label: '南', element: 'fire', angle: Math.PI / 2 },
  280. { label: '西', element: 'metal', angle: Math.PI },
  281. { label: '中', element: 'earth', angle: null }
  282. ]
  283. var elementColors = {
  284. wood: '#10B981',
  285. fire: '#FF6B9D',
  286. earth: '#FF8C42',
  287. metal: '#6366F1',
  288. water: '#3B82F6'
  289. }
  290. var luckyDir = this.luckyDirection.replace('方', '')
  291. var luckyColor = this.luckyElementColor
  292. // 外圈背景
  293. ctx.beginPath()
  294. ctx.arc(cx, cy, outerR, 0, Math.PI * 2)
  295. ctx.fillStyle = '#FFF5F7'
  296. ctx.fill()
  297. ctx.strokeStyle = luckyColor + '40'
  298. ctx.lineWidth = 1.5
  299. ctx.stroke()
  300. // 绘制四个方位的扇区
  301. for (var i = 0; i < 4; i++) {
  302. var d = directions[i]
  303. var color = elementColors[d.element]
  304. // 扇区线
  305. ctx.beginPath()
  306. ctx.moveTo(cx, cy)
  307. var ex = cx + outerR * Math.cos(d.angle)
  308. var ey = cy + outerR * Math.sin(d.angle)
  309. ctx.lineTo(ex, ey)
  310. ctx.strokeStyle = color + '30'
  311. ctx.lineWidth = 1
  312. ctx.stroke()
  313. // 方位标签
  314. var labelR = outerR * 0.7
  315. var lx = cx + labelR * Math.cos(d.angle)
  316. var ly = cy + labelR * Math.sin(d.angle)
  317. var isLucky = d.label === luckyDir
  318. if (isLucky) {
  319. // 吉位高亮圆
  320. ctx.beginPath()
  321. ctx.arc(lx, ly, 12, 0, Math.PI * 2)
  322. ctx.fillStyle = luckyColor + '20'
  323. ctx.fill()
  324. ctx.strokeStyle = luckyColor
  325. ctx.lineWidth = 1.5
  326. ctx.stroke()
  327. }
  328. ctx.fillStyle = isLucky ? luckyColor : '#9CA3AF'
  329. ctx.font = (isLucky ? 'bold ' : '') + '10px sans-serif'
  330. ctx.textAlign = 'center'
  331. ctx.textBaseline = 'middle'
  332. ctx.fillText(d.label, lx, ly)
  333. }
  334. // 中心点
  335. ctx.beginPath()
  336. ctx.arc(cx, cy, 5, 0, Math.PI * 2)
  337. ctx.fillStyle = luckyColor
  338. ctx.fill()
  339. ctx.strokeStyle = '#FFFFFF'
  340. ctx.lineWidth = 1.5
  341. ctx.stroke()
  342. }
  343. }
  344. }
  345. </script>
  346. <style scoped>
  347. .tianpan-card {
  348. margin: 20rpx 30rpx;
  349. background: #FFFFFF;
  350. border-radius: 24rpx;
  351. padding: 28rpx 24rpx;
  352. /* Claymorphism 双阴影 */
  353. box-shadow: 0 4rpx 16rpx rgba(255, 107, 157, 0.12),
  354. 0 2rpx 4rpx rgba(0, 0, 0, 0.04);
  355. border: 1rpx solid rgba(255, 107, 157, 0.08);
  356. overflow: hidden;
  357. }
  358. /* ===== 头部 ===== */
  359. .tp-header {
  360. display: flex;
  361. flex-direction: row;
  362. align-items: center;
  363. justify-content: space-between;
  364. margin-bottom: 24rpx;
  365. padding-bottom: 20rpx;
  366. border-bottom: 1rpx solid rgba(255, 107, 157, 0.10);
  367. }
  368. .tp-header-left {
  369. display: flex;
  370. flex-direction: row;
  371. align-items: center;
  372. }
  373. .tp-icon-badge {
  374. width: 64rpx;
  375. height: 64rpx;
  376. border-radius: 20rpx;
  377. background: linear-gradient(135deg, #FF6B9D, #FF8FB1);
  378. display: flex;
  379. align-items: center;
  380. justify-content: center;
  381. margin-right: 16rpx;
  382. box-shadow: 0 4rpx 12rpx rgba(255, 107, 157, 0.30);
  383. }
  384. .tp-icon-text {
  385. font-size: 32rpx;
  386. color: #FFFFFF;
  387. }
  388. .tp-header-info {
  389. display: flex;
  390. flex-direction: column;
  391. }
  392. .tp-title {
  393. font-size: 30rpx;
  394. font-weight: 700;
  395. color: #1E293B;
  396. }
  397. .tp-subtitle {
  398. font-size: 22rpx;
  399. color: #94A3B8;
  400. margin-top: 2rpx;
  401. }
  402. .tp-header-action {
  403. width: 56rpx;
  404. height: 56rpx;
  405. border-radius: 28rpx;
  406. background: #FFF0F3;
  407. display: flex;
  408. align-items: center;
  409. justify-content: center;
  410. }
  411. .tp-action-text {
  412. font-size: 28rpx;
  413. color: #FF6B9D;
  414. font-weight: 600;
  415. }
  416. .tp-header-action:active {
  417. opacity: 0.7;
  418. }
  419. /* ===== 三栏 body ===== */
  420. .tp-body {
  421. display: flex;
  422. flex-direction: row;
  423. justify-content: space-between;
  424. }
  425. .tp-col {
  426. flex: 1;
  427. display: flex;
  428. flex-direction: column;
  429. align-items: center;
  430. padding: 16rpx 8rpx;
  431. border-radius: 20rpx;
  432. background: #FAFBFC;
  433. }
  434. .tp-col-fortune {
  435. margin-right: 12rpx;
  436. }
  437. .tp-col-mood {
  438. margin-left: 6rpx;
  439. margin-right: 6rpx;
  440. }
  441. .tp-col-direction {
  442. margin-left: 12rpx;
  443. }
  444. /* 列通用 */
  445. .tp-col-icon {
  446. font-size: 36rpx;
  447. margin-bottom: 8rpx;
  448. }
  449. .tp-col-label {
  450. font-size: 22rpx;
  451. color: #94A3B8;
  452. margin-bottom: 12rpx;
  453. font-weight: 500;
  454. }
  455. /* 运势 */
  456. .tp-fortune-badge {
  457. padding: 6rpx 20rpx;
  458. border-radius: 20rpx;
  459. margin-bottom: 8rpx;
  460. }
  461. .fortune-level-0 {
  462. background: #FFEBEE;
  463. }
  464. .fortune-level-0 .tp-fortune-text {
  465. color: #D32F2F;
  466. }
  467. .fortune-level-1 {
  468. background: #FFF3E0;
  469. }
  470. .fortune-level-1 .tp-fortune-text {
  471. color: #E65100;
  472. }
  473. .fortune-level-2 {
  474. background: #FFFDE7;
  475. }
  476. .fortune-level-2 .tp-fortune-text {
  477. color: #F9A825;
  478. }
  479. .fortune-level-3 {
  480. background: #F3E5F5;
  481. }
  482. .fortune-level-3 .tp-fortune-text {
  483. color: #7B1FA2;
  484. }
  485. .fortune-level-4 {
  486. background: #FFCDD2;
  487. }
  488. .fortune-level-4 .tp-fortune-text {
  489. color: #B71C1C;
  490. }
  491. .tp-fortune-text {
  492. font-size: 26rpx;
  493. font-weight: 700;
  494. }
  495. .tp-fortune-desc {
  496. font-size: 20rpx;
  497. color: #94A3B8;
  498. text-align: center;
  499. line-height: 1.4;
  500. }
  501. /* 心情 */
  502. .tp-mood-value {
  503. font-size: 26rpx;
  504. font-weight: 600;
  505. color: #1E293B;
  506. margin-bottom: 10rpx;
  507. }
  508. .tp-mood-bar-track {
  509. width: 100%;
  510. height: 10rpx;
  511. background: #E2E8F0;
  512. border-radius: 5rpx;
  513. overflow: hidden;
  514. }
  515. .tp-mood-bar-fill {
  516. height: 100%;
  517. background: linear-gradient(90deg, #FF6B9D, #FF8FB1);
  518. border-radius: 5rpx;
  519. transition: width 0.5s;
  520. }
  521. /* 吉位罗盘 */
  522. .tp-compass-wrap {
  523. width: 120rpx;
  524. height: 120rpx;
  525. margin-bottom: 8rpx;
  526. }
  527. .tp-compass-canvas {
  528. width: 120rpx;
  529. height: 120rpx;
  530. }
  531. .tp-direction-value {
  532. font-size: 24rpx;
  533. font-weight: 700;
  534. color: #FF6B9D;
  535. }
  536. /* ===== 底部提示 ===== */
  537. .tp-footer {
  538. display: flex;
  539. flex-direction: row;
  540. align-items: flex-start;
  541. margin-top: 20rpx;
  542. padding: 16rpx;
  543. background: #FFF5F0;
  544. border-radius: 14rpx;
  545. }
  546. .tp-footer-icon {
  547. font-size: 24rpx;
  548. margin-right: 8rpx;
  549. flex-shrink: 0;
  550. }
  551. .tp-footer-text {
  552. font-size: 22rpx;
  553. color: #8B6914;
  554. line-height: 1.5;
  555. flex: 1;
  556. }
  557. /* ===== 今日宜忌 ===== */
  558. .tp-advice-section {
  559. margin: 20rpx 0;
  560. padding: 16rpx;
  561. background-color: rgba(255, 255, 255, 0.7);
  562. border-radius: 16rpx;
  563. }
  564. .tp-advice-item {
  565. display: flex;
  566. flex-direction: row;
  567. align-items: center;
  568. margin-bottom: 10rpx;
  569. }
  570. .tp-advice-item:last-child {
  571. margin-bottom: 0;
  572. }
  573. .tp-advice-icon {
  574. font-size: 24rpx;
  575. color: #FF6B9D;
  576. margin-right: 12rpx;
  577. }
  578. .tp-advice-label {
  579. font-size: 22rpx;
  580. font-weight: 600;
  581. color: #FF6B9D;
  582. margin-right: 12rpx;
  583. min-width: 60rpx;
  584. }
  585. .tp-advice-text {
  586. font-size: 22rpx;
  587. color: #374151;
  588. flex: 1;
  589. line-height: 1.4;
  590. }
  591. /* ===== 查看详情按钮 ===== */
  592. .tp-detail-btn {
  593. margin-top: 16rpx;
  594. text-align: center;
  595. padding: 14rpx;
  596. background: linear-gradient(135deg, #FFF0F3, #FFE0E8);
  597. border-radius: 14rpx;
  598. }
  599. .tp-detail-btn:active {
  600. opacity: 0.7;
  601. }
  602. .tp-detail-text {
  603. font-size: 24rpx;
  604. color: #FF6B9D;
  605. font-weight: 600;
  606. }
  607. </style>