소스 검색

文件上传

lizhenhao 2 년 전
부모
커밋
8fe015dd19
2개의 변경된 파일49개의 추가작업 그리고 21개의 파일을 삭제
  1. 5 4
      src/api/sys/OSSService.js
  2. 44 17
      src/views/modules/sys/project/AssessForm.vue

+ 5 - 4
src/api/sys/OSSService.js

@@ -94,13 +94,14 @@ export function beforeAvatarUpload (file) {
   return isLt2M
 }
 
-export function exnameFix (file) {
+export function exnameFix (file, isShow, names) {
   console.log('格式校验')
   const tmpcnt = file.name.lastIndexOf('.')
   const exname = file.name.substring(tmpcnt + 1) // 获取后缀名
-  const names = ['jpg', 'jpeg', 'webp', 'png', 'bmp', 'exe', 'yml', 'txt']
   if (names.indexOf(exname) < 0) {
-    Message.error('不支持的格式!')
+    if (isShow === '1') {
+      Message.error('不支持的格式!')
+    }
     return false
   }
   return true
@@ -128,7 +129,7 @@ export function httpRequest (file, name, type) { // 阿里云OSS上传
     }
   ).then(res => {
     console.log(res, 'res---header ')
-    return fileName
+    file.file.url = fileName
   }).catch(err => {
     console.log(err, 'err')
   })

+ 44 - 17
src/views/modules/sys/project/AssessForm.vue

@@ -297,14 +297,15 @@
           </el-col>
 
           <el-upload ref="upload" style="display: inline-block; margin-left: 5em; :show-header='status'" action=""
-                     :limit="5" :http-request="httpRequest"
+                     :limit="999" :http-request="httpRequest"
                      multiple
                      :on-exceed="(files, fileList) =>{
-                      $message.warning(`当前限制选择 5 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
+                      $message.warning(`当前限制选择 999 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
                      }"
                      :on-remove="handleRemove"
                      :show-file-list="false"
-                     :on-change="changes">
+                     :on-change="changes"
+                     :file-list="filesArra2">
             <el-button type="info" size="mini">点击上传</el-button>
           </el-upload>
 
@@ -327,10 +328,14 @@
             :data="dataListNew"
             :checkbox-config="{}">
             <vxe-column type="seq" width="40"></vxe-column>
-            <vxe-column title="文件名称" field="name"></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>
+              </template>
+            </vxe-column>
             <vxe-column title="创建人" field="createBy"></vxe-column>
             <vxe-column title="创建时间" field="createDate"></vxe-column>
-            <vxe-column title="文件描述" field="description"></vxe-column>
+<!--            <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>
@@ -353,9 +358,9 @@
   import OSSSerive, {
     httpRequest,
     handleRemove,
-    fileName,
-    exnameFix
+    fileName
   } from '@/api/sys/OSSService'
+  import moment from 'moment'
   export default {
     data () {
       return {
@@ -420,8 +425,6 @@
     },
     methods: {
       init (method, id) {
-        this.dataListNew = []
-        this.dataList = []
         this.ossService.findFileList(id).then(({data}) => {
           data.forEach((item) => {
             item.name = item.attachmentName
@@ -486,6 +489,7 @@
         this.visible = true
         this.loading = false
         this.$nextTick(() => {
+          this.$refs.upload.clearFiles()
           this.$refs.inputForm.resetFields()
           if (method === 'edit' || method === 'view') { // 修改或者查看
             this.loading = true
@@ -529,25 +533,48 @@
         this.fileList = handleRemove()
       },
       changes (file, fileList) {
-        console.log ("22", fileList)
+        console.log('file', file)
+        console.log('22', fileList)
         this.dataListNew = []
-        this.dataList.forEach((item) =>{
+        this.dataList.forEach((item) => {
           this.dataListNew.push(item)
         })
-        fileList.forEach((item) =>{
+        fileList.forEach((item) => {
+          item.createDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
+          item.createBy = this.$store.state.user.name
           this.dataListNew.push(item)
         })
-        console.log("11",this.dataList)
-        console.log("33",this.dataListNew)
+        console.log('11', this.dataList)
+        console.log('33', this.dataListNew)
         const isLt2M = file.size / 1024 / 1024 < 300
         if (isLt2M === false) {
           this.$message.error('文件大小不能超过 ' + 300 + 'M !')
           this.fileList = []
           this.filesArra2 = []
         } else {
-          if (exnameFix(file) === false) {
-            this.fileList = []
-            this.filesArra2 = []
+          // if (exnameFix(file, '1') === false) {
+          //   this.fileList = []
+          //   this.filesArra2 = []
+          // }
+        }
+      },
+      showFile (row) {
+        let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
+        if (row.url !== null && row.url !== undefined && row.url !== '') {
+          if (suffix === 'pdf') {
+            window.open('https://view.xdocin.com/xdoc?xdoc=' + row.url, '_blank')
+          } else if (suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
+            window.open('http://ow365.cn/?i=25008&furl=' + row.url, '_blank')
+          } else {
+            window.open('https://view.officeapps.live.com/op/view.aspx?src=' + row.url, '_blank')
+          }
+        } else if (row.raw.url !== null && row.raw.url !== undefined && row.raw.url !== '') {
+          if (suffix === 'pdf') {
+            window.open('https://view.xdocin.com/xdoc?xdoc=' + row.raw.url, '_blank')
+          } else if (suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
+            window.open('http://ow365.cn/?i=25008&furl=' + row.raw.url, '_blank')
+          } else {
+            window.open('https://view.officeapps.live.com/op/view.aspx?src=' + row.raw.url, '_blank')
           }
         }
       }