Browse Source

调试文件夹查询接口

zhangyu 4 years ago
parent
commit
6700194afc
1 changed files with 115 additions and 61 deletions
  1. 115 61
      src/components/homeView/leftFolder.vue

+ 115 - 61
src/components/homeView/leftFolder.vue

@@ -42,7 +42,12 @@
                         @keyup.native.enter="handleUpdateFolderName(folder)"
                         placeholder="请输入文件夹名称"
                     ></el-input>
-                    <i v-show="folder.showInput" class="el-icon-refresh-left revoke-icon" title="撤销" @click.stop="handleRevokeUpdateFolder(folder)"></i>
+                    <i
+                        v-show="folder.showInput"
+                        class="el-icon-refresh-left revoke-icon"
+                        title="撤销"
+                        @click.stop="handleRevokeUpdateFolder(folder)"
+                    ></i>
                     <i v-show="folder.showInput" class="el-icon-check confirm-icon" title="确认" @click.stop="handleUpdateFolderName(folder)"></i>
                 </li>
                 <!-- 右键菜单部分 -->
@@ -55,6 +60,8 @@
     </div>
 </template>
 <script>
+import { folderCreate, folderDelete, folderUpdate, folderQuery } from "@/api/labsl";
+
 export default {
     data() {
         return {
@@ -73,42 +80,54 @@ export default {
     },
     methods: {
         // 获取文件夹数据
-        getFolderData(folderId) {
+        async getFolderData(folderId) {
             this.loading = true;
-            setTimeout(() => {
-                const res = [
-                    {
-                        id: 1,
-                        name: "能源系统",
-                    },
-                    {
-                        id: 2,
-                        name: "排水系统",
-                    },
-                    {
-                        id: 3,
-                        name: "消防水系统",
-                    },
-                    {
-                        id: 4,
-                        name: "公共照明系统",
-                    },
-                    {
-                        id: 5,
-                        name: "暖通空调系统",
-                    },
-                ];
-                this.folderData = res.map(folder => {
-                    folder.updateName = folder.name;
-                    folder.checked = false;
-                    folder.showInput = false;
-                    return folder
-                })
-                if (folderId) {// 如果参数传入文件夹Id,则选中对应的文件夹
-                    this.handleCheckFolder(folderId)
-                }
-                this.loading = false;
-            }, 1000);
+            const res = await folderQuery({});
+            this.folderData = res.content.map((folder) => {
+                folder.updateName = folder.name;
+                folder.checked = false;
+                folder.showInput = false;
+                return folder;
+            });
+            if (folderId) {
+                // 如果参数传入文件夹Id,则选中对应的文件夹
+                this.handleCheckFolder(folderId);
+            }
+            this.loading = false;
+            // setTimeout(() => {
+            //     const res = [
+            //         {
+            //             id: 1,
+            //             name: "能源系统",
+            //         },
+            //         {
+            //             id: 2,
+            //             name: "排水系统",
+            //         },
+            //         {
+            //             id: 3,
+            //             name: "消防水系统",
+            //         },
+            //         {
+            //             id: 4,
+            //             name: "公共照明系统",
+            //         },
+            //         {
+            //             id: 5,
+            //             name: "暖通空调系统",
+            //         },
+            //     ];
+            //     this.folderData = res.map(folder => {
+            //         folder.updateName = folder.name;
+            //         folder.checked = false;
+            //         folder.showInput = false;
+            //         return folder
+            //     })
+            //     if (folderId) {// 如果参数传入文件夹Id,则选中对应的文件夹
+            //         this.handleCheckFolder(folderId)
+            //     }
+            //     this.loading = false;
+            // }, 1000);
         },
         // 点击添加文件夹icon打开弹窗
         handleShowAddFolder() {
@@ -118,7 +137,7 @@ export default {
             });
         },
         // 创建文件夹
-        handleClickAddFolder() {
+        async handleClickAddFolder() {
             if (!this.folderName) {
                 this.$message({ showClose: true, message: "请输入文件夹名称!" });
             } else if (
@@ -128,19 +147,36 @@ export default {
             ) {
                 this.$message({ showClose: true, message: "您输入的文件夹已存在!" });
             } else {
-                setTimeout(() => {
-                    const folderId = Math.floor(Math.random() * 1000);
-                    this.folderData.unshift({
-                        id: folderId,
-                        name: this.folderName,
-                        updateName: this.folderName,
-                        checked: false,
-                        showInput: false,
-                    });
+                const res = await folderCreate({content: [{name: this.folderName}]});
+                if (res.result === "success" && res.entityList.length) {
+                    res.forEach(item => {
+                        this.folderData.unshift({
+                            id: item.id,
+                            name: item.name,
+                            updateName: item.name,
+                            checked: false,
+                            showInput: false,
+                        });
+                    })
                     this.$message.success("添加文件夹成功!");
                     this.handleRevokeAddFolder();
-                    this.handleCheckFolder(folderId);
-                }, 1000);
+                    this.handleCheckFolder(res.entityList[res.entityList.length - 1].id);
+                } else {
+                    this.$message.error(res.message);
+                }
+                // setTimeout(() => {
+                //     const folderId = Math.floor(Math.random() * 1000);
+                //     this.folderData.unshift({
+                //         id: folderId,
+                //         name: this.folderName,
+                //         updateName: this.folderName,
+                //         checked: false,
+                //         showInput: false,
+                //     });
+                //     this.$message.success("添加文件夹成功!");
+                //     this.handleRevokeAddFolder();
+                //     this.handleCheckFolder(folderId);
+                // }, 1000);
             }
         },
         // 撤销添加文件夹
@@ -181,7 +217,7 @@ export default {
             }
         },
         // 文件夹重命名
-        handleUpdateFolderName(folder) {
+        async handleUpdateFolderName(folder) {
             if (!folder.updateName) {
                 this.$message({ showClose: true, message: "请输入文件夹名称!" });
             } else if (
@@ -191,11 +227,21 @@ export default {
             ) {
                 this.$message({ showClose: true, message: "您输入的文件夹已存在!" });
             } else {
-                setTimeout(() => {
-                    folder.name = folder.updateName;
-                    this.$message.success("文件夹重命名成功!");
-                    folder.showInput = false;
-                }, 1000);
+                const res = await folderUpdate({content: [{
+                    id: folder.id,
+                    name: folder.updateName
+                }]});
+                console.log(res)
+                // if () {
+
+                // } else {
+
+                // }
+                // setTimeout(() => {
+                //     folder.name = folder.updateName;
+                //     this.$message.success("文件夹重命名成功!");
+                //     folder.showInput = false;
+                // }, 1000);
             }
         },
         // 撤销重命名
@@ -210,16 +256,24 @@ export default {
                     confirmButtonText: "确定",
                     cancelButtonText: "取消",
                     type: "warning",
-                }).then(() => {
-                    setTimeout(() => {
+                }).then(async () => {
+                    const res = await folderDelete([{id: this.rightClickFolder.id}]);
+                    if (res.result === "success") {
                         this.folderData.splice(
                             this.folderData.findIndex((item) => {
                                 return item.id === this.rightClickFolder.id;
-                            }),
-                            1
-                        );
-                        this.$message({ type: "success", message: "删除成功!" });
-                    }, 1000);
+                        }), 1);
+                        this.$message.success("删除成功!");
+                    } else {
+                        this.$message.error(res.message);
+                    }
+                    // setTimeout(() => {
+                    //     this.folderData.splice(
+                    //         this.folderData.findIndex((item) => {
+                    //             return item.id === this.rightClickFolder.id;
+                    //     }), 1);
+                    //     this.$message({ type: "success", message: "删除成功!" });
+                    // }, 1000);
                 });
             }
         },