- products.find((p)) → ((product)),propertyList.find((p)) → ((property)) 等:把 .find / .filter / .map / .reduce 的单字母回调参数 (p / d / s / g / v / acc / val) 全部展开为 product / device / service / group / value / total 等完整命名 - 涉及 web-antd 与 web-ele 两侧 :device 列表 / 卡片 / 物模型属性历史 / ota 固件 / 场景执行器服务选择 / 属性选择器 / 产品选择组件 - 外层已绑定同名变量的场景,回调形参用 item 避免命名重复
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import type {
|
|
VbenFormProps as FormProps,
|
|
VbenFormSchema as FormSchema,
|
|
} from '@vben/common-ui';
|
|
|
|
import type { ComponentPropsMap, ComponentType } from './component';
|
|
|
|
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
|
|
import { $t } from '@vben/locales';
|
|
import { isMobile } from '@vben/utils';
|
|
|
|
async function initSetupVbenForm() {
|
|
setupVbenForm<ComponentType>({
|
|
config: {
|
|
modelPropNameMap: {
|
|
Upload: 'fileList',
|
|
CheckboxGroup: 'model-value',
|
|
},
|
|
},
|
|
defineRules: {
|
|
required: (value, _params, ctx) => {
|
|
if (value === undefined || value === null || value.length === 0) {
|
|
return $t('ui.formRules.required', [ctx.label]);
|
|
}
|
|
return true;
|
|
},
|
|
selectRequired: (value, _params, ctx) => {
|
|
if (value === undefined || value === null) {
|
|
return $t('ui.formRules.selectRequired', [ctx.label]);
|
|
}
|
|
return true;
|
|
},
|
|
// 手机号非必填
|
|
mobile: (value, _params, ctx) => {
|
|
if (value === undefined || value === null || value.length === 0) {
|
|
return true;
|
|
} else if (!isMobile(value)) {
|
|
return $t('ui.formRules.mobile', [ctx.label]);
|
|
}
|
|
return true;
|
|
},
|
|
// 手机号必填
|
|
mobileRequired: (value, _params, ctx) => {
|
|
if (value === undefined || value === null || value.length === 0) {
|
|
return $t('ui.formRules.required', [ctx.label]);
|
|
}
|
|
if (!isMobile(value)) {
|
|
return $t('ui.formRules.mobile', [ctx.label]);
|
|
}
|
|
return true;
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
const useVbenForm = useForm<ComponentType, ComponentPropsMap>;
|
|
|
|
export { initSetupVbenForm, useVbenForm, z };
|
|
|
|
export type VbenFormApi = ReturnType<typeof useVbenForm>[1]; // add by 芋艿:用于 data.ts 表单 schema 内调用 setFieldValue
|
|
export type VbenFormSchema = FormSchema<ComponentType, ComponentPropsMap>;
|
|
export type VbenFormProps = FormProps<ComponentType, ComponentPropsMap>;
|