Browse Source

feat: 添加BasicTree使用 fieldNames 后,actionList 和 插槽 会失效的示例代码

zuihou 3 years ago
parent
commit
13d660bede
2 changed files with 140 additions and 30 deletions
  1. 54 30
      src/views/demo/tree/EditTree.vue
  2. 86 0
      src/views/demo/tree/data.ts

+ 54 - 30
src/views/demo/tree/EditTree.vue

@@ -1,41 +1,65 @@
 <template>
   <PageWrapper title="Tree函数操作示例">
-    <div class="flex">
-      <BasicTree
-        class="w-1/3"
-        title="右侧操作按钮/自定义图标"
-        helpMessage="帮助信息"
-        :treeData="treeData"
-        :actionList="actionList"
-        :renderIcon="createIcon"
-      />
-      <BasicTree
-        class="w-1/3 mx-4"
-        title="右键菜单"
-        :treeData="treeData"
-        :beforeRightClick="getRightMenuList"
-      />
-      <BasicTree
-        class="w-1/3"
-        title="工具栏使用"
-        toolbar
-        checkable
-        search
-        :treeData="treeData"
-        :beforeRightClick="getRightMenuList"
-      />
-    </div>
+    <Row :gutter="[16, 16]">
+      <Col :span="8">
+        <BasicTree
+          title="右侧操作按钮/自定义图标"
+          helpMessage="帮助信息"
+          :treeData="treeData"
+          :actionList="actionList"
+          :renderIcon="createIcon"
+        />
+      </Col>
+      <Col :span="8">
+        <BasicTree title="右键菜单" :treeData="treeData" :beforeRightClick="getRightMenuList" />
+      </Col>
+      <Col :span="8">
+        <BasicTree
+          title="工具栏使用"
+          toolbar
+          checkable
+          search
+          :treeData="treeData"
+          :beforeRightClick="getRightMenuList"
+        />
+      </Col>
+      <Col :span="8">
+        <BasicTree title="没有fieldNames,插槽有效" helpMessage="正确的示例" :treeData="treeData3">
+          <template #title="item"> 插槽:{{ item.name }} </template>
+        </BasicTree>
+      </Col>
+      <Col :span="8">
+        <BasicTree
+          title="有fieldNames后,插槽失效"
+          helpMessage="错误的示例, 应该显示插槽的内容才对"
+          :fieldNames="{ key: 'id', title: 'name' }"
+          :treeData="treeData2"
+        >
+          <template #title="item"> 插槽:{{ item.title }} </template>
+        </BasicTree>
+      </Col>
+      <Col :span="8">
+        <BasicTree
+          title="有fieldNames后,actionList失效"
+          helpMessage="错误的示例,应该在鼠标移上去时,显示新增和删除按钮才对"
+          :treeData="treeData3"
+          :actionList="actionList"
+          :fieldNames="{ key: 'key', title: 'name' }"
+        />
+      </Col>
+    </Row>
   </PageWrapper>
 </template>
 <script lang="ts">
   import { defineComponent, h } from 'vue';
-  import { BasicTree, ActionItem, ContextMenuItem } from '/@/components/Tree/index';
-  import { treeData } from './data';
+  import { Row, Col } from 'ant-design-vue';
+  import { BasicTree, TreeActionItem, ContextMenuItem } from '/@/components/Tree/index';
+  import { treeData, treeData2, treeData3 } from './data';
   import { PlusOutlined, DeleteOutlined } from '@ant-design/icons-vue';
   import { PageWrapper } from '/@/components/Page';
 
   export default defineComponent({
-    components: { BasicTree, PageWrapper },
+    components: { BasicTree, PageWrapper, Row, Col },
     setup() {
       function handlePlus(node: any) {
         console.log(node);
@@ -59,7 +83,7 @@
           },
         ];
       }
-      const actionList: ActionItem[] = [
+      const actionList: TreeActionItem[] = [
         {
           // show:()=>boolean;
           render: (node) => {
@@ -90,7 +114,7 @@
         }
         return '';
       }
-      return { treeData, actionList, getRightMenuList, createIcon };
+      return { treeData, treeData2, treeData3, actionList, getRightMenuList, createIcon };
     },
   });
 </script>

+ 86 - 0
src/views/demo/tree/data.ts

@@ -33,3 +33,89 @@ export const treeData: TreeItem[] = [
     ],
   },
 ];
+
+export const treeData2: any[] = [
+  {
+    name: 'parent ',
+    id: '0-0',
+    slots: { title: 'title' },
+    children: [
+      { name: 'leaf', id: '0-0-0', slots: { title: 'title' } },
+      {
+        name: 'leaf',
+        id: '0-0-1',
+        slots: { title: 'title' },
+        children: [
+          {
+            name: 'leaf',
+            slots: { title: 'title' },
+            id: '0-0-0-0',
+            children: [{ name: 'leaf', id: '0-0-0-0-1', slots: { title: 'title' } }],
+          },
+          { name: 'leaf', slots: { title: 'title' }, id: '0-0-0-1' },
+        ],
+      },
+    ],
+  },
+  {
+    name: 'parent 2',
+    id: '1-1',
+    slots: { title: 'title' },
+    children: [
+      { name: 'leaf', slots: { title: 'title' }, id: '1-1-0' },
+      { name: 'leaf', slots: { title: 'title' }, id: '1-1-1' },
+    ],
+  },
+  {
+    name: 'parent 3',
+    id: '2-2',
+    slots: { title: 'title' },
+    children: [
+      { name: 'leaf', slots: { title: 'title' }, id: '2-2-0' },
+      { name: 'leaf', slots: { title: 'title' }, id: '2-2-1' },
+    ],
+  },
+];
+
+export const treeData3: any[] = [
+  {
+    name: 'parent ',
+    key: '0-0',
+    slots: { title: 'title' },
+    children: [
+      { name: 'leaf', key: '0-0-0', slots: { title: 'title' } },
+      {
+        name: 'leaf',
+        key: '0-0-1',
+        slots: { title: 'title' },
+        children: [
+          {
+            name: 'leaf',
+            slots: { title: 'title' },
+            key: '0-0-0-0',
+            children: [{ name: 'leaf', key: '0-0-0-0-1', slots: { title: 'title' } }],
+          },
+          { name: 'leaf', slots: { title: 'title' }, key: '0-0-0-1' },
+        ],
+      },
+    ],
+  },
+  {
+    name: 'parent 2',
+    key: '1-1',
+    slots: { title: 'title' },
+    children: [
+      { name: 'leaf', slots: { title: 'title' }, key: '1-1-0' },
+      { name: 'leaf', slots: { title: 'title' }, key: '1-1-1' },
+    ],
+  },
+  {
+    name: 'parent 3',
+    key: '2-2',
+    slots: { title: 'title' },
+    children: [
+      { name: 'leaf', slots: { title: 'title' }, key: '2-2-0' },
+      { name: 'leaf', slots: { title: 'title' }, key: '2-2-1' },
+    ],
+  },
+];