fix(client): cannot find namespace 'Formily'

This commit is contained in:
chenos 2021-11-29 11:36:36 +08:00
parent 9fe9790a19
commit e43da7d0ca
8 changed files with 24 additions and 22 deletions

View File

@ -19,6 +19,7 @@ import Checkbox from 'antd/lib/checkbox/Checkbox';
import { useState } from 'react'; import { useState } from 'react';
import { useCompile } from '../../../hooks/useCompile'; import { useCompile } from '../../../hooks/useCompile';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { ArrayField } from '@formily/core';
const actionTypeMap = new Map( const actionTypeMap = new Map(
Object.entries({ Object.entries({
@ -30,7 +31,7 @@ const actionTypeMap = new Map(
); );
const useActionDataSource = () => { const useActionDataSource = () => {
const field = useField<Formily.Core.Models.ArrayField>(); const field = useField<ArrayField>();
const dataSource = []; const dataSource = [];
for (const [actionName, value] of actionTypeMap) { for (const [actionName, value] of actionTypeMap) {
const item = field?.value?.find((item) => { const item = field?.value?.find((item) => {
@ -50,7 +51,7 @@ const useFieldPermissions = () => {
const compile = useCompile(); const compile = useCompile();
const role = useContext(RoleContext); const role = useContext(RoleContext);
const ctx = useContext(TableRowContext); const ctx = useContext(TableRowContext);
const field = useField<Formily.Core.Models.ArrayField>(); const field = useField<ArrayField>();
const [dataSource, setDataSource] = useState([]); const [dataSource, setDataSource] = useState([]);
const findFieldKeys = (actionName): any[] => { const findFieldKeys = (actionName): any[] => {
const item = field?.value?.find((item) => { const item = field?.value?.find((item) => {
@ -189,7 +190,7 @@ export const ActionPermissionField = observer((props) => {
const compile = useCompile(); const compile = useCompile();
const role = useContext(RoleContext); const role = useContext(RoleContext);
const ctx = useContext(TableRowContext); const ctx = useContext(TableRowContext);
const field = useField<Formily.Core.Models.ArrayField>(); const field = useField<ArrayField>();
const actionDataSource = useActionDataSource(); const actionDataSource = useActionDataSource();
const { columns, dataSource, service } = useFieldPermissions(); const { columns, dataSource, service } = useFieldPermissions();
console.log('actionPermissions', field?.value); console.log('actionPermissions', field?.value);

View File

@ -39,7 +39,7 @@ import { useContext } from 'react';
import { SchemaField, useDesignable } from '../../components/schema-renderer'; import { SchemaField, useDesignable } from '../../components/schema-renderer';
import { ActionBar } from './ActionBar'; import { ActionBar } from './ActionBar';
import { ActionDesignableBar } from './Action'; import { ActionDesignableBar } from './Action';
import { createForm } from '@formily/core'; import { ArrayField, createForm } from '@formily/core';
import { get } from 'lodash'; import { get } from 'lodash';
import flatten from 'flat'; import flatten from 'flat';
import { import {
@ -145,7 +145,7 @@ const toEvents = (data: any[], fieldNames: any) => {
export const Calendar: any = observer((props: any) => { export const Calendar: any = observer((props: any) => {
const { t } = useTranslation(); const { t } = useTranslation();
const field = useField<Formily.Core.Models.ArrayField>(); const field = useField<ArrayField>();
const { collectionName, fieldNames = {} } = props; const { collectionName, fieldNames = {} } = props;
console.log('Calendar', props); console.log('Calendar', props);
const { schema } = useDesignable(); const { schema } = useDesignable();

View File

@ -52,6 +52,7 @@ import {
import { DndContext, DragOverlay } from '@dnd-kit/core'; import { DndContext, DragOverlay } from '@dnd-kit/core';
import { createPortal } from 'react-dom'; import { createPortal } from 'react-dom';
import { useClient } from '../../constate'; import { useClient } from '../../constate';
import { ArrayField } from '@formily/core';
interface SelectOptionProps { interface SelectOptionProps {
id: any; id: any;
@ -88,7 +89,7 @@ function SelectOption(props: SelectOptionProps) {
} }
export const DatabaseCollection = observer((props) => { export const DatabaseCollection = observer((props) => {
const field = useField<Formily.Core.Models.ArrayField>(); const field = useField<ArrayField>();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const schema = useFieldSchema(); const schema = useFieldSchema();
@ -320,7 +321,7 @@ export const DatabaseCollection = observer((props) => {
}); });
export const DatabaseField: any = observer((props) => { export const DatabaseField: any = observer((props) => {
const field = useField<Formily.Core.Models.ArrayField>(); const field = useField<ArrayField>();
useEffect(() => { useEffect(() => {
if (!field.value) { if (!field.value) {
field.setValue([]); field.setValue([]);

View File

@ -20,6 +20,7 @@ import {
import { FullscreenOutlined } from '@ant-design/icons'; import { FullscreenOutlined } from '@ant-design/icons';
import moment from 'moment'; import moment from 'moment';
import { useCompile } from '../../hooks/useCompile'; import { useCompile } from '../../hooks/useCompile';
import { Field } from '@formily/core';
const PlaceholderContext = createContext<string>(''); const PlaceholderContext = createContext<string>('');
@ -113,7 +114,7 @@ const TextArea: React.FC<any> = (props) => {
}; };
const Select: React.FC<SelectProps<any>> = observer((props) => { const Select: React.FC<SelectProps<any>> = observer((props) => {
const field = useField<Formily.Core.Models.Field>(); const field = useField<Field>();
const prefixCls = usePrefixCls('description-select', props); const prefixCls = usePrefixCls('description-select', props);
const dataSource: any[] = field?.dataSource?.length const dataSource: any[] = field?.dataSource?.length
? field.dataSource ? field.dataSource
@ -157,7 +158,7 @@ const Select: React.FC<SelectProps<any>> = observer((props) => {
}); });
const ObjectSelect: React.FC<SelectProps<any>> = observer((props) => { const ObjectSelect: React.FC<SelectProps<any>> = observer((props) => {
const field = useField<Formily.Core.Models.Field>(); const field = useField<Field>();
const prefixCls = usePrefixCls('description-select', props); const prefixCls = usePrefixCls('description-select', props);
const dataSource: any[] = field?.dataSource?.length const dataSource: any[] = field?.dataSource?.length
? field.dataSource ? field.dataSource
@ -201,7 +202,7 @@ const ObjectSelect: React.FC<SelectProps<any>> = observer((props) => {
}); });
const TreeSelect: React.FC<TreeSelectProps<any>> = observer((props) => { const TreeSelect: React.FC<TreeSelectProps<any>> = observer((props) => {
const field = useField<Formily.Core.Models.Field>(); const field = useField<Field>();
const placeholder = usePlaceholder(); const placeholder = usePlaceholder();
const prefixCls = usePrefixCls('description-tree-select', props); const prefixCls = usePrefixCls('description-tree-select', props);
const dataSource = field?.dataSource?.length const dataSource = field?.dataSource?.length
@ -259,7 +260,7 @@ const TreeSelect: React.FC<TreeSelectProps<any>> = observer((props) => {
}); });
const Cascader: React.FC<CascaderProps> = observer((props) => { const Cascader: React.FC<CascaderProps> = observer((props) => {
const field = useField<Formily.Core.Models.Field>(); const field = useField<Field>();
const placeholder = usePlaceholder(); const placeholder = usePlaceholder();
const prefixCls = usePrefixCls('description-cascader', props); const prefixCls = usePrefixCls('description-cascader', props);
const dataSource: any[] = field?.dataSource?.length const dataSource: any[] = field?.dataSource?.length

View File

@ -34,9 +34,7 @@ export const DesignableBar = (props) => {
<Menu.Item onClick={() => {}}> <Menu.Item onClick={() => {}}>
<Switch <Switch
onChange={(checked) => { onChange={(checked) => {
// field.query(key).take((target: Formily.Core.Models.Field) => {
// target.required = checked;
// });
}} }}
checkedChildren="必填" checkedChildren="必填"
unCheckedChildren="非必填" unCheckedChildren="非必填"

View File

@ -439,7 +439,7 @@ Select.Drawer = connect(
mapReadPretty( mapReadPretty(
observer((props: any) => { observer((props: any) => {
const collectionField = useContext(CollectionFieldContext); const collectionField = useContext(CollectionFieldContext);
const field = useField<Formily.Core.Models.Field>(); const field = useField<Field>();
const { ...others } = props; const { ...others } = props;
const value = field.value || field.initialValue; const value = field.value || field.initialValue;
const { schema } = useDesignable(); const { schema } = useDesignable();

View File

@ -55,7 +55,7 @@ import {
import { useResource as useGeneralResource } from '../../hooks/useResource'; import { useResource as useGeneralResource } from '../../hooks/useResource';
import SwitchMenuItem from '../../components/SwitchMenuItem'; import SwitchMenuItem from '../../components/SwitchMenuItem';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { createForm,LifeCycleTypes } from '@formily/core'; import { ArrayField, createForm,LifeCycleTypes } from '@formily/core';
import { import {
ColDraggableContext, ColDraggableContext,
SortableBodyCell, SortableBodyCell,
@ -78,7 +78,7 @@ import { useCompile } from '../../hooks/useCompile';
export interface ITableContext { export interface ITableContext {
props: any; props: any;
field: Formily.Core.Models.ArrayField; field: ArrayField;
schema: Schema; schema: Schema;
service: BaseResult<any, any>; service: BaseResult<any, any>;
selectedRowKeys?: any; selectedRowKeys?: any;
@ -811,7 +811,7 @@ const TableMain = () => {
}; };
const usePagination = () => { const usePagination = () => {
const field = useField<Formily.Core.Models.ArrayField>(); const field = useField<ArrayField>();
const paginationProps = field.componentProps.pagination; const paginationProps = field.componentProps.pagination;
let pagination = paginationProps; let pagination = paginationProps;
@ -856,7 +856,7 @@ const TableProvider = (props: any) => {
...others ...others
} = props; } = props;
const { schema } = useDesignable(); const { schema } = useDesignable();
const field = useField<Formily.Core.Models.ArrayField>(); const field = useField<ArrayField>();
const [pagination, setPagination] = usePagination(); const [pagination, setPagination] = usePagination();
const { selectedRowKeys, setSelectedRowKeys } = useSelectedRowKeys(); const { selectedRowKeys, setSelectedRowKeys } = useSelectedRowKeys();
console.log('props.useSelectedRowKeys', selectedRowKeys); console.log('props.useSelectedRowKeys', selectedRowKeys);

View File

@ -29,6 +29,7 @@ import './style.less';
import cls from 'classnames'; import cls from 'classnames';
import { saveAs } from 'file-saver'; import { saveAs } from 'file-saver';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Field } from '@formily/core';
const toArr = (value) => { const toArr = (value) => {
if (!isValid(value)) { if (!isValid(value)) {
@ -140,7 +141,7 @@ const normalizeFileList = (fileList: UploadFile[]) => {
}; };
const useValidator = (validator: (value: any) => string) => { const useValidator = (validator: (value: any) => string) => {
const field = useField<Formily.Core.Models.Field>(); const field = useField<Field>();
useEffect(() => { useEffect(() => {
const dispose = reaction( const dispose = reaction(
() => field.value, () => field.value,
@ -196,7 +197,7 @@ export const Upload: ComposedUpload = connect(
value: 'fileList', value: 'fileList',
}), }),
mapReadPretty((props) => { mapReadPretty((props) => {
const field = useField<Formily.Core.Models.Field>(); const field = useField<Field>();
console.log('field.value', field.value); console.log('field.value', field.value);
return (field.value || []).map((item) => ( return (field.value || []).map((item) => (
<div> <div>
@ -474,7 +475,7 @@ Upload.Attachment = connect(
); );
}, },
mapReadPretty((props) => { mapReadPretty((props) => {
const field = useField<Formily.Core.Models.Field>(); const field = useField<Field>();
const images = toImages(toArr(field.value)); const images = toImages(toArr(field.value));
const [photoIndex, setPhotoIndex] = useState(0); const [photoIndex, setPhotoIndex] = useState(0);
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);