DESKTOP-USV654P\pc 9 місяців тому
батько
коміт
bed1b3bea5

+ 1 - 0
apps/web-baicai/src/api/system/role.ts

@@ -16,6 +16,7 @@ export namespace RoleApi {
   export interface BasicRecordItem {
     code: string;
     name: string;
+    status: number;
   }
 
   export interface RecordItem extends BasicRecordItem {

+ 7 - 6
apps/web-baicai/src/views/system/role/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 { RoleApi } from '#/api';
 
-import { formOptions } from '../data.config';
+import { useSchema } from '../data.config';
 
 defineOptions({
   name: 'RoleEdit',
@@ -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,

+ 59 - 44
apps/web-baicai/src/views/system/role/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 { RoleApi } from '#/api';
-import { formatterStatus } from '#/api/model';
 
-export const searchFormOptions: VbenFormProps = {
-  schema: [
+export const useSearchSchema = (): VbenFormSchema[] => {
+  return [
     {
       component: 'Input',
       fieldName: 'code',
@@ -16,18 +18,13 @@ export const searchFormOptions: VbenFormProps = {
       fieldName: 'name',
       label: '名称',
     },
-  ],
+  ];
 };
 
-export const gridOptions: VxeGridProps<RoleApi.RecordItem> = {
-  toolbarConfig: {
-    refresh: true,
-    print: false,
-    export: false,
-    zoom: true,
-    custom: true,
-  },
-  columns: [
+export function useColumns(
+  onActionClick?: OnActionClickFn<RoleApi.RecordItem>,
+): VxeTableGridOptions<RoleApi.RecordItem>['columns'] {
+  return [
     { title: '序号', type: 'seq', width: 50 },
     {
       align: 'left',
@@ -41,39 +38,58 @@ export const gridOptions: VxeGridProps<RoleApi.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: ['role:edit'],
+          },
+          {
+            code: 'grantMenu',
+            label: '授权菜单',
+            auth: ['role:grantMenu'],
+          },
+          {
+            code: 'grantUser',
+            label: '添加成员',
+            auth: ['role:grantUser'],
+          },
+          {
+            code: 'setStatus',
+            label: (row: RoleApi.RecordItem) => {
+              return row.status === 1 ? '禁用' : '启用';
+            },
+            auth: ['role:setStatus'],
+          },
+          {
+            code: 'delete',
+            auth: ['role:delete'],
+          },
+        ],
+      },
+      field: 'operation',
       fixed: 'right',
-      slots: { default: 'action' },
+      headerAlign: 'center',
+      showOverflow: false,
       title: '操作',
-      width: 170,
-    },
-  ],
-  height: 'auto',
-  keepSource: true,
-  proxyConfig: {
-    ajax: {
-      query: async ({ page }, formValues) => {
-        return await RoleApi.getPage({
-          pageIndex: page.currentPage,
-          pageSize: page.pageSize,
-          ...formValues,
-        });
-      },
+      width: 100,
     },
-  },
-};
+  ];
+}
 
-export const formOptions: VbenFormProps = {
-  commonConfig: {
-    componentProps: {
-      class: 'w-full',
-    },
-  },
-  schema: [
+export const useSchema = (): VbenFormSchema[] => {
+  return [
     {
       component: 'Input',
       componentProps: {
@@ -109,6 +125,5 @@ export const formOptions: VbenFormProps = {
       fieldName: 'remark',
       label: '备注',
     },
-  ],
-  wrapperClass: 'grid-cols-1',
+  ];
 };

+ 87 - 91
apps/web-baicai/src/views/system/role/index.vue

@@ -1,24 +1,72 @@
 <script lang="ts" setup>
-import { useAccess } from '@vben/access';
+import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
+
 import { Page, useVbenDrawer, 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 { RoleApi, UserApi } from '#/api';
 import { SelectCard } from '#/components/select-card';
-import { TableAction } from '#/components/table-action';
 import MenuGrant from '#/views/system/menu/components/grant.vue';
 
 import FormEdit from './components/edit.vue';
-import { gridOptions, searchFormOptions } from './data.config';
+import { useColumns, useSearchSchema } from './data.config';
 
-const { hasAccessByCodes } = useAccess();
+const handleDelete = async (id: number) => {
+  await RoleApi.deleteDetail(id);
+  message.success('数据删除成功');
+  reload();
+};
+const handleActionClick = async ({
+  code,
+  row,
+}: OnActionClickParams<RoleApi.RecordItem>) => {
+  switch (code) {
+    case 'delete': {
+      await handleDelete(row.id);
+      break;
+    }
+    case 'edit': {
+      handleEdit(row, true);
+      break;
+    }
+    case 'grantMenu': {
+      await handleGrantMenu(row.id);
+      break;
+    }
+    case 'grantUser': {
+      await handleGrantUser(row.id);
+      break;
+    }
+    case 'setStatus': {
+      await handleUpdateStatus(row);
+      break;
+    }
+  }
+};
 
-const [Grid, { reload }] = useVbenVxeGrid({
-  formOptions: searchFormOptions,
-  gridOptions,
-});
+const [Grid, { reload }] = useVbenVxeGrid(
+  useTableGridOptions({
+    formOptions: {
+      schema: useSearchSchema(),
+    },
+    gridOptions: {
+      columns: useColumns(handleActionClick),
+      proxyConfig: {
+        ajax: {
+          query: async ({ page }, formValues) => {
+            return await RoleApi.getPage({
+              pageIndex: page.currentPage,
+              pageSize: page.pageSize,
+              ...formValues,
+            });
+          },
+        },
+      },
+    } as VxeTableGridOptions,
+  }),
+);
 
 const [FormEditModal, formEditApi] = useVbenModal({
   connectedComponent: FormEdit,
@@ -31,19 +79,6 @@ const [MenuGrantModal, menuGrantApi] = useVbenDrawer({
 const [SelectCardModal, selectCardApi] = useVbenModal({
   connectedComponent: SelectCard,
 });
-const handleDelete = (id: number) => {
-  Modal.confirm({
-    iconType: 'info',
-    title: '删除提示',
-    content: `确定要删除选择的记录吗?`,
-    cancelText: `关闭`,
-    onOk: async () => {
-      await RoleApi.deleteDetail(id);
-      message.success('数据删除成功');
-      reload();
-    },
-  });
-};
 
 const handleUpdateStatus = async (record: any) => {
   await RoleApi.updateStatus({
@@ -54,43 +89,43 @@ const handleUpdateStatus = async (record: any) => {
 };
 
 const handleEdit = (record: any, isUpdate: boolean) => {
-  formEditApi.setData({
-    isUpdate,
-    baseData: { id: record.id },
-  });
-
-  formEditApi.open();
+  formEditApi
+    .setData({
+      isUpdate,
+      baseData: { id: record.id },
+    })
+    .open();
 };
 
 const handleGrantMenu = async (id: number) => {
-  menuGrantApi.setData({
-    baseData: { id, type: 'role' },
-  });
-
-  menuGrantApi.open();
+  menuGrantApi
+    .setData({
+      baseData: { id, type: 'role' },
+    })
+    .open();
 };
 
 const handleGrantUser = async (id: number) => {
   const selectedIds = await RoleApi.getUserIds(id);
-  selectCardApi.setData({
-    baseData: {
-      key: id,
-      selectedIds,
-      fieldNames: [
-        { label: '电话', value: 'phone', maxLength: 12 },
-        { label: '姓名', value: 'realName', maxLength: 8 },
-      ],
-      config: {
-        type: 'user',
-      },
-      api: {
-        url: UserApi.getPage,
+  selectCardApi
+    .setData({
+      baseData: {
+        key: id,
+        selectedIds,
+        fieldNames: [
+          { label: '电话', value: 'phone', maxLength: 12 },
+          { label: '姓名', value: 'realName', maxLength: 8 },
+        ],
+        config: {
+          type: 'user',
+        },
+        api: {
+          url: UserApi.getPage,
+        },
+        searchName: 'name',
       },
-      searchName: 'name',
-    },
-  });
-
-  selectCardApi.open();
+    })
+    .open();
 };
 
 const handelSuccess = () => {
@@ -123,45 +158,6 @@ const handelUserSuccess = async (data: any) => {
           新增角色
         </Button>
       </template>
-      <template #action="{ row }">
-        <TableAction
-          :actions="[
-            {
-              label: '编辑',
-              type: 'text',
-              danger: true,
-              disabled: !hasAccessByCodes(['role:edit']),
-              onClick: handleEdit.bind(null, row, true),
-            },
-            {
-              label: '授权菜单',
-              type: 'text',
-              disabled: !hasAccessByCodes(['role:grantMenu']),
-              onClick: handleGrantMenu.bind(null, row.id),
-            },
-          ]"
-          :drop-down-actions="[
-            {
-              label: '添加成员',
-              type: 'link',
-              disabled: !hasAccessByCodes(['role:grantUser']),
-              onClick: handleGrantUser.bind(null, row.id),
-            },
-            {
-              label: row.status === 1 ? '禁用' : '启用',
-              type: 'link',
-              disabled: !hasAccessByCodes(['role:setStatus']),
-              onClick: handleUpdateStatus.bind(null, row),
-            },
-            {
-              label: '删除',
-              type: 'link',
-              disabled: !hasAccessByCodes(['role:delete']),
-              onClick: handleDelete.bind(null, row.id),
-            },
-          ]"
-        />
-      </template>
     </Grid>
   </Page>
 </template>