1. uni.previewImage({
  2. urls: this.file.map(i => i.url ),
  3. current: idx
  4. })
  1. async handleSubmit() {
  2. if (this.submiting) {
  3. return
  4. }
  5. this.submiting = true
  6. try {
  7. let error = ''
  8. if (!this.form.landName.trim()) {
  9. error = '请输入地块名称'
  10. } else if (!this.form.plantType) {
  11. error = '请选择种植/养殖类型'
  12. } else if (!this.form.plantCategory) {
  13. error = `请选择${this.typeLabel}品类`
  14. } else if (!this.form.plantVarieties.trim()) {
  15. error = `请输入${this.typeLabel}品种`
  16. } else if (!this.form.plantQuantity || !(this.form.plantQuantity > 0)) {
  17. error = `请输入${this.typeLabel}数量`
  18. } else if (!/^\d{1,4}(\.\d{1,2})?$/.test(this.form.plantQuantity)) {
  19. error = `请输入最多两位小数,最多四位数的${this.typeLabel}数量`
  20. } else if (!this.form.cropsImgs || this.form.cropsImgs.length < 5) {
  21. error = this.plantType === '2' ? '请上传养殖动物图片' : '请上传农作物图片'
  22. }
  23. if (error) {
  24. uni.showToast({ icon: 'none', title: error })
  25. return
  26. }
  27. await serviceAPI.saveBlock({ ...this.form, farmerId: this.authInfo.farmerId })
  28. uni.showToast({ icon: 'none', title: '保存成功' })
  29. uni.navigateBack()
  30. } catch (error) {
  31. uni.showToast({ icon: 'none', title: error.message })
  32. throw error
  33. } finally {
  34. this.submiting = false
  35. }
  36. },
  1. :class="{'active':(current === idx)}"

代码格式化(全部格式化、局部格式化)

:::info yarn lint —write ::: image.png

  1. yarn prettier --list-different src/pages --write

image.pngimage.png