Merge branch 'main' into fix

pull/340/MERGE
Jin Mao 2026-03-24 10:24:18 +08:00 committed by GitHub
commit 9cd3987475
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 63 additions and 10 deletions

View File

@ -25,6 +25,7 @@
}, },
"type": "module", "type": "module",
"scripts": { "scripts": {
"bootstrap": "pnpm install",
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 turbo build", "build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 turbo build",
"build:analyze": "turbo build:analyze", "build:analyze": "turbo build:analyze",
"build:antd": "pnpm run build --filter=@vben/web-antd", "build:antd": "pnpm run build --filter=@vben/web-antd",

View File

@ -48,6 +48,7 @@ const {
modelPropName, modelPropName,
renderComponentContent, renderComponentContent,
rules, rules,
help,
} = defineProps< } = defineProps<
Props & { Props & {
commonComponentProps: MaybeComponentProps; commonComponentProps: MaybeComponentProps;
@ -174,6 +175,18 @@ const computedProps = computed(() => {
}; };
}); });
//
const computedHelp = computed(() => {
return help ? onHelpFunc : undefined;
});
const onHelpFunc = () => {
if (!help) {
return undefined;
}
return isFunction(help) ? help(values.value, formApi!) : help;
};
watch( watch(
() => computedProps.value?.autofocus, () => computedProps.value?.autofocus,
(value) => { (value) => {
@ -322,7 +335,7 @@ onUnmounted(() => {
labelClass, labelClass,
) )
" "
:help="help" :help="computedHelp"
:colon="colon" :colon="colon"
:label="label" :label="label"
:required="shouldRequired && !hideRequiredMark" :required="shouldRequired && !hideRequiredMark"

View File

@ -67,6 +67,14 @@ export type FormActions = FormContext<GenericObject>;
export type CustomRenderType = (() => Component | string) | string; export type CustomRenderType = (() => Component | string) | string;
// 动态渲染参数
export type CustomParamsRenderType =
| ((
value: Partial<Record<string, any>>,
actions: FormActions,
) => Component | string)
| string;
export type FormSchemaRuleType = export type FormSchemaRuleType =
| 'required' | 'required'
| 'selectRequired' | 'selectRequired'
@ -254,7 +262,7 @@ export interface FormSchema<
/** 字段名 */ /** 字段名 */
fieldName: string; fieldName: string;
/** 帮助信息 */ /** 帮助信息 */
help?: CustomRenderType; help?: CustomParamsRenderType;
/** 是否隐藏表单项 */ /** 是否隐藏表单项 */
hide?: boolean; hide?: boolean;
/** 表单项 */ /** 表单项 */

View File

@ -46,6 +46,8 @@ interface Props {
alwaysLoad?: boolean; alwaysLoad?: boolean;
/** 在api请求之前的回调函数 */ /** 在api请求之前的回调函数 */
beforeFetch?: AnyPromiseFunction<any, any>; beforeFetch?: AnyPromiseFunction<any, any>;
/** 在api请求之前的判断是否允许请求的回调函数 */
shouldFetch?: AnyPromiseFunction<any, boolean>;
/** 在api请求之后的回调函数 */ /** 在api请求之后的回调函数 */
afterFetch?: AnyPromiseFunction<any, any>; afterFetch?: AnyPromiseFunction<any, any>;
/** 直接传入选项数据也作为api返回空数据时的后备数据 */ /** 直接传入选项数据也作为api返回空数据时的后备数据 */
@ -88,6 +90,7 @@ const props = withDefaults(defineProps<Props>(), {
alwaysLoad: false, alwaysLoad: false,
loadingSlot: '', loadingSlot: '',
beforeFetch: undefined, beforeFetch: undefined,
shouldFetch: undefined,
afterFetch: undefined, afterFetch: undefined,
modelPropName: 'modelValue', modelPropName: 'modelValue',
api: undefined, api: undefined,
@ -159,7 +162,7 @@ const bindProps = computed(() => {
}); });
async function fetchApi() { async function fetchApi() {
const { api, beforeFetch, afterFetch, resultField } = props; const { api, beforeFetch, shouldFetch, afterFetch, resultField } = props;
if (!api || !isFunction(api)) { if (!api || !isFunction(api)) {
return; return;
@ -178,6 +181,14 @@ async function fetchApi() {
if (beforeFetch && isFunction(beforeFetch)) { if (beforeFetch && isFunction(beforeFetch)) {
finalParams = (await beforeFetch(cloneDeep(finalParams))) || finalParams; finalParams = (await beforeFetch(cloneDeep(finalParams))) || finalParams;
} }
//
if (
shouldFetch &&
isFunction(shouldFetch) &&
!(await shouldFetch(finalParams))
) {
return;
}
let res = await api(finalParams); let res = await api(finalParams);
if (afterFetch && isFunction(afterFetch)) { if (afterFetch && isFunction(afterFetch)) {
res = (await afterFetch(res)) || res; res = (await afterFetch(res)) || res;

View File

@ -1,5 +1,5 @@
export { setupVbenVxeTable } from './init'; export { setupVbenVxeTable } from './init';
export type { VxeTableGridOptions } from './types'; export type { VxeTableGridColumns, VxeTableGridOptions } from './types';
export * from './use-vxe-grid'; export * from './use-vxe-grid';
export { default as VbenVxeGrid } from './use-vxe-grid.vue'; export { default as VbenVxeGrid } from './use-vxe-grid.vue';

View File

@ -26,6 +26,8 @@ interface ToolbarConfigOptions extends VxeGridPropTypes.ToolbarConfig {
search?: boolean; search?: boolean;
} }
export type VxeTableGridColumns<T = any> = VxeTableGridOptions<T>['columns'];
export interface VxeTableGridOptions<T = any> extends VxeTableGridProps<T> { export interface VxeTableGridOptions<T = any> extends VxeTableGridProps<T> {
/** 工具栏配置 */ /** 工具栏配置 */
toolbarConfig?: ToolbarConfigOptions; toolbarConfig?: ToolbarConfigOptions;
@ -40,6 +42,10 @@ export interface VxeGridProps<
T extends Record<string, any> = any, T extends Record<string, any> = any,
D extends BaseFormComponentType = BaseFormComponentType, D extends BaseFormComponentType = BaseFormComponentType,
> { > {
/**
*
*/
tableData?: any[];
/** /**
* *
*/ */

View File

@ -72,6 +72,7 @@ const {
gridEvents, gridEvents,
formOptions, formOptions,
tableTitle, tableTitle,
tableData,
tableTitleHelp, tableTitleHelp,
showSearchForm, showSearchForm,
separator, separator,
@ -229,6 +230,9 @@ const options = computed(() => {
} }
if (mergedOptions.formConfig) { if (mergedOptions.formConfig) {
mergedOptions.formConfig.enabled = false; mergedOptions.formConfig.enabled = false;
if (tableData.value && tableData.value.length > 0) {
mergedOptions.data = tableData.value;
}
} }
return mergedOptions; return mergedOptions;
}); });

View File

@ -113,6 +113,10 @@ const [BaseForm, baseFormApi] = useVbenForm({
params: { params: {
keyword: keyword.value || undefined, keyword: keyword.value || undefined,
}, },
// trueapi
shouldFetch: (params: any) => {
return !!params?.keyword;
},
showSearch: true, showSearch: true,
}; };
}, },
@ -120,6 +124,7 @@ const [BaseForm, baseFormApi] = useVbenForm({
fieldName: 'remoteSearch', fieldName: 'remoteSearch',
// label // label
label: '远程搜索', label: '远程搜索',
help: '远程查询,仅有输入时方进行查询',
renderComponentContent: () => { renderComponentContent: () => {
return { return {
notFoundContent: fetching.value ? h(Spin) : undefined, notFoundContent: fetching.value ? h(Spin) : undefined,
@ -281,6 +286,8 @@ const [BaseForm, baseFormApi] = useVbenForm({
{ {
component: 'DatePicker', component: 'DatePicker',
fieldName: 'datePicker', fieldName: 'datePicker',
help: (values) =>
[`这是一个可输出其他字段值的帮助信息${values?.rate}`].map((v) => h('p', v)),
label: '日期选择框', label: '日期选择框',
}, },
{ {

View File

@ -1,4 +1,4 @@
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table'; import type { VxeTableGridColumns } from '@vben/plugins/vxe-table';
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn } from '#/adapter/vxe-table'; import type { OnActionClickFn } from '#/adapter/vxe-table';
@ -76,7 +76,7 @@ export function useSchema(): VbenFormSchema[] {
*/ */
export function useColumns( export function useColumns(
onActionClick?: OnActionClickFn<SystemDeptApi.SystemDept>, onActionClick?: OnActionClickFn<SystemDeptApi.SystemDept>,
): VxeTableGridOptions<SystemDeptApi.SystemDept>['columns'] { ): VxeTableGridColumns<SystemDeptApi.SystemDept> {
return [ return [
{ {
align: 'left', align: 'left',

View File

@ -1,4 +1,4 @@
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { OnActionClickFn, VxeTableGridColumns } from '#/adapter/vxe-table';
import type { SystemMenuApi } from '#/api/system/menu'; import type { SystemMenuApi } from '#/api/system/menu';
import { $t } from '#/locales'; import { $t } from '#/locales';
@ -23,7 +23,7 @@ export function getMenuTypeOptions() {
export function useColumns( export function useColumns(
onActionClick: OnActionClickFn<SystemMenuApi.SystemMenu>, onActionClick: OnActionClickFn<SystemMenuApi.SystemMenu>,
): VxeTableGridOptions<SystemMenuApi.SystemMenu>['columns'] { ): VxeTableGridColumns<SystemMenuApi.SystemMenu> {
return [ return [
{ {
align: 'left', align: 'left',

View File

@ -1,5 +1,5 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { OnActionClickFn, VxeTableGridColumns } from '#/adapter/vxe-table';
import type { SystemRoleApi } from '#/api'; import type { SystemRoleApi } from '#/api';
import { $t } from '#/locales'; import { $t } from '#/locales';
@ -77,7 +77,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
export function useColumns<T = SystemRoleApi.SystemRole>( export function useColumns<T = SystemRoleApi.SystemRole>(
onActionClick: OnActionClickFn<T>, onActionClick: OnActionClickFn<T>,
onStatusChange?: (newStatus: any, row: T) => PromiseLike<boolean | undefined>, onStatusChange?: (newStatus: any, row: T) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] { ): VxeTableGridColumns {
return [ return [
{ {
field: 'name', field: 'name',

View File

@ -12,12 +12,14 @@ packages:
- scripts/* - scripts/*
- docs - docs
- playground - playground
overrides: overrides:
'@ast-grep/napi': 'catalog:' '@ast-grep/napi': 'catalog:'
'@ctrl/tinycolor': 'catalog:' '@ctrl/tinycolor': 'catalog:'
clsx: 'catalog:' clsx: 'catalog:'
pinia: 'catalog:' pinia: 'catalog:'
vue: 'catalog:' vue: 'catalog:'
catalog: catalog:
'@ast-grep/napi': ^0.42.0 '@ast-grep/napi': ^0.42.0
'@changesets/changelog-github': ^0.6.0 '@changesets/changelog-github': ^0.6.0
@ -185,3 +187,4 @@ catalog:
yaml-eslint-parser: ^2.0.0 yaml-eslint-parser: ^2.0.0
zod: ^3.25.76 zod: ^3.25.76
zod-defaults: 0.1.3 zod-defaults: 0.1.3