wuxing-sandbox.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. <template>
  2. <view class="wuxing-sandbox">
  3. <!-- header slot -->
  4. <slot name="header">
  5. <view class="sandbox-header">
  6. <image class="sandbox-logo" src="/static/logo.png" mode="aspectFit"></image>
  7. <text class="sandbox-title">浠艾福能量沙盘</text>
  8. <!-- 右上角:live 模式显示个人/全家切换,preview 模式显示徽章文案 -->
  9. <view class="sandbox-switch" v-if="mode !== 'preview'" @click="onToggle(currentView === 'family' ? 'personal' : 'family')">
  10. <text class="sandbox-switch-icon">{{ currentView === 'family' ? '👨‍👩‍👧‍👦' : '👤' }}</text>
  11. <text class="sandbox-switch-label">{{ currentView === 'family' ? '全家' : (currentMember ? currentMember.name : '个人') }}</text>
  12. <text class="sandbox-switch-arrow">⇄</text>
  13. </view>
  14. <text class="sandbox-badge" v-else>{{ displayBadgeText }}</text>
  15. </view>
  16. </slot>
  17. <view class="sandbox-star" :style="{height: starHeight}">
  18. <view class="star-glow-bg"></view>
  19. <!-- Canvas 2D 五行星图 -->
  20. <canvas id="starCanvas" type="2d" style="width:100%;height:100%;position:absolute;top:0;left:0;z-index:1"></canvas>
  21. <!-- Canvas 粒子动画覆盖层 -->
  22. <canvas id="flowCanvas" type="2d" style="width:100%;height:100%;position:absolute;top:0;left:0;z-index:1;pointer-events:none"></canvas>
  23. <!-- Canvas 点击感应层 -->
  24. <view class="canvas-tap-area" @click="onCanvasTap"></view>
  25. <!-- 顶点:从 sortedDimensions 顺时针排 [心, 身, 智, 富, 行] -->
  26. <view class="star-point star-point--top star-point--row" @click="onPointClick(sortedDimensions[0].code)">
  27. <view class="point-dot" :class="'point-dot--' + dimElementColor(sortedDimensions[0].code)">
  28. <text class="point-icon">{{ sortedDimensions[0].icon }}</text>
  29. </view>
  30. <text class="point-label">{{ sortedDimensions[0].name }}</text>
  31. <text class="point-energy">{{ sortedDimensions[0].energy }}</text>
  32. </view>
  33. <view class="star-point star-point--right" @click="onPointClick(sortedDimensions[1].code)">
  34. <view class="point-dot" :class="'point-dot--' + dimElementColor(sortedDimensions[1].code)">
  35. <text class="point-icon">{{ sortedDimensions[1].icon }}</text>
  36. </view>
  37. <text class="point-label">{{ sortedDimensions[1].name }}</text>
  38. <text class="point-energy">{{ sortedDimensions[1].energy }}</text>
  39. </view>
  40. <view class="star-point star-point--lr star-point--row" @click="onPointClick(sortedDimensions[2].code)">
  41. <view class="point-dot" :class="'point-dot--' + dimElementColor(sortedDimensions[2].code)">
  42. <text class="point-icon">{{ sortedDimensions[2].icon }}</text>
  43. </view>
  44. <text class="point-label">{{ sortedDimensions[2].name }}</text>
  45. <text class="point-energy">{{ sortedDimensions[2].energy }}</text>
  46. </view>
  47. <view class="star-point star-point--ll star-point--rev" @click="onPointClick(sortedDimensions[3].code)">
  48. <view class="point-dot" :class="'point-dot--' + dimElementColor(sortedDimensions[3].code)">
  49. <text class="point-icon">{{ sortedDimensions[3].icon }}</text>
  50. </view>
  51. <text class="point-label">{{ sortedDimensions[3].name }}</text>
  52. <text class="point-energy">{{ sortedDimensions[3].energy }}</text>
  53. </view>
  54. <view class="star-point star-point--left" @click="onPointClick(sortedDimensions[4].code)">
  55. <view class="point-dot" :class="'point-dot--' + dimElementColor(sortedDimensions[4].code)">
  56. <text class="point-icon">{{ sortedDimensions[4].icon }}</text>
  57. </view>
  58. <text class="point-label">{{ sortedDimensions[4].name }}</text>
  59. <text class="point-energy">{{ sortedDimensions[4].energy }}</text>
  60. </view>
  61. <!-- 中心点击区域(太极由 Canvas 绘制) -->
  62. <view class="star-center" @click="onCenterClick"></view>
  63. </view>
  64. <!-- dimension-bar slot -->
  65. <slot name="dimension-bar" v-if="showDimensionBar && mode !== 'preview'">
  66. <view class="dimension-bar">
  67. <view class="dim-item dim-item--earth">🌏身 {{ activeScores[0] }}%</view>
  68. <view class="dim-item dim-item--fire">🔥心 {{ activeScores[1] }}%</view>
  69. <view class="dim-item dim-item--metal">⚡智 {{ activeScores[2] }}%</view>
  70. <view class="dim-item dim-item--wood">🌿行 {{ activeScores[3] }}%</view>
  71. <view class="dim-item dim-item--water">💧富 {{ activeScores[4] }}%</view>
  72. </view>
  73. </slot>
  74. </view>
  75. </template>
  76. <script>
  77. import { renderStar, calcStarVertices } from './wuxing-sandbox-helpers/render.js'
  78. import { FillAnimator } from './wuxing-sandbox-helpers/animation.js'
  79. import { detectHitArm, armIndexToDomain } from './wuxing-sandbox-helpers/hitdetect.js'
  80. import { FlowAnimation } from './wuxing-sandbox-helpers/flow-animation.js'
  81. var DIM_KEYS = ['body', 'mind', 'wisdom', 'action', 'wealth']
  82. /** 维度 → 五行映射(API 缺字段时的兜底) */
  83. var DIM_META = {
  84. mind: { name: '心', icon: '🔥', element: '火', color: 'fire' },
  85. action: { name: '行', icon: '🌿', element: '木', color: 'wood' },
  86. wealth: { name: '富', icon: '💧', element: '水', color: 'water' },
  87. wisdom: { name: '智', icon: '⚡', element: '金', color: 'metal' },
  88. body: { name: '身', icon: '🌏', element: '土', color: 'earth' }
  89. }
  90. export default {
  91. props: {
  92. /** 模式:'preview' 随机数据 / 'live' 真实数据 */
  93. mode: {
  94. type: String,
  95. default: 'preview',
  96. validator: function(v) { return v === 'preview' || v === 'live' }
  97. },
  98. /** 五维分值对象 {body,mind,wisdom,action,wealth},0-100 */
  99. scores: {
  100. type: Object,
  101. default: function() { return { body: 0, mind: 0, wisdom: 0, action: 0, wealth: 0 } }
  102. },
  103. /** 综合分值 0-100 */
  104. overallScore: {
  105. type: Number,
  106. default: 0
  107. },
  108. /** 家庭成员数组(MemberEnergyDTO 格式) */
  109. members: {
  110. type: Array,
  111. default: function() { return [] }
  112. },
  113. /** "我的"个人数据(参数指定成员的 EnergySandboxDTO,含 bodyScore/mindScore/.../overallScore) */
  114. personalData: {
  115. type: Object,
  116. default: null
  117. },
  118. /** 顶部徽章文字,空则自动计算 */
  119. badgeText: {
  120. type: String,
  121. default: ''
  122. },
  123. /** 是否显示底部维度条 */
  124. showDimensionBar: {
  125. type: Boolean,
  126. default: true
  127. },
  128. /** 五维能量数据(账本模式) */
  129. dimensions: {
  130. type: Array,
  131. default: function() { return [] }
  132. },
  133. totalEnergy: {
  134. type: Number,
  135. default: 0
  136. },
  137. totalHealthIndex: {
  138. type: Number,
  139. default: 0
  140. },
  141. /** 星图区域高度 */
  142. starHeight: {
  143. type: String,
  144. default: '540rpx'
  145. },
  146. /** 是否启用全家沙盘切换(控制个人/全家开关显隐) */
  147. familyUnlocked: {
  148. type: Boolean,
  149. default: false
  150. },
  151. /** 家庭真实成员数(来自 /api/family/member/list,用于全家切换判断;缺省时用 members 长度) */
  152. memberCount: {
  153. type: Number,
  154. default: 0
  155. },
  156. /** 当前视角模式(由父组件控制) */
  157. currentView: {
  158. type: String,
  159. default: 'personal',
  160. validator: function(v) { return v === 'personal' || v === 'family' }
  161. }
  162. },
  163. data: function() {
  164. return {
  165. viewMode: 'personal',
  166. selectedMemberIndex: 0,
  167. previewScores: [0, 0, 0, 0, 0],
  168. canvasReady: false,
  169. canvasWidth: 0,
  170. canvasHeight: 0,
  171. ctx: null,
  172. dpr: 1,
  173. _canvasLeft: 0,
  174. _canvasTop: 0,
  175. animBody: 0,
  176. animMind: 0,
  177. animWisdom: 0,
  178. animAction: 0,
  179. animWealth: 0,
  180. _animator: null,
  181. _flowAnim: null,
  182. _flowCanvasReady: false
  183. }
  184. },
  185. computed: {
  186. isPreview: function() {
  187. return this.mode === 'preview'
  188. },
  189. currentMember: function() {
  190. if (this.isPreview) return null
  191. var m = this.members
  192. if (!m || m.length === 0) return null
  193. if (this.selectedMemberIndex >= m.length) return m[0]
  194. return m[this.selectedMemberIndex]
  195. },
  196. /** 当前活跃的五维值数组 [body, mind, wisdom, action, wealth] */
  197. activeScores: function() {
  198. if (this.isPreview) return this.previewScores
  199. if (this.viewMode === 'family') {
  200. var s = this.scores
  201. return [
  202. s.body || 0,
  203. s.mind || 0,
  204. s.wisdom || 0,
  205. s.action || 0,
  206. s.wealth || 0
  207. ]
  208. }
  209. var p = this.personalData
  210. if (p) {
  211. return [
  212. p.bodyScore || 0,
  213. p.mindScore || 0,
  214. p.wisdomScore || 0,
  215. p.actionScore || 0,
  216. p.wealthScore || 0
  217. ]
  218. }
  219. var m = this.currentMember
  220. if (!m) return [0, 0, 0, 0, 0]
  221. return [
  222. m.bodyScore || 0,
  223. m.mindScore || 0,
  224. m.wisdomScore || 0,
  225. m.actionScore || 0,
  226. m.wealthScore || 0
  227. ]
  228. },
  229. activeOverall: function() {
  230. if (this.isPreview) {
  231. var s = this.previewScores
  232. return Math.round((s[0] + s[1] + s[2] + s[3] + s[4]) / 5)
  233. }
  234. if (this.viewMode === 'family') return this.overallScore || 0
  235. var p = this.personalData
  236. if (p && p.overallScore != null) return p.overallScore
  237. var m = this.currentMember
  238. return m ? (m.overallScore || 0) : 0
  239. },
  240. activeTs: function() {
  241. return [
  242. this.activeScores[0] / 100,
  243. this.activeScores[1] / 100,
  244. this.activeScores[2] / 100,
  245. this.activeScores[3] / 100,
  246. this.activeScores[4] / 100
  247. ]
  248. },
  249. displayBadgeText: function() {
  250. if (this.badgeText) return this.badgeText
  251. var label = this.viewMode === 'family' ? '家庭能量' : (this.currentMember ? this.currentMember.name : '个人能量')
  252. return label + ' ' + (this.activeOverall || 0) + '%'
  253. },
  254. _allDimTs: function() {
  255. return this.activeTs
  256. },
  257. hasMultipleMembers: function() {
  258. return this.members && this.members.length > 1
  259. },
  260. activeClassName: function() {
  261. return this.currentView === 'personal' ? 'toggle-item--active' : ''
  262. },
  263. activeFamilyClassName: function() {
  264. return this.currentView === 'family' ? 'toggle-item--active' : ''
  265. },
  266. /** 家庭能量值(用于太极阳面) */
  267. familyEnergy: function() {
  268. if (this.isPreview) {
  269. var s = this.previewScores
  270. return Math.round((s[0] + s[1] + s[2] + s[3] + s[4]) / 5)
  271. }
  272. return this.viewMode === 'family' ? (this.overallScore || 0) : (this.overallScore || 0)
  273. },
  274. /** 个人能量值(用于太极阴面) */
  275. personalEnergy: function() {
  276. if (this.isPreview) return 0
  277. if (this.viewMode === 'member') {
  278. var m = this.currentMember
  279. return m ? (m.overallScore || 0) : 0
  280. }
  281. // 家庭模式下取当前选中成员
  282. var m = this.currentMember
  283. return m ? (m.overallScore || 0) : 0
  284. },
  285. /** 按五行顺序绕圈排列
  286. * 固定序:心(火)→身(土)→智(金)→富(水)→行(木),心始终在顶部
  287. * 其余按五行相生序顺时针依次排:左边→右边→左下→右下
  288. */
  289. sortedDimensions: function() {
  290. var order = ['mind', 'body', 'wisdom', 'wealth', 'action']
  291. var dimMap = {}
  292. for (var i = 0; i < this.dimensions.length; i++) {
  293. var d = this.dimensions[i]
  294. if (d && d.code) dimMap[d.code] = d
  295. }
  296. var all = []
  297. for (var j = 0; j < order.length; j++) {
  298. var code = order[j]
  299. var d = dimMap[code]
  300. var meta = DIM_META[code] || {}
  301. if (d) {
  302. if (!d.name) d.name = meta.name || ''
  303. if (!d.icon) d.icon = meta.icon || ''
  304. if (!d.element) d.element = meta.element || ''
  305. all.push(d)
  306. } else {
  307. all.push({ code: code, name: meta.name || '', icon: meta.icon || '', element: meta.element || '', energy: 0, healthIndex: 0 })
  308. }
  309. }
  310. return all
  311. // all = [心→顶, 身→右, 智→右下, 富→左下, 行→左]
  312. }
  313. },
  314. watch: {
  315. _allDimTs: function() {
  316. if (this.canvasReady) {
  317. this._startAnimation()
  318. }
  319. },
  320. sortedDimensions: function(newVal) {
  321. if (this._flowAnim && this._flowCanvasReady) {
  322. var dimOrder = newVal.map(function(d) { return d.code })
  323. this._flowAnim.refreshPaths({ dimOrder: dimOrder })
  324. }
  325. },
  326. currentView: function(newVal) {
  327. if (newVal && newVal !== this.viewMode) {
  328. this.viewMode = newVal
  329. }
  330. },
  331. hasMultipleMembers: function(newVal) {
  332. if (!newVal && this.viewMode === 'family') {
  333. this.viewMode = 'personal'
  334. }
  335. }
  336. },
  337. mounted: function() {
  338. var self = this
  339. // 预览模式:生成随机五维值(缓存以避免每次 mount 重算)
  340. if (this.isPreview) {
  341. var cacheKey = '_wuxing_preview_scores'
  342. var cached = uni.getStorageSync(cacheKey)
  343. if (cached && Array.isArray(cached) && cached.length === 5) {
  344. this.previewScores = cached
  345. } else {
  346. var scores = []
  347. for (var i = 0; i < 5; i++) {
  348. scores.push(Math.floor(Math.random() * 51) + 35)
  349. }
  350. this.previewScores = scores
  351. uni.setStorageSync(cacheKey, scores)
  352. }
  353. }
  354. // 等待 DOM 就绪后初始化 Canvas
  355. setTimeout(function() {
  356. self.initCanvas()
  357. }, 100)
  358. },
  359. beforeDestroy: function() {
  360. if (this._animator) {
  361. this._animator.cancel()
  362. this._animator = null
  363. }
  364. if (this._flowAnim) {
  365. this._flowAnim.stop()
  366. this._flowAnim = null
  367. }
  368. },
  369. methods: {
  370. /* ===========================
  371. 视图切换
  372. =========================== */
  373. onCenterClick: function() {
  374. // 预览模式不切换
  375. if (this.isPreview) {
  376. this.$emit('center-click', { viewMode: this.viewMode, selectedMemberIndex: this.selectedMemberIndex })
  377. return
  378. }
  379. var members = this.members
  380. if (!members || members.length === 0) {
  381. this.viewMode = 'family'
  382. this.$emit('center-click', { viewMode: this.viewMode, selectedMemberIndex: this.selectedMemberIndex })
  383. return
  384. }
  385. if (this.viewMode === 'family') {
  386. this.viewMode = 'member'
  387. } else {
  388. if (members.length === 1) {
  389. this.viewMode = 'family'
  390. this.selectedMemberIndex = 0
  391. } else {
  392. var nextIdx = this.selectedMemberIndex + 1
  393. if (nextIdx >= members.length) {
  394. this.viewMode = 'family'
  395. this.selectedMemberIndex = 0
  396. } else {
  397. this.selectedMemberIndex = nextIdx
  398. }
  399. }
  400. }
  401. this.$emit('center-click', { viewMode: this.viewMode, selectedMemberIndex: this.selectedMemberIndex })
  402. this.$emit('mode-change', { viewMode: this.viewMode, selectedMemberIndex: this.selectedMemberIndex })
  403. },
  404. onPointClick: function(code) {
  405. this.$emit('point-click', {
  406. code: code,
  407. viewMode: this.viewMode,
  408. member: this.currentMember
  409. })
  410. },
  411. /** 个人/全家切换(由父组件控制数据源) */
  412. onToggle: function(view) {
  413. if (view === 'family') {
  414. var total = this.memberCount > 0 ? this.memberCount : (this.members ? this.members.length : 0)
  415. if (total < 2) {
  416. uni.showModal({
  417. title: '需要更多家庭成员',
  418. content: '至少需要 2 位家庭成员才能查看全家能量,快去添加吧!',
  419. confirmText: '去添加',
  420. cancelText: '取消',
  421. success: function(res) {
  422. if (res.confirm) {
  423. uni.navigateTo({ url: '/pages/profile-extra/family-members' })
  424. }
  425. }
  426. })
  427. return
  428. }
  429. }
  430. this.viewMode = view
  431. if (view === this.currentView) return
  432. this.$emit('view-change', view)
  433. },
  434. /** 维度 code → CSS 颜色类名(不依赖 API 的 element 字段) */
  435. dimElementColor: function(code) {
  436. var meta = DIM_META[code]
  437. return meta ? meta.color : 'fire'
  438. },
  439. /* ===========================
  440. Canvas 初始化 & 渲染
  441. =========================== */
  442. initCanvas: function() {
  443. var self = this
  444. uni.createSelectorQuery().in(this).select('#starCanvas')
  445. .fields({ node: true, size: true, rect: true })
  446. .exec(function(res) {
  447. if (!res || !res[0] || !res[0].node) return
  448. var canvas = res[0].node
  449. var width = res[0].width
  450. var height = res[0].height
  451. if (!width || !height) return
  452. var pixelRatio = uni.getWindowInfo().pixelRatio || 2
  453. canvas.width = width * pixelRatio
  454. canvas.height = height * pixelRatio
  455. var ctx = canvas.getContext('2d')
  456. ctx.scale(pixelRatio, pixelRatio)
  457. self.ctx = ctx
  458. self.canvasWidth = width
  459. self.canvasHeight = height
  460. self.dpr = pixelRatio
  461. self._canvasLeft = res[0].left || 0
  462. self._canvasTop = res[0].top || 0
  463. self.canvasReady = true
  464. self._startAnimation()
  465. self._initFlowCanvas()
  466. })
  467. },
  468. _doRender: function() {
  469. if (!this.ctx) return
  470. var ts = [this.animBody, this.animMind, this.animWisdom, this.animAction, this.animWealth]
  471. renderStar(this.ctx, this.canvasWidth, this.canvasHeight, ts, {
  472. familyEnergy: this.familyEnergy,
  473. personalEnergy: this.personalEnergy
  474. })
  475. },
  476. /* ===========================
  477. 动画控制
  478. =========================== */
  479. _startAnimation: function() {
  480. var self = this
  481. if (!this._animator) {
  482. this._animator = new FillAnimator(
  483. function() {
  484. return [self.animBody, self.animMind, self.animWisdom, self.animAction, self.animWealth]
  485. },
  486. function(interpolated) {
  487. self.animBody = interpolated[0]
  488. self.animMind = interpolated[1]
  489. self.animWisdom = interpolated[2]
  490. self.animAction = interpolated[3]
  491. self.animWealth = interpolated[4]
  492. self._doRender()
  493. }
  494. )
  495. }
  496. this._animator.start(this.activeTs, 600)
  497. },
  498. /* ===========================
  499. 粒子流量动画
  500. =========================== */
  501. _initFlowCanvas: function() {
  502. var self = this
  503. var dimOrder = this.sortedDimensions.map(function(d) { return d.code })
  504. uni.createSelectorQuery().in(this).select('#flowCanvas')
  505. .fields({ node: true, size: true })
  506. .exec(function(res) {
  507. if (!res || !res[0] || !res[0].node) return
  508. var canvas = res[0].node
  509. var width = res[0].width
  510. var height = res[0].height
  511. if (!width || !height) return
  512. var pixelRatio = uni.getWindowInfo().pixelRatio || 2
  513. canvas.width = width * pixelRatio
  514. canvas.height = height * pixelRatio
  515. var ctx = canvas.getContext('2d')
  516. ctx.scale(pixelRatio, pixelRatio)
  517. var outerR = Math.min(width, height) * 0.50
  518. var vertices = calcStarVertices(width / 2, height / 2, outerR)
  519. self._flowAnim = new FlowAnimation(ctx, width, height, {
  520. outer: vertices.outer,
  521. inner: vertices.inner,
  522. dimOrder: dimOrder
  523. })
  524. self._flowAnim.start()
  525. self._flowCanvasReady = true
  526. })
  527. },
  528. /* ===========================
  529. 点击检测
  530. =========================== */
  531. onCanvasTap: function(e) {
  532. if (!this.canvasReady) return
  533. var pageX = e.detail.x
  534. var pageY = e.detail.y
  535. if (typeof pageX !== 'number') {
  536. var touch = e.touches ? e.touches[0] : null
  537. if (touch) {
  538. pageX = touch.x || touch.clientX || 0
  539. pageY = touch.y || touch.clientY || 0
  540. } else {
  541. var changedTouch = e.changedTouches ? e.changedTouches[0] : null
  542. if (changedTouch) {
  543. pageX = changedTouch.x || changedTouch.clientX || 0
  544. pageY = changedTouch.y || changedTouch.clientY || 0
  545. } else {
  546. return
  547. }
  548. }
  549. }
  550. var relX = pageX - (this._canvasLeft || 0)
  551. var relY = pageY - (this._canvasTop || 0)
  552. if (relX < 0 || relY < 0 || relX > this.canvasWidth || relY > this.canvasHeight) return
  553. var cx = this.canvasWidth / 2
  554. var cy = this.canvasHeight / 2
  555. var outerR = Math.min(this.canvasWidth, this.canvasHeight) * 0.46
  556. var armIdx = detectHitArm(relX, relY, cx, cy, outerR, calcStarVertices)
  557. if (armIdx >= 0) {
  558. this.onPointClick(armIndexToDomain(armIdx))
  559. }
  560. }
  561. }
  562. }
  563. </script>
  564. <style scoped>
  565. /* ============================================================
  566. 容器
  567. ============================================================ */
  568. .wuxing-sandbox {
  569. margin: 20rpx 30rpx;
  570. padding: 20rpx 24rpx 24rpx;
  571. background: linear-gradient(135deg, #1A2A4A, #1E3A5F, #16213E);
  572. border-radius: 24rpx;
  573. position: relative;
  574. overflow: hidden;
  575. }
  576. .wuxing-sandbox::before {
  577. content: '';
  578. position: absolute;
  579. top: -50%;
  580. left: -50%;
  581. width: 200%;
  582. height: 200%;
  583. background: radial-gradient(ellipse at 30% 20%, rgba(91, 155, 213, 0.04), transparent 60%),
  584. radial-gradient(ellipse at 70% 80%, rgba(66, 165, 245, 0.03), transparent 60%);
  585. pointer-events: none;
  586. }
  587. /* ---- 标题 ---- */
  588. .sandbox-header {
  589. display: flex;
  590. justify-content: flex-start;
  591. align-items: center;
  592. margin-bottom: 12rpx;
  593. position: relative;
  594. z-index: 5;
  595. }
  596. .sandbox-title { font-size: 26rpx; font-weight: bold; color: #8FC5E8; margin-left: 8rpx; }
  597. .sandbox-logo { width: 32rpx; height: 32rpx; flex-shrink: 0; }
  598. .sandbox-badge {
  599. font-size: 20rpx;
  600. color: rgba(143,197,232,0.7);
  601. background: rgba(143,197,232,0.1);
  602. padding: 4rpx 14rpx;
  603. border-radius: 20rpx;
  604. margin-left: auto;
  605. }
  606. .sandbox-switch {
  607. display: flex;
  608. align-items: center;
  609. gap: 6rpx;
  610. font-size: 22rpx;
  611. color: #fff;
  612. background: linear-gradient(135deg, #667eea, #764ba2);
  613. padding: 10rpx 20rpx;
  614. border-radius: 28rpx;
  615. margin-left: auto;
  616. flex-shrink: 0;
  617. box-shadow: 0 4rpx 12rpx rgba(102,126,234,0.45);
  618. border: 1rpx solid rgba(255,255,255,0.25);
  619. }
  620. .sandbox-switch:active {
  621. opacity: 0.85;
  622. box-shadow: none;
  623. }
  624. .sandbox-switch-icon { font-size: 24rpx; line-height: 1; }
  625. .sandbox-switch-label { font-size: 22rpx; font-weight: 700; max-width: 140rpx; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  626. .sandbox-switch-arrow { font-size: 20rpx; opacity: 0.8; }
  627. /* ---- 五角星区域 ---- */
  628. .sandbox-star {
  629. position: relative;
  630. width: 100%;
  631. display: flex;
  632. justify-content: center;
  633. align-items: center;
  634. }
  635. /* 背景光晕 */
  636. .star-glow-bg {
  637. position: absolute; width: 500rpx; height: 500rpx;
  638. top: 50%; left: 50%; transform: translate(-50%, -50%);
  639. background: radial-gradient(circle, rgba(91,155,213,0.10), transparent 70%);
  640. border-radius: 50%; pointer-events: none;
  641. }
  642. /* Canvas 点击感应层 */
  643. .canvas-tap-area {
  644. position: absolute;
  645. top: 0; left: 0; right: 0; bottom: 0;
  646. z-index: 2;
  647. }
  648. /* ============================================================
  649. 顶点:图标 + 中文标签
  650. ============================================================ */
  651. .star-point {
  652. position: absolute; transform: translate(-50%, -50%); z-index: 3; cursor: pointer;
  653. display: flex; flex-direction: column; align-items: center;
  654. }
  655. /* 横排 */
  656. .star-point--row {
  657. flex-direction: row;
  658. gap: 6rpx;
  659. }
  660. .star-point--rev {
  661. flex-direction: row-reverse;
  662. gap: 6rpx;
  663. }
  664. .star-point--top { top: 1%; left: 50%; }
  665. .star-point--left { top: 38%; left: 5%; }
  666. .star-point--right { top: 38%; left: 95%; }
  667. .star-point--lr { top: 89%; left: 85%; }
  668. .star-point--ll { top: 89%; left: 15%; }
  669. .point-dot {
  670. width: 52rpx; height: 52rpx; border-radius: 50%;
  671. display: flex; align-items: center; justify-content: center;
  672. box-shadow: 0 0 24rpx rgba(255,255,255,0.25);
  673. }
  674. .point-dot--fire { background: linear-gradient(135deg, #FF6B35, #E65100); }
  675. .point-dot--water { background: linear-gradient(135deg, #42A5F5, #1565C0); }
  676. .point-dot--earth { background: linear-gradient(135deg, #8D6E63, #5D4037); }
  677. .point-dot--metal { background: linear-gradient(135deg, #FFD700, #FF8F00); }
  678. .point-dot--wood { background: linear-gradient(135deg, #4CAF50, #2E7D32); }
  679. .point-icon { font-size: 26rpx; line-height: 1; }
  680. .point-label {
  681. font-size: 22rpx; font-weight: bold; color: rgba(255,255,255,0.9);
  682. margin-top: 6rpx; text-shadow: 0 1rpx 4rpx rgba(0,0,0,0.5);
  683. letter-spacing: 2rpx;
  684. }
  685. .star-point--row .point-label,
  686. .star-point--rev .point-label {
  687. margin-top: 0;
  688. }
  689. .point-energy {
  690. font-size: 18rpx; color: rgba(143,197,232,0.8);
  691. background: rgba(143,197,232,0.12);
  692. padding: 1rpx 10rpx; border-radius: 12rpx;
  693. margin-top: 2rpx;
  694. }
  695. .star-point--row .point-energy,
  696. .star-point--rev .point-energy {
  697. margin-top: 0;
  698. }
  699. /* ============================================================
  700. 中心点击区域
  701. ============================================================ */
  702. .star-center {
  703. position: absolute; top: 50%; left: 50%;
  704. transform: translate(-50%, -50%); z-index: 4;
  705. width: 180rpx; height: 180rpx; border-radius: 50%;
  706. cursor: pointer;
  707. }
  708. /* ============================================================
  709. 维度详情条
  710. ============================================================ */
  711. .dimension-bar {
  712. display: flex; align-items: center; justify-content: center;
  713. margin-top: 16rpx; gap: 8rpx;
  714. position: relative; z-index: 5; flex-wrap: wrap;
  715. }
  716. .dim-item {
  717. font-size: 20rpx; padding: 4rpx 12rpx; border-radius: 10rpx; white-space: nowrap;
  718. }
  719. .dim-item--wood { color: #4CAF50; background: rgba(76,175,80,0.12); }
  720. .dim-item--fire { color: #FF6B35; background: rgba(255,107,53,0.12); }
  721. .dim-item--earth { color: #8D6E63; background: rgba(141,110,99,0.12); }
  722. .dim-item--metal { color: #FFD700; background: rgba(255,215,0,0.12); }
  723. .dim-item--water { color: #42A5F5; background: rgba(66,165,245,0.12); }
  724. /* ============================================================
  725. 个人/全家切换开关
  726. ============================================================ */
  727. .sandbox-toggle {
  728. display: flex;
  729. justify-content: center;
  730. align-items: center;
  731. margin-bottom: 12rpx;
  732. position: relative;
  733. z-index: 5;
  734. gap: 0;
  735. }
  736. .toggle-item {
  737. display: flex;
  738. align-items: center;
  739. justify-content: center;
  740. padding: 8rpx 28rpx;
  741. font-size: 24rpx;
  742. color: rgba(143,197,232,0.6);
  743. background: rgba(143,197,232,0.08);
  744. border: 1rpx solid rgba(143,197,232,0.15);
  745. border-radius: 30rpx 0 0 30rpx;
  746. transition: all 0.2s;
  747. }
  748. .toggle-item--family {
  749. border-radius: 0 30rpx 30rpx 0;
  750. border-left: none;
  751. }
  752. .toggle-item--active {
  753. color: #fff;
  754. background: linear-gradient(135deg, #5B9BD5, #3A7CC2);
  755. border-color: #5B9BD5;
  756. }
  757. .toggle-icon {
  758. font-size: 26rpx;
  759. margin-right: 8rpx;
  760. }
  761. .toggle-text {
  762. font-weight: bold;
  763. }
  764. </style>