Browse Source

暂存产品资料

qymljy 1 year ago
parent
commit
e62b52ec9d

+ 1 - 1
src/HDrpManagement/prodectFileData/components/fileTable.vue

@@ -40,7 +40,7 @@ export default {
       })
 
       this.list = res.data
-      console.log(this.list);
+      console.log(this.list,'附件列表');
 
     }
   },

+ 30 - 12
src/HDrpManagement/prodectFileData/modules/add.vue

@@ -53,7 +53,7 @@
 </template>
 
 <script>
-import uploadFile from '../../../components/upload/hw_obs_upload.vue'
+import uploadFile from '../../../components/upload/hw_obs_upload_new.vue'
 import file_table from "../components/fileTable";
 import file_delete from "../components/fileDel"
 export default {
@@ -75,7 +75,8 @@ export default {
       },
       folderid:JSON.parse(sessionStorage.getItem('folderid')).appfolderid,
       attachmentids:[],
-      linksids:[]
+      linksids:[],
+      listFiles:[]
     }
   },
   components:{
@@ -87,7 +88,7 @@ export default {
     onShow() {
       this.drawer = true
       this.typeDetails();
-      this.plm_technicalinfoid = '0'
+      this.plm_technicalinfoid = '99999999'
     },
     onClose() {
       if (this.linksids.length > 0){
@@ -106,7 +107,6 @@ export default {
         if (!valid) return false
         const res = await this.$api.requested({
           "id": "20220926095703",
-          "version":1,
           "content": {
             "plm_technicalinfoid":0,
             "type":this.form.type,
@@ -114,8 +114,7 @@ export default {
           }
         })
         this.tool.showMessage(res,() => {
-          console.log("输出创建id")
-          console.log(res)
+          this.listFiles = this.$refs.list.list
           this.batchBinding(res.data)
           this.drawer = false
           this.$refs.form.resetFields()
@@ -130,14 +129,21 @@ export default {
       })
     },
     onCancel(){
+      console.log('执行1111')
       this.drawer = false
       this.$refs.form.resetFields()
       this.plm_technicalinfoid = ''
+      this.attachmentids = []
+      this.linksids = []
       this.form = {
         type:'',
         remarks:'',
         attinfos:[]
       }
+      this.listFiles = this.$refs.list.list
+      this.batchDeletion()
+
+
     },
     /*资料类别明细*/
     async typeDetails(){
@@ -158,15 +164,21 @@ export default {
       this.options = res.data
     },
     uploadSuccess(res){
-      console.log("输出")
-      if(typeof res.attinfos == 'string') {
+      console.log(res.data,'附件列表')
+      this.form.attinfos = this.form.attinfos.push(res.data.attachmentids)
+      this.$refs['upload'].dialogUploadVisible = false
+      this.$refs.list.listData()
+      let listFiles = this.$refs.list.list
+      console.log(listFiles,4444)
+      /*if(typeof res.attinfos == 'string') {
          this.$refs.list.listData()
       } else {
         console.log(res)
         this.bindEnclosure(res.data.attachmentids)
         this.form.attinfos = this.form.attinfos.push(res.data.attachmentids)
         this.$refs['upload'].dialogUploadVisible = false
-      }
+      }*/
+
 
     },
     async bindEnclosure(attachmentids){
@@ -177,7 +189,7 @@ export default {
         "method": "createFileLink",
         "content": {
           "ownertable": "plm_technicalinfo",
-          "ownerid": 0,
+          "ownerid": this.plm_technicalinfoid,
           "usetype": "default",
           "attachmentids": attachmentids
         }
@@ -205,6 +217,10 @@ export default {
     },
     /*批量绑定*/
     async batchBinding(id){
+      this.attachmentids = []
+      this.listFiles.forEach((item,index)=>{
+        this.attachmentids[index] = item
+      })
       const res = await this.$api.requested({
         "classname": "system.attachment.Attachment",
         "method": "createFileLink",
@@ -219,6 +235,10 @@ export default {
     },
     /*批量删除*/
     async batchDeletion(){
+      this.linksids = []
+      this.listFiles.forEach((item,index)=>{
+        this.linksids[index] = item.linksid
+      })
       const res = await this.$api.requested({
         "classname": "system.attachment.Attachment",
         "method": "deleteFileLink",
@@ -226,8 +246,6 @@ export default {
           "linksids": this.linksids
         }
       })
-      console.log("删除")
-      console.log(res)
       this.$refs.form.resetFields()
       this.plm_technicalinfoid = ''
       this.form = {

+ 2 - 2
src/HDrpManagement/prodectFileData/modules/edit.vue

@@ -4,7 +4,7 @@
     <el-drawer
       title="编辑资料"
       :visible.sync="drawer"
-      size="30%"
+      size="600px"
       direction="rtl"
       append-to-body>
       <div class="drawer__panel">
@@ -161,4 +161,4 @@ export default {
 
 <style scoped>
 
-</style>
+</style>

+ 237 - 0
src/components/upload/hw_obs_upload_new.vue

@@ -0,0 +1,237 @@
+<template>
+  <div>
+    <!-- 缩略图类型 -->
+    <div v-if="btntype === 'smallimage'" @click="dialogUploadVisible = true" class="small-image-upload-btn">
+      <i class="el-icon-plus"></i>
+    </div>
+    <!-- 图片类型 -->
+    <div v-else-if="btntype === 'image'" @click="dialogUploadVisible = true" class="image-upload-btn">
+      <i class="el-icon-plus"></i>
+    </div>
+    <!-- 宽图类型 -->
+    <div v-else-if="btntype === 'limage'" @click="dialogUploadVisible = true" class="image-upload-btn limage-upload-btn">
+      <i class="el-icon-plus"></i>
+    </div>
+    <!-- 图标类型 -->
+    <div v-else-if="btntype === 'icon'" >
+      <el-button icon="el-icon-paperclip" type="text" size="mini" @click="dialogUploadVisible = true" :disabled="status === '已结案' || status === '已失败' || disabled">附件上传</el-button>
+    </div>
+    <!-- 按钮类型 -->
+    <el-button v-else :type="status === '已结案' || status === '已失败' || disabled?'':'primary'" size="small" @click="dialogUploadVisible = true" icon="el-icon-upload" :disabled="status === '已结案' || status === '已失败' || disabled">上 传</el-button>
+    <el-dialog title="文件上传" :visible.sync="dialogUploadVisible" width="500px" append-to-body :close-on-click-modal="false" :before-close="clearFiles">
+      <selectMedia v-if = "!hidemediastock" @onShow="onShow" :accept="accept" :bindData="bindData" @onBindSuccess="onBindSuccess"></selectMedia>
+      <el-upload
+        style="width:100%"
+        ref="my-upload"
+        class="upload-demo"
+        :accept="accept"
+        action="#"
+        :auto-upload="false"
+        :show-file-list="false"
+        :on-change="handleChange"
+        drag
+        multiple>
+        <i class="el-icon-upload"></i>
+        <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
+      </el-upload>
+      <div class="progress_panel" v-for="file in filelist" :key="file.uid">
+        <img v-if="file.type === 'DOC' || file.type === 'DOCX'" width="30" src="../../assets/file_icons/word.png"
+          alt="">
+        <img v-else-if="file.type === 'PDF'" width="30" src="../../assets/file_icons/PDF.png" alt="">
+        <img v-else-if="file.type === 'MP4' || file.type === 'AVI'" width="30" src="../../assets/file_icons/video.png"
+          alt="">
+        <img v-else-if="file.type === 'XLS' || file.type === 'XLSX'" width="30" src="../../assets/file_icons/excel.png"
+          alt="">
+        <img v-else-if="file.type === 'PNG' || file.type === 'JPG'|| file.type === 'JPEG'" width="30"
+          src="../../assets/file_icons/image.png" alt="">
+        <img v-else-if="file.type === 'PPT' || file.type === 'PPTX'" width="30" src="../../assets/file_icons/PPT.png"
+          alt="">
+        <img v-else width="30" src="../../assets/file_icons/unknow.png" alt="">
+        <div>
+          <p v-if="file.progress === 100" style="float:right"><span style="color:#67C23A">●</span>上传成功</p>
+          <p>{{file.raw?file.raw.name:'暂无上传文件'}}</p>
+          <el-progress :percentage="file.progress" :show-text="false"></el-progress>
+        </div>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import selectMedia from '@/components/uploadBindMediaStock/index.vue'
+export default {
+  /*
+    folderid:文件夹id; 必填
+    btntype:展示上传按钮的类型;
+    accept:限制上传文件类型;
+    bindData:附件上传成功后对应需要绑定的数据信息,
+    hidemediastock:是否隐藏媒体库选择
+  */
+  props:['folderid','btntype','accept','bindData','hidemediastock','status','disabled'],
+  components:{
+    selectMedia
+  },
+  data () {
+    return {
+      dialogUploadVisible: false,
+      params: {
+        "classname": "system.attachment.huawei.OBS",
+        "method": "getFileName",
+        "content": {
+          "filename": '',
+          "filetype": '',
+          "parentid": ""//归属文件夹ID
+        }
+      },
+      file: {},
+      filelist: [],
+      count:0
+    }
+  },
+  methods: {
+    handleChange (file, filelist) {
+      console.log(file,file)
+      this.filelist = filelist
+      console.log(filelist,'1111')
+      var index = file.raw.name.lastIndexOf(".");
+      var ext = file.name.substr(index + 1);
+      this.params.content.filename = file.raw.name
+      this.params.content.filetype = ext
+      this.getUploadUrl(file, ext)
+    },
+
+    // 获取华为云上传地址
+    async getUploadUrl (file, ext) {
+      this.params.content.parentid = this.folderid
+      const res = await this.$api.requested(this.params)
+      let url = res.data.uploadurl
+      let obsfilename = res.data.serialfilename
+
+      this.upoladFileToServer(url, file, ext, obsfilename)
+    },
+
+    // 上传到华为云
+    async upoladFileToServer (url, file, ext, obsfilename) {
+      console.log(file)
+      let THIS = this
+      let config = {
+        headers: ext === 'pdf' ? { 'Content-Type': 'application/pdf' } : ext === 'svg'?{ 'Content-Type': 'image/svg+xml' } : { 'Content-Type': 'application/octet-stream' },
+        onUploadProgress: function (progressEvent) {
+          let percent = progressEvent.loaded / progressEvent.total * 100
+          THIS.filelist.forEach(e => {
+            if (e.uid === file.uid) {
+              THIS.$set(e, 'type', ext.toUpperCase());
+              THIS.$set(e, 'progress', percent);
+            }
+          })
+        },
+      }
+      const res = await this.$upload.hw_upload(url, file.raw, config)
+      this.createFileRecord(obsfilename)
+    },
+
+    // 上传成功以后生成附件记录
+    async createFileRecord (obsfilename,attinfos) {
+      let obj = {
+         "serialfilename": obsfilename
+      }
+      obj = Object.assign({},obj,this.bindData)
+      let param = {
+        "classname": "system.attachment.huawei.OBS",
+        "method": "uploadSuccess",
+        "content":obj
+      }
+      const res = await this.$api.requested(param)
+      this.count++
+      console.log(this.count);
+      console.log(this.filelist.length,'filelistL')
+      if (this.count == this.filelist.length) {
+
+        this.count = 0
+        console.log('触发');
+        this.$refs['my-upload'].clearFiles()
+        this.filelist = []
+        this.$emit('onSuccess',res)
+      }
+      // if (res.code ===  1) {
+      //   this.$emit('onSuccess',res)
+      // }
+    },
+
+    clearFiles () {
+      this.$refs['my-upload'].clearFiles()
+      this.filelist = []
+      this.dialogUploadVisible = false
+    },
+
+    // 监听打开媒体库的时候关闭上传弹窗
+    onShow () {
+      this.dialogUploadVisible = false
+    },
+    onBindSuccess (res) {
+      this.$emit('onSuccess',res)
+    }
+  }
+}
+
+</script>
+<style>
+.upload-demo > div {
+  width: 100% !important;
+}
+.upload-demo .el-upload-dragger {
+  width: 100% !important;
+}
+</style>
+<style scoped>
+.progress_panel {
+  display: flex;
+  align-items: center;
+  padding: 10px;
+  margin: 10px 0;
+  border-radius: 5px;
+  transition: linear 0.2s all;
+}
+.progress_panel:hover {
+  box-shadow: 0px 0px 5px #ccc;
+}
+.progress_panel > div {
+  flex: 1;
+  padding: 0 10px;
+}
+.progress_panel > div > p {
+  line-height: 30px;
+}
+.image-upload-btn{
+  display: flex;
+  align-items: center;
+  justify-content: space-around;
+  width: 150px;
+  height: 150px;
+  background: #FFFFFF;
+  border-radius: 4px 4px 4px 4px;
+  opacity: 1;
+  border: 1px solid #CCCCCC;
+  color: #CCCCCC;
+  font-size: 4rem;
+  cursor: pointer;
+}
+.small-image-upload-btn{
+  display: flex;
+  align-items: center;
+  justify-content: space-around;
+  width: 40px;
+  height: 40px;
+  border-radius: 4px 4px 4px 4px;
+  opacity: 1;
+  border: 1px solid #CCCCCC;
+  color: #CCCCCC;
+  font-size: 2rem;
+  cursor: pointer;
+  margin:0 auto;
+}
+.limage-upload-btn{
+  width: 384px !important;
+}
+</style>
+