DESKTOP-USV654P\pc před 9 měsíci
rodič
revize
cb0f8c09ef

+ 1 - 1
apps/web-baicai/src/adapter/vxe-table.ts

@@ -84,7 +84,7 @@ setupVbenVxeTable({
         const value = row[column.field];
         const tagOptions = options || [
           { color: 'success', label: $t('common.enabled'), value: 1 },
-          { color: 'error', label: $t('common.disabled'), value: 0 },
+          { color: 'error', label: $t('common.disabled'), value: 2 },
         ];
         const tagItem = tagOptions.find((item) => item.value === value);
         return h(

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

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

+ 3 - 6
apps/web-baicai/src/views/system/personal/components/update-avatar.vue

@@ -1,14 +1,11 @@
 <script setup lang="ts">
+import type { UploadChangeParam } from 'ant-design-vue';
+
 import { computed } from 'vue';
 
 import { useAccessStore, useUserStore } from '@vben/stores';
 
-import {
-  Avatar,
-  message,
-  Upload,
-  type UploadChangeParam,
-} from 'ant-design-vue';
+import { Avatar, message, Upload } from 'ant-design-vue';
 
 import { Icon } from '#/components/icon';
 

+ 1 - 1
apps/web-baicai/src/views/system/personal/components/update-info.vue

@@ -5,7 +5,7 @@ import { useUserStore } from '@vben/stores';
 
 import { Button, message } from 'ant-design-vue';
 
-import { useVbenForm } from '#/adapter/form';
+import { useVbenForm } from '#/adapter';
 import { EnumApi, UserApi } from '#/api';
 
 const userStore = useUserStore();

+ 1 - 1
apps/web-baicai/src/views/system/personal/components/update-password.vue

@@ -3,7 +3,7 @@ import { h, ref } from 'vue';
 
 import { Button, message } from 'ant-design-vue';
 
-import { useVbenForm, z } from '#/adapter/form';
+import { useVbenForm, z } from '#/adapter';
 import { UserApi } from '#/api';
 
 const loading = ref<boolean>(false);

+ 7 - 6
apps/web-baicai/src/views/system/post/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 { PostApi } 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,

+ 49 - 44
apps/web-baicai/src/views/system/post/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 { PostApi } 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<PostApi.RecordItem> = {
-  toolbarConfig: {
-    refresh: true,
-    print: false,
-    export: false,
-    zoom: true,
-    custom: true,
-  },
-  columns: [
+export function useColumns(
+  onActionClick?: OnActionClickFn<PostApi.RecordItem>,
+): VxeTableGridOptions<PostApi.RecordItem>['columns'] {
+  return [
     { title: '序号', type: 'seq', width: 50 },
     {
       align: 'left',
@@ -40,39 +37,48 @@ export const gridOptions: VxeGridProps<PostApi.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: ['post:edit'],
+          },
+          {
+            code: 'delete',
+            auth: ['post:delete'],
+          },
+          {
+            code: 'setStatus',
+            label: (row: PostApi.RecordItem) => {
+              return row.status === 1 ? '禁用' : '启用';
+            },
+            auth: ['post:setStatus'],
+          },
+        ],
+      },
+      field: 'operation',
       fixed: 'right',
-      slots: { default: 'action' },
+      headerAlign: 'center',
+      showOverflow: false,
       title: '操作',
-      width: 150,
-    },
-  ],
-  height: 'auto',
-  keepSource: true,
-  proxyConfig: {
-    ajax: {
-      query: async ({ page }, formValues) => {
-        return await PostApi.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: {
@@ -108,6 +114,5 @@ export const formOptions: VbenFormProps = {
       fieldName: 'remark',
       label: '备注',
     },
-  ],
-  wrapperClass: 'grid-cols-1',
+  ];
 };

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

@@ -1,38 +1,27 @@
 <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 { PostApi } 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 handleDelete = (id: number) => {
-  Modal.confirm({
-    iconType: 'info',
-    title: '删除提示',
-    content: `确定要删除选择的记录吗?`,
-    cancelText: `关闭`,
-    onOk: async () => {
-      await PostApi.deleteDetail(id);
-      message.success('数据删除成功');
-      reload();
-    },
-  });
+
+const handelSuccess = () => {
+  reload();
+};
+const handleDelete = async (id: number) => {
+  await PostApi.deleteDetail(id);
+  message.success('数据删除成功');
+  handelSuccess();
 };
 
 const handleUpdateStatus = async (record: any) => {
@@ -40,21 +29,59 @@ const handleUpdateStatus = async (record: any) => {
     id: record.id,
     status: record.status === 1 ? 2 : 1,
   });
-  reload();
+  handelSuccess();
 };
 
 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<PostApi.RecordItem>) => {
+  switch (code) {
+    case 'delete': {
+      await handleDelete(row.id);
+      break;
+    }
+    case 'edit': {
+      handleEdit(row, true);
+      break;
+    }
+    case 'setStatus': {
+      await handleUpdateStatus(row);
+      break;
+    }
+  }
 };
+
+const [Grid, { reload }] = useVbenVxeGrid(
+  useTableGridOptions({
+    formOptions: {
+      schema: useSearchSchema(),
+    },
+    gridOptions: {
+      columns: useColumns(handleActionClick),
+      proxyConfig: {
+        ajax: {
+          query: async ({ page }, formValues) => {
+            return await PostApi.getPage({
+              pageIndex: page.currentPage,
+              pageSize: page.pageSize,
+              ...formValues,
+            });
+          },
+        },
+      },
+    } as VxeTableGridOptions,
+  }),
+);
 </script>
 
 <template>
@@ -71,33 +98,6 @@ const handelSuccess = () => {
           新增岗位
         </Button>
       </template>
-      <template #action="{ row }">
-        <TableAction
-          :actions="[
-            {
-              label: '编辑',
-              type: 'text',
-              disabled: !hasAccessByCodes(['post:edit']),
-              onClick: handleEdit.bind(null, row, true),
-            },
-            {
-              label: '删除',
-              type: 'text',
-              danger: true,
-              disabled: !hasAccessByCodes(['post:delete']),
-              onClick: handleDelete.bind(null, row.id),
-            },
-          ]"
-          :drop-down-actions="[
-            {
-              label: row.status === 1 ? '禁用' : '启用',
-              type: 'link',
-              disabled: !hasAccessByCodes(['role:setStatus']),
-              onClick: handleUpdateStatus.bind(null, row),
-            },
-          ]"
-        />
-      </template>
     </Grid>
   </Page>
 </template>