Fixiaobai
2023-12-11 5d64e2573f5e0b9dc06891cf441c02b057310e1c
src/views/quality/exception/exception.vue
@@ -31,8 +31,8 @@
            action="/mes/exception/upload"
            :headers="headers"
            :before-upload="submitUpload"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :on-preview="handlePreview"
            :on-success="uploadSuccess"
            :data="paramData"
            :file-list="fileList"
@@ -41,7 +41,7 @@
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传jpg图片,且不超过2MB
              只能上传jpg/png图片,且不超过5MB
            </div>
          </el-upload>
        </el-col>
@@ -53,6 +53,9 @@
        @refreshDataList="getData"
      ></table-form>
    </div>
    <el-dialog title="图片预览" width="60%" :visible.sync="previewVisible" top="5vh">
        <img style="width:100%;height: 70vh" :src="dialogImageUrl" alt="">
    </el-dialog>
  </div>
</template>
<style lang="scss" scoped>
@@ -111,6 +114,8 @@
  },
  data() {
    return {
      previewVisible: false,
      dialogImageUrl: null,
      fileList: [],
      headers: {
        Authorization: 'Bearer ' + getStore({ name: 'access_token' })
@@ -293,7 +298,7 @@
      }
    },
    handlePreview(file) {
      window.open(file.url)
      this.previewVisible = true
    },
    uploadSuccess(response, file, fileList) {
      this.getFileList()
@@ -312,6 +317,7 @@
              fileEl = {}
              fileEl.name = attachment.original
              fileEl.url = attachment.url
              this.dialogImageUrl = attachment.url
              fileEl.id = attachment.id
              fileEl.fileName = attachment.fileName
              this.fileList.push(fileEl)
@@ -320,10 +326,21 @@
        })
      }
    },
    submitUpload() {
    submitUpload(file) {
      console.info(this.currentRow && this.currentRow.id)
      if (this.currentRow && this.currentRow.id) {
        const maxSize = 5 * 1024 *1024
        let jpgType = 'image/jpeg'
        let pngType = 'image/png'
        if(file.type != jpgType && file.type != pngType){
          this.$message.error('只能上传.jpg/.png类型的图片')
          return false
        }
        if(file.szie > maxSize){
          this.$message.error('图片大小不能超过5MB')
        }
        this.paramData.exceptionId = this.currentRow.id
      } else {
        this.$message.error('请先选择生产异常记录')
        return false