Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: 在vxe-table中的form中,设置 submitOnChange: true 时,RangePicker fieldMappingTime 不生效 #5289

Closed
5 tasks done
li-yi-hong opened this issue Jan 2, 2025 · 0 comments · Fixed by #5333
Closed
5 tasks done

Comments

@li-yi-hong
Copy link

li-yi-hong commented Jan 2, 2025

Version

Vben Admin V5

Describe the bug?

在vxe-table中的searchForm中,设置formOptions为 submitOnChange: true 时,RangePicker fieldMappingTime 不生效。submitOnChange: false 时,手动查询生成的params正常。

submitOnChange: true时,没有经过handleRangeTimeValue方法处理,生成的url:
http://localhost:5555/api/table/list?page=1&pageSize=20&category=1&createTime[]=Thu, 02 Jan 2025 09:57:23 GMT&createTime[]=Fri, 31 Jan 2025 09:57:23 GMT

submitOnChange: false时,生成的url:
http://localhost:5555/api/table/list?page=1&pageSize=20&category=1&startTime=2025-01-02&endTime=2025-01-31

Reproduction

复现代码,将 /playground/src/views/examples/vxe-table/form.vue 最后的一列 DatePicker改为 RangePicker,并在 formOptions中添加属性 fieldMappingTime: [['createTime', ['startTime', 'endTime'], 'YYYY-MM-DD']]

完整代码如下:

<script lang="ts" setup>
import type { VbenFormProps } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { Page } from '@vben/common-ui';

import { message } from 'ant-design-vue';

import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getExampleTableApi } from '#/api';

interface RowType {
  category: string;
  color: string;
  id: string;
  price: string;
  productName: string;
  releaseDate: string;
}

const formOptions: VbenFormProps = {
  // 默认展开
  collapsed: false,
  fieldMappingTime: [['createTime', ['startTime', 'endTime'], 'YYYY-MM-DD']],
  schema: [
    {
      component: 'Input',
      defaultValue: '1',
      fieldName: 'category',
      label: 'Category',
    },
    {
      component: 'Input',
      fieldName: 'productName',
      label: 'ProductName',
    },
    {
      component: 'Input',
      fieldName: 'price',
      label: 'Price',
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [
          {
            label: 'Color1',
            value: '1',
          },
          {
            label: 'Color2',
            value: '2',
          },
        ],
        placeholder: '请选择',
      },
      fieldName: 'color',
      label: 'Color',
    },
    {
      component: 'RangePicker',
      fieldName: 'createTime',
      label: 'Date',
    },
  ],
  // 控制表单是否显示折叠按钮
  showCollapseButton: true,
  // 是否在字段值改变时提交表单
  submitOnChange: true,
  // 按下回车时是否提交表单
  submitOnEnter: false,
};

const gridOptions: VxeTableGridOptions<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: 'name',
  },
  columns: [
    { title: '序号', type: 'seq', width: 50 },
    { align: 'left', title: 'Name', type: 'checkbox', width: 100 },
    { field: 'category', title: 'Category' },
    { field: 'color', title: 'Color' },
    { field: 'productName', title: 'Product Name' },
    { field: 'price', title: 'Price' },
    { field: 'releaseDate', formatter: 'formatDateTime', title: 'Date' },
  ],
  exportConfig: {},
  height: 'auto',
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        message.success(`Query params: ${JSON.stringify(formValues)}`);
        return await getExampleTableApi({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  toolbarConfig: {
    custom: true,
    export: true,
    refresh: true,
    resizable: true,
    search: true,
    zoom: true,
  },
};

const [Grid] = useVbenVxeGrid({
  formOptions,
  gridOptions,
});
</script>

<template>
  <Page auto-content-height>
    <Grid />
  </Page>
</template>

System Info

no output

Relevant log output

No response

Validations

@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant