zhengnaiwen_citu hace 3 meses
padre
commit
721d28f4a7

+ 19 - 0
src/utils/request.js

@@ -2,6 +2,7 @@ import axios from 'axios'
 import { getToken } from '@/utils/auth'
 import qs from 'qs'
 import router from '@/router'
+import { blobToJson } from '@/utils'
 const service = axios.create({
   baseURL: process.env.VUE_APP_BASE_API,
   timeout: 120000 // request timeout
@@ -25,6 +26,24 @@ service.interceptors.response.use(
   async response => {
     const res = response.data
 
+    if (response.request.responseType === 'blob') {
+      // 返回的文件流当报错时转化成json
+      if (response.headers['content-type'] === 'application/json') {
+        try {
+          const result = await blobToJson(res)
+          return Promise.reject(result.msg)
+        } catch (error) {
+          return Promise.reject(error)
+        }
+      }
+      const name = response.headers['content-disposition']
+      // console.log(name)
+      return {
+        data: res,
+        name: name ? decodeURI(name.replace('attachment;filename=', '')) : '未命名'
+      }
+    }
+
     // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
     if ([50008, 50012, 50014, 402000, 401].includes(res.code)) {
       router.push({ path: '/login-local' })

+ 10 - 4
src/views/dataOrigin/unstructuredData/manualCollection/components/imageImportEdit.vue

@@ -173,13 +173,15 @@ export default {
         { slotName: 'systemInfo' }
       ],
       formQuery: {},
-      id: null
+      id: null,
+      itemData: null
     }
   },
   methods: {
     async open (item) {
       this.show = true
       this.loading = false
+      this.itemData = null
       this.formQuery = this.formItems.reduce((res, val) => {
         if (val.key) {
           res[val.key] = null
@@ -193,6 +195,7 @@ export default {
         return
       }
       this.id = item.id
+      this.itemData = { ...item }
       Object.keys(this.formQuery).forEach(key => {
         this.formQuery[key] = item[key] || null
       })
@@ -202,10 +205,11 @@ export default {
         this.previewUrl = null
         return
       }
-      this.file = item.image_path
+      // this.file = item.image_path
       try {
         const { data } = await getBusinessCardImage(item.image_path)
-        console.log(data)
+        this.file = data
+        this.previewUrl = new Blob([data], { type: 'image/jpeg' })
         this.handlePreview(this.file)
       } catch (error) {
         this.$snackbar.error(error)
@@ -234,6 +238,7 @@ export default {
       try {
         const { data } = await businessCardParse(query)
         this.id = data.id
+        this.itemData = { ...data }
         Object.keys(this.formQuery).forEach(key => {
           this.formQuery[key] = data[key] || null
         })
@@ -249,8 +254,9 @@ export default {
         this.$snackbar.error('ID获取异常')
         return
       }
+      Object.assign(this.itemData, this.formQuery)
       try {
-        await updateBusinessCardStatus(this.formQuery, this.id)
+        await updateBusinessCardStatus(this.itemData, this.id)
         this.$snackbar.success('更新成功')
       } catch (error) {
         this.$snackbar.error(error)