lodash#words JavaScript Examples
The following examples show how to use
lodash#words.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DimensionConfigsEditForm.js From hzero-front with Apache License 2.0 | 4 votes |
DimensionConfigsEditForm = ({
form,
dimensions = [],
isCreate = true,
dimensionConfig,
dimensionTypes = [],
interactedRef,
rateLimitLine, // 只有在新建规则后才能编辑维度规则
}) => {
let tenantId = form.getFieldValue(getDimensionValueDataIndex('tenant'));
if (isUndefined(tenantId)) {
tenantId = dimensionConfig[getDimensionValueDataIndex('tenant')];
}
React.useImperativeHandle(
interactedRef,
() => ({
getValidateData() {
return new Promise((resolve, reject) => {
form.validateFields((err, values) => {
if (err) {
reject(err);
} else {
resolve(values);
}
});
});
},
}),
[interactedRef, form]
);
return (
<Form>
{dimensions
.map(dimension => {
const dimensionItem = dimensionTypes.find(item => item.value === dimension);
const fieldName = getDimensionValueDataIndex(dimensionItem.value);
const meaningField = getDimensionMeaningDataIndex(dimensionItem.value);
const hasTenant = dimensions.includes('tenant');
let inputEle;
switch (dimensionItem.value) {
case 'user':
inputEle = (
<Form.Item label={dimensionItem.meaning} {...MODAL_FORM_ITEM_LAYOUT}>
{form.getFieldDecorator(fieldName, {
initialValue: isCreate ? undefined : dimensionConfig[fieldName],
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: dimensionItem.meaning,
}),
},
],
})(
<Lov
code="HIAM.TENANT.USER"
textField={meaningField}
textValue={dimensionConfig[meaningField]}
queryParams={{
organizationId: hasTenant ? tenantId : getCurrentOrganizationId(),
}}
disabled={hasTenant && isUndefined(tenantId)}
/>
)}
</Form.Item>
);
break;
case 'role':
inputEle = (
<Form.Item label={dimensionItem.meaning} {...MODAL_FORM_ITEM_LAYOUT}>
{form.getFieldDecorator(fieldName, {
initialValue: isCreate ? undefined : dimensionConfig[fieldName],
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: dimensionItem.meaning,
}),
},
],
})(
<Lov
code="HIAM.TENANT_ROLE"
textField={meaningField}
textValue={dimensionConfig[meaningField]}
queryParams={{
tenantId: dimensions.includes('tenant')
? tenantId
: getCurrentOrganizationId(),
}}
disabled={hasTenant && isUndefined(tenantId)}
/>
)}
</Form.Item>
);
break;
case 'tenant':
inputEle = (
<Form.Item label={dimensionItem.meaning} {...MODAL_FORM_ITEM_LAYOUT}>
{form.getFieldDecorator(fieldName, {
initialValue: isCreate ? undefined : dimensionConfig[fieldName],
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: dimensionItem.meaning,
}),
},
],
})(
<Lov
code="HPFM.TENANT"
textField={meaningField}
textValue={dimensionConfig[meaningField]}
/>
)}
</Form.Item>
);
break;
case 'url':
{
const args = words(
rateLimitLine['data-extra__rateLimitDimension_url'] || '',
/\{\d+\}/g
);
inputEle = (
<>
{args.map((arg, argIndex) => {
if (argIndex === 0) {
return (
<Form.Item
label={
<span>
{dimensionItem.meaning}
<Tooltip
title={intl
.get('hadm.zuulRateLimit.view.message.url.arg')
.d('URL参数不能包含;')}
>
<Icon type="question-circle-o" />
</Tooltip>
</span>
}
{...MODAL_FORM_ITEM_LAYOUT}
>
{form.getFieldDecorator(`${fieldName}[${argIndex}]`, {
initialValue: isCreate
? undefined
: (dimensionConfig[fieldName] || [])[argIndex],
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: dimensionItem.meaning,
}),
},
{
pattern: /^[^;]+$/,
message: intl
.get('hadm.zuulRateLimit.view.validation.url.argg')
.d('参数不合法'),
},
],
})(<Input />)}
</Form.Item>
);
} else {
return (
<Row type="flex">
<Col {...MODAL_FORM_ITEM_LAYOUT.labelCol} />
<Col {...MODAL_FORM_ITEM_LAYOUT.wrapperCol}>
<Form.Item>
{form.getFieldDecorator(`${fieldName}[${argIndex}]`, {
initialValue: isCreate
? undefined
: (dimensionConfig[fieldName] || [])[argIndex],
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: dimensionItem.meaning,
}),
},
{
pattern: /^[^;]+$/,
message: intl
.get('hadm.zuulRateLimit.view.validation.url.argg')
.d('参数不合法'),
},
],
})(<Input />)}
</Form.Item>
</Col>
</Row>
);
}
})}
</>
);
}
break;
default:
break;
}
return (
<>
{/* 维度 */}
{form.getFieldDecorator(getDimensionDataIndex(dimensionItem.value), {
initialValue: dimensionItem.value,
})(<></>)}
{/* 维度值 */}
{inputEle || (
<Form.Item label={dimensionItem.meaning} {...MODAL_FORM_ITEM_LAYOUT}>
{form.getFieldDecorator(fieldName, {
initialValue: isCreate ? undefined : dimensionConfig[fieldName],
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: dimensionItem.meaning,
}),
},
],
})(<Input />)}
</Form.Item>
)}
</>
);
})
.filter(Boolean)}
<Form.Item
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get(`hadm.zuulRateLimit.model.zuulRateLimit.replenishRate`).d('每秒流量限制值')}
>
{form.getFieldDecorator('replenishRate', {
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl
.get('hadm.zuulRateLimit.model.zuulRateLimit.replenishRate')
.d('每秒流量限制值'),
}),
},
],
initialValue: isCreate ? 1 : dimensionConfig.replenishRate,
})(<InputNumber min={1} />)}
</Form.Item>
<Form.Item
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hadm.zuulRateLimit.model.zuulRateLimit.burstCapacity').d('突发流量限制值')}
>
{form.getFieldDecorator('burstCapacity', {
initialValue: isCreate ? undefined : dimensionConfig.burstCapacity,
})(<InputNumber min={1} />)}
</Form.Item>
</Form>
);
}