FamilyTianpanCard.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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-detail-btn" @click="goDetail">
  61. <text class="tp-detail-text">查看家庭天盘详情 &#x2192;</text>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. /**
  67. * FamilyTianpanCard — 家庭天盘概览卡片(嵌入心维度页面)
  68. *
  69. * Props:
  70. * fortune — { level: 0-4, text, description }
  71. * mood — { emoji, text, score: 0-100 }
  72. * dominantElement — 'wood'|'fire'|'earth'|'metal'|'water'
  73. * weeklyTip — string 本周提示
  74. * visible — boolean 是否显示
  75. *
  76. * 吉位 Canvas 绘制五元素罗盘,高亮吉位方向。
  77. */
  78. export default {
  79. name: 'FamilyTianpanCard',
  80. props: {
  81. fortune: {
  82. type: Object,
  83. default: function() { return null }
  84. },
  85. mood: {
  86. type: Object,
  87. default: function() { return null }
  88. },
  89. dominantElement: {
  90. type: String,
  91. default: ''
  92. },
  93. weeklyTip: {
  94. type: String,
  95. default: ''
  96. },
  97. visible: {
  98. type: Boolean,
  99. default: true
  100. }
  101. },
  102. data: function() {
  103. return {
  104. canvasCtx: null,
  105. canvasReady: false,
  106. // 五行 → 方位映射
  107. elementDirMap: {
  108. wood: '东',
  109. fire: '南',
  110. earth: '中',
  111. metal: '西',
  112. water: '北'
  113. },
  114. // 方位 → 颜色映射
  115. dirColorMap: {
  116. '东': '#10B981',
  117. '南': '#FF6B9D',
  118. '中': '#FF8C42',
  119. '西': '#6366F1',
  120. '北': '#3B82F6'
  121. },
  122. // 方位 → 角度(从北顺时针,Canvas 默认从右/东开始)
  123. dirAngleMap: {
  124. '东': Math.PI / 2,
  125. '南': Math.PI,
  126. '中': 0,
  127. '西': -Math.PI / 2,
  128. '北': 0
  129. }
  130. }
  131. },
  132. computed: {
  133. fortuneLevel: function() {
  134. if (!this.fortune) return 2
  135. return this.fortune.level !== undefined ? this.fortune.level : 2
  136. },
  137. fortuneText: function() {
  138. if (!this.fortune || !this.fortune.text) return '平'
  139. return this.fortune.text
  140. },
  141. fortuneDesc: function() {
  142. if (!this.fortune || !this.fortune.description) return '今日宜静心养性'
  143. return this.fortune.description
  144. },
  145. moodEmoji: function() {
  146. if (this.mood && this.mood.emoji) return this.mood.emoji
  147. return '\u{1F60A}' // 默认笑脸
  148. },
  149. moodText: function() {
  150. if (this.mood && this.mood.text) return this.mood.text
  151. return '平静'
  152. },
  153. moodPercent: function() {
  154. if (this.mood && this.mood.score !== undefined) return this.mood.score
  155. return 60
  156. },
  157. luckyDirection: function() {
  158. if (this.dominantElement && this.elementDirMap[this.dominantElement]) {
  159. return this.elementDirMap[this.dominantElement] + '方'
  160. }
  161. return '东方'
  162. },
  163. luckyElementColor: function() {
  164. var dir = this.luckyDirection
  165. return this.dirColorMap[dir] || '#FF6B9D'
  166. }
  167. },
  168. watch: {
  169. visible: function(val) {
  170. if (val) {
  171. var self = this
  172. setTimeout(function() {
  173. self.initCanvas()
  174. }, 300)
  175. }
  176. },
  177. dominantElement: function() {
  178. if (this.canvasReady) {
  179. this.drawCompass()
  180. }
  181. }
  182. },
  183. mounted: function() {
  184. if (this.visible) {
  185. var self = this
  186. setTimeout(function() {
  187. self.initCanvas()
  188. }, 500)
  189. }
  190. },
  191. methods: {
  192. goDetail: function() {
  193. uni.navigateTo({
  194. url: '/pages/mind-detail/family-dashboard'
  195. })
  196. },
  197. initCanvas: function() {
  198. var self = this
  199. var query = uni.createSelectorQuery().in(self)
  200. query.select('#tianpanCompass')
  201. .fields({ node: true, size: true })
  202. .exec(function(res) {
  203. if (!res || !res[0] || !res[0].node) return
  204. var ctx = res[0].node.getContext('2d')
  205. var dpr = uni.getSystemInfoSync().pixelRatio || 2
  206. var w = res[0].width
  207. var h = res[0].height
  208. res[0].node.width = w * dpr
  209. res[0].node.height = h * dpr
  210. ctx.scale(dpr, dpr)
  211. self.canvasCtx = ctx
  212. self.canvasReady = true
  213. self._compassW = w
  214. self._compassH = h
  215. self.drawCompass()
  216. })
  217. },
  218. drawCompass: function() {
  219. var ctx = this.canvasCtx
  220. if (!ctx) return
  221. var w = this._compassW || 100
  222. var h = this._compassH || 100
  223. var cx = w / 2
  224. var cy = h / 2
  225. var outerR = Math.min(cx, cy) - 4
  226. // 清空
  227. ctx.clearRect(0, 0, w, h)
  228. // 五个方位: 北(上), 东(右), 南(下), 西(左), 中(中心)
  229. var directions = [
  230. { label: '北', element: 'water', angle: -Math.PI / 2 },
  231. { label: '东', element: 'wood', angle: 0 },
  232. { label: '南', element: 'fire', angle: Math.PI / 2 },
  233. { label: '西', element: 'metal', angle: Math.PI },
  234. { label: '中', element: 'earth', angle: null }
  235. ]
  236. var elementColors = {
  237. wood: '#10B981',
  238. fire: '#FF6B9D',
  239. earth: '#FF8C42',
  240. metal: '#6366F1',
  241. water: '#3B82F6'
  242. }
  243. var luckyDir = this.luckyDirection.replace('方', '')
  244. var luckyColor = this.luckyElementColor
  245. // 外圈背景
  246. ctx.beginPath()
  247. ctx.arc(cx, cy, outerR, 0, Math.PI * 2)
  248. ctx.fillStyle = '#FFF5F7'
  249. ctx.fill()
  250. ctx.strokeStyle = luckyColor + '40'
  251. ctx.lineWidth = 1.5
  252. ctx.stroke()
  253. // 绘制四个方位的扇区
  254. for (var i = 0; i < 4; i++) {
  255. var d = directions[i]
  256. var color = elementColors[d.element]
  257. // 扇区线
  258. ctx.beginPath()
  259. ctx.moveTo(cx, cy)
  260. var ex = cx + outerR * Math.cos(d.angle)
  261. var ey = cy + outerR * Math.sin(d.angle)
  262. ctx.lineTo(ex, ey)
  263. ctx.strokeStyle = color + '30'
  264. ctx.lineWidth = 1
  265. ctx.stroke()
  266. // 方位标签
  267. var labelR = outerR * 0.7
  268. var lx = cx + labelR * Math.cos(d.angle)
  269. var ly = cy + labelR * Math.sin(d.angle)
  270. var isLucky = d.label === luckyDir
  271. if (isLucky) {
  272. // 吉位高亮圆
  273. ctx.beginPath()
  274. ctx.arc(lx, ly, 12, 0, Math.PI * 2)
  275. ctx.fillStyle = luckyColor + '20'
  276. ctx.fill()
  277. ctx.strokeStyle = luckyColor
  278. ctx.lineWidth = 1.5
  279. ctx.stroke()
  280. }
  281. ctx.fillStyle = isLucky ? luckyColor : '#9CA3AF'
  282. ctx.font = (isLucky ? 'bold ' : '') + '10px sans-serif'
  283. ctx.textAlign = 'center'
  284. ctx.textBaseline = 'middle'
  285. ctx.fillText(d.label, lx, ly)
  286. }
  287. // 中心点
  288. ctx.beginPath()
  289. ctx.arc(cx, cy, 5, 0, Math.PI * 2)
  290. ctx.fillStyle = luckyColor
  291. ctx.fill()
  292. ctx.strokeStyle = '#FFFFFF'
  293. ctx.lineWidth = 1.5
  294. ctx.stroke()
  295. }
  296. }
  297. }
  298. </script>
  299. <style scoped>
  300. .tianpan-card {
  301. margin: 20rpx 30rpx;
  302. background: #FFFFFF;
  303. border-radius: 24rpx;
  304. padding: 28rpx 24rpx;
  305. /* Claymorphism 双阴影 */
  306. box-shadow: 0 4rpx 16rpx rgba(255, 107, 157, 0.12),
  307. 0 2rpx 4rpx rgba(0, 0, 0, 0.04);
  308. border: 1rpx solid rgba(255, 107, 157, 0.08);
  309. overflow: hidden;
  310. }
  311. /* ===== 头部 ===== */
  312. .tp-header {
  313. display: flex;
  314. flex-direction: row;
  315. align-items: center;
  316. justify-content: space-between;
  317. margin-bottom: 24rpx;
  318. padding-bottom: 20rpx;
  319. border-bottom: 1rpx solid rgba(255, 107, 157, 0.10);
  320. }
  321. .tp-header-left {
  322. display: flex;
  323. flex-direction: row;
  324. align-items: center;
  325. }
  326. .tp-icon-badge {
  327. width: 64rpx;
  328. height: 64rpx;
  329. border-radius: 20rpx;
  330. background: linear-gradient(135deg, #FF6B9D, #FF8FB1);
  331. display: flex;
  332. align-items: center;
  333. justify-content: center;
  334. margin-right: 16rpx;
  335. box-shadow: 0 4rpx 12rpx rgba(255, 107, 157, 0.30);
  336. }
  337. .tp-icon-text {
  338. font-size: 32rpx;
  339. color: #FFFFFF;
  340. }
  341. .tp-header-info {
  342. display: flex;
  343. flex-direction: column;
  344. }
  345. .tp-title {
  346. font-size: 30rpx;
  347. font-weight: 700;
  348. color: #1E293B;
  349. }
  350. .tp-subtitle {
  351. font-size: 22rpx;
  352. color: #94A3B8;
  353. margin-top: 2rpx;
  354. }
  355. .tp-header-action {
  356. width: 56rpx;
  357. height: 56rpx;
  358. border-radius: 28rpx;
  359. background: #FFF0F3;
  360. display: flex;
  361. align-items: center;
  362. justify-content: center;
  363. }
  364. .tp-action-text {
  365. font-size: 28rpx;
  366. color: #FF6B9D;
  367. font-weight: 600;
  368. }
  369. .tp-header-action:active {
  370. opacity: 0.7;
  371. }
  372. /* ===== 三栏 body ===== */
  373. .tp-body {
  374. display: flex;
  375. flex-direction: row;
  376. justify-content: space-between;
  377. }
  378. .tp-col {
  379. flex: 1;
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. padding: 16rpx 8rpx;
  384. border-radius: 20rpx;
  385. background: #FAFBFC;
  386. }
  387. .tp-col-fortune {
  388. margin-right: 12rpx;
  389. }
  390. .tp-col-mood {
  391. margin-left: 6rpx;
  392. margin-right: 6rpx;
  393. }
  394. .tp-col-direction {
  395. margin-left: 12rpx;
  396. }
  397. /* 列通用 */
  398. .tp-col-icon {
  399. font-size: 36rpx;
  400. margin-bottom: 8rpx;
  401. }
  402. .tp-col-label {
  403. font-size: 22rpx;
  404. color: #94A3B8;
  405. margin-bottom: 12rpx;
  406. font-weight: 500;
  407. }
  408. /* 运势 */
  409. .tp-fortune-badge {
  410. padding: 6rpx 20rpx;
  411. border-radius: 20rpx;
  412. margin-bottom: 8rpx;
  413. }
  414. .fortune-level-0 {
  415. background: #FFEBEE;
  416. }
  417. .fortune-level-0 .tp-fortune-text {
  418. color: #D32F2F;
  419. }
  420. .fortune-level-1 {
  421. background: #FFF3E0;
  422. }
  423. .fortune-level-1 .tp-fortune-text {
  424. color: #E65100;
  425. }
  426. .fortune-level-2 {
  427. background: #FFFDE7;
  428. }
  429. .fortune-level-2 .tp-fortune-text {
  430. color: #F9A825;
  431. }
  432. .fortune-level-3 {
  433. background: #F3E5F5;
  434. }
  435. .fortune-level-3 .tp-fortune-text {
  436. color: #7B1FA2;
  437. }
  438. .fortune-level-4 {
  439. background: #FFCDD2;
  440. }
  441. .fortune-level-4 .tp-fortune-text {
  442. color: #B71C1C;
  443. }
  444. .tp-fortune-text {
  445. font-size: 26rpx;
  446. font-weight: 700;
  447. }
  448. .tp-fortune-desc {
  449. font-size: 20rpx;
  450. color: #94A3B8;
  451. text-align: center;
  452. line-height: 1.4;
  453. }
  454. /* 心情 */
  455. .tp-mood-value {
  456. font-size: 26rpx;
  457. font-weight: 600;
  458. color: #1E293B;
  459. margin-bottom: 10rpx;
  460. }
  461. .tp-mood-bar-track {
  462. width: 100%;
  463. height: 10rpx;
  464. background: #E2E8F0;
  465. border-radius: 5rpx;
  466. overflow: hidden;
  467. }
  468. .tp-mood-bar-fill {
  469. height: 100%;
  470. background: linear-gradient(90deg, #FF6B9D, #FF8FB1);
  471. border-radius: 5rpx;
  472. transition: width 0.5s;
  473. }
  474. /* 吉位罗盘 */
  475. .tp-compass-wrap {
  476. width: 120rpx;
  477. height: 120rpx;
  478. margin-bottom: 8rpx;
  479. }
  480. .tp-compass-canvas {
  481. width: 120rpx;
  482. height: 120rpx;
  483. }
  484. .tp-direction-value {
  485. font-size: 24rpx;
  486. font-weight: 700;
  487. color: #FF6B9D;
  488. }
  489. /* ===== 底部提示 ===== */
  490. .tp-footer {
  491. display: flex;
  492. flex-direction: row;
  493. align-items: flex-start;
  494. margin-top: 20rpx;
  495. padding: 16rpx;
  496. background: #FFF5F0;
  497. border-radius: 14rpx;
  498. }
  499. .tp-footer-icon {
  500. font-size: 24rpx;
  501. margin-right: 8rpx;
  502. flex-shrink: 0;
  503. }
  504. .tp-footer-text {
  505. font-size: 22rpx;
  506. color: #8B6914;
  507. line-height: 1.5;
  508. flex: 1;
  509. }
  510. /* ===== 查看详情按钮 ===== */
  511. .tp-detail-btn {
  512. margin-top: 16rpx;
  513. text-align: center;
  514. padding: 14rpx;
  515. background: linear-gradient(135deg, #FFF0F3, #FFE0E8);
  516. border-radius: 14rpx;
  517. }
  518. .tp-detail-btn:active {
  519. opacity: 0.7;
  520. }
  521. .tp-detail-text {
  522. font-size: 24rpx;
  523. color: #FF6B9D;
  524. font-weight: 600;
  525. }
  526. </style>