Skip to content

Commit

Permalink
fix field
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtanglove committed Jul 23, 2021
1 parent ce7f7d4 commit 8000b51
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
},
proxy: {
'/api/': {
target: 'http://quark-admin.test',
target: 'http://www.web.com',
changeOrigin: true,
pathRewrite: { '^/api': '/api' },
},
Expand Down
13 changes: 3 additions & 10 deletions mock/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export default {
component: "when",
items: [
{
condition: "<%=username == 'abc' %>",
condition: "<%=(['love','tt'].indexOf(username) !=-1) %>",
body: [
{
component: "text",
body: "您输入的用户名超过100个字符了",
body: "您输入的用户名中包含了${username}字符串",
},
]
},
Expand All @@ -54,14 +54,7 @@ export default {
}
]
}
},
{
component: "passwordField",
label: "密码",
name: "password",
displayWhen: "username === 'abcd'",
style: {width: 200}
},
}
]
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/Form/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Geofence from './Geofence';
import Editor from './Editor';
import Cascader from './Cascader';
import Render from '@/components/Render';
import { tplEngine } from '@/utils/template';

const Field : React.FC<any> = (props:any) => {

Expand Down Expand Up @@ -95,6 +96,7 @@ const Field : React.FC<any> = (props:any) => {
addonAfter={props.addonAfter}
addonBefore={props.addonBefore}
size={props.size}
onChange={(e)=>{onChange(e.target.value, props.name)}}
/>
</Form.Item>;
break;
Expand All @@ -118,6 +120,7 @@ const Field : React.FC<any> = (props:any) => {
onKeyPress={(e) => {
e.stopPropagation();
}}
onChange={(e)=>{onChange(e.target.value, props.name)}}
/>
</Form.Item>;
break;
Expand All @@ -141,6 +144,7 @@ const Field : React.FC<any> = (props:any) => {
max={props.max}
step={props.step}
precision={props.precision}
onChange={(value)=>{onChange(value,props.name)}}
/>
</Form.Item>;
break;
Expand Down Expand Up @@ -191,6 +195,7 @@ const Field : React.FC<any> = (props:any) => {
style={props.style ? props.style : []}
options={props.options}
disabled={props.disabled}
onChange={(value)=>{onChange(value,props.name)}}
/>
</Form.Item>;
break;
Expand All @@ -208,6 +213,7 @@ const Field : React.FC<any> = (props:any) => {
style={props.style ? props.style : []}
options={props.options}
disabled={props.disabled}
onChange={(e)=>{onChange(e.target.value,props.name)}}
/>
</Form.Item>;
break;
Expand Down Expand Up @@ -271,6 +277,7 @@ const Field : React.FC<any> = (props:any) => {
disabled={props.disabled}
checkedChildren={props.options.on}
unCheckedChildren={props.options.off}
onChange={(value)=>{onChange(value,props.name)}}
/>
</Form.Item>;
break;
Expand Down Expand Up @@ -516,7 +523,9 @@ const Field : React.FC<any> = (props:any) => {

// 解析when
if(props.when) {
return <>{component}<Render body={props.when} data={window[props.data.formKey]?.getFieldsValue()} callback={props.callback} /></>;
let fieldData:any = {};
fieldData[props.name] = window[props.data.formKey]?.getFieldValue(props.name);
return <>{component}<Render body={props.when} data={fieldData} callback={props.callback} /></>;
} else {
return component;
}
Expand Down

0 comments on commit 8000b51

Please sign in to comment.