曹睿
2025-04-25 ec1bef3a37e8dcdf22f1bf52e7c272a18306f4b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<template>
  <view class="feedback-container">
    <!-- 问题类型选择 -->
    <wd-cell-group title="问题类型" border>
      <view class="radio-group">
        <label v-for="item in feedbackTypes" :key="item.value" class="radio-item">
          <text class="radio-text">{{ item.label }}</text>
          <radio
            :value="item.value"
            :checked="feedbackType === item.value"
            color="#0083ff"
            class="radio-button"
            style="transform: scale(0.8)"
            @click="handleRadioChange(item.value)"
          />
        </label>
      </view>
    </wd-cell-group>
 
    <!-- 问题描述 -->
    <wd-cell-group title="问题描述" border>
      <wd-textarea
        v-model="description"
        placeholder="请详细描述您遇到的问题或建议..."
        :maxlength="500"
        show-count
        :rows="5"
      />
    </wd-cell-group>
 
    <!-- 图片上传 -->
    <wd-cell-group title="相关截图(选填)" border>
      <view class="upload-box">
        <wd-upload
          v-model="fileList"
          :max-count="3"
          :before-read="beforeRead"
          @delete="handleDelete"
        />
      </view>
    </wd-cell-group>
 
    <!-- 联系方式 -->
    <wd-cell-group title="联系方式(选填)" border>
      <wd-input v-model="contact" placeholder="请输入您的手机号或邮箱" clearable />
    </wd-cell-group>
 
    <!-- 提交按钮 -->
    <view class="submit-btn">
      <wd-button type="primary" block :loading="submitting" @click="handleSubmit">
        提交反馈
      </wd-button>
    </view>
 
    <wd-toast />
  </view>
</template>
 
<script lang="ts" setup>
import { ref } from "vue";
import { useToast } from "wot-design-uni";
import { checkLogin } from "@/utils/auth";
 
const toast = useToast();
 
// 检查登录状态
onLoad(() => {
  if (!checkLogin()) return;
});
 
// 问题类型选项
const feedbackTypes = [
  { label: "功能异常", value: "bug" },
  { label: "优化建议", value: "suggestion" },
  { label: "其他问题", value: "other" },
];
 
// 表单数据
const feedbackType = ref("bug");
const description = ref("");
const fileList = ref<any[]>([]);
const contact = ref("");
const submitting = ref(false);
 
// 图片上传前的校验
const beforeRead = (file: any) => {
  // 验证文件类型
  const validTypes = ["image/jpeg", "image/png", "image/gif"];
  if (!validTypes.includes(file.type)) {
    toast.error("请上传 jpg、png 或 gif 格式的图片");
    return false;
  }
  // 验证文件大小(限制为 5MB)
  if (file.size > 5 * 1024 * 1024) {
    toast.error("图片大小不能超过 5MB");
    return false;
  }
  return true;
};
 
// 删除图片
const handleDelete = (detail: any) => {
  const index = detail.index;
  fileList.value.splice(index, 1);
};
 
// 处理单选框变化
const handleRadioChange = (value: string) => {
  feedbackType.value = value;
};
 
// 提交反馈
const handleSubmit = async () => {
  // 表单验证
  if (!description.value.trim()) {
    toast.error("请描述您遇到的问题");
    return;
  }
 
  submitting.value = true;
  try {
    // TODO: 调用提交反馈的接口
    await new Promise((resolve) => setTimeout(resolve, 1500)); // 模拟提交
    toast.success("提交成功");
    // 重置表单
    description.value = "";
    fileList.value = [];
    contact.value = "";
 
    // 延迟返回上一页
    setTimeout(() => {
      uni.navigateBack();
    }, 1500);
  } catch {
    toast.error("提交失败,请重试");
  } finally {
    submitting.value = false;
  }
};
</script>
 
<style lang="scss" scoped>
.feedback-container {
  min-height: 100vh;
  padding: 20rpx 0;
  background-color: #f5f5f5;
 
  :deep(.wd-cell-group__title) {
    padding: 20rpx 30rpx 10rpx;
    font-size: 28rpx;
    color: #666;
  }
 
  .radio-group {
    padding: 4rpx 0;
    background-color: #fff;
  }
 
  .radio-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10rpx 30rpx;
    border-bottom: 1px solid #eee;
 
    &:last-child {
      border-bottom: none;
    }
  }
 
  .radio-text {
    font-size: 22rpx;
    color: #333;
  }
 
  .upload-box {
    padding: 20rpx 30rpx;
  }
 
  .submit-btn {
    margin: 40rpx 30rpx;
  }
 
  :deep(.wd-textarea) {
    padding: 20rpx 30rpx;
    background-color: #fff;
  }
 
  .radio-button {
    margin-right: -8rpx;
  }
}
</style>