portrait-edit.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="portrait-edit-page">
  3. <view class="section">
  4. <view class="section-title">我的画像描述</view>
  5. <view class="hint">请输入你的个人画像描述,AI 会根据这些信息提供更有针对性的建议(最多 2000 字)</view>
  6. <textarea
  7. class="portrait-textarea"
  8. :value="portraitPrompt"
  9. placeholder="例如:我家孩子 8 岁,偏瘦,挑食,容易积食,睡眠不足..."
  10. maxlength="2000"
  11. @input="onInput"
  12. auto-height
  13. ></textarea>
  14. <view class="char-count">{{ portraitPrompt.length }}/2000</view>
  15. </view>
  16. <view class="section" v-if="renderedSnapshot">
  17. <view class="section-title">参考指标(自动生成)</view>
  18. <view class="snapshot-text">{{ renderedSnapshot }}</view>
  19. </view>
  20. </view>
  21. <view class="save-bar">
  22. <button class="save-btn" :loading="saving" @click="onSave">保存</button>
  23. </view>
  24. </template>
  25. <script>
  26. import { getPortrait, editPortrait } from '../../utils/api.js'
  27. export default {
  28. data() {
  29. return {
  30. portraitPrompt: '',
  31. renderedSnapshot: '',
  32. saving: false
  33. }
  34. },
  35. onLoad() {
  36. this.loadPortrait()
  37. },
  38. methods: {
  39. async loadPortrait() {
  40. try {
  41. const res = await getPortrait({ memberId: this.$store.state.currentMemberId })
  42. if (res.code === 200 && res.data) {
  43. this.portraitPrompt = res.data.portraitPrompt || ''
  44. this.renderedSnapshot = res.data.renderedSnapshot || ''
  45. }
  46. } catch (e) {
  47. console.error('加载画像失败', e)
  48. }
  49. },
  50. onInput(e) {
  51. this.portraitPrompt = e.detail.value
  52. },
  53. async onSave() {
  54. this.saving = true
  55. try {
  56. const res = await editPortrait({ portraitPrompt: this.portraitPrompt })
  57. if (res.code === 200) {
  58. uni.showToast({ title: '保存成功', icon: 'success' })
  59. this.loadPortrait()
  60. } else {
  61. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  62. }
  63. } catch (e) {
  64. uni.showToast({ title: '保存失败', icon: 'none' })
  65. } finally {
  66. this.saving = false
  67. }
  68. }
  69. }
  70. }
  71. </script>
  72. <style scoped>
  73. .portrait-edit-page {
  74. padding: 24rpx;
  75. padding-bottom: 160rpx;
  76. min-height: 100vh;
  77. background: #f5f5f5;
  78. box-sizing: border-box;
  79. }
  80. .section {
  81. background: #fff;
  82. border-radius: 16rpx;
  83. padding: 24rpx;
  84. margin-bottom: 24rpx;
  85. }
  86. .section-title {
  87. font-size: 32rpx;
  88. font-weight: bold;
  89. margin-bottom: 12rpx;
  90. color: #333;
  91. }
  92. .hint {
  93. font-size: 24rpx;
  94. color: #999;
  95. margin-bottom: 16rpx;
  96. }
  97. .portrait-textarea {
  98. width: 100%;
  99. min-height: 500rpx;
  100. border: 1rpx solid #eee;
  101. border-radius: 8rpx;
  102. padding: 16rpx;
  103. font-size: 28rpx;
  104. box-sizing: border-box;
  105. line-height: 1.6;
  106. }
  107. .char-count {
  108. text-align: right;
  109. font-size: 22rpx;
  110. color: #999;
  111. margin-top: 8rpx;
  112. }
  113. .snapshot-text {
  114. font-size: 26rpx;
  115. color: #555;
  116. white-space: pre-wrap;
  117. line-height: 1.6;
  118. }
  119. .save-bar {
  120. position: fixed;
  121. left: 0;
  122. right: 0;
  123. bottom: 0;
  124. padding: 20rpx 24rpx;
  125. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  126. background: #fff;
  127. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.08);
  128. box-sizing: border-box;
  129. z-index: 100;
  130. }
  131. .save-btn {
  132. background: #F97316;
  133. color: #fff;
  134. border-radius: 44rpx;
  135. height: 88rpx;
  136. line-height: 88rpx;
  137. font-size: 32rpx;
  138. }
  139. </style>