Skip to content

Commit

Permalink
fix: 修复一些细小的代码逻辑问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Grothendieck42 committed Sep 20, 2024
1 parent c82376e commit 5e2886f
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/editor/src/components/InputSelect/InputSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const InputSelect: React.FC = ({ value, onChange, ...props }: any) => {
const addItem = (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
e.preventDefault();
if (name.trim() === '') return;
if (items.find((item) => item.value === name)) return;
setItems([...items, { label: name, value: name }]);
setName('');
setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const SelectVariableModal = ({ onSelect }: { onSelect: (record: any) => void },
} else if (node.type === 'EditTable') {
const name = elementsMap[node.id]?.config.props.field;
if (name) form.setFieldValue('expression', `${beforeExpression} context.${node.parentId}.${name}`.trimStart());
} else if (node.type === 'Form') {
} else if (node.type === 'Form' || node.type === 'SearchForm') {
form.setFieldValue('expression', `${beforeExpression} context.${node.id}`);
} else {
const formItem = elementsMap[node.id]?.config.props.formItem;
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/packages/FormItems/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as icons from '@ant-design/icons';
import { ComponentType } from '@/packages/types';
import { isNull } from '@/packages/utils/util';
import { FormContext } from '@/packages/utils/context';
import omit from 'lodash-es/omit';

/* 泛型只需要定义组件本身用到的属性,当然也可以不定义,默认为any */
export interface IConfig {
Expand Down Expand Up @@ -76,7 +77,7 @@ const MInput = ({ id, type, config, onChange, onBlur, onPressEnter }: ComponentT
visible && (
<Form.Item {...config.props.formItem} data-id={id} data-type={type}>
<Input
{...config.props.formWrap}
{...omit(config.props.formWrap, ['prefixIcons', 'suffixIcons'])}
disabled={disabled}
variant={config.props.formWrap.variant || undefined}
style={config.style}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default {
name: ['formWrap', 'multiple'],
},
{
type: 'Switch',
type: 'Input',
label: '默认提示',
name: ['formWrap', 'placeholder'],
},
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/packages/utils/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ const handleVisible = async ({ action, next }: ActionNode<{ target: string; show
ref.hide({ ...data });
}
} else {
const result = action.expression;
const expression = action.expression ?? {};
const formula = expression.value;
const result = renderFormula(formula);
if (result) {
ref.show({ ...data });
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/packages/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export const handleArrayVariable = (list: any = [], data: any = {}) => {
}
} else {
if (next.value.type === 'static') {
if (isNotEmpty(next.value)) {
if (isNotEmpty(next.value.value)) {
// 解析模板语法
const val: any = renderTemplate(next.value.value, data);
// 数字转换
Expand Down Expand Up @@ -369,7 +369,7 @@ export const loadStyle = (id: string, src: string) => {
link.href = src;
link.onload = resolve;
link.onerror = reject;

link.setAttribute('id', id);
// 将link元素添加到DOM的head部分
document.getElementsByTagName('HEAD')[0].appendChild(link);
});
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/pages/admin/menu/CreateMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export default function CreateMenu(props: IModalProp<Menu.EditParams>) {
setVisible(true);
setLoading(true);
// 获取菜单列表
await getMenus();
await getMyPageList();
const p1 = getMenus();
const p2 = getMyPageList();
await Promise.all([p1, p2]);
setLoading(false);
if (data && project_id) {
form.setFieldsValue({ ...data, project_id: parseInt(project_id), code: data.code?.split('_')[2] || '' });
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/pages/welcome/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function Welcome() {
setShadow(false);
}
};
() => {
return () => {
el.onscroll = null;
};
}, []);
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/stores/pageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export const usePageStore = create<PageState & PageAction>((set) => ({
if (!item.config.props.items) item.config.props.items = [];
item.config.props.items[payload.index] = payload.props;
} else {
if (!item.config.props.actionList) item.config.props.actionList = [];
if (!item.config.props.bulkActionList) item.config.props.bulkActionList = [];
item.config.props.bulkActionList[payload.index] = payload.props;
}
state.isUpdateToolbar = !state.isUpdateToolbar;
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function generateUUID(): string {
if (crypto?.getRandomValues) {
return crypto.getRandomValues(new Uint8Array(1))[0];
} else {
return Math.floor(Math.random()) * 256;
return Math.floor(Math.random() * 256);
}
};
return (String(1e7) + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) => (Number(c) ^ (randomMethod() & (15 >> (Number(c) / 4)))).toString(16));
Expand Down Expand Up @@ -68,7 +68,7 @@ export const parseStyle = (inputCss: string) => {
.replace('}', '');
parse(inputCss, (name, value) => {
// 把中划线语法替换为驼峰
cssObject[name.replace(/-\w/, (item) => item.toUpperCase().replace('-', ''))] = value;
cssObject[name.replace(/-\w/g, (item) => item.toUpperCase().replace('-', ''))] = value;
});
} catch (error) {
// 如果报错,说明CSS没写完,不能生成对应object,此时直接返回,不需要保存
Expand Down
3 changes: 2 additions & 1 deletion packages/materials/FormItems/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as icons from '@ant-design/icons';
import { ComponentType } from '../../types';
import { isNull } from '../../utils/util';
import { FormContext } from '../../utils/context';
import omit from 'lodash-es/omit';

/* 泛型只需要定义组件本身用到的属性,当然也可以不定义,默认为any */
export interface IConfig {
Expand Down Expand Up @@ -79,7 +80,7 @@ const MInput = ({ config, onChange, onBlur, onPressEnter }: ComponentType<IConfi
visible && (
<Form.Item {...config.props.formItem}>
<Input
{...config.props.formWrap}
{...omit(config.props.formWrap, ['prefixIcons', 'suffixIcons'])}
disabled={disabled}
variant={config.props.formWrap.variant || undefined}
style={config.style}
Expand Down
4 changes: 3 additions & 1 deletion packages/materials/utils/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ const handleVisible = async ({ action, next }: ActionNode<{ target: string; show
ref.hide({ ...data });
}
} else {
const result = action.expression;
const expression = action.expression ?? {};
const formula = expression.value;
const result = renderFormula(formula);
if (result) {
ref.show({ ...data });
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/materials/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const handleArrayVariable = (list: any = [], data: any = {}) => {
}
} else {
if (next.value.type === 'static') {
if (isNotEmpty(next.value)) {
if (isNotEmpty(next.value.value)) {
// 解析模板语法
const val: any = renderTemplate(next.value.value, data);
// 数字转换
Expand Down Expand Up @@ -367,7 +367,7 @@ export const loadStyle = (id: string, src: string) => {
link.href = src;
link.onload = resolve;
link.onerror = reject;

link.setAttribute('id', id);
// 将link元素添加到DOM的head部分
document.getElementsByTagName('HEAD')[0].appendChild(link);
});
Expand Down

0 comments on commit 5e2886f

Please sign in to comment.