portrait-edit.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. ></textarea>
  13. <view class="char-count">{{ portraitPrompt.length }}/2000</view>
  14. </view>
  15. <view class="section" v-if="renderedSnapshot">
  16. <view class="section-title">参考指标(自动生成)</view>
  17. <view class="snapshot-text">{{ renderedSnapshot }}</view>
  18. </view>
  19. <button class="save-btn" :loading="saving" @click="onSave">保存</button>
  20. </view>
  21. </template>
  22. <script>
  23. import { getPortrait, editPortrait } from '../../utils/api.js'
  24. export default {
  25. data() {
  26. return {
  27. portraitPrompt: '',
  28. renderedSnapshot: '',
  29. saving: false
  30. }
  31. },
  32. onLoad() {
  33. this.loadPortrait()
  34. },
  35. methods: {
  36. async loadPortrait() {
  37. try {
  38. const res = await getPortrait({ memberId: this.$store.state.currentMemberId })
  39. if (res.code === 200 && res.data) {
  40. this.portraitPrompt = res.data.portraitPrompt || ''
  41. this.renderedSnapshot = res.data.renderedSnapshot || ''
  42. }
  43. } catch (e) {
  44. console.error('加载画像失败', e)
  45. }
  46. },
  47. onInput(e) {
  48. this.portraitPrompt = e.detail.value
  49. },
  50. async onSave() {
  51. this.saving = true
  52. try {
  53. const res = await editPortrait({ portraitPrompt: this.portraitPrompt })
  54. if (res.code === 200) {
  55. uni.showToast({ title: '保存成功', icon: 'success' })
  56. this.loadPortrait()
  57. } else {
  58. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  59. }
  60. } catch (e) {
  61. uni.showToast({ title: '保存失败', icon: 'none' })
  62. } finally {
  63. this.saving = false
  64. }
  65. }
  66. }
  67. }
  68. </script>
  69. <style scoped>
  70. .portrait-edit-page {
  71. padding: 24rpx;
  72. min-height: 100vh;
  73. background: #f5f5f5;
  74. }
  75. .section {
  76. background: #fff;
  77. border-radius: 16rpx;
  78. padding: 24rpx;
  79. margin-bottom: 24rpx;
  80. }
  81. .section-title {
  82. font-size: 32rpx;
  83. font-weight: bold;
  84. margin-bottom: 12rpx;
  85. color: #333;
  86. }
  87. .hint {
  88. font-size: 24rpx;
  89. color: #999;
  90. margin-bottom: 16rpx;
  91. }
  92. .portrait-textarea {
  93. width: 100%;
  94. height: 300rpx;
  95. border: 1rpx solid #eee;
  96. border-radius: 8rpx;
  97. padding: 16rpx;
  98. font-size: 28rpx;
  99. box-sizing: border-box;
  100. line-height: 1.6;
  101. }
  102. .char-count {
  103. text-align: right;
  104. font-size: 22rpx;
  105. color: #999;
  106. margin-top: 8rpx;
  107. }
  108. .snapshot-text {
  109. font-size: 26rpx;
  110. color: #555;
  111. white-space: pre-wrap;
  112. line-height: 1.6;
  113. }
  114. .save-btn {
  115. background: #F97316;
  116. color: #fff;
  117. border-radius: 44rpx;
  118. height: 88rpx;
  119. line-height: 88rpx;
  120. font-size: 32rpx;
  121. margin-top: 32rpx;
  122. }
  123. </style>