Kaynağa Gözat

文件上传

lizhenhao 2 yıl önce
ebeveyn
işleme
9370e01b39

+ 7 - 0
src/api/sys/OSSService.js

@@ -31,6 +31,13 @@ export default class OSSSerive {
       params: {id: id}
     })
   }
+  downLoadAttach (url) {
+    return request({
+      url: '/oss/file/downLoadAttach',
+      method: 'get',
+      params: {file: url}
+    })
+  }
 }
 
 export const client = new OSS({

+ 50 - 6
src/views/modules/sys/project/AssessForm.vue

@@ -329,7 +329,16 @@
             <vxe-column type="seq" width="40"></vxe-column>
             <vxe-column title="文件名称" field="name">
               <template slot-scope="scope">
-                <el-link  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>
+                <div v-if="ifName(scope.row) === true">
+                  <el-image
+                    style="width: 100px; height: 100px"
+                    :src="getsrc(scope.row)"
+                    :preview-src-list="srcList">
+                  </el-image>
+                </div>
+                <div v-else>
+                  <el-link  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>
+                </div>
               </template>
             </vxe-column>
             <vxe-column title="创建人" field="createBy"></vxe-column>
@@ -337,7 +346,7 @@
 <!--            <vxe-column title="文件描述" field="description"></vxe-column>-->
             <vxe-column title="操作" width="200px" fixed="right" align="center">
               <template  slot-scope="scope">
-                <el-button type="text"  icon="el-icon-delete" size="small" @click="del(scope.row.id)">删除</el-button>
+                <el-button type="text"  icon="el-icon-delete" size="small" @click="deleteMsgById(scope.row, scope.$rowIndex)">删除</el-button>
                 <el-button type="text"  icon="el-icon-edit" size="small" @click="toHref(scope.row)">下载</el-button>
               </template>
             </vxe-column>
@@ -349,7 +358,8 @@
       <el-image-viewer
         v-if="showViewer"
         :on-close="closeViewer"
-        :url-list="[url]" />
+        :url-list="[url]"
+        zIndex="9999"/>
       <span slot="footer" class="dialog-footer">
       <el-button size="small" @click="close()" icon="el-icon-circle-close">关闭</el-button>
       <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
@@ -366,6 +376,7 @@
     fileName
   } from '@/api/sys/OSSService'
   import moment from 'moment'
+  import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
   export default {
     data () {
       return {
@@ -426,6 +437,7 @@
         rowurl: ''
       }
     },
+    components: { ElImageViewer },
     projectService: null,
     ossService: null,
     created () {
@@ -433,7 +445,34 @@
       this.projectService = new ProjectService()
     },
     methods: {
+      async getsrc (row) {
+        console.log('rrrr', row)
+        if (row.id === null || row.id === undefined || row.id === '') {
+          await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
+            return data.data
+          })
+        } else {
+          return row.url
+        }
+      },
+      ifName (row) {
+        let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
+        if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
+          return true
+        } else {
+          return false
+        }
+      },
       async toHref (row) {
+        let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
+        if (suffix === 'pdf' || suffix === 'txt') {
+          if (row.id === null || row.id === undefined || row.id === '') {
+            this.ossService.downLoadAttach(row.raw.url)
+          } else {
+            this.ossService.downLoadAttach(row.url)
+          }
+          return
+        }
         console.log('rr', row)
         const link = document.createElement('a')
         link.setAttribute('download', row.name)
@@ -444,7 +483,7 @@
             link.click()
           })
         } else {
-          link.setAttribute('href', row.url)
+          link.setAttribute('href', row.temporaryUrl)
           link.click()
         }
       },
@@ -613,7 +652,7 @@
             return
           } else {
             await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
-              this.onPreview(data)
+              this.onPreview(data.data)
             })
             return
           }
@@ -647,7 +686,12 @@
         }
         this.refreshList()
       },
-      deleteMsgById (row) {
+      deleteMsgById (row, index) {
+        console.log(index)
+        this.dataListNew.splice(index, 1)
+        if (row.id !== null && row.id !== '' && row.id !== undefined) {
+          this.ossService.deleteMsgById(row.id)
+        }
       }
     }
   }