Browse Source

feat: 查询设计

DESKTOP-USV654P\pc 9 months ago
parent
commit
e1e8253755

+ 52 - 56
apps/web-baicai/src/views/system/design/query/components/step/baseConfig.vue

@@ -1,70 +1,66 @@
 <script lang="ts" setup>
 import { onMounted } from 'vue';
 
-import { useVbenForm } from '#/adapter/form';
+import { useFormOptions, useVbenForm } from '#/adapter';
 import { TenantApi } from '#/api';
 
-const [Form, { validate, setValues, getValues }] = useVbenForm({
-  commonConfig: {
-    componentProps: {
-      class: 'w-full',
-    },
-  },
-  schema: [
-    {
-      component: 'Input',
-      componentProps: {
-        placeholder: '请输入',
+const [Form, { validate, setValues, getValues }] = useVbenForm(
+  useFormOptions({
+    schema: [
+      {
+        component: 'Input',
+        componentProps: {
+          placeholder: '请输入',
+        },
+        fieldName: 'code',
+        label: '查询编号',
+        rules: 'required',
       },
-      fieldName: 'code',
-      label: '查询编号',
-      rules: 'required',
-    },
-    {
-      component: 'Input',
-      componentProps: {
-        placeholder: '请输入',
+      {
+        component: 'Input',
+        componentProps: {
+          placeholder: '请输入',
+        },
+        fieldName: 'name',
+        label: '查询名称',
+        rules: 'required',
       },
-      fieldName: 'name',
-      label: '查询名称',
-      rules: 'required',
-    },
-    {
-      component: 'ApiSelect',
-      componentProps: {
-        placeholder: '请输入',
-        api: {
-          url: TenantApi.getOptions,
+      {
+        component: 'ApiSelect',
+        componentProps: {
+          placeholder: '请输入',
+          api: {
+            url: TenantApi.getOptions,
+          },
+          showSearch: true,
+          numberToString: true,
         },
-        showSearch: true,
-        numberToString: true,
+        fieldName: 'configId',
+        label: '数据库',
+        rules: 'required',
       },
-      fieldName: 'configId',
-      label: '数据库',
-      rules: 'required',
-    },
-    {
-      component: 'InputNumber',
-      componentProps: {
-        placeholder: '请输入',
+      {
+        component: 'InputNumber',
+        componentProps: {
+          placeholder: '请输入',
+        },
+        fieldName: 'sort',
+        label: '排序',
+        rules: 'required',
       },
-      fieldName: 'sort',
-      label: '排序',
-      rules: 'required',
-    },
-    {
-      component: 'Textarea',
-      componentProps: {
-        placeholder: '请输入',
+      {
+        component: 'Textarea',
+        componentProps: {
+          placeholder: '请输入',
+        },
+        fieldName: 'remark',
+        label: '备注',
+        formItemClass: 'col-span-2 items-baseline',
       },
-      fieldName: 'remark',
-      label: '备注',
-      formItemClass: 'col-span-2 items-baseline',
-    },
-  ],
-  showDefaultActions: false,
-  wrapperClass: 'grid-cols-2',
-});
+    ],
+    wrapperClass: 'grid-cols-2',
+  }),
+);
 
 const stepValidate = async () => {
   const { valid } = await validate();

+ 3 - 1
apps/web-baicai/src/views/system/design/query/components/view.vue

@@ -1,11 +1,13 @@
 <script lang="ts" setup>
+import type { VxeGridProps } from '#/adapter';
+
 import { reactive, ref, unref } from 'vue';
 
 import { useVbenModal } from '@vben/common-ui';
 
 import { Button } from 'ant-design-vue';
 
-import { useVbenVxeGrid, type VxeGridProps } from '#/adapter/vxe-table';
+import { useVbenVxeGrid } from '#/adapter';
 import { QueryApi } from '#/api';
 
 defineOptions({

+ 42 - 34
apps/web-baicai/src/views/system/design/query/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 { QueryApi } from '#/api';
 
-export const searchFormOptions: VbenFormProps = {
-  showCollapseButton: false,
-  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<QueryApi.RecordItem> = {
-  toolbarConfig: {
-    refresh: true,
-    print: false,
-    export: false,
-    zoom: true,
-    custom: true,
-  },
-  columns: [
+export function useColumns(
+  onActionClick?: OnActionClickFn<QueryApi.RecordItem>,
+): VxeTableGridOptions<QueryApi.RecordItem>['columns'] {
+  return [
     { title: '序号', type: 'seq', width: 50 },
     {
       align: 'left',
@@ -39,25 +36,36 @@ export const gridOptions: VxeGridProps<QueryApi.RecordItem> = {
     { field: 'sort', title: '排序', width: 50 },
     { align: 'left', field: 'remark', title: '备注' },
     {
-      field: 'action',
+      align: 'right',
+      cellRender: {
+        attrs: {
+          nameField: 'name',
+          nameTitle: '查询名称',
+          onClick: onActionClick,
+        },
+        name: 'CellAction',
+        options: [
+          {
+            code: 'edit',
+            auth: ['query:edit'],
+          },
+          {
+            code: 'view',
+            label: '查看',
+            auth: ['query:view'],
+          },
+          {
+            code: 'delete',
+            auth: ['query:delete'],
+          },
+        ],
+      },
+      field: 'operation',
       fixed: 'right',
-      slots: { default: 'action' },
+      headerAlign: 'center',
+      showOverflow: false,
       title: '操作',
-      width: 140,
-    },
-  ],
-  height: 'auto',
-  keepSource: true,
-  pagerConfig: {},
-  proxyConfig: {
-    ajax: {
-      query: async ({ page }, formValues) => {
-        return await QueryApi.getPage({
-          pageIndex: page.currentPage,
-          pageSize: page.pageSize,
-          ...formValues,
-        });
-      },
+      width: 100,
     },
-  },
-};
+  ];
+}

+ 58 - 58
apps/web-baicai/src/views/system/design/query/index.vue

@@ -1,23 +1,16 @@
 <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 { QueryApi } from '#/api';
-import { TableAction } from '#/components/table-action';
 
 import FormEdit from './components/edit.vue';
 import FormView from './components/view.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,
@@ -26,37 +19,70 @@ const [FormEditModal, formEditApi] = useVbenModal({
 const [FormViewModal, formViewApi] = useVbenModal({
   connectedComponent: FormView,
 });
-const handleDelete = (id: number) => {
-  Modal.confirm({
-    iconType: 'info',
-    title: '删除提示',
-    content: `确定要删除选择的记录吗?`,
-    cancelText: `关闭`,
-    onOk: async () => {
-      await QueryApi.deleteDetail(id);
-      message.success('数据删除成功');
-      reload();
-    },
-  });
+const handleDelete = async (id: number) => {
+  await QueryApi.deleteDetail(id);
+  message.success('数据删除成功');
+  reload();
 };
 
 const handleEdit = (record: any, isUpdate: boolean) => {
-  formEditApi.setData({
-    isUpdate,
-    baseData: { ...record },
-  });
-
-  formEditApi.open();
+  formEditApi
+    .setData({
+      isUpdate,
+      baseData: { ...record },
+    })
+    .open();
 };
 
 const handleView = (code: string) => {
-  formViewApi.setData({ baseData: { code } });
-  formViewApi.open();
+  formViewApi.setData({ baseData: { code } }).open();
 };
 
 const handelSuccess = () => {
   reload();
 };
+
+const handleActionClick = async ({
+  code,
+  row,
+}: OnActionClickParams<QueryApi.RecordItem>) => {
+  switch (code) {
+    case 'delete': {
+      await handleDelete(row.id);
+      break;
+    }
+    case 'edit': {
+      handleEdit(row, true);
+      break;
+    }
+    case 'view': {
+      handleView(row.code);
+      break;
+    }
+  }
+};
+
+const [Grid, { reload }] = useVbenVxeGrid(
+  useTableGridOptions({
+    formOptions: {
+      schema: useSearchSchema(),
+    },
+    gridOptions: {
+      columns: useColumns(handleActionClick),
+      proxyConfig: {
+        ajax: {
+          query: async ({ page }, formValues) => {
+            return await QueryApi.getPage({
+              pageIndex: page.currentPage,
+              pageSize: page.pageSize,
+              ...formValues,
+            });
+          },
+        },
+      },
+    } as VxeTableGridOptions,
+  }),
+);
 </script>
 
 <template>
@@ -74,32 +100,6 @@ const handelSuccess = () => {
           新增查询
         </Button>
       </template>
-      <template #action="{ row }">
-        <TableAction
-          :actions="[
-            {
-              label: '编辑',
-              type: 'text',
-              disabled: !hasAccessByCodes(['query:edit']),
-              onClick: handleEdit.bind(null, row, true),
-            },
-            {
-              label: '查看',
-              type: 'text',
-              disabled: !hasAccessByCodes(['query:view']),
-              onClick: handleView.bind(null, row.code),
-            },
-          ]"
-          :drop-down-actions="[
-            {
-              label: '删除',
-              type: 'link',
-              disabled: !hasAccessByCodes(['query:delete']),
-              onClick: handleDelete.bind(null, row.id),
-            },
-          ]"
-        />
-      </template>
     </Grid>
   </Page>
 </template>