Skip to content

Commit

Permalink
Merge pull request #1442 from alibaba/fr-mobile-removehidden
Browse files Browse the repository at this point in the history
Fr mobile removehidden
  • Loading branch information
lhbxs authored Nov 13, 2023
2 parents 96bd324 + dd52e13 commit 784fb51
Show file tree
Hide file tree
Showing 26 changed files with 99 additions and 936 deletions.
3 changes: 3 additions & 0 deletions packages/form-render-mobile/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 更新日志

### 1.0.15
- [!] 修复 removeHidden 配置不生效

### 1.0.14
- [+] labelWidget、descWidget 增加 addons 访问属性
- [-] 兼容 widget 大小写配置
Expand Down
5 changes: 3 additions & 2 deletions packages/form-render-mobile/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-render-mobile",
"version": "1.0.14",
"version": "1.0.15",
"description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
"keywords": [
"Form",
Expand Down Expand Up @@ -64,7 +64,8 @@
"rc-color-picker": "^1.2.6",
"virtualizedtableforantd4": "^1.1.2",
"zustand": "^4.1.5",
"ahooks": "3.7.5"
"ahooks": "3.7.5",
"form-render": "^2.3.6"
},
"devDependencies": {
"deep-equal": "^2.0.3",
Expand Down
62 changes: 29 additions & 33 deletions packages/form-render-mobile/src/form-core/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React, { useEffect, useContext } from 'react';
import { Form, Grid } from 'antd-mobile';
import { useStore } from 'zustand';
import cx from 'classnames';
import classnames from 'classnames';
import { cloneDeep } from 'lodash-es';
import { parseValuesToBind } from 'form-render/es/models/bindValues';
import filterValuesUndefined from 'form-render/es/models/filterValuesUndefined';
import filterValuesHidden from 'form-render/es/models/filterValuesHidden';

import { valueRemoveUndefined, _cloneDeep, isFunction } from '../utils';
import { FRContext } from '../models/context';
import transformProps from '../models/transformProps';
import { parseValuesToBind } from '../models/bindValues';

import {
valuesWatch,
Expand All @@ -15,7 +18,7 @@ import {
msToTime,
getSessionItem,
setSessionItem
} from '../models/formCoreUtils';
} from 'form-render/es/models/formCoreUtils';
import RenderCore from '../render-core';

import './index.less';
Expand Down Expand Up @@ -59,6 +62,10 @@ const FormCore = (props: any) => {
form.setSchema(props.schema, true);
}, [JSON.stringify(props.schema || {})]);

useEffect(() => {
store.setState({ removeHiddenData });
}, [removeHiddenData]);

useEffect(() => {
const context = {
column,
Expand All @@ -74,9 +81,11 @@ const FormCore = (props: any) => {

const initial = async () => {
onMount && await onMount();
const values = form.getValues();
immediateWatch(watch, values);
onMountLogger();
setTimeout(() => {
const values = form.getValues();
immediateWatch(watch, values);
}, 0);
};

const onMountLogger = () => {
Expand Down Expand Up @@ -144,52 +153,39 @@ const FormCore = (props: any) => {
valuesWatch(changedValues, allValues, watch);
};

const handleFinish = async (_values: any) => {
onSubmitLogger({ values: _values });
let values = _cloneDeep(_values);
if (!removeHiddenData) {
values = _cloneDeep(form.getFieldsValue(true));
}
const transFormValues = (_values: any) => {
let values = cloneDeep(_values);
values = removeHiddenData ? filterValuesHidden(values, flattenSchema) : cloneDeep(form.getFieldsValue(true));
values = parseValuesToBind(values, flattenSchema);
values = valueRemoveUndefined(values);

let fieldsError = beforeFinish
? await beforeFinish({ data: values, schema, errors: [] })
: null;
values = filterValuesUndefined(values);
return values;
};

// console.log(values, form.getValues(true));
// Stop submit
if (fieldsError) {
const handleFinish = async (_values: any) => {
const values = transFormValues(_values);
const fieldsError = beforeFinish ? await beforeFinish({ data: values, schema, errors: [] }) : null;
// console.log(values, form.getValues(true), _values);
if (fieldsError?.length > 0) {
form.setFields(fieldsError);
return;
}

onSubmitLogger({ values });
onFinish && onFinish(values, []);
};

const handleFinishFailed = async (params: any) => {
onSubmitLogger(params);
const values = transFormValues(params.values);
onSubmitLogger({ ...params, values });
if (!onFinishFailed) {
return;
}
let values = _cloneDeep(params?.values);
if (!removeHiddenData) {
values = _cloneDeep(form.getFieldsValue(true));
}
values = parseValuesToBind(values, flattenSchema);
values = valueRemoveUndefined(values);

onFinishFailed({ ...params, values });
};

const formClassName = cx('frm-form', className, {
['frm-form-card']: isCardMode,
});

return (
<Form
{...formProps}
className={formClassName}
className={classnames('frm-form', className, { ['frm-form-card']: isCardMode })}
form={form}
onFinish={handleFinish}
onFinishFailed={handleFinishFailed}
Expand Down
172 changes: 0 additions & 172 deletions packages/form-render-mobile/src/models/bindValues.ts

This file was deleted.

Loading

0 comments on commit 784fb51

Please sign in to comment.