portrait-edit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <view class="portrait-edit-page" :class="{ 'no-scroll': editing }" v-if="!editing">
  3. <!-- 五维画像(原我的页面内容迁移至此) -->
  4. <view class="section" v-if="portrait">
  5. <view class="section-header-row">
  6. <text class="section-title">🧭 用户画像</text>
  7. <text class="section-sub">{{ portrait.tierLabel }}</text>
  8. </view>
  9. <view class="portrait-summary">
  10. <text class="portrait-desc">{{ portrait.summary }}</text>
  11. </view>
  12. <view class="portrait-dimensions">
  13. <view class="portrait-dim-item" v-for="dim in portrait.dims" :key="dim.code">
  14. <view class="portrait-dim-header">
  15. <view class="portrait-dim-icon" :style="{ background: dim.color }">{{ dim.icon }}</view>
  16. <text class="portrait-dim-name">{{ dim.name }}</text>
  17. <text class="portrait-dim-score">{{ dim.score }}</text>
  18. </view>
  19. <view class="portrait-dim-bar-track">
  20. <view class="portrait-dim-bar-fill" :style="{ width: dim.score + '%', background: dim.color }"></view>
  21. </view>
  22. <text class="portrait-dim-desc">{{ dim.desc }}</text>
  23. </view>
  24. </view>
  25. <view class="portrait-tip" v-if="portrait.tip">
  26. <text class="portrait-tip-text">{{ portrait.tip }}</text>
  27. </view>
  28. </view>
  29. <!-- 画像描述(可编辑) -->
  30. <view class="section">
  31. <view class="section-header-row">
  32. <text class="section-title">我的画像描述</text>
  33. <text class="edit-btn" @click="enterEdit">编辑</text>
  34. </view>
  35. <view class="hint">AI 会根据这些信息提供更有针对性的建议(最多 2000 字)。每日自动基于最新使用情况更新。 </view>
  36. <view class="portrait-prompt-text" v-if="portraitPrompt">{{ portraitPrompt }}</view>
  37. <view class="portrait-prompt-empty" v-else>暂无画像描述,点击「编辑」填写或由 AI 自动生成</view>
  38. </view>
  39. <!-- 参考指标(自动生成) -->
  40. <view class="section" v-if="renderedSnapshot">
  41. <view class="section-title">参考指标(自动生成)</view>
  42. <view class="snapshot-text">{{ renderedSnapshot }}</view>
  43. </view>
  44. </view>
  45. <!-- 全屏编辑模式 -->
  46. <view class="editor-fullscreen" v-else>
  47. <view class="editor-topbar">
  48. <text class="editor-cancel" @click="cancelEdit">取消</text>
  49. <text class="editor-title">编辑画像</text>
  50. <text class="editor-save" @click="saveEdit">保存</text>
  51. </view>
  52. <view class="editor-body">
  53. <textarea
  54. class="editor-textarea"
  55. :value="editingText"
  56. placeholder="例如:我家孩子 8 岁,偏瘦,挑食,容易积食,睡眠不足..."
  57. maxlength="2000"
  58. :focus="editing"
  59. @input="onEditInput"
  60. ></textarea>
  61. <view class="char-count">{{ editingText.length }}/2000</view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import { BrandColors } from '../../utils/brand-colors.js'
  67. import { getPortrait, editPortrait, getEnergySandbox } from '../../utils/api.js'
  68. export default {
  69. data() {
  70. return {
  71. portrait: null,
  72. portraitPrompt: '',
  73. renderedSnapshot: '',
  74. saving: false,
  75. editing: false,
  76. editingText: ''
  77. }
  78. },
  79. onLoad() {
  80. this.loadPortrait()
  81. this.loadEnergy()
  82. },
  83. methods: {
  84. async loadPortrait() {
  85. try {
  86. const res = await getPortrait({ memberId: this.$store.state.currentMemberId })
  87. if (res.code === 200 && res.data) {
  88. this.portraitPrompt = res.data.portraitPrompt || ''
  89. this.renderedSnapshot = res.data.renderedSnapshot || ''
  90. }
  91. } catch (e) {
  92. console.error('加载画像失败', e)
  93. }
  94. },
  95. loadEnergy() {
  96. var self = this
  97. getEnergySandbox('family').then(function(res) {
  98. if (res && res.code === 200 && res.data) {
  99. var d = res.data.familyData || null
  100. if (!d && res.data.personalData) {
  101. // 个人数据模式:使用个人数据
  102. d = res.data.personalData
  103. }
  104. if (!d || typeof d !== 'object') return
  105. self.portrait = self.mapToPortrait(d)
  106. }
  107. }).catch(function(e) {
  108. console.error('获取五维能量沙盘失败', e)
  109. self.portrait = null
  110. })
  111. },
  112. mapToPortrait(d) {
  113. // 计算总分和平均分
  114. var scores = { body: 0, mind: 0, wisdom: 0, action: 0, wealth: 0 }
  115. var dims = []
  116. var total = 0
  117. var count = 0
  118. var defs = [
  119. { key: 'body', label: '身', icon: '💪', color: BrandColors.body, desc: '身体健康状况,体质好坏的综合反映' },
  120. { key: 'mind', label: '心', icon: '💖', color: BrandColors.mind, desc: '情绪与心理状态,情绪波动与心理平衡' },
  121. { key: 'wisdom', label: '智', icon: '📚', color: BrandColors.wisdom, desc: '智力与知识水平,认知能力与知识储备' },
  122. { key: 'action', label: '行', icon: '🚀', color: BrandColors.success, desc: '行动力与执行力,计划与行动的落实情况' },
  123. { key: 'wealth', label: '富', icon: '💰', color: BrandColors.wealth, desc: '财富与资源,物质丰富程度与创富能力' }
  124. ]
  125. for (var i = 0; i < defs.length; i++) {
  126. var raw = d[defs[i].key + 'Score']
  127. var n = 0
  128. if (raw != null && !isNaN(raw)) {
  129. n = Math.max(0, Math.min(100, Number(raw)))
  130. }
  131. scores[defs[i].key] = n
  132. total += n
  133. count++
  134. dims.push({
  135. code: defs[i].key,
  136. name: defs[i].label,
  137. icon: defs[i].icon,
  138. score: n,
  139. color: defs[i].color,
  140. desc: defs[i].desc
  141. })
  142. }
  143. var overall = count > 0 ? Math.round(total / count) : 0
  144. // 确定等级和描述
  145. var tierLabel = ''
  146. var summary = ''
  147. var tip = ''
  148. if (overall >= 80) {
  149. tierLabel = '卓越守护者'
  150. summary = '你的五维能量处于卓越水平,身心健康,知行合一。家庭成员都受益于你的正向能量场。'
  151. tip = '保持当前的良好习惯,继续关注家庭成员的需求'
  152. } else if (overall >= 60) {
  153. tierLabel = '进取者'
  154. summary = '你的五维能量处于良好水平,各方面有所提升,但仍有提升空间。'
  155. tip = '可以尝试在其中一个维度上突破瓶颈,带动全家进步'
  156. } else if (overall >= 40) {
  157. tierLabel = '探索者'
  158. summary = '你的五维能量处于起步水平,正在探索和学习中。这是成长的起点。'
  159. tip = '从关注最容易改进的维度开始,每一点进步都很重要'
  160. } else {
  161. tierLabel = '起步者'
  162. summary = '你的五维能量处于起始水平,正处于开始关注全家健康的阶段。'
  163. tip = '从现在开始,每天关注一项小健康行动,逐步建立五维能量基础'
  164. }
  165. return {
  166. overall: overall,
  167. tierLabel: tierLabel,
  168. summary: summary,
  169. dims: dims,
  170. tip: tip
  171. }
  172. },
  173. enterEdit() {
  174. this.editingText = this.portraitPrompt
  175. this.editing = true
  176. },
  177. cancelEdit() {
  178. this.editing = false
  179. this.editingText = ''
  180. },
  181. onEditInput(e) {
  182. this.editingText = e.detail.value
  183. },
  184. async saveEdit() {
  185. this.saving = true
  186. try {
  187. const res = await editPortrait({ portraitPrompt: this.editingText })
  188. if (res.code === 200) {
  189. uni.showToast({ title: '保存成功', icon: 'success' })
  190. this.portraitPrompt = this.editingText
  191. this.editing = false
  192. this.editingText = ''
  193. } else {
  194. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  195. }
  196. } catch (e) {
  197. uni.showToast({ title: '保存失败', icon: 'none' })
  198. } finally {
  199. this.saving = false
  200. }
  201. }
  202. }
  203. }
  204. </script>
  205. <style scoped lang="scss">
  206. .portrait-edit-page {
  207. padding: 24rpx;
  208. padding-bottom: 60rpx;
  209. min-height: 100vh;
  210. background: $facade-fill-2;
  211. box-sizing: border-box;
  212. }
  213. .no-scroll {
  214. overflow: hidden;
  215. height: 100vh;
  216. }
  217. .section {
  218. background: $app-surface;
  219. border-radius: 16rpx;
  220. padding: 24rpx;
  221. margin-bottom: 24rpx;
  222. }
  223. .section-header-row {
  224. display: flex;
  225. align-items: center;
  226. justify-content: space-between;
  227. margin-bottom: 12rpx;
  228. }
  229. .section-title {
  230. font-size: 32rpx;
  231. font-weight: bold;
  232. color: $facade-text-strong;
  233. }
  234. .section-sub {
  235. font-size: 24rpx;
  236. color: $brand-primary;
  237. }
  238. .hint {
  239. font-size: 24rpx;
  240. color: $facade-text-muted;
  241. margin-bottom: 16rpx;
  242. line-height: 1.5;
  243. }
  244. .edit-btn {
  245. font-size: 26rpx;
  246. color: $brand-primary;
  247. padding: 6rpx 24rpx;
  248. border: 1rpx solid $brand-primary;
  249. border-radius: 30rpx;
  250. }
  251. .portrait-summary {
  252. margin-bottom: 16rpx;
  253. }
  254. .portrait-desc {
  255. font-size: 26rpx;
  256. color: $facade-text-deep;
  257. line-height: 1.6;
  258. }
  259. .portrait-dimensions {
  260. margin-bottom: 12rpx;
  261. }
  262. .portrait-dim-item {
  263. margin-bottom: 20rpx;
  264. }
  265. .portrait-dim-header {
  266. display: flex;
  267. align-items: center;
  268. margin-bottom: 8rpx;
  269. }
  270. .portrait-dim-icon {
  271. width: 44rpx;
  272. height: 44rpx;
  273. line-height: 44rpx;
  274. text-align: center;
  275. border-radius: 50%;
  276. font-size: 24rpx;
  277. margin-right: 12rpx;
  278. }
  279. .portrait-dim-name {
  280. font-size: 28rpx;
  281. color: $facade-text-strong;
  282. flex: 1;
  283. }
  284. .portrait-dim-score {
  285. font-size: 28rpx;
  286. font-weight: bold;
  287. color: $facade-text-strong;
  288. }
  289. .portrait-dim-bar-track {
  290. height: 16rpx;
  291. background: $facade-hairline-2;
  292. border-radius: 8rpx;
  293. overflow: hidden;
  294. margin-bottom: 8rpx;
  295. }
  296. .portrait-dim-bar-fill {
  297. height: 100%;
  298. border-radius: 8rpx;
  299. }
  300. .portrait-dim-desc {
  301. font-size: 22rpx;
  302. color: $facade-text-muted;
  303. line-height: 1.5;
  304. display: block;
  305. }
  306. .portrait-tip {
  307. margin-top: 8rpx;
  308. background: rgba(249, 115, 22, 0.08);
  309. border-radius: 12rpx;
  310. padding: 16rpx 20rpx;
  311. }
  312. .portrait-tip-text {
  313. font-size: 24rpx;
  314. color: $status-warning-deep;
  315. line-height: 1.5;
  316. }
  317. .portrait-prompt-text {
  318. font-size: 28rpx;
  319. color: $facade-text-strong;
  320. white-space: pre-wrap;
  321. line-height: 1.7;
  322. word-break: break-all;
  323. }
  324. .portrait-prompt-empty {
  325. font-size: 26rpx;
  326. color: $facade-text-muted;
  327. line-height: 1.6;
  328. }
  329. .snapshot-text {
  330. font-size: 26rpx;
  331. color: $facade-text-deep;
  332. white-space: pre-wrap;
  333. line-height: 1.6;
  334. }
  335. /* ===== 全屏编辑模式 ===== */
  336. .editor-fullscreen {
  337. position: fixed;
  338. top: 0;
  339. left: 0;
  340. right: 0;
  341. bottom: 0;
  342. width: 100%;
  343. height: 100%;
  344. background: $app-surface;
  345. z-index: 999;
  346. display: flex;
  347. flex-direction: column;
  348. box-sizing: border-box;
  349. }
  350. .editor-topbar {
  351. height: 88rpx;
  352. display: flex;
  353. align-items: center;
  354. justify-content: space-between;
  355. padding: 0 24rpx;
  356. border-bottom: 1rpx solid $facade-fill;
  357. flex-shrink: 0;
  358. }
  359. .editor-cancel {
  360. font-size: 30rpx;
  361. color: $facade-text-body;
  362. }
  363. .editor-title {
  364. font-size: 32rpx;
  365. font-weight: bold;
  366. color: $facade-text-strong;
  367. }
  368. .editor-save {
  369. font-size: 30rpx;
  370. color: $brand-primary;
  371. font-weight: bold;
  372. }
  373. .editor-body {
  374. flex: 1;
  375. display: flex;
  376. flex-direction: column;
  377. min-height: 0;
  378. position: relative;
  379. }
  380. .editor-textarea {
  381. width: 100%;
  382. height: calc(100vh - 88rpx);
  383. padding: 24rpx;
  384. font-size: 30rpx;
  385. line-height: 1.6;
  386. box-sizing: border-box;
  387. color: $facade-text-strong;
  388. }
  389. .char-count {
  390. position: absolute;
  391. right: 24rpx;
  392. bottom: 16rpx;
  393. font-size: 22rpx;
  394. color: $facade-text-muted;
  395. }
  396. </style>