sunruiqi 2 年 前
コミット
2a020c87c4

+ 29 - 16
src/api/sys/OSSService.js

@@ -1,19 +1,32 @@
-import request from '@/utils/httpRequest'
+import OSS from 'ali-oss'
+// or
+// const OSS = require('ali-oss')
 
-export default class FileService {
-  uploadFile (formData, uploadPath) {
-    return request({
-      url: `/oss/oss/getAccess`,
-      method: 'post',
-      data: null
-    })
-  }
+export const client = new OSS({
+  region: 'oss-cn-hangzhou', // oss地址
+  accessKeyId: 'LTAI5tQDWoM9c1WyJNPs86rX', // 通过阿里云控制台创建的AccessKey ID。
+  accessKeySecret: '84dDIx4edT1n78KUOqqSmDZ35pchJv', // 通过阿里云控制台创建的AccessKey Secret。
+  bucket: 'xgxm-test', // 仓库名字
+  useFetch: true, // 支持上传大于100KB的文件
+  secure: false // 返回的url为https
+})
 
-  getUrl (params) {
-    return request({
-      url: `/sys/file/getUrl`,
-      method: 'get',
-      params: params
-    })
-  }
+export const headers = {
+  // 指定该Object被下载时网页的缓存行为。
+  'Cache-Control': 'no-cache',
+  // 指定该Object被下载时的名称。
+  'Content-Disposition': 'inline',
+  // 指定该Object被下载时的内容编码格式。
+  'Content-Encoding': 'UTF-8',
+  // 指定过期时间。
+  Expires: 'Wed, 08 Jul 2023 16:57:01 GMT',
+  // 指定Object的存储类型。
+  'x-oss-storage-class': 'Standard',
+  // 指定Object的访问权限。
+  // 'x-oss-object-acl': 'private',
+  // 设置Object的标签,可同时设置多个标签。
+  'x-oss-tagging': 'Tag1=1&Tag2=2',
+  // 指定CopyObject操作时是否覆盖同名目标Object。此处设置为true,表示禁止覆盖同名Object。
+  'x-oss-forbid-overwrite': 'true'
+  // 'secure': 'true'
 }

+ 0 - 223
src/components/antIcon/SunTest.vue

@@ -1,223 +0,0 @@
-<template>
-  <div>
-    <el-dialog
-      :title="title"
-      :close-on-click-modal="false"
-      append-to-body
-      v-dialogDrag
-      :visible.sync="visible">
-      <el-form size="small" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view' || method === 'read'?'readonly':''" :disabled="method==='view' || method === 'read'" @keyup.enter.native="doSubmit()"
-               label-width="120px" @submit.native.prevent>
-        <el-row  :gutter="15">
-          <el-col :span="24">
-            <el-form-item label="类型" prop="type"
-                          :rules="[
-                  {required: true, message:'类型不能为空', trigger:'blur'}
-                 ]">
-              <el-select v-model="inputForm.type" placeholder="请选择"  style="width: 100%;">
-                <el-option
-                  v-for="item in $dictUtils.getDictList('oa_notify_type')"
-                  :key="item.value"
-                  :label="item.label"
-                  :value="item.value">
-                </el-option>
-              </el-select>
-            </el-form-item>
-          </el-col>
-          <el-col :span="24">
-            <el-form-item label="标题" prop="title"
-                          :rules="[
-                  {required: true, message:'标题不能为空', trigger:'blur'}
-                 ]">
-              <el-input v-model="inputForm.title" placeholder="请填写标题"     ></el-input>
-            </el-form-item>
-          </el-col>
-          <el-col :span="24">
-            <el-form-item label="内容" prop="content"
-                          :rules="[
-                  {required: true, message:'内容不能为空', trigger:'blur'}
-                 ]">
-              <el-input type="textarea"   :rows="8" v-model="inputForm.content" placeholder="请填写内容"     ></el-input>
-            </el-form-item>
-          </el-col>
-          <el-col :span="24">
-            <el-form-item label="附件" prop="files">
-              <el-upload ref="files"
-                         :action="`${this.$http.BASE_URL}/oss/oss/upload?storeAs=notify`"
-                         :headers="{token: $cookie.get('token')}"
-                         :on-preview="(file, fileList) => {$window.location.href = file.url}"
-                         :on-success="(response, file, fileList) => {
-                       inputForm.files = fileList.map(item => item.url || item.response.url).join('|')
-                    }"
-                         :on-error="(response) => {
-                      $message.error(response.message)
-                    }"
-                         :on-remove="(file, fileList) => {
-                      $http.delete(`/oss/oss/deleteByUrl?url=${file.url}`).then(({data}) => {
-                        $message.success(data)
-                      })
-                      inputForm.files = fileList.map(item => item.url).join('|')
-                    }"
-                         :before-remove="(file, fileList) => {
-                      return $confirm(`确定移除 ${file.name}?`)
-                    }"
-                         multiple
-                         :limit="5"
-                         :on-exceed="(files, fileList) =>{
-                      $message.warning(`当前限制选择 5 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
-                    }"
-                         :file-list="filesArra">
-                <el-button size="small" type="primary">点击上传</el-button>
-                <div slot="tip" class="el-upload__tip">添加相关附件</div>
-              </el-upload>
-            </el-form-item>
-          </el-col>
-          <el-col :span="24"  v-if="method !== 'read'">
-            <el-form-item label="状态" prop="status"
-                          :rules="[
-                  {required: true, message:'状态不能为空', trigger:'blur'}
-                 ]">
-              <el-radio-group v-model="inputForm.status">
-                <el-radio v-for="item in $dictUtils.getDictList('oa_notify_status')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
-              </el-radio-group>
-            </el-form-item>
-          </el-col>
-          <el-col :span="24">
-            <el-form-item label="接收人" prop="notifyRecordIds"
-                          :rules="[
-                  {required: true, message:'接收人不能为空', trigger:'blur'}
-                 ]">
-              <user-select  :value="inputForm.notifyRecordIds" @getValue='(value) => {inputForm.notifyRecordIds=value}'></user-select>
-            </el-form-item>
-          </el-col>
-          <el-col :span="24" v-if="method ==='view' && inputForm.status === '1'">
-            <el-form-item label="接收人">
-              <el-table
-                size="small"
-                :data="notifyRecordDTOList"
-                style="width: 100%">
-                <el-table-column
-                  prop="userDTO.name"
-                  label="接收人"
-                  width="180">
-                </el-table-column>
-                <el-table-column
-                  prop="userDTO.officeDTO.name"
-                  label="接收部门"
-                  width="180">
-                </el-table-column>
-                <el-table-column
-                  prop="readFlag"
-                  label="阅读状态">
-                  <template slot-scope="scope">
-                    <el-tag type="success" v-if="scope.row.readFlag === '1'"> {{ $dictUtils.getDictLabel("oa_notify_read", scope.row.readFlag, '-') }}</el-tag>
-                    <el-tag type="danger" v-if="scope.row.readFlag === '0'"> {{ $dictUtils.getDictLabel("oa_notify_read", scope.row.readFlag, '-') }}</el-tag>
-                  </template>
-                </el-table-column>
-                <el-table-column
-                  prop="readDate"
-                  label="阅读时间"
-                  width="180">
-                </el-table-column>
-              </el-table>
-            </el-form-item>
-          </el-col>
-        </el-row>
-      </el-form>
-      <span slot="footer" class="dialog-footer">
-      <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
-      <el-button size="small" type="primary" v-if="method != 'view' && method != 'read'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
-    </span>
-    </el-dialog>
-  </div>
-</template>
-
-<script>
-  import UserSelect from '@/components/userSelect'
-  import NotifyService from '@/api/notify/NotifyService'
-  export default {
-    data () {
-      return {
-        title: '',
-        method: '',
-        visible: false,
-        loading: false,
-        filesArra: [],
-        notifyRecordDTOList: [],
-        inputForm: {
-          id: '',
-          type: '',
-          title: '',
-          content: '',
-          files: '',
-          status: '',
-          notifyRecordIds: ''
-        }
-      }
-    },
-    components: {
-      UserSelect
-    },
-    notifyService: null,
-    created () {
-      this.notifyService = new NotifyService()
-    },
-    methods: {
-      init (method, id) {
-        this.method = method
-        this.inputForm.id = id
-        if (method === 'add') {
-          this.title = `新建通知`
-        } else if (method === 'edit') {
-          this.title = '修改通知'
-        } else if (method === 'view') {
-          this.title = '查看通知'
-        } else if (method === 'read') {
-          this.title = '阅读通知'
-        }
-        this.visible = true
-        this.loading = false
-        this.$nextTick(() => {
-          this.$refs.inputForm.resetFields()
-          this.$refs.files.clearFiles()
-          this.filesArra = []
-          if (method === 'edit' || method === 'view' || method === 'read') { // 修改或者查看
-            this.loading = true
-            this.notifyService.query({
-              id: this.inputForm.id,
-              isSelf: method === 'read'
-            }).then(({data}) => {
-              this.inputForm = this.recover(this.inputForm, data)
-              this.notifyRecordDTOList = data.notifyRecordDTOList
-              this.inputForm.files.split('|').forEach((item) => {
-                if (item.trim().length > 0) {
-                  this.filesArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
-                }
-              })
-              if (method === 'read') {
-                this.$emit('refreshDataList')
-              }
-              this.loading = false
-            })
-          }
-        })
-      },
-      // 表单提交
-      doSubmit () {
-        this.$refs['inputForm'].validate((valid) => {
-          if (valid) {
-            this.loading = true
-            this.notifyService.save(this.inputForm).then(({data}) => {
-              this.loading = false
-              this.visible = false
-              this.$message.success(data)
-              this.$emit('refreshDataList')
-            }).catch(() => {
-              this.loading = false
-            })
-          }
-        })
-      }
-    }
-  }
-</script>

+ 59 - 1
src/views/modules/notify/NotifyForm.vue

@@ -122,6 +122,13 @@
               </el-table>
            </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-row>
     </el-form>
     <span slot="footer" class="dialog-footer">
@@ -135,6 +142,7 @@
 <script>
   import UserSelect from '@/components/userSelect'
   import NotifyService from '@/api/notify/NotifyService'
+  import {client, headers} from '@/api/sys/OSSService'
   export default {
     data () {
       return {
@@ -217,7 +225,57 @@
             })
           }
         })
+      },
+      onChange (file, files) {
+        // console.log(file, 'file', files, 'Filest');
+        this.fileList = files
+      },
+      handleUploadSuccess (response, file, files) {
+        console.log(response, file, files, 'response, file, fileList')
+      },
+      handleRemove (e, files) {
+        this.fileList = files
+      },
+      beforeAvatarUpload (file) {
+        // 文件大小校验
+        const isLt2M = file.size / 1024 / 1024 < 10
+        if (!isLt2M) {
+          this.$message.error('文件大小不能超过 10M !')
+        }
+        return isLt2M
+      },
+      httpRequest (file) {//阿里云OSS上传
+        //判断扩展名
+        const tmpcnt = file.file.name.lastIndexOf(".") // 获取.的下标
+        const uploadFileName = file.file.name.substring(0, tmpcnt) // 获取文件名
+        console.log(uploadFileName, '文件名——uploadFileName')
+        const exname = file.file.name.substring(tmpcnt + 1) // 获取后缀名
+        console.log(exname, '后缀名');
+        const names = ['jpg', 'jpeg', 'webp', 'png', 'bmp', 'exe', 'yml', 'txt']
+        if (names.indexOf(exname) < 0) {
+          this.$message.error("不支持的格式!")
+          return false
+        }
+        const fileName = uploadFileName
+        console.log(fileName, '文件名')
+        client.put(
+          fileName,
+          file.file,
+          {
+            headers
+          },
+        ).then(res => {
+          console.log(res, 'res---header ')
+          // this.handleUploadSuccess()
+          //   if (res.url) {
+          //     this.url.push(res.url)
+          //   } else {
+          //     this.$message.error('文件上传失败')
+          //   }
+        }).catch(err => {
+          console.log(err, 'err')
+        })
       }
     }
   }
-</script>
+</script>