Просмотр исходного кода

oss文件上传代码修改完善

sunruiqi 2 лет назад
Родитель
Сommit
e27bb12d46
1 измененных файлов с 14 добавлено и 6 удалено
  1. 14 6
      src/views/modules/notify/NotifyForm.vue

+ 14 - 6
src/views/modules/notify/NotifyForm.vue

@@ -123,11 +123,12 @@
            </el-form-item>
       </el-col>
 
-        <el-upload ref="upload" style="display: inline-block;" action="" :limit="1" :http-request="httpRequest"
-                   :on-remove="handleRemove" :on-change="onChange" :before-upload="beforeAvatarUpload"
-                   :on-success="handleUploadSuccess" :file-list="fileS">
-          <el-button type="info" size="mini">点击上传</el-button>
-        </el-upload>
+          <el-upload ref="upload" style="display: inline-block; margin-left: 5em;" action=""
+                     :limit="1" :http-request="httpRequest"
+                     :on-remove="handleRemove" :on-change="onChange" :before-upload="beforeAvatarUpload"
+                     :on-success="handleUploadSuccess" :file-list="fileS">
+            <el-button type="info" size="mini">点击上传</el-button>
+          </el-upload>
 
         </el-row>
     </el-form>
@@ -143,6 +144,7 @@
   import UserSelect from '@/components/userSelect'
   import NotifyService from '@/api/notify/NotifyService'
   import {client, headers} from '@/api/sys/OSSService'
+
   export default {
     data () {
       return {
@@ -256,7 +258,13 @@
           this.$message.error('不支持的格式!')
           return false
         }
-        const fileName = uploadFileName
+        const now = new Date()
+        const year = now.getFullYear()
+        const month = now.getMonth()+1
+        const day = now.getDate()>10?now.getDate():'0'+now.getDate()
+        const filePath = 'attachment-file/workAttachment/'+year+'/'+month+'/'+day+'/'+now.getTime()
+        console.log(filePath, '文件存储路径')
+        const fileName = filePath + uploadFileName
         console.log(fileName, '文件名')
         client.put(
           fileName,