Browse Source

上传代码

YaolongHan 5 years ago
parent
commit
18b7cdf046

+ 3 - 2
src/api/model/file.js

@@ -125,7 +125,7 @@ let api = {
                                 ModelName: params.Form.file.name,        //模型名字
                                 UserName: params.userName,
                                 Note: params.Form.desc,
-                                ReplaceReason: 0
+                                // ReplaceReason: 0
                             }]
                         }
                         //创建模型文件
@@ -226,7 +226,8 @@ let api = {
                 FloorModelId:data.replaceModelItem.Id, //模型id
                 ModelName: data.Form.file.name,        //模型名字
                 UserName: UserName,
-                Note: data.replaceModelItem.Note
+                Note: data.replaceModelItem.Note,
+                ReplaceReason: data.Form.ReplaceReason
             }]
         }
         // //创建模型文件

+ 1 - 1
src/components/model/file/changeFolderName.vue

@@ -81,7 +81,7 @@ export default {
     },
     resetForm() {
       this.$refs["changeFolderModelName"].resetFields();
-    }
+    },
   },
   watch: {
     folderName: function(val, oldVal) {

+ 57 - 15
src/components/model/file/floorTable.vue

@@ -4,6 +4,7 @@
     :data="tableData"
     style="width: 100%"
     :header-cell-style="{background:'#ccc',color:'#000'}"
+     height="600"
   >
     <el-table-column prop="FloorName" label="模型文件" width="180">
       <template slot-scope="scope">
@@ -26,13 +27,20 @@
           <el-button type="primary" class="iconfont icon-replace" @click="repliaceModel(scope.row)"></el-button>
           <el-button type="primary" class="iconfont icon-Log" @click="queryModelLog(scope.row)"></el-button>
         </div>
-        <div class="upLoad" v-show="scope.row.isDown">
+        <div :class="[scope.row.Status == 1 ||scope.row.Status == 2 ? 'upLoad-loading':'','upLoad']" v-show="scope.row.isDown">
+          <div class="progress">
           <el-progress
-            :text-inside="true"
+            :text-inside="scope.row.Status == 1 || scope.row.Status == 2 ?false:true"
             :stroke-width="20"
             :percentage="scope.row.precent"
-            status="success"
+            :status="scope.row.Status == 1 || scope.row.Status == 2 ?'warning':'success'"
           ></el-progress>
+          </div>
+          <div class="progress-right">
+          <el-button v-show="!scope.row.Status" type="danger" icon="el-icon-delete" @click="closeUpdate(scope.row)" circle></el-button>
+          <span v-show="scope.row.Status == 1">等待检查...</span>
+          <span v-show="scope.row.Status == 2">模型检查中</span>
+          </div>
         </div>
       </template>
     </el-table-column>
@@ -42,7 +50,7 @@
 export default {
   props: {
     tableData: Array,
-    ceshiList: Array
+    persentList: Array
   },
   data() {
     return {};
@@ -59,9 +67,15 @@ export default {
     filterTag(Id, precent) {
       this.$refs.filterTable.data.map(item => {
         if (item.Id == Id) {
-          if (precent >= 97) {
-            item.precent = 100;
-            item.isDown = false;
+          if (precent >= 100) {
+            // 如过precent == 100 不能关闭进度条,
+            if(precent == 100){
+              item.precent = 99;
+            }else if(precent == 101){
+               // 如过precent == 101 则返回结果为suceess 不能关闭进度条,
+                   item.precent = 100;
+                   item.isDown = false;
+            }
             return;
           } else {
             item.precent = precent;
@@ -71,7 +85,6 @@ export default {
     },
     // 下载模型文件
     downloadModel(item) {
-      console.log(item);
       if (item.Url) {
         window.open(item.Url);
       } else {
@@ -80,26 +93,55 @@ export default {
           type: "error"
         });
       }
+    },
+    // 停止上传
+    closeUpdate(item) {
+      this.$emit("closeUpdateFile", item);
     }
   },
   watch: {
-    ceshiList: {
+    persentList: {
       immediate: true,
       deep: true,
       handler: function(val, oldVal) {
-        val.map(item=>{
-          if(item.precent != 0){
-                this.filterTag(item.Id,item.precent)
-          }
-        })
+        if (val.length != 0) {
+          val.map(item => {
+            if (item.precent != 0) {
+              this.filterTag(item.Id, item.precent);
+            }
+          });
+        }
       }
     }
   },
   mounted() {}
 };
 </script>
-<style scoped>
+<style scoped lang="less">
 .box-card {
   min-height: 800px;
+  .upLoad{
+    display: flex;
+    justify-content: flex-start;
+    align-items: center;
+    .progress{
+      width: 160px;
+      height: 20px;
+    }
+  }
+  .upLoad-loading{
+    position: relative;
+     justify-content: center;
+     .progress{
+       width: 200px
+     }
+    .progress-right{
+      position: absolute;
+      left: 40%;
+      top: 50%;
+      transform: translate(-50%,-50%);
+      color: #909399;
+    }
+  }
 }
 </style>

+ 17 - 6
src/components/model/file/replaceModelDialog.vue

@@ -28,15 +28,15 @@
         <el-form-item label="选择模型文件替换原因:">
           <ul>
             <li>
-              <el-radio :disabled="isChioce" v-model="form.radio" label="1">之前模型画错要修改</el-radio>
+              <el-radio :disabled="isChioce" v-model="form.ReplaceReason" label="0">之前模型画错要修改</el-radio>
             </li>
             <li>
-              <el-radio :disabled="isChioce" v-model="form.radio" label="2">因工程改造,更新模型文件</el-radio>
+              <el-radio :disabled="isChioce" v-model="form.ReplaceReason" label="1">因工程改造,更新模型文件</el-radio>
             </li>
           </ul>
         </el-form-item>
         <el-form-item>
-          <div class="dateTime" v-show="form.radio == '2'">
+          <div class="dateTime" v-show="form.ReplaceReason == '1'">
             <p>工程改造竣工时间:</p>
             <el-date-picker v-model="form.finishTime" type="date" placeholder="选择日期"></el-date-picker>
           </div>
@@ -59,7 +59,7 @@ export default {
     return {
       form: {
         file: null, //上传文件
-        radio: "1",
+        ReplaceReason: "0",
         finishTime: ""
       },
       isChioce: true, //是否可以选择替换原因
@@ -71,8 +71,11 @@ export default {
       if (this.form.file == null) {
         this.$message.error("模型文件不能为空!");
       } else {
-        this.$emit("updataModel", {Form:this.form,replaceModelItem:this.replaceModelItem});
-        this.handleClose()
+        this.$emit("updataModel", {
+          Form: this.form,
+          replaceModelItem: this.replaceModelItem
+        });
+        this.handleClose();
       }
     },
     // /上传到服务器/
@@ -84,6 +87,7 @@ export default {
     },
     handleRemove(file, fileList) {
       this.form.file = null;
+      this.fileList = []
     },
     handlePreview(file) {
       console.log(file);
@@ -95,6 +99,13 @@ export default {
         this.form.file = file;
       }
     }
+  },
+  watch: {
+    repliceModelVisible(val) {
+      if (val) {
+        this.handleRemove();
+      }
+    }
   }
 };
 </script>

+ 196 - 102
src/views/model/file/index.vue

@@ -54,7 +54,8 @@
           :tableData="tableData"
           @openModelLog="queryModelLog"
           @replaceModel="repliaceModel"
-          :ceshiList="ceshiList"
+          @closeUpdateFile="removePersentList"
+          :persentList="persentList"
         ></floorTable>
       </el-card>
     </el-col>
@@ -153,16 +154,8 @@ export default {
       updataData: {
         model: {}
       },
-      ceshiList: [
-        {
-          Id: "239ce3d4c33811e993aceb3be9a05be5",
-          precent: 0
-        },
-        {
-          Id: "7d30fd76c33b11e993ac11710b8cb126",
-          precent: 0
-        }
-      ]
+      persentList: [], //请求进度列表
+      uploadClassList: [] //请求list 用与缓存多个请求问题
     };
   },
   methods: {
@@ -240,25 +233,26 @@ export default {
       return new Promise((resolve, reject) => {
         request.queryFloorList(data, res => {
           res.Content.map(item => {
-            Object.assign(item, { isDown:false, precent: 0 });
+            // 显示进度条
+            if (item.Status == 3) {
+              Object.assign(item, { isDown: false, precent: 0 });
+            } else {
+               Object.assign(item, { isDown: true, precent: 0 });
+              if (this.persentList.length != 0) {
+                this.persentList.forEach(pItem => {
+                  if (item.Id == pItem.Id) {
+                    Object.assign(item, { isDown: true, precent: 0 });
+                  }
+                });
+              }
+            }
           });
           this.tableData = res.Content;
           this.loading = false;
           resolve();
-          //测试代码
-          this.ceshi();
         });
       });
     },
-    ceshi() {
-      // let a = setInterval(() => {
-      //  this.ceshiList[0].precent += 5 ;
-      //    this.ceshiList[1].precent += 8
-      //   if (this.ceshiList[0] >= 100) {
-      //     clearInterval(a);
-      //   }
-      // }, 1000);
-    },
     //添加楼层文件
     addFloorFile() {
       this.addFloorFileVisible = true;
@@ -273,105 +267,184 @@ export default {
     },
     // 上传模型文件
     uploadModelFIle(data) {
-      
       // 在列表中添加
-      this.ceshiList.push({
+      this.persentList.push({
         Id: data.FloorModelId,
         precent: 0
       });
-      // 获取当前文件夹下所有模型文件
-      this.queryFloorFile(this.currentFolderId).then(() => {
-        // 开始上传文件
-        // 开始处理数据
-        let formData = new FormData();
-        formData.append(
-          "model",
-          JSON.stringify({
-            FloorModelId: data.FloorModelId,
-            Id: data.CurrentModelId
-          })
-        );
-        formData.append("file", data.Form.file.raw);
-        // 处理数据结束
+      let uploadClass = this.uploadClass();
+      this.uploadClassList.push({
+        obj: new uploadClass(data),
+        Id: data.FloorModelId
+      });
+    },
+    // 上传文件的类
+    uploadClass() {
+      let that = this;
+      return class {
+        constructor(data) {
+          this.upload(data);
+        }
+        upload(data) {
+          that.queryFloorFile(that.currentFolderId).then(() => {
+            // 开始上传文件
+            // 开始处理数据
+            let formData = new FormData();
+            formData.append(
+              "model",
+              JSON.stringify({
+                FloorModelId: data.FloorModelId,
+                Id: data.CurrentModelId
+              })
+            );
+            formData.append("file", data.Form.file.raw);
+            // 处理数据结束
 
-        // 修改isdown得值
-        this.tableData.map(item => {
-          if (item.Id == data.FloorModelId) {
-            item.isDown = true;
-            item.precent = 0;
-          }
-        });
+            // 修改isdown得值
+            that.tableData.map(item => {
+              if (item.Id == data.FloorModelId) {
+                item.isDown = true;
+                item.precent = 0;
+              }
+            });
 
-        // 开始上传
-        request.uploadModelFile(
-          formData,
-          this.projectId,
-          res => {
-            let loaded = res.loaded, //加载量
-              total = res.total; //文件大小
-            this.$nextTick(() => {
-              let precent = Math.round((loaded / total) * 100);
-              // this.$refs.floorTable.filterTag(data.FloorModelId, precent);
-              this.ceshiList.map(item => {
-                if (item.Id == data.FloorModelId) {
-                     item.precent = precent
+            // 开始上传
+            request.uploadModelFile(
+              formData,
+              that.projectId,
+              res => {
+                let loaded = res.loaded, //加载量
+                  total = res.total; //文件大小
+                that.$nextTick(() => {
+                  let precent = Math.round((loaded / total) * 100);
+                  // this.$refs.floorTable.filterTag(data.FloorModelId, precent);
+                  if (that.persentList.length != 0) {
+                    that.persentList.map(item => {
+                      if (item.Id == data.FloorModelId) {
+                        item.precent = precent;
+                      }
+                    });
+                  }
+                });
+              },
+              val => {
+                if (val.data.Result === "success") {
+                  if (that.persentList.length != 0) {
+                    that.persentList.forEach((item, index) => {
+                      if (item.Id == data.FloorModelId) {
+                        item.precent = 101;
+                        that.persentList.splice(index, 0);
+                        return;
+                      }
+                    });
+                  }
+                  that.$message({
+                    message: "文件上传成功",
+                    type: "success"
+                  });
+                } else {
+                  if (that.persentList.length != 0) {
+                    that.persentList.forEach((item, index) => {
+                      if (item.Id == data.FloorModelId) {
+                        item.precent = 101;
+                        that.persentList.splice(index, 0);
+                        return;
+                      }
+                    });
+                  }
+                  that.$message({
+                    message: val.data.Message,
+                    type: "error"
+                  });
                 }
-              });
-            });
-          },
-          (val) => {
-            if (val.Result.Result === "success") {
-              this.ceshiList = [];
-              this.$message({
-                message: "文件上传成功",
-                type: "success"
-              });
-            }
-          }
-        );
-      });
+              }
+            );
+          });
+        }
+      };
     },
     //更新模型文件;
     updateModelFile(data) {
-        this.ceshiList.push({
-          Id:data.FloorModelId,
-          precent:0
-        })
+      this.persentList.push({
+        Id: data.replaceModelItem.Id,
+        precent: 0
+      });
       // 修改isdown得值
       this.tableData.map(item => {
-        if (item.Id == data.FloorModelId) {
+        if (item.Id == data.replaceModelItem.Id) {
           item.isDown = true;
           item.precent = 0;
         }
       });
       // 开始上传
-      request.upDateModelFile(
-        data,
-        this.projectId,
-        this.userInfo.username,
-        res => {
-          let loaded = res.loaded, //加载量
-            total = res.total; //文件大小
-          this.$nextTick(() => {
-            let precent = Math.round((loaded / total) * 100);
-            // this.$refs.floorTable.filterTag(data.FloorModelId, precent);
-             this.ceshiList.map(item => {
-                if (item.Id == data.FloorModelId) {
-                     item.precent = precent
+      let updataclass = this.updateModelClass();
+      this.uploadClassList.push({
+        obj: new updataclass(data),
+        Id: data.replaceModelItem.Id
+      });
+    },
+    // 更新文件的类
+    updateModelClass() {
+      let that = this;
+      // 开始上传
+      return class {
+        constructor(data) {
+          this.upDateModel(data);
+        }
+        upDateModel(data) {
+          request.upDateModelFile(
+            data,
+            that.projectId,
+            that.userInfo.username,
+            res => {
+              let loaded = res.loaded, //加载量
+                total = res.total; //文件大小
+              that.$nextTick(() => {
+                let precent = Math.round((loaded / total) * 100);
+                // this.$refs.floorTable.filterTag(data.FloorModelId, precent);
+                if (that.persentList.length != 0) {
+                  that.persentList.map(item => {
+                    if (item.Id == data.replaceModelItem.Id) {
+                      item.precent = precent;
+                    }
+                  });
                 }
               });
-          });
-        },
-         (val) => {
-            if (val.Result.Result === "success") {
-              this.ceshiList = [];
-              this.$message({
-                message: "文件上传成功",
-                type: "success"
-              });
+            },
+            val => {
+              if (val.data.Result === "success") {
+                if (that.persentList.length != 0) {
+                  that.persentList.forEach((item, index) => {
+                    if (item.Id == data.replaceModelItem.Id) {
+                      item.precent = 101;
+                      that.persentList.splice(index, 0);
+                      return;
+                    }
+                  });
+                }
+                that.$message({
+                  message: "文件上传成功",
+                  type: "success"
+                });
+              } else {
+                if (that.persentList.length != 0) {
+                  that.persentList.forEach((item, index) => {
+                    if (item.Id == data.FloorModelId) {
+                      item.precent = 101;
+                      that.persentList.splice(index, 0);
+                      return;
+                    }
+                  });
+                }
+                that.$message({
+                  message: val.data.Message,
+                  type: "error"
+                });
+              }
             }
-          }
-      );
+          );
+        }
+      };
     },
     //查看模型日志
     queryModelLog(item) {
@@ -386,6 +459,27 @@ export default {
       request.queryModelFile(this.FloorModelId, res => {
         this.logData = res.Content;
       });
+    },
+    // 删除上传列表item
+    removePersentList(item) {
+      this.uploadClassList.forEach((i, index) => {
+        if (item.Id == i.Id) {
+          this.$delete(this.uploadClassList, index);
+          //  this.uploadClassList.splice(index,0)
+          return;
+        }
+      });
+      this.persentList.forEach((i, index) => {
+        if (item.Id == i.Id) {
+          this.$delete(this.persentList, index);
+          return;
+        }
+      });
+      this.queryFloorFile(this.currentFolderId);
+      this.$message({
+        message: "中止上传!",
+        type: "success"
+      });
     }
   },
   mounted() {