index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="bg-gray-50 p-2 min-h-screen">
  3. <view class="bg-white rounded-xl shadow-sm p-4">
  4. <!-- 标题 -->
  5. <view class="text-gray-900 text-lg font-medium mb-6 flex justify-between items-center">
  6. <text>意见反馈</text>
  7. <text class="text-sm text-blue-600 font-normal" @click="goToFeedbackList">反馈列表</text>
  8. </view>
  9. <!-- 表单内容 -->
  10. <view class="space-y-6">
  11. <!-- 反馈输入框(带边框) -->
  12. <view>
  13. <textarea
  14. v-model="feedback.content"
  15. placeholder="请输入"
  16. class="bg-transparent outline-none border-gray-200 border-solid border-1 rounded-lg p-4 min-h-[180rpx] resize-none"
  17. ></textarea>
  18. </view>
  19. <!-- 图片上传区域(使用plus.png) -->
  20. <view>
  21. <text class="text-gray-700 text-sm block mb-3">图片信息</text>
  22. <view class="border-2 border-dashed border-gray-200 rounded-lg p-4 w-32 h-32 flex items-center justify-center relative" @click="chooseImage">
  23. <!-- 初始状态显示plus.png -->
  24. <image
  25. src="/static/plus.png"
  26. class="w-42 h-42 text-gray-400"
  27. v-if="!feedback.imageUrl"
  28. />
  29. <!-- 已选择图片时显示预览 -->
  30. <image
  31. :src="feedback.imageUrl"
  32. class="w-full h-full object-cover rounded"
  33. v-else
  34. />
  35. <!-- 已选择图片时显示删除按钮 -->
  36. <view v-if="feedback.imageUrl" class="absolute top-2 right-2 w-6 h-6 bg-black/50 rounded-full flex items-center justify-center" @click.stop="removeImage">
  37. <text class="text-white text-xs">×</text>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 确认按钮 -->
  44. <view class="mt-6 px-8">
  45. <view
  46. class="w-full text-center bg-blue-600 text-white py-3 rounded-2xl font-medium shadow-sm hover:bg-blue-700 transition-colors"
  47. @click="submitFeedback"
  48. >
  49. <text>确认</text>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script setup>
  55. import { ref } from 'vue'
  56. // 反馈数据
  57. const feedback = ref({
  58. content: '',
  59. imageUrl: ''
  60. })
  61. // 跳转到反馈列表
  62. const goToFeedbackList = () => {
  63. uni.navigateTo({
  64. url: '/pages/feedback/list/index'
  65. })
  66. }
  67. // 选择图片
  68. const chooseImage = () => {
  69. // 如果已有图片则先清空
  70. if (feedback.value.imageUrl) {
  71. feedback.value.imageUrl = ''
  72. return
  73. }
  74. // 调用图片选择API
  75. uni.chooseImage({
  76. count: 1,
  77. sizeType: ['original', 'compressed'],
  78. sourceType: ['album', 'camera'],
  79. success: (res) => {
  80. feedback.value.imageUrl = res.tempFilePaths[0]
  81. }
  82. })
  83. }
  84. // 移除图片
  85. const removeImage = () => {
  86. feedback.value.imageUrl = ''
  87. }
  88. // 提交反馈
  89. const submitFeedback = () => {
  90. // 验证反馈内容
  91. if (!feedback.value.content.trim()) {
  92. uni.showToast({
  93. title: '请输入反馈内容',
  94. icon: 'none'
  95. })
  96. return
  97. }
  98. // 提交逻辑
  99. console.log('提交反馈:', feedback.value)
  100. uni.showToast({
  101. title: '反馈提交成功',
  102. icon: 'none'
  103. })
  104. // 实际项目中这里调用接口提交数据
  105. // 清空表单
  106. feedback.value.content = ''
  107. feedback.value.imageUrl = ''
  108. }
  109. </script>