wuxing-sandbox.vue 30 KB

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