Browse Source

Merge remote-tracking branch 'origin/master'

lizhenhao 2 years atrás
parent
commit
76d7a46cd1

+ 104 - 2
src/api/sys/OSSService.js

@@ -1,6 +1,23 @@
 import OSS from 'ali-oss'
-// or
-// const OSS = require('ali-oss')
+import { Message } from 'element-ui'
+import request from '@/utils/httpRequest'
+
+export default class OSSSerive {
+  saveMsg (param) {
+    return request({
+      url: '/oss/file/saveMsg',
+      method: 'post',
+      data: param
+    })
+  }
+  findFileList (attachmentId) {
+    return request({
+      url: '/oss/file/findFileList',
+      method: 'get',
+      params: {attachmentId: attachmentId}
+    })
+  }
+}
 
 export const client = new OSS({
   region: 'oss-cn-hangzhou', // oss地址
@@ -30,3 +47,88 @@ export const headers = {
   'x-oss-forbid-overwrite': 'true'
   // 'secure': 'true'
 }
+
+export function onChange (file, files) {
+  console.log(file, 'file', files, 'Filest')
+  return files
+}
+
+export function handleUploadSuccess (response, file, fileS) {
+  console.log(response, file, fileS, 'response, file, fileList')
+}
+
+export function handleRemove (e, files) {
+  return files
+}
+
+export function fileName (file) {
+  console.log('文件名称处理')
+  const tmpcnt = file.file.name.lastIndexOf('.')
+  let fileName = file.file.name.substring(0, tmpcnt)
+  // 将单引号‘’都转换成',将双引号“”都转换成"
+  fileName = fileName.replace(/’|‘/g, '\'').replace(/“|”/g, '')
+  // 将中括号【】转换成[],将大括号{}转换成{}
+  fileName = fileName.replace(/【/g, '(').replace(/】/g, ')').replace(/{/g, '(').replace(/}/g, ')')
+  fileName = fileName.replace(/\[/g, '(').replace(/]/g, ')').replace(/{/g, '(').replace(/}/g, ')')
+  // 将逗号,转换成,,将:转换成:
+  fileName = fileName.replace(/,/g, ',').replace(/:/g, ':')
+  // 将中文——转换为英文-
+  fileName = fileName.replace(/—/g, '-')
+  fileName = fileName.replace(/……/g, '')
+  fileName = fileName.replace(/±/g, '')
+  fileName = fileName.replace(/#/g, '')
+  fileName = fileName.replace(/%/g, '')
+  fileName = fileName.replace(/Π/g, '')
+  fileName = fileName.replace(/π/g, '')
+  fileName = fileName.replace(/·/g, '.')
+  console.log('文件名处理结果', fileName)
+  return fileName
+}
+
+export function beforeAvatarUpload (file) {
+  // 文件大小校验
+  const isLt2M = file.size / 1024 / 1024 < 300
+  if (!isLt2M) {
+    this.$message.error('文件大小不能超过 300M !')
+  }
+  return isLt2M
+}
+
+export function exnameFix (file) {
+  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('不支持的格式!')
+    return false
+  }
+  return true
+}
+
+export function httpRequest (file, name, type) { // 阿里云OSS上传
+  console.log('开始上传')
+  // 判断扩展名
+  const tmpcnt = file.file.name.lastIndexOf('.') // 获取.的下标
+  const exname = file.file.name.substring(tmpcnt + 1) // 获取后缀名
+  console.log(exname, '后缀名')
+  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/' + type + '/' + year + '/' + month + '/' + day + '/' + now.getTime()
+  console.log(filePath, '文件存储路径')
+  const fileName = filePath + name + '.' + exname
+  console.log(fileName, '文件名')
+  client.put(
+    fileName,
+    file.file,
+    {
+      headers
+    }
+  ).then(res => {
+    console.log(res, 'res---header ')
+  }).catch(err => {
+    console.log(err, 'err')
+  })
+}

+ 72 - 130
src/views/modules/notify/NotifyForm.vue

@@ -1,99 +1,99 @@
 <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">
+  <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="[
+                          :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-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="[
+                          :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-input v-model="inputForm.title" placeholder="请填写标题"     ></el-input>
+            </el-form-item>
+          </el-col>
+          <el-col :span="24">
             <el-form-item label="内容" prop="content"
-                :rules="[
+                          :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-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}/sys/file/webupload/upload?uploadPath=/notify/notify`"
-                    :headers="{token: $cookie.get('token')}"
-                    :on-preview="(file, fileList) => {$window.location.href = file.url}"
-                    :on-success="(response, file, fileList) => {
+              <el-upload ref="files"
+                         :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/notify/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) => {
+                         :on-error="(response) => {
                       $message.error(response.message)
                     }"
-                    :on-remove="(file, fileList) => {
+                         :on-remove="(file, fileList) => {
                       $http.delete(`/sys/file/webupload/deleteByUrl?url=${file.url}`).then(({data}) => {
                         $message.success(data)
                       })
                       inputForm.files = fileList.map(item => item.url).join('|')
                     }"
-                    :before-remove="(file, fileList) => {
+                         :before-remove="(file, fileList) => {
                       return $confirm(`确定移除 ${file.name}?`)
                     }"
-                    multiple
-                    :limit="5"
-                    :on-exceed="(files, fileList) =>{
+                         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'">
+                         :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="[
+                          :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="[
+              <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="接收人">
+              <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"
+                size="small"
                 :data="notifyRecordDTOList"
                 style="width: 100%">
                 <el-table-column
@@ -120,29 +120,21 @@
                   width="180">
                 </el-table-column>
               </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-form-item>
+          </el-col>
         </el-row>
-    </el-form>
-    <span slot="footer" class="dialog-footer">
+      </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>
+    </el-dialog>
+  </div>
 </template>
 
 <script>
   import UserSelect from '@/components/userSelect'
   import NotifyService from '@/api/notify/NotifyService'
-  import {client, headers} from '@/api/sys/OSSService'
   export default {
     data () {
       return {
@@ -225,56 +217,6 @@
             })
           }
         })
-      },
-      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')
-        })
       }
     }
   }

+ 80 - 1
src/views/modules/sys/project/AssessForm.vue

@@ -296,6 +296,45 @@
             </el-form-item>
           </el-col>
 
+          <el-upload ref="upload" style="display: inline-block; margin-left: 5em; :show-header='status'" action=""
+                     :limit="5" :http-request="httpRequest"
+                     multiple
+                     :on-exceed="(files, fileList) =>{
+                      $message.warning(`当前限制选择 5 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
+                     }"
+                     :on-remove="handleRemove"
+                     :on-change="changes"
+                     :file-list="dataList">
+            <el-button type="info" size="mini">点击上传</el-button>
+          </el-upload>
+
+          <vxe-table
+            style="margin-left: 5em"
+            border="inner"
+            auto-resize
+            resizable
+            height="auto"
+            :loading="loading"
+            size="small"
+            ref="projectTable"
+            show-header-overflow
+            show-overflow
+            highlight-hover-row
+            :menu-config="{}"
+            :print-config="{}"
+            @sort-change="sortChangeHandle"
+            :sort-config="{remote:true}"
+            :data="dataList"
+            :checkbox-config="{}">
+            <vxe-column type="seq" width="40"></vxe-column>
+            <vxe-column title="文件名称" field="name"></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>
+              </template>
+            </vxe-column>
+          </vxe-table>
+
         </el-row>
       </el-form>
       <span slot="footer" class="dialog-footer">
@@ -308,9 +347,16 @@
 
 <script>
   import ProjectService from '@/api/sys/ProjectService'
+  import OSSSerive, {
+    httpRequest,
+    handleRemove,
+    fileName,
+    exnameFix
+  } from '@/api/sys/OSSService'
   export default {
     data () {
       return {
+        dataList: [],
         title: '',
         method: '',
         visible: false,
@@ -356,15 +402,29 @@
           invoiceMessage: '',
           isCommissionReimbursement: '',
           itemType: ''
-        }
+        },
+        filesArra2: [],
+        fileList: [],
+        isFlag: true
       }
     },
     projectService: null,
+    ossService: null,
     created () {
+      this.ossService = new OSSSerive()
       this.projectService = new ProjectService()
     },
     methods: {
       init (method, id) {
+        this.filesArra2 = []
+        this.ossService.findFileList(id).then(({data}) => {
+          this.dataList = data
+          data.forEach((item) => {
+            console.log(item)
+            item.name = item.attachmentName
+            this.filesArra2.push(item)
+          })
+        })
         this.method = method
         this.inputForm = {
           customerName: '',
@@ -454,6 +514,25 @@
       close () {
         this.$refs.inputForm.resetFields()
         this.visible = false
+      },
+      httpRequest (file) {
+        httpRequest(file, fileName(file), 'project')
+      },
+      handleRemove () {
+        this.fileList = handleRemove()
+      },
+      changes (file) {
+        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 = []
+          }
+        }
       }
     }
   }