Commit be8a7ba5de205735c3a765a8081c90fd91cd8e58

Authored by fengtao
1 parent 1d3fb3f1

fix:修复意见反馈图片上传大小

... ... @@ -31,7 +31,8 @@
31 31 <view class="info" style="margin-top: 15rpx;background: rgba(1, 1, 1, 0);">
32 32 <view class="info-contain">
33 33 <u-form-item label="图片" prop="feedbackInfo.images" borderBottom ref="item1">
34   - <u-upload :sizeType="compressed" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="6"></u-upload>
  34 + <u-upload :sizeType="compressed" :fileList="fileList1"
  35 + @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="6"></u-upload>
35 36 </u-form-item>
36 37 </view>
37 38 </view>
... ... @@ -89,12 +90,14 @@ export default {
89 90 'feedbackInfo.phone': {
90 91 type: 'number',
91 92 min: 11,
  93 + max:11,
92 94 message: '请填写手机或者手机格式错误',
93 95 trigger: ['blur', 'change']
94 96 },
95 97 'feedbackInfo.qq': {
96 98 type: 'number',
97   - min: 8,
  99 + min: 5,
  100 + max:10,
98 101 message: '请填写qq或者qq格式错误',
99 102 trigger: ['blur', 'change']
100 103 },
... ... @@ -134,25 +137,38 @@ export default {
134 137 let lists = [].concat(event.file);
135 138 let fileListLen = this[`fileList${event.name}`].length;
136 139 lists.map(item => {
  140 + if(item.size>5242880){
  141 + this[`fileList${event.name}`].push({
  142 + ...item,
  143 + status: 'error',
  144 + message: '上传失败'
  145 + });
  146 + }else{
137 147 this[`fileList${event.name}`].push({
138 148 ...item,
139 149 status: 'uploading',
140 150 message: '上传中'
141 151 });
  152 + }
142 153 });
143 154 for (let i = 0; i < lists.length; i++) {
144   - const result = await this.uploadFilePromise(lists[i].url);
145   - let item = this[`fileList${event.name}`][fileListLen];
146   - this[`fileList${event.name}`].splice(
147   - fileListLen,
148   - 1,
149   - Object.assign(item, {
150   - status: 'success',
151   - message: '',
152   - url: result
153   - })
154   - );
155   - fileListLen++;
  155 + const judgeImageSize=lists[0].size
  156 + if(judgeImageSize>5242880){
  157 + return uni.$u.toast('图片限定5M')
  158 + }else{
  159 + const result = await this.uploadFilePromise(lists[i].url);
  160 + let item = this[`fileList${event.name}`][fileListLen];
  161 + this[`fileList${event.name}`].splice(
  162 + fileListLen,
  163 + 1,
  164 + Object.assign(item, {
  165 + status: 'success',
  166 + message: '',
  167 + url: result
  168 + })
  169 + );
  170 + fileListLen++;
  171 + }
156 172 }
157 173 },
158 174 uploadFilePromise(url) {
... ... @@ -174,12 +190,16 @@ export default {
174 190 formData: {},
175 191 success: res => {
176 192 setTimeout(() => {
177   - if (res) {
  193 + if(res.statusCode===200){
  194 + if(res.data){
178 195 let objImage = JSON.parse(res.data);
179 196 if (this.feedbackData.feedbackInfo.images.length < 6) {
180 197 this.feedbackData.feedbackInfo.images.push(objImage.fileStaticUri);
181 198 }
182 199 resolve(res.data?.fileStaticUri);
  200 + }
  201 + }else{
  202 + return uni.$u.toast('图片上传失败')
183 203 }
184 204 }, 1000);
185 205 }
... ...