Browse Source

删除无用的代码

xiaochan 8 months ago
parent
commit
39aa39112e
1 changed files with 135 additions and 121 deletions
  1. 135 121
      src/views/data-base/page-editor-help-v2/components/left-sidebar/PageTree.vue

+ 135 - 121
src/views/data-base/page-editor-help-v2/components/left-sidebar/PageTree.vue

@@ -1,29 +1,30 @@
 <script setup lang="ts">
-import {onMounted, ref} from "vue";
+import { onMounted, ref } from "vue";
 import {
   deleteById,
   fileSave,
   folderSave,
-  getPermissionsByUserCode,
   getReportCenterTree,
   modifyTheFileName,
-  move
+  move,
 } from "@/api/base-data/report-center";
-import {CyMessageBox} from "@/components/cy/message-box";
-import {SaveFile} from "@/api/base-data/type/magic-api";
-import {useCompRef} from "@/utils/useCompRef";
-import {ElTree} from "element-plus";
-import {Document, Folder} from "@element-plus/icons-vue";
+import { CyMessageBox } from "@/components/cy/message-box";
+import { SaveFile } from "@/api/base-data/type/magic-api";
+import { useCompRef } from "@/utils/useCompRef";
+import { ElTree } from "element-plus";
+import { Document, Folder } from "@element-plus/icons-vue";
 import RightClickMenu from "@/components/menu-item/RightClickMenu.vue";
-import {ReportForms} from "@/api/reports/report-query-center";
-import {createFile, pageHelpV2Mitt, REPORT_FOLDER} from "@/views/data-base/page-editor-help-v2/page-help-v2";
-import type Node from 'element-plus/es/components/tree/src/model/node'
-import type {DragEvents} from 'element-plus/es/components/tree/src/model/useDragNode'
-import type {
-  NodeDropType,
-} from 'element-plus/es/components/tree/src/tree.type'
+import { ReportForms } from "@/api/reports/report-query-center";
+import {
+  createFile,
+  pageHelpV2Mitt,
+  REPORT_FOLDER,
+} from "@/views/data-base/page-editor-help-v2/page-help-v2";
+import type Node from "element-plus/es/components/tree/src/model/node";
+import type { DragEvents } from "element-plus/es/components/tree/src/model/useDragNode";
+import type { NodeDropType } from "element-plus/es/components/tree/src/tree.type";
 import CyAutoSize from "@/components/cy/auto-size/cy-auto-size.vue";
-import {useElementSize} from "@vueuse/core";
+import { useElementSize } from "@vueuse/core";
 
 enum FILE_ENUM {
   FILE = 0,
@@ -31,27 +32,26 @@ enum FILE_ENUM {
 }
 
 interface Props {
-  nodeClick?: (data: ReportForms) => void,
-  editor?: boolean
+  nodeClick?: (data: ReportForms) => void;
+  editor?: boolean;
 }
 
 //@ts-ignore
 const props = withDefaults(defineProps<Props>(), {
   editor: false,
-})
-
-const treeData = ref([])
-const treeRef = useCompRef(ElTree)
-const mousePosition = ref()
-const inputValue = ref('')
-const headerRef = ref()
+});
 
-const {height: headerHeight} = useElementSize(headerRef)
+const treeData = ref([]);
+const treeRef = useCompRef(ElTree);
+const mousePosition = ref();
+const inputValue = ref("");
+const headerRef = ref();
 
+const { height: headerHeight } = useElementSize(headerRef);
 
 function generateRandomPath() {
-  const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
-  let result = '';
+  const characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+  let result = "";
   let lastCharTypeIsLowerCase = true; // 用于记录上一个字符是否为小写
 
   // 第一个字符为小写
@@ -65,17 +65,20 @@ function generateRandomPath() {
       charIndex = Math.floor(Math.random() * 26);
     }
     result += characters.charAt(charIndex);
-    lastCharTypeIsLowerCase = (charIndex < 26); // 判断当前字符类型
+    lastCharTypeIsLowerCase = charIndex < 26; // 判断当前字符类型
   }
 
   return "/" + result;
 }
 
-async function createANewReport(flag: FILE_ENUM, parentId: string = REPORT_FOLDER) {
+async function createANewReport(
+  flag: FILE_ENUM,
+  parentId: string = REPORT_FOLDER
+) {
   const res = await CyMessageBox.prompt({
-    message: `输入 ${flag === FILE_ENUM.FILE ? '文件' : '文件夹'} 名称!`,
-    type: "info"
-  })
+    message: `输入 ${flag === FILE_ENUM.FILE ? "文件" : "文件夹"} 名称!`,
+    type: "info",
+  });
 
   const path = generateRandomPath();
 
@@ -83,7 +86,7 @@ async function createANewReport(flag: FILE_ENUM, parentId: string = REPORT_FOLDE
     const data: SaveFile = {
       groupId: parentId,
       headers: [],
-      method: 'POST',
+      method: "POST",
       name: res.value,
       options: [],
       parameters: [],
@@ -95,153 +98,166 @@ return {
     data: data,
     columns: []
 }`,
-      pageJson: createFile()
-    }
-    await fileSave(data)
+      pageJson: createFile(),
+    };
+    await fileSave(data);
   } else {
-    await folderSave({name: res.value, path, parentId, type: 'api'})
+    await folderSave({ name: res.value, path, parentId, type: "api" });
   }
-  queryData()
+  queryData();
 }
 
 const contextmenu = (event: Event, data: ReportForms) => {
   if (!props.editor) {
-    return
+    return;
   }
   mousePosition.value = {
     event,
     data: data,
-    index: data['$treeNodeId']
-  }
-}
+    index: data["$treeNodeId"],
+  };
+};
 const config = [
   {
-    name: '新增文件夹',
-    click: (data) => {
-      createANewReport(FILE_ENUM.FOLDER, data.id)
-    }
+    name: "新增文件夹",
+    click: data => {
+      createANewReport(FILE_ENUM.FOLDER, data.id);
+    },
   },
   {
-    name: '新增文件',
-    click: (data) => {
-      createANewReport(FILE_ENUM.FILE, data.id)
-    }
+    name: "新增文件",
+    click: data => {
+      createANewReport(FILE_ENUM.FILE, data.id);
+    },
   },
   {
-    name: '修改文件名',
-    click: async (data) => {
+    name: "修改文件名",
+    click: async data => {
       const box = await CyMessageBox.prompt({
         message: `输入新的文件名!`,
-        type: 'info',
-        inputDefaultValue: data.name
-      })
+        type: "info",
+        inputDefaultValue: data.name,
+      });
       await modifyTheFileName({
         id: data.id,
         name: box.value,
-        type: data.type
-      })
-      data.name = box.value
-    }
+        type: data.type,
+      });
+      data.name = box.value;
+    },
   },
   {
-    name: '删除',
-    click: async (data) => {
+    name: "删除",
+    click: async data => {
       await CyMessageBox.confirm({
-        message: `确认删除【${data.name}】吗?`
-      })
-      await deleteById(data.id)
-      queryData()
-    }
-  }
-]
+        message: `确认删除【${data.name}】吗?`,
+      });
+      await deleteById(data.id);
+      queryData();
+    },
+  },
+];
 
 function nodeClick(data: ReportForms) {
   if (data.type === 1) {
-    return
+    return;
   }
   if (props.nodeClick) {
-    props.nodeClick(data)
+    props.nodeClick(data);
   } else {
-    pageHelpV2Mitt.emit('changePageJson', data)
+    pageHelpV2Mitt.emit("changePageJson", data);
   }
 }
 
 function handleDragEnd(
-    draggingNode: Node,
-    dropNode: Node,
-    dropType: NodeDropType,
-    _ev: DragEvents) {
-  let src = draggingNode.data.id
-  let groupId = ''
-  if (dropType === 'inner') {
-    groupId = dropNode.data.id
+  draggingNode: Node,
+  dropNode: Node,
+  dropType: NodeDropType,
+  _ev: DragEvents
+) {
+  let src = draggingNode.data.id;
+  let groupId = "";
+  if (dropType === "inner") {
+    groupId = dropNode.data.id;
   } else {
-    groupId = dropNode.data.parentId || REPORT_FOLDER
+    groupId = dropNode.data.parentId || REPORT_FOLDER;
   }
-  move(src, groupId)
+  move(src, groupId);
 }
 
-
 function queryData() {
   getReportCenterTree().then(res => {
-    treeData.value = res
-  })
+    treeData.value = res;
+  });
 }
 
 function handleInputChange(val) {
-  treeRef.value!.filter(val)
+  treeRef.value!.filter(val);
 }
 
 function handelFilter(value, data) {
-  return data.name.includes(value)
+  return data.name.includes(value);
 }
 
-function rowClick(row) {
-  getPermissionsByUserCode(row.code).then(res => {
-    treeRef.value!.setCheckedKeys(res)
-  })
-}
-
-
 onMounted(() => {
-  queryData()
+  queryData();
 
-  pageHelpV2Mitt.on('queryTree', () => {
-    queryData()
-  })
-})
+  pageHelpV2Mitt.on("queryTree", () => {
+    queryData();
+  });
+});
 </script>
 
 <template>
-  <RightClickMenu v-if="props.editor" :config="config" :mouse-position="mousePosition"/>
+  <RightClickMenu
+    v-if="props.editor"
+    :config="config"
+    :mouse-position="mousePosition"
+  />
   <cy-auto-size>
-    <template #default="{height , width}">
+    <template #default="{ height, width }">
       <div ref="headerRef">
         <div v-if="props.editor">
           <el-button-group>
-            <el-button @click="createANewReport(FILE_ENUM.FOLDER)"> 文件夹</el-button>
-            <el-button @click="createANewReport(FILE_ENUM.FILE)">文件</el-button>
+            <el-button @click="createANewReport(FILE_ENUM.FOLDER)">
+              文件夹
+            </el-button>
+            <el-button @click="createANewReport(FILE_ENUM.FILE)"
+              >文件
+            </el-button>
           </el-button-group>
         </div>
         <div>
-          <el-input placeholder="搜索报表" @input="handleInputChange" v-model="inputValue"/>
+          <el-input
+            placeholder="搜索报表"
+            @input="handleInputChange"
+            v-model="inputValue"
+          />
         </div>
       </div>
-      <div :style="{height : height - headerHeight - 10 + 'px'  , width: width - 5 + 'px' }" style="overflow: auto">
-        <el-tree :data="treeData"
-                 ref="treeRef"
-                 :filter-node-method="handelFilter"
-                 @node-click="nodeClick"
-                 @node-contextmenu="contextmenu"
-                 @node-drag-end="handleDragEnd"
-                 highlight-current
-                 :draggable="props.editor"
-                 node-key="id"
-                 default-expand-all>
-          <template #default="{node,data}">
+      <div
+        :style="{
+          height: height - headerHeight - 10 + 'px',
+          width: width - 5 + 'px',
+        }"
+        style="overflow: auto"
+      >
+        <el-tree
+          :data="treeData"
+          ref="treeRef"
+          :filter-node-method="handelFilter"
+          @node-click="nodeClick"
+          @node-contextmenu="contextmenu"
+          @node-drag-end="handleDragEnd"
+          highlight-current
+          :draggable="props.editor"
+          node-key="id"
+          default-expand-all
+        >
+          <template #default="{ node, data }">
             <el-icon>
-              <Document v-if="data.type === 0"/>
-              <Folder v-else/>
+              <Document v-if="data.type === 0" />
+              <Folder v-else />
             </el-icon>
             {{ data.name }}
           </template>
@@ -251,6 +267,4 @@ onMounted(() => {
   </cy-auto-size>
 </template>
 
-<style scoped lang="scss">
-
-</style>
+<style scoped lang="scss"></style>