|
95 | 95 | if (newVal == this.myIndex) { |
96 | 96 | this.isShow = true |
97 | 97 | if (!this.initDone) { |
98 | | - this.$nextTick(function(){ |
| 98 | + this.$nextTick(function() { |
99 | 99 | this.$refs.paging.reload(true) |
100 | 100 | this.initDone = true |
101 | 101 | }) |
|
257 | 257 | console.log('allInOneSign.type', type) |
258 | 258 | let result = null, |
259 | 259 | isShowToast = true; |
260 | | - uni.showLoading({ |
261 | | - title: '签到中', |
262 | | - mask: true, |
263 | | - }) |
264 | 260 | switch (type) { |
265 | 261 | case Constant.signType.generalSign: |
| 262 | + uni.showLoading({ |
| 263 | + title: '签到中', |
| 264 | + mask: true, |
| 265 | + }) |
266 | 266 | result = await CourseBiz.generalSign(this, activity) |
267 | 267 | break; |
268 | 268 | case Constant.signType.photoSign: |
269 | | - let uploadData = await CourseBiz.chaoxingPanUpload(this, activity, params.filePath) |
270 | | - if (uploadData) { |
271 | | - // isShowToast = false |
272 | | - result = await CourseBiz.photoSign( |
273 | | - this, |
274 | | - this.checkedActivity, |
275 | | - uploadData.objectId |
276 | | - ) |
277 | | - // uni.hideLoading() |
278 | | - // if (responseData !== true) { |
279 | | - // plus.nativeUI.toast(responseData) |
280 | | - // return null; |
281 | | - // } |
282 | | - // // plus.nativeUI.toast('签到成功') |
| 269 | + isShowToast = false |
| 270 | + /** |
| 271 | + * @description 确认选择该图片进行签到 |
| 272 | + */ |
| 273 | + const chooseImageHandler = async (res, uploadData) => { |
| 274 | + console.log(`chooseImageHandler`, res, uploadData) |
| 275 | + uni.closePreviewImage() |
| 276 | + if (Number(res.tapIndex) !== 0) { |
| 277 | + uni.showToast({ |
| 278 | + title: '取消签到', |
| 279 | + icon: 'error', |
| 280 | + }) |
| 281 | + return null; |
| 282 | + } |
| 283 | + uni.showLoading({ |
| 284 | + title: '签到中', |
| 285 | + mask: true, |
| 286 | + }) |
| 287 | + |
| 288 | + let responseData = await CourseBiz.photoSign(this, |
| 289 | + this.checkedActivity, uploadData.objectId) |
| 290 | + uni.hideLoading() |
| 291 | + if (responseData !== true) { |
| 292 | + // 这里出问题了 |
| 293 | + uni.showToast({ |
| 294 | + title: responseData, |
| 295 | + position: 'center' |
| 296 | + }) |
| 297 | + return null; |
| 298 | + } |
| 299 | + uni.showToast({ |
| 300 | + title: '签到成功', |
| 301 | + icon: 'success' |
| 302 | + }) |
| 303 | + |
| 304 | + } |
| 305 | + |
| 306 | + /** |
| 307 | + * @description 获取图片信息成功,提示是否选择该图片 |
| 308 | + */ |
| 309 | + const previewHandler = (image, uploadData) => { |
| 310 | + uni.hideLoading() |
| 311 | + uni.showModal({ |
| 312 | + title: '提示', |
| 313 | + content: '上传图片成功,请长按', |
| 314 | + success: () => { |
| 315 | + uni.previewImage({ |
| 316 | + current: 0, |
| 317 | + urls: [image.path], |
| 318 | + longPressActions: { |
| 319 | + itemList: ['选择该图片签到', '取消签到'], |
| 320 | + success: (res) => chooseImageHandler(res, |
| 321 | + uploadData), |
| 322 | + }, |
| 323 | + }) |
| 324 | + } |
| 325 | + }) |
| 326 | + } |
| 327 | + |
| 328 | + /** |
| 329 | + * @description 压缩图片成功回调 |
| 330 | + */ |
| 331 | + const compressImageSuccessHandler = async ({ |
| 332 | + tempFilePath |
| 333 | + }) => { |
| 334 | + console.log(`compressImageSuccessHandler `, tempFilePath) |
283 | 335 | // uni.showToast({ |
284 | | - // title:'签到成功', |
285 | | - // icon:'success' |
| 336 | + // title: '压缩图片成功', |
| 337 | + // position: 'center' |
286 | 338 | // }) |
287 | | - } else |
288 | | - result = uploadData |
| 339 | + let uploadData = await CourseBiz.chaoxingPanUpload(this, activity, tempFilePath) |
| 340 | + console.log(`uploadData`, uploadData) |
| 341 | + if (uploadData?.objectId === undefined) { |
| 342 | + uni.hideLoading() |
| 343 | + console.error(`uploadData?.objectId === undefined`, `上传失败`) |
| 344 | + uni.showToast({ |
| 345 | + title: '上传失败', |
| 346 | + icon: 'error' |
| 347 | + }) |
| 348 | + throw new Error('上传图片失败') |
| 349 | + } |
| 350 | + console.log(`uploadData.previewUrl`, uploadData.previewUrl) |
| 351 | + uni.getImageInfo({ |
| 352 | + src: uploadData.previewUrl, |
| 353 | + success: (res) => previewHandler(res, uploadData), |
| 354 | + fail() { |
| 355 | + uni.hideLoading() |
| 356 | + plus.nativeUI.confirm( |
| 357 | + `请确认图片的格式是不是jpg或者png\n下面是图片地址:\n${uploadData.previewUrl}\n可以复制到浏览器打开看下是什么情况`, |
| 358 | + (e) => { |
| 359 | + if (e.index === 0) |
| 360 | + uni.setClipboardData({ |
| 361 | + data: uploadData.previewUrl |
| 362 | + }) |
| 363 | + else if (e.index === 1) |
| 364 | + uni.showToast({ |
| 365 | + title: '取消签到', |
| 366 | + icon: 'error' |
| 367 | + }) |
| 368 | + }, { |
| 369 | + title: '上传成功但获取预览图失败', |
| 370 | + buttons: ['复制链接', '知道了'] |
| 371 | + }) |
| 372 | + } |
| 373 | + }) |
| 374 | + } |
| 375 | + |
| 376 | + uni.showLoading({ |
| 377 | + title: '压缩并上传中', |
| 378 | + mask: true, |
| 379 | + }) |
| 380 | + |
| 381 | + /** |
| 382 | + * @description 先压缩图片,避免超时 |
| 383 | + */ |
| 384 | + uni.compressImage({ |
| 385 | + src: params.filePath, |
| 386 | + success: compressImageSuccessHandler, |
| 387 | + fail: () => { |
| 388 | + uni.hideLoading() |
| 389 | + uni.showToast({ |
| 390 | + title: '压缩图片失败', |
| 391 | + icon: 'error' |
| 392 | + }) |
| 393 | + } |
| 394 | + }) |
| 395 | + // let uploadData = await CourseBiz.chaoxingPanUpload(this, activity, params.filePath) |
| 396 | + // if (uploadData) { |
| 397 | + // // isShowToast = false |
| 398 | + // result = await CourseBiz.photoSign( |
| 399 | + // this, |
| 400 | + // this.checkedActivity, |
| 401 | + // uploadData.objectId |
| 402 | + // ) |
| 403 | + // // uni.hideLoading() |
| 404 | + // // if (responseData !== true) { |
| 405 | + // // plus.nativeUI.toast(responseData) |
| 406 | + // // return null; |
| 407 | + // // } |
| 408 | + // // // plus.nativeUI.toast('签到成功') |
| 409 | + // // uni.showToast({ |
| 410 | + // // title:'签到成功', |
| 411 | + // // icon:'success' |
| 412 | + // // }) |
| 413 | + // } else |
| 414 | + // result = uploadData |
289 | 415 | break; |
290 | 416 | case Constant.signType.QRCodeSign: |
| 417 | + uni.showLoading({ |
| 418 | + title: '签到中', |
| 419 | + mask: true, |
| 420 | + }) |
291 | 421 | console.log('allInOneSign.params', params) |
292 | 422 | result = await CourseBiz.QRCodeSign(this, activity, params.enc) |
293 | 423 | break; |
294 | 424 | case Constant.signType.locationSign: |
| 425 | + uni.showLoading({ |
| 426 | + title: '签到中', |
| 427 | + mask: true, |
| 428 | + }) |
295 | 429 | console.log('Constant.signType.locationSign', Constant.signType.locationSign) |
296 | 430 | result = await CourseBiz.locationSign(this, activity, { |
297 | 431 | address: params.address, |
|
0 commit comments