gaoluyang
2 天以前 2323c93baf009d2f60acaec545622611673203cb
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
<template>
  <div>
    <el-dialog title="上传"
               v-model="dialogVisitable" width="400px" @close="cancel">
      <el-form :model="form" ref="formRef" label-width="120px">
        <el-form-item label="生产前" prop="fileList0">
          <el-upload
              v-model:file-list="fileList0"
              ref="fileUpload0"
              :action="uploadFileUrl"
              multiple
              name="files"
              :data="{type: 0}"
              style="width: 100%"
              :headers="headers"
              :before-upload="handleBeforeUpload"
              :on-success="handleUploadSuccess"
          >
            <el-button type="primary">上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="生产后" prop="fileList1">
          <el-upload
              v-model:file-list="fileList1"
              ref="fileUpload1"
              :action="uploadFileUrl"
              multiple
              name="files"
              :data="{type: 1}"
              style="width: 100%"
              :headers="headers"
              :before-upload="handleBeforeUpload"
              :on-success="handleUploadSuccess1"
          >
            <el-button type="primary">上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="生产问题" prop="fileList2">
          <el-upload
              v-model:file-list="fileList2"
              ref="fileUpload2"
              :action="uploadFileUrl"
              multiple
              name="files"
              :data="{type: 2}"
              style="width: 100%"
              :headers="headers"
              :before-upload="handleBeforeUpload"
              :on-success="handleUploadSuccess2"
          >
            <el-button type="primary">上传</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancel">取消</el-button>
          <el-button type="primary" @click="submitForm">保存</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import {reactive, ref} from "vue";
import {addOrEditInspectionTask} from "@/api/inspectionManagement/index.js";
import {getToken} from "@/utils/auth.js";
 
const { proxy } = getCurrentInstance()
const emit = defineEmits()
const dialogVisitable = ref(false);
const data = reactive({
  form: {
    id: '',
    storageBlobDTO: {}
  },
})
 
const { form } = toRefs(data)
const fileList0 = ref([])
const fileList1 = ref([])
const fileList2 = ref([])
const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + '/common/minioUploads'); // 上传文件服务器地址
const headers = ref({ Authorization: "Bearer " + getToken() });
 
// 打开弹框
const openDialog = async (row) => {
  dialogVisitable.value = true
  form.value.id = row.id
}
// 上传前校检格式和大小
function handleBeforeUpload(file) {
  
  return true
}
// 上传成功回调
function handleUploadSuccess(res, file) {
  if (res.code === 200) {
    console.log("上传成功", res);
    proxy.$modal.msgSuccess("文件上传成功");
    console.log('fileList0---', fileList0)
  } else {
    proxy.$modal.msgError(res.msg)
    proxy.$refs.fileUpload0.handleRemove(file)
  }
}
function handleUploadSuccess1(res, file) {
  if (res.code === 200) {
    proxy.$modal.msgSuccess("文件上传成功");
  } else {
    proxy.$modal.msgError(res.msg)
    proxy.$refs.fileUpload1.handleRemove(file)
  }
}
function handleUploadSuccess2(res, file) {
  if (res.code === 200) {
    proxy.$modal.msgSuccess("文件上传成功");
  } else {
    proxy.$modal.msgError(res.msg)
    proxy.$refs.fileUpload2.handleRemove(file)
  }
}
 
// 提交合并表单
const submitForm = () => {
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
      // 初始化 storageBlobDTO 为一个空数组
      form.value.storageBlobDTO = []
      // 合并所有 fileList 到 storageBlobDTO
      const allFiles = [
        ...fileList0.value,
        ...fileList1.value,
        ...fileList2.value
      ]
      // 将文件列表赋值给 form
      form.value.storageBlobDTO = allFiles
      // 提交数据
      addOrEditInspectionTask(form.value).then(() => {
        cancel()
        proxy.$modal.msgSuccess('提交成功')
      })
    }
  })
}
// 关闭合并表单
const cancel = () => {
  proxy.resetForm("formRef")
  dialogVisitable.value = false
  emit('closeDia')
}
defineExpose({ openDialog })
</script>
 
<style scoped>
 
</style>