Quellcode durchsuchen

feat: 修改菜单

DESKTOP-USV654P\pc vor 9 Monaten
Ursprung
Commit
63f58a9e8e

+ 7 - 7
apps/web-baicai/src/components/table-action/src/table-action.vue

@@ -134,12 +134,12 @@ const getButtonProps = (action: ActionItem) => {
   delete res.icon;
   return res;
 };
-const handleMenuClick = (e: any) => {
-  const action = getDropdownList.value[e.key];
-  if (action.onClick && isFunction(action.onClick)) {
-    action.onClick();
-  }
-};
+// const handleMenuClick = (e: any) => {
+//   const action = getDropdownList.value[e.key];
+//   if (action.onClick && isFunction(action.onClick)) {
+//     action.onClick();
+//   }
+// };
 </script>
 
 <template>
@@ -178,7 +178,7 @@ const handleMenuClick = (e: any) => {
         </Button>
       </slot>
       <template #overlay>
-        <Menu @click="handleMenuClick">
+        <Menu>
           <MenuItem v-for="(action, index) in getDropdownList" :key="index">
             <template v-if="action.popConfirm">
               <Popconfirm v-bind="getPopConfirmProps(action.popConfirm)">

+ 7 - 6
apps/web-baicai/src/views/system/menu/components/edit.vue

@@ -5,10 +5,10 @@ import { useVbenDrawer } from '@vben/common-ui';
 
 import { message } from 'ant-design-vue';
 
-import { useVbenForm } from '#/adapter/form';
+import { useFormOptions, useVbenForm } from '#/adapter';
 import { MenuApi } from '#/api';
 
-import { formOptions } from '../data.config';
+import { useSchema } from '../data.config';
 
 defineOptions({
   name: 'MenuEdit',
@@ -17,10 +17,11 @@ const emit = defineEmits(['success']);
 const modelRef = ref<Record<string, any>>({});
 const isUpdate = ref(true);
 
-const [Form, { validate, setValues, getValues }] = useVbenForm({
-  showDefaultActions: false,
-  ...formOptions,
-});
+const [Form, { validate, setValues, getValues }] = useVbenForm(
+  useFormOptions({
+    schema: useSchema(),
+  }),
+);
 
 const [Drawer, { close, setState, getData }] = useVbenDrawer({
   onCancel() {

+ 8 - 6
apps/web-baicai/src/views/system/menu/components/editMenu.vue

@@ -5,10 +5,10 @@ import { useVbenModal } from '@vben/common-ui';
 
 import { message } from 'ant-design-vue';
 
-import { useVbenForm } from '#/adapter/form';
+import { useFormOptions, useVbenForm } from '#/adapter';
 import { MenuApi } from '#/api';
 
-import { formMenuOptions } from '../data.config';
+import { useMenuSchema } from '../data.config';
 
 defineOptions({
   name: 'Menu1Edit',
@@ -17,10 +17,12 @@ const emit = defineEmits(['success']);
 const modelRef = ref<Record<string, any>>({});
 const isUpdate = ref(true);
 
-const [Form, { validate, setValues, getValues }] = useVbenForm({
-  showDefaultActions: false,
-  ...formMenuOptions,
-});
+const [Form, { validate, setValues, getValues }] = useVbenForm(
+  useFormOptions({
+    wrapperClass: 'grid-cols-2',
+    schema: useMenuSchema(),
+  }),
+);
 
 const [Modal, { close, setState, getData }] = useVbenModal({
   fullscreen: false,

+ 3 - 1
apps/web-baicai/src/views/system/menu/components/grant.vue

@@ -1,4 +1,6 @@
 <script lang="ts" setup>
+import type { TreeProps } from 'ant-design-vue';
+
 import type { Recordable } from '@vben/types';
 
 import type { RelationRequest } from '#/api/model';
@@ -7,7 +9,7 @@ import { onMounted, reactive, ref, unref } from 'vue';
 
 import { useVbenDrawer } from '@vben/common-ui';
 
-import { Button, message, Tree, type TreeProps } from 'ant-design-vue';
+import { Button, message, Tree } from 'ant-design-vue';
 
 import { MenuApi, RoleApi, TenantApi } from '#/api';
 import { Icon } from '#/components/icon';

+ 52 - 65
apps/web-baicai/src/views/system/menu/data.config.ts

@@ -1,14 +1,17 @@
-import type { VbenFormProps } from '#/adapter/form';
-import type { VxeGridProps } from '#/adapter/vxe-table';
+import type {
+  OnActionClickFn,
+  VbenFormSchema,
+  VxeTableGridOptions,
+} from '#/adapter';
 
 import { h } from 'vue';
 
 import { EnumApi, MenuApi } from '#/api';
-import { boolOptions, formatterStatus } from '#/api/model';
+import { boolOptions } from '#/api/model';
 import { Icon } from '#/components/icon';
 
-export const searchFormOptions: VbenFormProps = {
-  schema: [
+export const useSearchSchema = (): VbenFormSchema[] => {
+  return [
     {
       component: 'Input',
       fieldName: 'title',
@@ -25,18 +28,13 @@ export const searchFormOptions: VbenFormProps = {
         },
       },
     },
-  ],
+  ];
 };
 
-export const gridOptions: VxeGridProps<MenuApi.RecordItem> = {
-  toolbarConfig: {
-    refresh: true,
-    print: false,
-    export: false,
-    zoom: true,
-    custom: true,
-  },
-  columns: [
+export function useColumns(
+  onActionClick?: OnActionClickFn<MenuApi.RecordItem>,
+): VxeTableGridOptions<MenuApi.RecordItem>['columns'] {
+  return [
     { title: '序号', type: 'seq', width: 50 },
     {
       align: 'left',
@@ -87,48 +85,47 @@ export const gridOptions: VxeGridProps<MenuApi.RecordItem> = {
     {
       field: 'status',
       title: '状态',
-      width: 60,
-      formatter: formatterStatus,
+      width: 82,
+      cellRender: { name: 'CellTag' },
     },
     { field: 'sort', title: '排序', width: 80 },
     {
-      field: 'action',
+      align: 'right',
+      cellRender: {
+        attrs: {
+          nameField: 'name',
+          nameTitle: '配置',
+          onClick: onActionClick,
+        },
+        name: 'CellAction',
+        options: [
+          {
+            code: 'append',
+            label: '添加项',
+            auth: ['menu:add'],
+          },
+          {
+            code: 'edit',
+            auth: ['menu:edit'],
+          },
+          {
+            code: 'delete',
+            auth: ['menu:delete'],
+          },
+        ],
+      },
+      field: 'operation',
       fixed: 'right',
-      slots: { default: 'action' },
+      headerAlign: 'center',
+      showOverflow: false,
       title: '操作',
-      width: 150,
-    },
-  ],
-  height: 'auto',
-  keepSource: true,
-  pagerConfig: {
-    enabled: false,
-  },
-  treeConfig: {
-    rowField: 'id',
-    childrenField: 'children',
-  },
-  proxyConfig: {
-    ajax: {
-      query: async ({ page }, formValues) => {
-        return await MenuApi.getList({
-          pageIndex: page.currentPage,
-          pageSize: page.pageSize,
-          ...formValues,
-        });
-      },
-    },
-  },
-};
-
-export const formOptions: VbenFormProps = {
-  commonConfig: {
-    componentProps: {
-      class: 'w-full',
-      labelWidth: 110,
+      width: 100,
     },
-  },
-  schema: [
+  ];
+}
+
+export const useSchema = (): VbenFormSchema[] => {
+  return [
     {
       component: 'ApiRadio',
       defaultValue: 0,
@@ -359,19 +356,11 @@ export const formOptions: VbenFormProps = {
       fieldName: 'status',
       label: '状态',
     },
-  ],
-  showDefaultActions: false,
-  wrapperClass: 'grid-cols-1',
+  ];
 };
 
-export const formMenuOptions: VbenFormProps = {
-  commonConfig: {
-    componentProps: {
-      class: 'w-full',
-      labelWidth: 110,
-    },
-  },
-  schema: [
+export const useMenuSchema = (): VbenFormSchema[] => {
+  return [
     {
       component: 'ApiTreeSelect',
       componentProps: {
@@ -530,7 +519,5 @@ export const formMenuOptions: VbenFormProps = {
       fieldName: 'status',
       label: '状态',
     },
-  ],
-  showDefaultActions: false,
-  wrapperClass: 'grid-cols-2',
+  ];
 };

+ 66 - 59
apps/web-baicai/src/views/system/menu/index.vue

@@ -1,53 +1,87 @@
 <script lang="ts" setup>
-import { useAccess } from '@vben/access';
+import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/';
+
 import { Page, useVbenDrawer } from '@vben/common-ui';
 
-import { Button, message, Modal } from 'ant-design-vue';
+import { Button, message } from 'ant-design-vue';
 
-import { useVbenVxeGrid } from '#/adapter/vxe-table';
+import { useTableGridOptions, useVbenVxeGrid } from '#/adapter';
 import { MenuApi } from '#/api';
-import { TableAction } from '#/components/table-action';
 
 import FormEdit from './components/edit.vue';
-import { gridOptions, searchFormOptions } from './data.config';
-
-const { hasAccessByCodes } = useAccess();
-
-const [Grid, { reload }] = useVbenVxeGrid({
-  formOptions: searchFormOptions,
-  gridOptions,
-});
+import { useColumns, useSearchSchema } from './data.config';
 
 const [FormEditModal, formEditApi] = useVbenDrawer({
   connectedComponent: FormEdit,
 });
 
-const handleDelete = (id: number) => {
-  Modal.confirm({
-    iconType: 'info',
-    title: '删除提示',
-    content: `确定要删除选择的记录吗?`,
-    cancelText: `关闭`,
-    onOk: async () => {
-      await MenuApi.deleteDetail(id);
-      message.success('数据删除成功');
-      reload();
-    },
-  });
+const handelSuccess = () => {
+  reload();
 };
 
-const handleEdit = (record: any, isUpdate: boolean) => {
-  formEditApi.setData({
-    isUpdate,
-    baseData: { ...record },
-  });
+const handleDelete = async (id: number) => {
+  await MenuApi.deleteDetail(id);
+  message.success('数据删除成功');
+  reload();
+};
 
-  formEditApi.open();
+const handleEdit = (record: any, isUpdate: boolean) => {
+  formEditApi
+    .setData({
+      isUpdate,
+      baseData: { ...record },
+    })
+    .open();
 };
 
-const handelSuccess = () => {
-  reload();
+const handleActionClick = async ({
+  code,
+  row,
+}: OnActionClickParams<MenuApi.RecordItem>) => {
+  switch (code) {
+    case 'append': {
+      handleEdit({ pid: row.id }, false);
+      break;
+    }
+    case 'delete': {
+      await handleDelete(row.id);
+      break;
+    }
+    case 'edit': {
+      handleEdit({ id: row.id }, true);
+      break;
+    }
+  }
 };
+
+const [Grid, { reload }] = useVbenVxeGrid(
+  useTableGridOptions({
+    formOptions: {
+      schema: useSearchSchema(),
+    },
+    gridOptions: {
+      pagerConfig: {
+        enabled: false,
+      },
+      treeConfig: {
+        rowField: 'id',
+        childrenField: 'children',
+      },
+      columns: useColumns(handleActionClick),
+      proxyConfig: {
+        ajax: {
+          query: async ({ page }, formValues) => {
+            return await MenuApi.getList({
+              pageIndex: page.currentPage,
+              pageSize: page.pageSize,
+              ...formValues,
+            });
+          },
+        },
+      },
+    } as VxeTableGridOptions,
+  }),
+);
 </script>
 
 <template>
@@ -64,33 +98,6 @@ const handelSuccess = () => {
           新增菜单
         </Button>
       </template>
-      <template #action="{ row }">
-        <TableAction
-          :actions="[
-            {
-              label: '添加项',
-              type: 'text',
-              disabled: !hasAccessByCodes(['menu:add']),
-              onClick: handleEdit.bind(null, { pid: row.id }, false),
-            },
-            {
-              label: '编辑',
-              type: 'text',
-              danger: true,
-              disabled: !hasAccessByCodes(['menu:edit']),
-              onClick: handleEdit.bind(null, { id: row.id }, true),
-            },
-          ]"
-          :drop-down-actions="[
-            {
-              label: '删除',
-              type: 'link',
-              disabled: !hasAccessByCodes(['menu:delete']),
-              onClick: handleDelete.bind(null, row.id),
-            },
-          ]"
-        />
-      </template>
     </Grid>
   </Page>
 </template>