yz3456
2024-05-10 fa3615d2dcad3eb020a7ac59581546a6560e37ae
ruoyi-ui/src/views/device/equipmentInfo.vue
@@ -24,7 +24,7 @@
        <el-input v-model="formData.name" placeholder="请输入设备名称" clearable :style="{width: '100%'}" :disabled="dsb"></el-input>
      </el-form-item>
      <el-form-item label="时间" prop="happenTime">
        <el-input v-model="formData.happenTime" placeholder="请输入时间" clearable :style="{width: '100%'}" :disabled="dsb">
        <el-input v-model="formData.happenTime" placeholder="请输入时间" type="date" clearable :style="{width: '100%'}" :disabled="dsb">
        </el-input>
      </el-form-item>
      <el-form-item label="购买人" prop="buyer">
@@ -67,8 +67,10 @@
        :disabled="!btn"
        :class="{ hide: !btn }"
      :on-change="handleChange"
     :auto-upload="false"
      >
        <div v-if="uploading" class="upload-status">正在上传...</div>
        <i v-if="!uploading" slot="default" class="el-icon-plus"></i>
        <div slot="file" slot-scope="{file}">
          <img
@@ -106,23 +108,32 @@
        </div>
      </el-upload>
    <el-button
                style="margin-left: 10px"
                size="small"
                type="success"
              v-if="btn"
                @click="picUpload"
              >上传到服务器</el-button>
      <h4 class="form-header">其他附件 </h4>
      <el-upload
        action=""
        :file-list="fileListOther"
        class="upload-demo"
        multiple
        list-type="picture-card"
        :on-preview="handleFileCardPreview"
        :on-remove="handleRemoveFile"
        :http-request="requestUpload"
        :show-file-list="true"
      ref="upload1"
      :on-remove="handleRemoveFile"
        :http-request="requestUpload1"
         :file-list="fileListOther"
         :on-change="handleChange1"
         :auto-upload="false"
        :disabled="!btn"
        :class="{ hide: !btn }"
      >
        <div v-if="uploading" class="upload-status">正在上传...</div>
        <i v-if="!uploading" slot="default" class="el-icon-plus"></i>
        <div slot="file" slot-scope="{file}">
          <!-- 添加video元素用于显示视频 -->
@@ -168,7 +179,14 @@
      </el-upload>
    <el-button
                style="margin-left: 10px"
                size="small"
                type="success"
                v-if="btn"
                @click="fileUpload"
              >上传到服务器</el-button>
                           <h4 class="form-header"> </h4>
      <el-form-item size="large">
        <el-button v-if="isShow" type="primary" @click="submitForm" :disabled="dsb">修改</el-button>
      </el-form-item>
@@ -199,9 +217,13 @@
      fileList:[
      ],
      fileList1:[],
      uploadFileList:[],
      uploadFileList1:[],
      fileListOther:[
      ],
      fileListOther1:[],
      dsb:true,
      btn:false,
      isShow:true,
@@ -214,7 +236,7 @@
        content: undefined,
        remark: undefined,
        status:undefined,
        url: undefined,
        url: "",
        happenTime:undefined
      },
      typeOptions2: [
@@ -312,17 +334,27 @@
        {
          if(paths[i]!="") {
            let pth = paths[i].substr(paths[i].length - 4, paths[i].length)
              let pth = paths[i].substr(paths[i].length - 4, paths[i].length)
          //   alert(pth)
              if (_this.fot.includes(pth) === true)
             {
                if(paths[i][0]=="/")
                _this.fileList.push({name:paths[i],url: process.env.VUE_APP_BASE_TRUE_API+paths[i].substr(1),res:false})
               else
                  _this.fileList.push({name:paths[i],url: process.env.VUE_APP_BASE_TRUE_API+paths[i],res:false})
               }
              else {
                // alert(paths[i])
              // alert()
                let nms = paths[i].split("\/")
                let nm = nms[nms.length - 1]
               if(paths[i][0]=="/")
                _this.fileListOther.push({name:nm, url: process.env.VUE_APP_BASE_TRUE_API+paths[i].substr(1),res:false})
                else
                _this.fileListOther.push({name:nm, url: process.env.VUE_APP_BASE_TRUE_API+paths[i],res:false})
            if (_this.fot.includes(pth) === true)
              _this.fileList.push({name:paths[i],url: process.env.VUE_APP_BASE_TRUE_API+paths[i]})
            else {
              // alert(paths[i])
              let nms = paths[i].split("\/")
              let nm = nms[nms.length - 1]
              _this.fileListOther.push({name:nm, url: process.env.VUE_APP_BASE_TRUE_API+paths[i]})
             }
            }
          }
        }
        this.loading = false;
      });
@@ -332,6 +364,45 @@
  },
  mounted() {},
  methods: {
    getData(){
      const id = this.$route.params && this.$route.params.id;
      let _this = this
      if (id) {
        this.loading = true;
        getEquipmentInfo(id).then((response) => {
          this.formData = response.data;
          if(this.formData.status==1)
            this.formData.status = '是'
          else
          this.formData.status = '否'
          let paths = response.data.url.split(",");
          for(let i = 0; i < paths.length; i++)
          {
            if(paths[i]!="") {
                let pth = paths[i].substr(paths[i].length - 4, paths[i].length)
            //   alert(pth)
                if (_this.fot.includes(pth) === true)
               {
              console.log()
                 }
                else {
                  let nms = paths[i].split("\/")
                  let nm = nms[nms.length - 1]
                 if(paths[i][0]=="/")
                  _this.fileListOther1.push({name:nm, url: process.env.VUE_APP_BASE_TRUE_API+paths[i].substr(1),res:false})
                  else
                  _this.fileListOther1.push({name:nm, url: process.env.VUE_APP_BASE_TRUE_API+paths[i],res:false})
               }
              }
          }
          _this.fileListOther = _this.fileListOther1
          this.loading = false;
        });
      }
    },
    /** 查询类别信息 */
    // getCateInfor()
    // {
@@ -344,13 +415,7 @@
    //   })
    // },
    submitForm() {
      let ul = this.fileList.map(function (elem){
        return elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
      }).join(",")
      let uls = this.fileListOther.map(function (elem){
        return elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
      }).join(",")
      this.formData.url = ul+","+uls
      this.$refs['elForm'].validate(valid => {
if(this.formData.status=='是')
@@ -396,18 +461,93 @@
      })
    },
    handleRemoveFile(file) {
    //判读是否是之前的图片
      let res = false
      for(let i = 0; i < this.fileListOther.length; i++)
      {
        if(this.fileListOther[i].url==file.url)
       {
          if(this.fileListOther[i].res==false)
             res = true
          else
          {
             this.$delete(this.uploadFileList1, Math.abs(i - this.uploadFileList1.length-1))
          }
          this.$delete(this.fileListOther,i);
       }
      }
      let ul = ""
      this.fileList.map(function (elem){
            if(elem.res==false)
               ul = ul + ","+elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
      })
      let uls = ""
      this.fileListOther.map(function (elem){
        if(elem.res==false)
               uls = uls +","+elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
      })
      this.formData.url = ul+","+uls;
    //  alert(this.formData.url)
   if(this.formData.status=='是')
             this.formData.status = 1
           else
           this.formData.status = 0
      if(res==true){
         updateEquipment(this.formData).then(response => {
          this.$modal.msgSuccess("删除成功");
          // this.open = false;
         });
      }
    },
    handleRemove(file) {
      for(let i = 0; i < this.fileList.length; i++)
      {
        if(this.fileList[i].url==file.url)
          this.$delete(this.fileList,i);
      }
      //判断是否是之前的图片
        let res = false
      //  alert(this.fileList.length)
        for(let i = 0; i < this.fileList.length; i++)
        {
          if(this.fileList[i].url==file.url)
         {
            //原来图像标记为false
            //alert(this.fileList[i].res)
           if(this.fileList[i].res==false)
            res = true
           else
           {
            //  alert(this.uploadFileList.length)
            //  alert(87)
             this.$delete(this.uploadFileList, Math.abs(i - this.uploadFileList.length-1))
                //     alert(this.uploadFileList.length)
             }
            this.$delete(this.fileList,i);
        }
        }
        let ul = ""
        this.fileList.map(function (elem){
         if(elem.res==false)
            ul = ul + ","+elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
        })
        let uls = ""
        this.fileListOther.map(function (elem){
          if(elem.res==false)
            uls = uls +","+elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
        })
        this.formData.url = ul+","+uls;
      if(this.formData.status=='是')
                this.formData.status = 1
              else
              this.formData.status = 0
        if(res==true){
           updateEquipment(this.formData).then(response => {
            this.$modal.msgSuccess("删除成功");
           });
        }
    },
    handleFileCardPreview(file){
      this.dialogFileUrl = file.url;
@@ -452,46 +592,137 @@
      this.$router.push("/familymodel/Device/memo/" + id );
    },
    requestUpload(params)
    {
      var file = params.file;
      var formData = new FormData();
      formData.append('uploadFile', file);
      let _this = this
      this.uploading = true;
      uploadPic(formData).then(response => {
        let pth = response.data.originalFilename.substr(response.data.originalFilename.length-4, response.data.originalFilename.length)
        this.uploading = false;
        this.$modal.msgSuccess("上传成功");
        if(_this.fot.includes(pth) === true)
        {
          _this.fileList.push({name:response.data.fileName, "url":response.data.url})
   //自定义上传方法
       handleChange(file, fileList1) {
          //定义一个全局数组uploadFileList来做存储
        }
        // this.uploadFileList.push(file.raw);
         console.log("=========5555=========")
        this.uploadFileList.push(file.raw);
         this.fileList.push({name:file.name,url:file.url,res:true})
       },
      //自定义上传方法
      handleChange1(file, fileListOther12) {
             //定义一个全局数组uploadFileList来做存储
        else{
          _this.fileListOther.push({name:response.data.fileName, url:response.data.url})
           // this.uploadFileList.push(file.raw);
          this.uploadFileList1.push(file.raw);
           this.fileListOther.push({name:file.name,url:file.url,res:true})
            console.log("=========5555=========")
            //console.log(file)
          //  console.log(this.uploadFileList)
         //  this.fileList = fileList
      },
      fileUpload(){
      //   var file = params.file;
        }
        let ul = _this.fileList.map(function (elem){
            return elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
          }).join(",")
          let uls = _this.fileListOther.map(function (elem){
            return elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
          }).join(",")
          _this.formData.url = ul+","+uls
          console.log(_this.formData.url)
        //  alert(87)
          updateEquipment(_this.formData).then(response => {
            this.$modal.msgSuccess("图片上传成功");
            // this.open = false;
         var formData = new FormData();
         //this.$refs.upload1.submit();
      //   alert(this.uploadFileList1.length)
         // formData.append('uploadFile', file);
         if(this.uploadFileList1.length==0){
              this.$modal.msgSuccess("文档上传列表不能为空!");
              return}
          });
      })
         this.uploadFileList1.forEach((elem)=>{
            formData.append("files", elem)
    }
         })
         console.log(this.uploadFileList1)
         let _this = this
         this.uploading = true;
         uploadPic(formData).then(response => {
         _this.uploadFileList1 = []
         if(_this.formData.status=='是')
                   _this.formData.status = 1
                 else
                 _this.formData.status = 0
           _this.formData.url = _this.formData.url+","+response.fileNames
             updateEquipment(_this.formData).then(response => {
               this.$modal.msgSuccess("文档上传成功");
               // this.open = false;
            this.getData()
            this.fileListOther1=[]
             });
           })
      },
      picUpload()
      {
         var formData = new FormData();
         //this.$refs.upload.submit();
         //alert(this.uploadFileList.length)
      if(this.uploadFileList.length==0){
           this.$modal.msgSuccess("图像上传列表不能为空!");
           return}
         this.uploadFileList.forEach((elem)=>{
            formData.append("files", elem)
         })
         let _this = this
           uploadPic(formData).then(response => {
            // console.log(response.originalFilenames)
            // console.log(response.urls)
            // console.log(response.fileNames)
            //       console.log(response.newFileNames)
           // let pth = response.data.originalFilename.substr(response.data.originalFilename.length-4, response.data.originalFilename.length)
           // _this.uploading1= false;
           // console.log(_this.fot.includes(pth))
           // // debugger
           // if(_this.fot.includes(pth) === true)
           // {
           //   _this.fileList.push({name:response.data.fileName, "url":response.data.url})
           //   let ul = _this.fileList.map(function (elem){
           //     return elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
           //   }).join(",")
           //   let uls = _this.fileListOther.map(function (elem){
           //     return elem.url.replace(process.env.VUE_APP_BASE_TRUE_API,"")
           //   }).join(",")
         //console.log(_this.fileList)
      //   alert(response.fileNames)
             _this.formData.url = _this.formData.url+","+response.fileNames
         _this.uploadFileList = []
            // alert(87)
          if(_this.formData.status=='是')
                    _this.formData.status = 1
                  else
                  _this.formData.status = 0
             updateEquipment(_this.formData).then(response => {
               _this.$modal.msgSuccess("图片上传成功");
               // this.open = false;
             });
           // }
           // else{
           //   _this.fileListOther.push({name:response.data.fileName, url:response.data.url})
           // }
         });
      },
        requestUpload(params)
       {
      //  alert(124)
   //    this.uploadFileList.push(params.file);
        //alert(34)
       },
       requestUpload1(params)
       {
      //   alert(123)
      // this.uploadFileList1.push(params.file);
     //  console.log("-----------")
      //console.log(this.uploadFileList1)
       },
  }
}