portrait-edit.vue 11 KB

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