Pārlūkot izejas kodu

feat: 修改组织

DESKTOP-USV654P\pc 9 mēneši atpakaļ
vecāks
revīzija
81b33a98bf

+ 0 - 2
apps/web-baicai/src/views/system/config/components/edit.vue

@@ -45,8 +45,6 @@ const [Modal, { close, setState, getData }] = useVbenModal({
         close();
         emit('success');
       }
-    } catch {
-      message.error('操作失败');
     } finally {
       setState({ confirmLoading: false });
     }

+ 0 - 3
apps/web-baicai/src/views/system/config/index.vue

@@ -33,9 +33,6 @@ const handleEdit = (record: Record<string, any>, isUpdate: boolean) => {
     })
     .open();
 };
-/**
- * 表格操作按钮的回调函数
- */
 const handleActionClick = async ({
   code,
   row,

+ 7 - 8
apps/web-baicai/src/views/system/department/components/edit.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 { DepartmentApi } from '#/api';
 
-import { formOptions } from '../data.config';
+import { useSchema } from '../data.config';
 
 defineOptions({
   name: 'ConfigEdit',
@@ -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 [Modal, { close, setState, getData }] = useVbenModal({
   fullscreenButton: false,
@@ -46,8 +47,6 @@ const [Modal, { close, setState, getData }] = useVbenModal({
         close();
         emit('success');
       }
-    } catch {
-      message.error('操作失败');
     } finally {
       setState({ confirmLoading: false });
     }

+ 42 - 50
apps/web-baicai/src/views/system/department/data.config.ts

@@ -1,11 +1,13 @@
-import type { VbenFormProps } from '#/adapter/form';
-import type { VxeGridProps } from '#/adapter/vxe-table';
+import type {
+  OnActionClickFn,
+  VbenFormSchema,
+  VxeTableGridOptions,
+} from '#/adapter';
 
 import { DepartmentApi } from '#/api';
-import { formatterStatus } from '#/api/model';
 
-export const searchFormOptions: VbenFormProps = {
-  schema: [
+export const useSearchSchema = (): VbenFormSchema[] => {
+  return [
     {
       component: 'Input',
       fieldName: 'name',
@@ -16,22 +18,13 @@ export const searchFormOptions: VbenFormProps = {
       fieldName: 'code',
       label: '编码',
     },
-  ],
+  ];
 };
 
-export const gridOptions: VxeGridProps<DepartmentApi.RecordItem> = {
-  toolbarConfig: {
-    refresh: true,
-    print: false,
-    export: false,
-    zoom: true,
-    custom: true,
-  },
-  treeConfig: {
-    rowField: 'id',
-    childrenField: 'children',
-  },
-  columns: [
+export function useColumns(
+  onActionClick?: OnActionClickFn<DepartmentApi.RecordItem>,
+): VxeTableGridOptions<DepartmentApi.RecordItem>['columns'] {
+  return [
     { title: '序号', type: 'seq', width: 50 },
     { align: 'left', field: 'name', title: '名称', width: 200, treeNode: true },
     {
@@ -44,40 +37,40 @@ export const gridOptions: VxeGridProps<DepartmentApi.RecordItem> = {
     {
       field: 'status',
       title: '状态',
-      width: 60,
-      formatter: formatterStatus,
+      width: 82,
+      cellRender: { name: 'CellTag' },
     },
     {
-      field: 'action',
+      align: 'right',
+      cellRender: {
+        attrs: {
+          nameField: 'name',
+          nameTitle: '组织',
+          onClick: onActionClick,
+        },
+        name: 'CellAction',
+        options: [
+          {
+            code: 'edit',
+            auth: ['department:edit'],
+          },
+          {
+            code: 'delete',
+            auth: ['department:delete'],
+          },
+        ],
+      },
+      field: 'operation',
       fixed: 'right',
-      slots: { default: 'action' },
+      headerAlign: 'center',
+      showOverflow: false,
       title: '操作',
-      width: 110,
-    },
-  ],
-  height: 'auto',
-  keepSource: true,
-  pagerConfig: {
-    enabled: false,
-  },
-  proxyConfig: {
-    ajax: {
-      query: async (_, formValues) => {
-        return await DepartmentApi.getTree({
-          ...formValues,
-        });
-      },
-    },
-  },
-};
-
-export const formOptions: VbenFormProps = {
-  commonConfig: {
-    componentProps: {
-      class: 'w-full',
+      width: 100,
     },
-  },
-  schema: [
+  ];
+}
+export const useSchema = (): VbenFormSchema[] => {
+  return [
     {
       component: 'ApiTreeSelect',
       componentProps: {
@@ -127,6 +120,5 @@ export const formOptions: VbenFormProps = {
       fieldName: 'remark',
       label: '备注',
     },
-  ],
-  wrapperClass: 'grid-cols-1',
+  ];
 };

+ 60 - 52
apps/web-baicai/src/views/system/department/index.vue

@@ -1,53 +1,80 @@
 <script lang="ts" setup>
-import { useAccess } from '@vben/access';
+import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
+
 import { Page, useVbenModal } 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 { DepartmentApi } 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] = useVbenModal({
   connectedComponent: FormEdit,
 });
+const handelSuccess = () => {
+  reload();
+};
 
-const handleDelete = (id: number) => {
-  Modal.confirm({
-    iconType: 'info',
-    title: '删除提示',
-    content: `确定要删除选择的记录吗?`,
-    cancelText: `关闭`,
-    onOk: async () => {
-      await DepartmentApi.deleteDetail(id);
-      message.success('数据删除成功');
-      reload();
-    },
-  });
+const handleDelete = async (id: number) => {
+  await DepartmentApi.deleteDetail(id);
+  message.success('数据删除成功');
+  reload();
 };
 
 const handleEdit = (record: any, isUpdate: boolean) => {
-  formEditApi.setData({
-    isUpdate,
-    baseData: { id: record.id },
-  });
-
-  formEditApi.open();
+  formEditApi
+    .setData({
+      isUpdate,
+      baseData: { id: record.id },
+    })
+    .open();
 };
-
-const handelSuccess = () => {
-  reload();
+const handleActionClick = async ({
+  code,
+  row,
+}: OnActionClickParams<DepartmentApi.RecordItem>) => {
+  switch (code) {
+    case 'delete': {
+      await handleDelete(row.id);
+      break;
+    }
+    case 'edit': {
+      handleEdit(row, true);
+      break;
+    }
+  }
 };
+
+const [Grid, { reload }] = useVbenVxeGrid(
+  useTableGridOptions({
+    formOptions: {
+      schema: useSearchSchema(),
+    },
+    gridOptions: {
+      pagerConfig: {
+        enabled: false,
+      },
+      treeConfig: {
+        rowField: 'id',
+        childrenField: 'children',
+        transform: false,
+      },
+      columns: useColumns(handleActionClick),
+      proxyConfig: {
+        ajax: {
+          query: async (_, formValues) => {
+            return await DepartmentApi.getTree({
+              ...formValues,
+            });
+          },
+        },
+      },
+    } as VxeTableGridOptions,
+  }),
+);
 </script>
 
 <template>
@@ -64,25 +91,6 @@ const handelSuccess = () => {
           新增组织
         </Button>
       </template>
-      <template #action="{ row }">
-        <TableAction
-          :actions="[
-            {
-              label: '编辑',
-              type: 'text',
-              disabled: !hasAccessByCodes(['department:edit']),
-              onClick: handleEdit.bind(null, row, true),
-            },
-            {
-              label: '删除',
-              type: 'text',
-              danger: true,
-              disabled: !hasAccessByCodes(['department:delete']),
-              onClick: handleDelete.bind(null, row.id),
-            },
-          ]"
-        />
-      </template>
     </Grid>
   </Page>
 </template>