portrait-edit.vue 12 KB

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