Ben Lin
2024-08-28 0a8a3f71f2e50f0603077197d9b1971431a64b36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<template>
  <PageWrapper title="菜单管理" content="这里是菜单的增加删除和修改" contentBackground>
    <template #footer>
      <a-tabs default-active-key="detail" v-model:activeKey="currentKey">
        <a-tab-pane key="detailfirst" tab="BS菜单" />
        <a-tab-pane key="detailsecond" tab="PDA菜单" />
      </a-tabs>
    </template>
    <div>
      <div v-if="currentKey == 'detailfirst'">
        <div class="p-2">
          <BasicTable
            @register="registerTable"
            @fetch-success="onFetchSuccess"
            @expanded-rows-change="onExpandedRChg"
          >
            <template #toolbar>
              <a-button type="primary" @click="handleCreate('BS 菜单')"> 新增菜单 </a-button>
            </template>
            <template #action="{ record }">
              <TableAction
                :actions="[
                  {
                    icon: 'clarity:note-edit-line',
                    onClick: handleEdit.bind(null, record, 'BS 菜单'),
                    name: '',
                  },
                  {
                    icon: 'ant-design:delete-outlined',
                    color: 'error',
                    popConfirm: {
                      title: '是否确认删除?',
                      placement: 'left',
                      confirm: handleDelete.bind(null, record),
                    },
                    name: '',
                  },
                ]"
              />
            </template>
          </BasicTable>
        </div>
      </div>
      <div v-if="currentKey == 'detailsecond'">
        <div class="p-2">
          <BasicTable
            @register="registerTableSecond"
            @fetch-success="onFetchSuccess"
            @expanded-rows-change="onExpandedRChg"
          >
            <template #toolbar>
              <a-button type="primary" @click="handleCreate('PDA')"> 新增菜单 </a-button>
            </template>
            <template #action="{ record }">
              <TableAction
                :actions="[
                  {
                    icon: 'clarity:note-edit-line',
                    onClick: handleEdit.bind(null, record, 'PDA'),
                    name: '',
                  },
                  {
                    icon: 'ant-design:delete-outlined',
                    color: 'error',
                    popConfirm: {
                      title: '是否确认删除?',
                      placement: 'left',
                      confirm: handleDelete.bind(null, record),
                    },
                    name: '',
                  },
                ]"
              />
            </template>
          </BasicTable>
        </div>
      </div>
      <MenuDrawer @register="registerDrawer" @success="handleSuccess" />
    </div>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { nextTick, ref, unref } from 'vue';
  import { PageWrapper } from '/@/components/Page';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getMenuList, DeleteMenu } from '/@/api/tigerapi/system';
  import { useDrawer } from '/@/components/Drawer';
  import MenuDrawer from './MenuDrawer.vue';
  import { Tabs } from 'ant-design-vue';
  import { columns, searchFormSchema } from './menu.data';
 
  const ATabs = ref(Tabs);
  const ATabPane = ref(Tabs.TabPane);
  var currentKey = ref('detailfirst');
  const expandedRowKeys = ref<string[]>([]);
  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload, expandAll, expandRows }] = useTable({
    // const [registerTable, { reload, expandRows }] = useTable({
    title: '菜单列表',
    api: getMenuList,
    searchInfo: { menuName: 'BS 菜单' },
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    isTreeTable: true,
    // pagination: false,
    // striped: false,
    useSearchForm: true,
    showTableSetting: true,
    // bordered: true,
    // showIndexColumn: false,
    // canResize: false,
    actionColumn: {
      width: 80,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: undefined,
    },
    rowKey: 'id',
  });
 
  const [
    registerTableSecond,
    { reload: reloadSecond, expandAll: expandAllSecond, expandRows: expandRowsSecond },
  ] = useTable({
    // const [registerTable, { reload, expandRows }] = useTable({
    title: '菜单列表',
    api: getMenuList,
    searchInfo: { menuName: 'PDA' },
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    isTreeTable: true,
    // pagination: false,
    // striped: false,
    useSearchForm: true,
    showTableSetting: true,
    // bordered: true,
    // showIndexColumn: false,
    // canResize: false,
    actionColumn: {
      width: 80,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: undefined,
    },
    rowKey: 'id',
  });
 
  function handleCreate(menuName: string) {
    openDrawer(true, {
      isUpdate: false,
      menuName: menuName,
    });
  }
 
  function handleEdit(record: Recordable, menuName: string) {
    openDrawer(true, {
      record,
      isUpdate: true,
      menuName: menuName,
    });
  }
 
  function handleDelete(record: Recordable) {
    console.log(record);
    //删除菜单
    const apiAction = DeleteMenu(record);
    apiAction.then((onfulfilled) => {
      if (onfulfilled.IsSuccessed) {
          reloadSecond();
          reload();
      }
    });
  }
 
  function handleSuccess(d) {
    if (d.menuName == 'PDA') {
      reloadSecond();
    } else {
      reload();
    }
    nextTick(() => {
      setTimeout(() => {
        var tdList = document.querySelectorAll(
          '.ant-table-cell.ant-table-cell-ellipsis.ant-table-cell-with-append',
        );
        for (var i = 0; i < tdList.length; i++) {
          if (tdList[i].attributes['title'].nodeValue == d.values.menuName) {
            tdList[i].scrollIntoView();
          }
        }
      }, 1000);
      // console.log(
      //   document.querySelectorAll(
      //     '.ant-table-cell.ant-table-cell-ellipsis.ant-table-cell-with-append',
      //   )[8].attributes['title'].nodeValue, //[8].attributes['data-row-key'].nodeValue
      //   values.menuName,
      // );
    });
  }
 
  function onFetchSuccess(record: Recordable) {
    // 演示默认展开所有表项
    nextTick(() => {
      if (expandedRowKeys.value.length == 0) {
        // expandAll();
      } else {
        expandRows(expandedRowKeys.value);
      }
    });
    console.log(record);
    //nextTick(collapseAll);
    // expandRows([record.items[1].id]);
  }
 
  function onExpandedRChg(record: Recordable) {
    expandedRowKeys.value = record;
    console.log(11, record);
  }
</script>