fix(公共): 编译报错

This commit is contained in:
xinxin.wu 2023-12-05 11:57:53 +08:00 committed by 刘瑞斌
parent aa81334f3f
commit b4915df347
3 changed files with 28 additions and 22 deletions

View File

@ -16,7 +16,7 @@
import type { FormItem } from './types';
import { FormRuleItem } from './types';
import formCreate from '@form-create/arco-design';
import formCreate, { Rule } from '@form-create/arco-design';
const formCreateStore = useFormCreateStore();
@ -49,7 +49,7 @@
formCreateKey: FormCreateKeyEnum[keyof FormCreateKeyEnum]; // Key
}>();
const emit = defineEmits(['update:form-rule']);
// const emit = defineEmits(['update:form-rule']);
const formApi = ref<any>({});
@ -59,25 +59,27 @@
// cascadeitem
if (currentFormCreateRules) {
const cascade = currentFormCreateRules
.map((item: FormRuleItem) => item.link)
.filter((item) => item)
.map((item: Record<string, any>) => item.link)
.filter((item: Record<string, any>) => item)
.flatMap((flatItem: any) => flatItem);
// linkitem
return currentFormCreateRules.filter((item: FormRuleItem) => {
return currentFormCreateRules.filter((item: Record<string, any>) => {
return cascade.indexOf(item.field) > -1;
});
}
});
//
const getOptionsRequest = debounce((val: FormRuleItem) => {
const getOptionsRequest = debounce((val: any) => {
//
// link
const totalFormList = formCreateStore.formCreateRuleMap.get(props.formCreateKey);
if (totalFormList) {
const resultItem = totalFormList.find(
(item) => item.link && (item.link as string[]).indexOf(val.field as string) > -1
(item: Record<string, any>) => item.link && (item.link as string[]).indexOf(val.field as string) > -1
);
if (resultItem) formCreateStore.getOptions(val, props.formCreateKey, resultItem, formApi.value);
if (resultItem) {
formCreateStore.getOptions(val, props.formCreateKey, resultItem as Rule, formApi.value);
}
}
}, 300);
@ -86,7 +88,7 @@
(val) => {
// options
if (val) {
val.forEach(async (item) => {
val.forEach(async (item: any) => {
if (item.value) {
await getOptionsRequest(item);
}
@ -100,7 +102,7 @@
const formRules = ref<FormItem[]>([]);
watch(
() => props.formRule,
(val) => {
() => {
formRules.value = props.formRule;
formCreateStore.setInitFormCreate(props.formCreateKey, props.formRule);
formCreateStore.initFormCreateFormRules(props.formCreateKey);
@ -115,7 +117,7 @@
watch(
() => formData.value,
(val) => {
() => {
formRuleList.value = formCreateStore.formCreateRuleMap.get(props.formCreateKey) as FormRuleItem[];
}
);
@ -125,7 +127,7 @@
() => {
//
const result = formRuleList.value.map((item: any) => {
const type = props.formRule.find((it) => it.name === item.field)?.type;
const type = props.formRule.find((it: any) => it.name === item.field)?.type;
const formItemRule = {
name: item.field,
type,

View File

@ -1,6 +1,6 @@
import { FieldRule } from '@arco-design/web-vue';
import { FormRule } from '@form-create/arco-design';
import { Rule } from '@form-create/arco-design';
export type FormItemType =
| 'INPUT'
@ -30,9 +30,10 @@ export interface FormItemDefaultOptions {
text: string;
value: string;
}
export type FormRuleItem = FormRule & {
// 内置formCreateRule所有配置的项
export type FormRuleItem = Rule & {
props: Record<string, any>;
[key: string]: any;
};
// 表单配置项
export interface FormItem {

View File

@ -7,8 +7,9 @@ import { useI18n } from '@/hooks/useI18n';
import { FormCreateKeyEnum } from '@/enums/formCreateEnum';
const { t } = useI18n();
import type { Rule } from '@form-create/arco-design';
const { t } = useI18n();
const useFormCreateStore = defineStore('form-create', {
persist: false,
state: (): {
@ -104,17 +105,19 @@ const useFormCreateStore = defineStore('form-create', {
async getOptions(
val: FormRuleItem,
key: FormCreateKeyEnum[keyof FormCreateKeyEnum],
cascadeItem: FormRuleItem,
cascadeItem: Rule,
formValueApi: any
) {
const formValue = formValueApi.formData();
// 设置自定义属性给到searchSelect
const formCreateRuleArr = this.formCreateRuleMap.get(key);
const formCreateItem = formCreateRuleArr?.find((items: FormRuleItem) => cascadeItem.field === items.field);
if (formCreateItem) {
const formCreateRuleArr = this.formCreateRuleMap.get(key) as Rule[];
if (formCreateRuleArr) {
const formCreateItem = formCreateRuleArr.find((item: Rule) => cascadeItem.field === item.field);
if (formCreateItem && formCreateItem.props) {
formCreateItem.props.keyword = val.value;
formCreateItem.props.formValue = formValue;
}
}
},
},
getters: {},