text-edit.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="container">
  3. <view class="header" v-if="title">
  4. <text class="title">{{ title }}</text>
  5. </view>
  6. <textarea
  7. class="textarea"
  8. v-model="text"
  9. :placeholder="placeholder"
  10. :maxlength="500"
  11. show-confirm-bar
  12. auto-focus
  13. />
  14. <view class="footer">
  15. <button class="btn cancel" @click="cancel">取消</button>
  16. <button class="btn save" @click="save">保存</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. key: 'bio',
  25. text: '',
  26. placeholder: '请输入内容',
  27. title: ''
  28. }
  29. },
  30. onLoad(options) {
  31. this.key = options.key || 'bio'
  32. const value = options.value || ''
  33. this.text = value ? decodeURIComponent(value) : ''
  34. this.placeholder = options.placeholder ? decodeURIComponent(options.placeholder) : '请输入内容'
  35. this.title = options.title ? decodeURIComponent(options.title) : '编辑文本'
  36. },
  37. methods: {
  38. cancel() {
  39. uni.navigateBack()
  40. },
  41. save() {
  42. // 保存到临时存储,编辑资料页会在 onShow 时读取
  43. const trimmedText = this.text.trim()
  44. uni.setStorageSync(`temp_text_${this.key}`, trimmedText)
  45. uni.showToast({
  46. title: '已保存',
  47. icon: 'success',
  48. duration: 1000
  49. })
  50. setTimeout(() => {
  51. uni.navigateBack()
  52. }, 500)
  53. }
  54. }
  55. }
  56. </script>
  57. <style scoped>
  58. .container {
  59. display: flex;
  60. flex-direction: column;
  61. height: 100vh;
  62. background-color: #FFFFFF;
  63. }
  64. .header {
  65. padding: 30rpx;
  66. border-bottom: 1rpx solid #F0F0F0;
  67. }
  68. .title {
  69. font-size: 36rpx;
  70. font-weight: bold;
  71. color: #333333;
  72. }
  73. .textarea {
  74. flex: 1;
  75. width: 100%;
  76. padding: 30rpx;
  77. box-sizing: border-box;
  78. background: #fff;
  79. font-size: 30rpx;
  80. color: #333;
  81. line-height: 1.6;
  82. }
  83. .footer {
  84. display: flex;
  85. justify-content: space-between;
  86. gap: 20rpx;
  87. padding: 30rpx;
  88. border-top: 1rpx solid #F0F0F0;
  89. background-color: #FFFFFF;
  90. }
  91. .btn {
  92. flex: 1;
  93. height: 88rpx;
  94. border-radius: 44rpx;
  95. font-size: 30rpx;
  96. display: flex;
  97. align-items: center;
  98. justify-content: center;
  99. }
  100. .btn::after {
  101. border: none;
  102. }
  103. .cancel {
  104. background: #f5f5f5;
  105. color: #666;
  106. border: none;
  107. }
  108. .save {
  109. background: #4FC3F7;
  110. color: #fff;
  111. border: none;
  112. }
  113. </style>