lodash#isNumber JavaScript Examples
The following examples show how to use
lodash#isNumber.
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: index.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* todo 要将 site 字段放到 removeSiteFields 中
* @param {object} component
* @param {object} field
* @param {object} fieldOptions
*/
handleRemoveField(component, field, fieldOptions) {
// 保证数据一定正确
// TODO 跨行的处理
if (field.colspan && isNumber(field.colspan)) {
const fillFields = [];
for (let index = 0; index < field.colspan; index += 1) {
fillFields.push(cloneDeep(emptyField));
}
// eslint-disable-next-line
component.fields[fieldOptions.rowIndex] = concat(
[],
slice(component.fields[fieldOptions.rowIndex], 0, fieldOptions.colIndex),
fillFields,
slice(component.fields[fieldOptions.rowIndex], fieldOptions.colIndex + 1)
);
} else {
// eslint-disable-next-line
component.fields[fieldOptions.rowIndex][fieldOptions.colIndex] = cloneDeep(emptyField);
}
// // todo 租户级代码
// if(field.siteFlag === 1) {
// // 平台级 需要放在 removeSiteFields 中
// // eslint-disable-next-line no-param-reassign
// field.visiableFlag = 0;
// component.removeSiteFields.push(field);
// }
this.handleRefresh();
}
Example #2
Source File: utils.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* 会直接改变参数
* @param {object} dynamicForm
* @returns {object} dynamicForm
*/
function processDynamicForm(dynamicForm) {
// 认为组件的 col 和 组件字段的 leftOffset 与 rightOffset 对得上
const newFields = [];
// 处理组件的 属性
const formProps = {};
forEach(dynamicForm.config, prop => {
formProps[prop.attributeName] = prop.value;
});
const col = formProps.col || defaultFormCol;
let walkerCount = 0;
let row = [];
forEach(dynamicForm.fields, field => {
let fieldWalkerCount = 0;
if (isNumber(field.leftOffset)) {
while (fieldWalkerCount < field.leftOffset) {
row.push(cloneDeep(emptyField));
fieldWalkerCount += 1;
}
}
walkerCount += fieldWalkerCount;
fieldWalkerCount = 0;
row.push(field);
if (isNumber(field.colspan) && field.colspan) {
walkerCount += field.colspan;
} else {
walkerCount += 1;
}
if (isNumber(field.rightOffset)) {
while (fieldWalkerCount < field.rightOffset) {
row.push(cloneDeep(emptyField));
fieldWalkerCount += 1;
}
}
walkerCount += fieldWalkerCount;
if (walkerCount >= col) {
newFields.push(row);
row = [];
walkerCount = 0;
}
});
// 也许数据库中出现问题了,leftOffset rightOffset 和字段对不上
// if(row.length > 0){
// newFields.push(row);
// }
if (newFields.length === 0) {
for (let index = 0; index < col; index += 1) {
row.push(cloneDeep(emptyField));
}
newFields.push(row);
}
return {
...dynamicForm,
fields: newFields,
};
}
Example #3
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* 参数列表- 行编辑
* @param {object} record - 规则对象
*/
@Bind()
handleFetchWebHook(record) {
if (isNumber(record.objectVersionNumber) && record.typeCode === 'WEB_HOOK') {
const {
dispatch,
tenantId,
tenantRoleLevel,
form: { getFieldValue },
} = this.props;
this.ds
.getField('code')
.setLovPara('tenantId', tenantRoleLevel ? tenantId : getFieldValue('tenantId'));
this.ds.getField('code').setLovPara('tempServerLineId', record.tempServerLineId);
dispatch({
type: 'sendConfig/getWebhook',
payload: { ...record },
}).then((res) => {
if (res) {
this.state.clearSelect();
}
});
}
}
Example #4
Source File: CellControl.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* 合并右侧空
*/
handleMergeRight() {
const { rowIndex, colIndex, pComponent } = this.props;
const { fields = [] } = pComponent;
const currentRow = fields[rowIndex];
if (!(currentRow[colIndex + 1] && currentRow[colIndex + 1].componentType === emptyFieldType)) {
notification.warning({
message: intl
.get('hpfm.codeRule.model.codeRule.canCombineRightFiled')
.d('只能合并右侧空字段'),
});
return;
}
const currentField = currentRow[colIndex];
// 重写 field 的 colspan
if (currentField.colspan && isNumber(currentField.colspan)) {
currentField.colspan += 1;
} else {
currentField.colspan = 2;
}
// 去除多余的 emptyField
pComponent.fields[rowIndex] = concat(
[],
slice(currentRow, 0, colIndex + 1),
slice(currentRow, colIndex + 2)
);
this.handleRefresh();
}
Example #5
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* fetchList - 查询列表数据
* @param {object} [params = {}] - 查询参数
* @param {string} params.name - 目录/菜单名
* @param {string} params.parentName - 上级目录
*/
fetchList(params) {
const { dispatch } = this.props;
const { record } = this.state;
dispatch({
type: 'roleManagement/queryList',
params: { ...params, adminRoleId: record.id },
}).then(() => {
const { roleManagement } = this.props;
const { list } = roleManagement;
const { name, tenantId, roleSource } = params || {};
if (!isEmpty(name) || !isEmpty(roleSource) || isNumber(tenantId)) {
this.setState({
expandedRowKeys: list.rowKeys || [],
});
}
});
}
Example #6
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* fetchList - 查询列表数据
* @param {object} [params = {}] - 查询参数
* @param {string} params.name - 目录/菜单名
* @param {string} params.parentName - 上级目录
*/
fetchList(params) {
const { dispatch } = this.props;
dispatch({ type: 'roleManagement/queryList', params }).then(() => {
const { roleManagement } = this.props;
const { list } = roleManagement;
const { name, tenantId, roleSource } = params || {};
if (!isEmpty(name) || !isEmpty(roleSource) || isNumber(tenantId)) {
this.setState({
expandedRowKeys: list.rowKeys || [],
});
}
});
}
Example #7
Source File: CellControl.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* 取消合并
*/
handleCancelMergeRight() {
const { component, pComponent, rowIndex, colIndex } = this.props;
if (!(component.colspan && isNumber(component.colspan))) {
notification.warning({
message: intl.get('hpfm.codeRule.model.codeRule.canQCFiled').d('只能拆分合并后的字段'),
});
}
if (component.colspan > 2) {
component.colspan -= 1;
} else {
delete component.colspan;
}
// 加上 空字段
const currentRow = pComponent.fields[rowIndex];
const sliceIndex = colIndex + 1;
pComponent.fields[rowIndex] = concat(
[],
slice(currentRow, 0, sliceIndex),
[cloneDeep(emptyField)],
slice(currentRow, sliceIndex)
);
this.handleRefresh();
}
Example #8
Source File: EditableCell.js From hzero-front with Apache License 2.0 | 6 votes |
@Bind()
onIdChange(selectedRow, form) {
const { assignRowData = () => {}, record = {}, roleDatasource = {} } = this.props;
const { setFields = () => {} } = form;
const assignLevelDisabled =
!isNumber(record.organizationId) ||
roleDatasource.level === 'site' ||
!isNil(roleDatasource.parentRoleAssignUnitId);
const { id, loginName, realName, tenantName } = selectedRow;
let newRecord = record;
newRecord = {
...newRecord,
id,
loginName,
realName,
tenantName,
organizationId:
VERSION_IS_OP && getCurrentOrganizationId() !== 0
? getCurrentOrganizationId()
: selectedRow.organizationId,
assignLevelMeaning: null,
assignLevelValueMeaning: assignLevelDisabled ? newRecord.assignLevelValueMeaning : null,
assignLevelValue: assignLevelDisabled
? newRecord.assignLevelValue
: VERSION_IS_OP && getCurrentOrganizationId() !== 0
? selectedRow.organizationId
: null,
};
if (!assignLevelDisabled) {
setFields({
assignLevel: {
value: undefined,
},
});
}
assignRowData(newRecord);
}
Example #9
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* 编辑的保存
*/
handleSave() {
const {
save,
form: { validateFields = (e) => e },
roleId,
currentRowData = {},
labelList = [],
} = this.props;
validateFields((error, values) => {
if (!isEmpty(error)) {
return;
}
const { description, name, tenantId, _tls, roleLabels } = values;
const data = {
...currentRowData,
description,
name,
_tls,
roleLabels: labelList
.filter((item) => roleLabels.includes(item.name))
.map((item) => ({ ...item, labelId: item.id })),
tenantId:
// eslint-disable-next-line no-nested-ternary
VERSION_IS_OP && getCurrentOrganizationId() !== 0
? getCurrentOrganizationId()
: isNumber(tenantId)
? tenantId
: currentRowData.tenantId,
};
save(roleId, data, this.handleClose.bind(this));
});
}
Example #10
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* deal component attribute change
*/
handleComponentValuesChange(props, changeValues, allValues) {
// 使用 allValues 重写 component 的属性
// use allValues override component's props
const { component, onRefresh } = this.props;
const { validateFields } = this.editFormRef.current || {};
if (validateFields) {
validateFields(err => {
if (!err) {
const newConfig = [];
// common component's prop;
component.templateCode = allValues.templateCode;
component.description = allValues.description;
component.enabledFlag = allValues.enabledFlag;
if (isNumber(allValues.style.marginBottom)) {
newConfig.push({
[attributeNameProp]: 'style.marginBottom',
[attributeValueProp]: allValues.style.marginBottom,
[attributeTypeProp]: DataType.Number,
});
}
const prevComponentConfigs = component.config;
component.config = newConfig.map(componentConfig => {
const prevComponentConfig = find(
prevComponentConfigs,
prevC => prevC[attributeNameProp] === componentConfig[attributeNameProp]
);
return { ...prevComponentConfig, ...componentConfig };
});
if (isFunction(onRefresh)) {
onRefresh();
}
}
});
}
}
Example #11
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
/**
* deal component attribute change
*/
handleComponentValuesChange(props, changeValues, allValues) {
// 使用 allValues 重写 component 的属性
// use allValues override component's props
const { component, onRefresh } = this.props;
const { validateFields } = this.editFormRef.current || {};
if (validateFields) {
validateFields(err => {
if (!err) {
const newConfig = [];
// common component's prop;
component.templateCode = allValues.templateCode;
component.description = allValues.description;
component.enabledFlag = allValues.enabledFlag;
// DynamicToolbar's attributes;
if (isNumber(allValues.style.marginBottom)) {
newConfig.push({
[attributeNameProp]: 'style.marginBottom',
[attributeValueProp]: allValues.style.marginBottom,
[attributeTypeProp]: DataType.Number,
});
}
const prevComponentConfigs = component.config;
component.config = newConfig.map(componentConfig => {
const prevComponentConfig = find(
prevComponentConfigs,
prevC => prevC[attributeNameProp] === componentConfig[attributeNameProp]
);
return { ...prevComponentConfig, ...componentConfig };
});
if (isFunction(onRefresh)) {
onRefresh();
}
}
});
}
}
Example #12
Source File: Loading.jsx From kube-design with MIT License | 6 votes |
renderIndicator() {
const { size } = this.props;
return (
<span className="spin-dot spin-dot-spin">
<Icon
name="loading"
type="dark"
size={isNumber(size) ? size : sizeObj[size]}
style={{ display: "block", margin: "auto" }}
/>
</span>
);
}
Example #13
Source File: InputNumber.js From hzero-front with Apache License 2.0 | 6 votes |
export function getConfigOfPropValues(propValues, newConfig = []) {
if (isBoolean(propValues.allowThousandth)) {
newConfig.push({
[attributeNameProp]: 'allowThousandth',
[attributeValueProp]: propValues.allowThousandth,
[attributeTypeProp]: DataType.Boolean,
});
}
if (isNumber(propValues.precision)) {
newConfig.push({
[attributeNameProp]: 'precision',
[attributeValueProp]: propValues.precision,
[attributeTypeProp]: DataType.Number,
});
}
if (isNumber(propValues.max)) {
newConfig.push({
[attributeNameProp]: 'max',
[attributeValueProp]: propValues.max,
[attributeTypeProp]: DataType.Number,
});
}
if (isNumber(propValues.min)) {
newConfig.push({
[attributeNameProp]: 'min',
[attributeValueProp]: propValues.min,
[attributeTypeProp]: DataType.Number,
});
}
if (isNumber(propValues.step)) {
newConfig.push({
[attributeNameProp]: 'step',
[attributeValueProp]: propValues.step,
[attributeTypeProp]: DataType.Number,
});
}
return newConfig;
}
Example #14
Source File: ethereum.js From RRWallet with MIT License | 6 votes |
formatInput = input => {
if (isNil(input)) {
throw new Error("invaild input");
} else if (isString(input)) {
return input.startsWith("0x") ? input.substring(2) : input;
} else if (isNumber(input)) {
return input.toString(16);
}
}
Example #15
Source File: TextArea.js From hzero-front with Apache License 2.0 | 6 votes |
export function getConfigOfPropValues(propValues, newConfig = []) {
if (isNumber(propValues.autosize.minRows)) {
newConfig.push({
[attributeNameProp]: 'autosize.minRows',
[attributeValueProp]: propValues.autosize.minRows,
[attributeTypeProp]: DataType.Number,
});
}
if (isNumber(propValues.autosize.maxRows)) {
newConfig.push({
[attributeNameProp]: 'autosize.maxRows',
[attributeValueProp]: propValues.autosize.maxRows,
[attributeTypeProp]: DataType.Number,
});
}
return newConfig;
}
Example #16
Source File: verification.js From jafar with MIT License | 6 votes |
// Check if hooks are defined properly
function checkSettings(settings) {
['changeValueDebounceWait', 'changeValueDebounceMaxWait', 'changeStateDebounceWait', 'changeStateDebounceMaxWait']
.forEach((key) => {
if (!isUndefined(settings[key])
&& (!isNumber(settings[key]) || settings[key] < 0)) {
throwError(ERROR_PREFIX, errors.INVALID_SETTING, { settings }, ['key', 'a positive number']);
}
});
}
Example #17
Source File: cursorPaginate.js From rate-repository-api with MIT License | 6 votes |
getValidLimitOrFail = ({ first, last }) => {
const limit = isNumber(first) ? first : isNumber(last) ? last : 30;
if (limit < 0 || limit > 100) {
throw new Error(
'Limit must be greater than 0 and less than or equal to 100',
);
}
return limit;
}
Example #18
Source File: ETHWallet.js From RRWallet with MIT License | 5 votes |
sendTransaction(
to,
amount,
gasPrice,
gasLimit,
note,
pwd,
broadcast = true,
nonce = -1,
chainID = ethereumChainID()
) {
to = to.toLowerCase();
return new Promise(async (resolve, reject) => {
try {
if (nonce == -1) {
nonce = await ETHRPCProvider.ethGetTransactionCount(this.address, "pending");
nonce = Math.max(nonce, this.lastNonce + 1);
}
const result = await this.sendContractTransaction(
to,
ethereum.toWei(amount),
null,
gasPrice,
gasLimit,
pwd,
false,
nonce
);
// const result = await RRRNEthereum.sendTranscation(this.id, this.address, to, gasLimit, ethereum.toWei(gasPrice, 'gwei'), ethereum.toWei(amount), nonce, pwd)
const broadcastResult = await _broadcastTx(this.address, to, amount, result.fee, note, result.rawData);
if (_.isPlainObject(broadcastResult)) {
const txHash = broadcastResult.data;
if (txHash) {
if (_.isString(result.nonce)) {
result.nonce = parseInt(result.nonce);
}
if (result.hasOwnProperty("nonce") && _.isNumber(result.nonce)) {
this.lastNonce = parseInt(result.nonce);
}
resolve(txHash);
} else {
reject(broadcastResult);
}
} else {
reject(new Error("节点服务异常"));
}
} catch (error) {
error.name = "ETHTransaction";
reject(error);
}
});
}
Example #19
Source File: Row.js From hzero-front with Apache License 2.0 | 5 votes |
render() {
const {
cols = [],
rowCount,
component,
onRemoveField,
wrapperFieldComponent,
colLayout,
fieldLabelWidth,
rowIndex,
currentEditField,
onUpdateComponent,
willRemovePositionX,
positionY,
onUpdateWillRemovePositionX,
onRefreshTemplate,
} = this.props;
const { willRemovePositionY } = this.state;
let colCount = 0;
forEach(cols, c => {
if (c.colspan && isNumber(c.colspan)) {
colCount += c.colspan;
} else {
colCount += 1;
}
});
let positionX = 0;
const colElements = map(cols, (c, colIndex) => {
let positionRightX = positionX;
if (c.colspan && isNumber(c.colspan)) {
positionRightX += c.colspan;
} else {
positionRightX += 1;
}
const colElement = (
<Col
key={colIndex}
rowIndex={rowIndex}
colIndex={colIndex}
rowCount={rowCount}
colCount={colCount}
component={c}
pComponent={component}
onRemoveField={onRemoveField}
wrapperFieldComponent={wrapperFieldComponent}
colLayout={colLayout}
fieldLabelWidth={fieldLabelWidth}
currentEditField={currentEditField}
onUpdateComponent={onUpdateComponent}
// 删除
willRemovePositionY={willRemovePositionY}
willRemovePositionX={willRemovePositionX}
positionY={positionY}
positionX={positionX}
positionRightX={positionRightX}
onUpdateWillRemovePositionX={onUpdateWillRemovePositionX}
onUpdateWillRemovePositionY={this.handleUpdateWillRemovePositionY}
onRefreshTemplate={onRefreshTemplate}
/>
);
positionX = positionRightX;
return colElement;
});
return <HzeroRow type="flex">{colElements}</HzeroRow>;
}
Example #20
Source File: index.js From hzero-front with Apache License 2.0 | 5 votes |
// field props
/**
* deal Button
*/
getButtonConfigOfPropValues(propValues, newConfig = [], field) {
if (isString(propValues.type)) {
newConfig.push({
[attributeNameProp]: 'type',
[attributeValueProp]: propValues.type,
[attributeTypeProp]: DataType.String,
});
// warn will remove when save
// eslint-disable-next-line no-param-reassign
field.type = propValues.type;
}
if (isString(propValues.onClick)) {
newConfig.push({
[attributeNameProp]: 'onClick',
[attributeValueProp]: propValues.onClick,
[attributeTypeProp]: DataType.String,
});
}
if (isNumber(propValues.style.marginRight)) {
newConfig.push({
[attributeNameProp]: 'style.marginRight',
[attributeValueProp]: propValues.style.marginRight,
[attributeTypeProp]: DataType.Number,
});
// warn will remove when save
// eslint-disable-next-line no-param-reassign
field.style = {
marginRight: propValues.style.marginRight,
};
}
const { btnProps, btnConfigs } = propValues;
forEach(btnProps, (btnPropValue, btnPropKey) => {
if (btnPropKey === 'modalBtns') {
for (let i = 0; i < btnPropValue.length; i += 1) {
newConfig.push({
[attributeNameProp]: `${TOOLBAR_BTN_PREFIX}${modalBtnPrefix}[${i}]`,
[attributeValueProp]: btnPropValue[i][attributeValueProp],
[attributeTypeProp]: DataType.String,
});
}
} else if (btnPropKey === 'subEvents') {
for (let i = 0; i < btnPropValue.length; i += 1) {
newConfig.push({
[attributeNameProp]: `${TOOLBAR_BTN_PREFIX}${subEventPrefix}[${i}]`,
[attributeValueProp]: btnPropValue[i][attributeValueProp],
[attributeTypeProp]: DataType.String,
});
}
} else {
newConfig.push({
[attributeNameProp]: `${TOOLBAR_BTN_PREFIX}[${btnPropKey}]`,
[attributeValueProp]: btnPropValue,
[attributeTypeProp]: btnConfigs[btnPropKey],
});
}
});
}
Example #21
Source File: dynamicForm.js From hzero-front with Apache License 2.0 | 5 votes |
/**
* 将 存储的 dynamicForm 转换成 设计器 可以识别的
* 认为组件的 col 和 组件字段的 leftOffset 与 rightOffset 对得上
* @param {object} template - 新增 或 从服务器查询出来的 dynamicForm
* @return {object} newTemplate 新的为设计器准备好的字段
*/
function dynamicFormDirtyExtra(template, options) {
const noCloneDeep = options && options.noCloneDeep;
const newTemplate = noCloneDeep ? template : cloneDeep(template);
// todo 删除表格多余的属性
const newFields = [];
// 查找 form 的 col 属性
let col;
forEach(newTemplate.config, prop => {
if (prop.attributeName === 'col') {
col = prop.value;
return false;
}
});
col = col || defaultFormCol;
let walkerCount = 0;
let row = [];
forEach(newTemplate.fields, field => {
let fieldWalkerCount = 0;
if (isNumber(field.leftOffset)) {
// 字段的左空位 其实就是编辑时候的空字段
// 在字段有左空位的时候 补 空字段
while (fieldWalkerCount < field.leftOffset) {
row.push(cloneDeep(emptyField));
fieldWalkerCount += 1;
}
}
walkerCount += fieldWalkerCount;
fieldWalkerCount = 0;
row.push(field);
if (isNumber(field.colspan) && field.colspan) {
walkerCount += field.colspan;
} else {
walkerCount += 1;
}
if (isNumber(field.rightOffset)) {
// 字段的右空位 其实就是编辑时候的空字段
// 在字段有右空位的时候 补 空字段
while (fieldWalkerCount < field.rightOffset) {
row.push(cloneDeep(emptyField));
fieldWalkerCount += 1;
}
}
walkerCount += fieldWalkerCount;
if (walkerCount >= col) {
// 将 表单的 字段 转换成 二维数组
newFields.push(row);
row = [];
walkerCount = 0;
}
});
// 也许数据库中出现问题了,leftOffset rightOffset 和字段对不上
// if(row.length > 0){
// newFields.push(row);
// }
if (newFields.length === 0) {
// 如果没有字段, 则将 第一行 都补上空字段
for (let index = 0; index < col; index += 1) {
row.push(cloneDeep(emptyField));
}
newFields.push(row);
}
return {
...newTemplate,
fields: newFields,
};
}
Example #22
Source File: CellControl.js From hzero-front with Apache License 2.0 | 5 votes |
/**
* todo 要将 site 字段放到 removeSiteFields 中
* 删除列 实际方法
*/
handleRemoveCol() {
const { pComponent, rowIndex, colIndex } = this.props;
// 找到要删除的位置
const currentRow = pComponent.fields[rowIndex];
let positionX = 0;
for (let index = 0; index <= colIndex; index += 1) {
const f = currentRow[index];
if (f.colspan && isNumber(f.colspan)) {
positionX += f.colspan;
} else {
positionX += 1;
}
}
forEach(pComponent.fields, (fArr, rIndex) => {
let endPositionX = 0;
forEach(fArr, (f, cIndex) => {
const isColspan = f.colspan && isNumber(f.colspan);
if (isColspan) {
endPositionX += f.colspan;
} else {
endPositionX += 1;
}
if (endPositionX >= positionX && isColspan) {
// colspan -1
if (f.colspan === 2) {
// eslint-disable-next-line
delete f.colspan;
} else {
// eslint-disable-next-line
f.colspan -= 1;
}
return false;
} else if (endPositionX === positionX) {
// const removeField = fArr[cIndex];
// // todo 租户级的代码
// if (removeField.siteFlag === 1) {
// removeField.visiableFlag = 0;
// pComponent.removeSiteFields.push(removeField);
// }
pComponent.fields[rIndex] = concat([], slice(fArr, 0, cIndex), slice(fArr, cIndex + 1));
return false;
}
});
});
this.handleCleanWillRemovePositionX();
this.handleRefresh();
}
Example #23
Source File: CellControl.js From hzero-front with Apache License 2.0 | 5 votes |
/**
* 新增列
*/
handleAppendCol() {
const { pComponent, rowIndex, colIndex } = this.props;
// 先找到当前字段的位置所占位置的最后
const currentRow = pComponent.fields[rowIndex];
let positionX = 0;
for (let index = 0; index <= colIndex; index += 1) {
const f = currentRow[index];
if (f.colspan && isNumber(f.colspan)) {
positionX += f.colspan;
} else {
positionX += 1;
}
}
// 得到当前字段的位置
forEach(pComponent.fields, (fArr, rIndex) => {
let endPositionX = 0;
forEach(fArr, (f, cIndex) => {
const isColspan = f.colspan && isNumber(f.colspan);
if (isColspan) {
endPositionX += f.colspan;
} else {
endPositionX += 1;
}
if (endPositionX > positionX) {
// 改变 colspan
// eslint-disable-next-line
f.colspan += 1;
return false;
} else if (endPositionX === positionX) {
// 增加新的 emptyField
const sliceIndex = cIndex + 1;
pComponent.fields[rIndex] = concat(
[],
slice(fArr, 0, sliceIndex),
[cloneDeep(emptyField)],
slice(fArr, sliceIndex)
);
return false;
}
});
});
this.handleRefresh();
}
Example #24
Source File: Drawer.js From hzero-front with Apache License 2.0 | 5 votes |
getSnapshotBeforeUpdate(prevProps) {
const { visible, currentInterface = {} } = this.props;
const { id } = currentInterface;
return visible && isNumber(id) && id !== (prevProps.currentInterface || {}).id;
}
Example #25
Source File: Drawer.js From hzero-front with Apache License 2.0 | 5 votes |
/**
* 新增角色模态框确认按钮点击
*/
@Bind()
handleRoleAddSaveBtnClick(roles) {
const { tenantId, dispatch, paginationRole, initData } = this.props;
const { roleType } = this.state;
const memberRoleList = [];
forEach(roles, (record) => {
const newRecord = {
id: record.id,
roleId: record.id,
assignLevel: 'organization',
memberType: 'client',
memberId: initData.id,
sourceId: tenantId,
sourceType: record.level,
assignLevelValue: record.tenantId,
name: record.name,
assignLevelValueMeaning: record.assignLevelValueMeaning,
tenantName: record.tenantName,
createFlag: true,
};
if (roleType === 'visit') {
delete newRecord.memberType;
}
// newRecord.assignLevelValue = record.assignLevelValue || tenantId;
if (!isEmpty(newRecord.assignLevel) && isNumber(newRecord.assignLevelValue)) {
memberRoleList.push(newRecord);
}
});
const payload =
roleType === 'permission'
? [...memberRoleList]
: {
memberRoleList,
clientId: initData.id,
// organizationId: initData.organizationId,
};
return dispatch({
type: roleType === 'permission' ? 'client/saveRoleSet' : 'client/saveVisitRoleSet',
payload,
}).then((res) => {
if (res) {
if (roleType === 'permission') {
this.setState(
{
visibleRole: false,
},
() => {
this.setState({
ownedRoleList: this.state.ownedRoleList.concat(res),
});
// this.handleAfterAddPermissionRole(paginationRole);
}
);
} else {
this.setState(
{
visibleRole: false,
},
() => {
notification.success();
this.queryOwnedRole(paginationRole);
// this.handleAfterAddPermissionRole(paginationRole);
}
);
}
}
});
}
Example #26
Source File: ETHWallet.js From RRWallet with MIT License | 5 votes |
async sendContractTransaction(
contract,
amount,
data,
gasPrice,
gasLimit,
pwd,
broadcast = true,
nonce = -1,
chainID = ethereumChainID()
) {
contract = contract.toLowerCase();
gasPrice = toFixedString(gasPrice);
gasLimit = toFixedString(gasLimit);
const fee = toFixedString(ethereum.toEther(new BigNumber(gasLimit).multipliedBy(gasPrice), "gwei"));
data = data || "";
if (nonce == -1) {
nonce = await ETHRPCProvider.ethGetTransactionCount(this.address, "pending");
nonce = Math.max(nonce, this.lastNonce + 1);
}
const result = await RRRNEthereum.sendContractTransaction(
this.id,
this.address,
contract,
amount + "",
data,
gasLimit,
ethereum.toWei(gasPrice, "gwei"),
Platform.select({ ios: nonce, android: nonce + "" }),
chainID,
broadcast,
pwd
);
if (broadcast) {
if (_.isString(result.nonce)) {
result.nonce = parseInt(result.nonce);
}
if (result.hasOwnProperty("nonce") && _.isNumber(result.nonce)) {
this.lastNonce = result.nonce;
}
}
result.fee = fee;
return result;
}
Example #27
Source File: ETHWallet.js From RRWallet with MIT License | 5 votes |
sendERC20Transaction(
to,
contract,
amount,
gasPrice,
gasLimit,
note,
pwd,
broadcast = true,
nonce = -1,
batchStatus = 0
) {
to = to.toLowerCase();
contract = contract.toLowerCase();
return new Promise(async (resolve, reject) => {
if (nonce == -1) {
nonce = await ETHRPCProvider.ethGetTransactionCount(this.address, "pending");
nonce = Math.max(nonce, this.lastNonce + 1);
}
let correctAmount = new BigNumber(amount);
let token = this.findERC20Token(contract);
if (token && token.decimals) {
let unit = new BigNumber(10).pow(18 - token.decimals);
correctAmount = correctAmount.div(unit);
}
const hexAmount = ethereum.toWei(correctAmount).toString(16);
const transferABI = ethereum.encodeContractABI(ethereum.transferMethodID, [to, hexAmount]);
try {
const result = await this.sendContractTransaction(
contract,
"0",
transferABI,
gasPrice,
gasLimit,
pwd,
false,
nonce
);
const broadcastResult = await _broadcastERC20Tx(
contract,
this.address,
to,
amount,
result.fee,
note,
result.rawData
);
if (_.isPlainObject(broadcastResult)) {
const txHash = broadcastResult.data;
if (txHash) {
if (_.isString(result.nonce)) {
result.nonce = parseInt(result.nonce);
}
if (result.hasOwnProperty("nonce") && _.isNumber(result.nonce)) {
this.lastNonce = result.nonce;
}
resolve(txHash);
} else {
reject(broadcastResult);
}
} else {
reject(new Error("节点服务异常"));
}
} catch (error) {
error.name = "ETHTransaction";
reject(error);
}
});
}
Example #28
Source File: DataList.js From hzero-front with Apache License 2.0 | 4 votes |
/**
* render
* @returns React.element
*/
render() {
const {
loading,
dataSource,
pagination,
organizationId,
onSearch,
onEditRow,
onDelete,
onCancel,
match,
} = this.props;
const columns = [
{
title: intl.get(`${modelPrompt}.locationCode`).d('库位编码'),
width: 120,
dataIndex: 'locationCode',
render: (text, record) => {
if (['update', 'create'].includes(record._status)) {
const { getFieldDecorator } = record.$form;
return (
<Form.Item>
{getFieldDecorator('locationCode', {
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get(`${modelPrompt}.locationCode`).d('库位编码'),
}),
},
{
max: 30,
message: intl.get('hzero.common.validation.max', {
max: 30,
}),
},
{
pattern: CODE_UPPER,
message: intl
.get('hzero.common.validation.codeUpper')
.d('全大写及数字,必须以字母、数字开头,可包含“-”、“_”、“.”、“/”'),
},
],
initialValue: record.locationCode,
})(
<Input
typeCase="upper"
inputChinese={false}
disabled={!!record.isErp || record._status === 'update'}
/>
)}
</Form.Item>
);
}
return text;
},
},
{
title: intl.get(`${modelPrompt}.locationName`).d('库位名称'),
width: 140,
dataIndex: 'locationName',
render: (text, record) => {
if (['update', 'create'].includes(record._status)) {
const { getFieldDecorator } = record.$form;
return (
<Form.Item>
{getFieldDecorator('locationName', {
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get(`${modelPrompt}.locationName`).d('库位名称'),
}),
},
{
max: 60,
message: intl.get('hzero.common.validation.max', {
max: 60,
}),
},
],
initialValue: record.locationName,
})(<Input disabled={!!record.isErp} />)}
</Form.Item>
);
}
return text;
},
},
{
title: intl.get(`${modelPrompt}.inventoryName`).d('库房'),
dataIndex: 'inventoryName',
width: 140,
render: (text, record) => {
if (['update', 'create'].includes(record._status)) {
const { getFieldDecorator, setFieldsValue } = record.$form;
getFieldDecorator('inventoryId', {
initialValue: record.inventoryId,
});
getFieldDecorator('invOrganizationName', {
initialValue: record.invOrganizationName,
});
getFieldDecorator('ouName', { initialValue: record.ouName });
getFieldDecorator('ouId', { initialValue: record.ouId });
getFieldDecorator('organizationId', {
initialValue: record.organizationId,
});
return (
<Form.Item>
{getFieldDecorator('inventoryName', {
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get(`${modelPrompt}.inventoryName`).d('库房'),
}),
},
],
initialValue: record.inventoryName,
})(
<Lov
code="HPFM.LOCATION.INVENTORY"
queryParams={{ tenantId: organizationId, enabledFlag: 1 }}
textValue={record.inventoryName || ''}
disabled={!!record.isErp}
onChange={(value, lovRecord) => {
const setFormData = {
invOrganizationName: lovRecord.invOrganizationName,
inventoryId: lovRecord.inventoryId,
ouName: lovRecord.ouName,
ouId: lovRecord.ouId,
organizationId: lovRecord.organizationId,
};
setFieldsValue(setFormData);
}}
/>
)}
</Form.Item>
);
}
return text;
},
},
{
title: intl.get(`${modelPrompt}.invOrganizationName`).d('库存组织'),
dataIndex: 'invOrganizationName',
width: 120,
render: (text, record) => {
if (['update', 'create'].includes(record._status)) {
const { getFieldDecorator } = record.$form;
return (
<Form.Item>
{getFieldDecorator('invOrganizationName', {
initialValue: record.invOrganizationName,
})(<Input disabled />)}
</Form.Item>
);
}
return text;
},
},
{
title: intl.get(`${modelPrompt}.ouName`).d('业务实体'),
dataIndex: 'ouName',
width: 80,
render: (text, record) => {
if (['update', 'create'].includes(record._status)) {
const { getFieldDecorator } = record.$form;
return (
<Form.Item>
{getFieldDecorator('ouName', {
initialValue: record.ouName,
})(<Input disabled />)}
</Form.Item>
);
}
return text;
},
},
{
title: intl.get(`${modelPrompt}.sourceCode`).d('数据来源'),
width: 75,
align: 'center',
dataIndex: 'sourceCode',
},
{
title: intl.get(`${modelPrompt}.externalSystemCode`).d('来源系统'),
width: 75,
align: 'center',
dataIndex: 'externalSystemCode',
},
{
title: intl.get('hzero.common.status').d('状态'),
width: 75,
align: 'center',
dataIndex: 'enabledFlag',
render: (text, record) => {
if (['update', 'create'].includes(record._status)) {
const { getFieldDecorator } = record.$form;
return (
<Form.Item>
{getFieldDecorator('enabledFlag', {
initialValue: record.enabledFlag ? 1 : 0,
})(<Checkbox />)}
</Form.Item>
);
}
return enableRender(text);
},
},
{
title: intl.get('hzero.common.button.action').d('操作'),
align: 'center',
dataIndex: 'edit',
width: 75,
render: (text, record) => {
const operators = [];
if (record._status === 'create') {
operators.push({
key: 'delete',
ele: (
<a onClick={() => onDelete(record)}>
{intl.get('hzero.common.button.clean').d('清除')}
</a>
),
len: 2,
title: intl.get('hzero.common.button.clean').d('清除'),
});
} else if (record._status === 'update') {
operators.push({
key: 'cancel',
ele: (
<a onClick={() => onCancel(record)}>
{intl.get('hzero.common.button.cancel').d('取消')}
</a>
),
len: 2,
title: intl.get('hzero.common.button.cancel').d('取消'),
});
} else {
operators.push({
key: 'edit',
ele: (
<ButtonPermission
type="text"
permissionList={[
{
code: `${match.path}.button.edit`,
type: 'button',
meaning: '库位-编辑',
},
]}
onClick={() => onEditRow(record)}
>
{intl.get('hzero.common.button.edit').d('编辑')}
</ButtonPermission>
),
len: 2,
title: intl.get('hzero.common.button.edit').d('编辑'),
});
}
return operatorRender(operators);
},
},
];
const scrollX = sum(columns.map(n => (isNumber(n.width) ? n.width : 0))) + 200;
return (
<Fragment>
<EditTable
bordered
rowKey="locationId"
scroll={{ x: scrollX }}
className={classNames(styles['data-list'])}
loading={loading}
columns={columns}
dataSource={dataSource}
pagination={pagination}
onChange={onSearch}
/>
</Fragment>
);
}
Example #29
Source File: Drawer.js From hzero-front with Apache License 2.0 | 4 votes |
/**
* render
* @returns React.element
*/
render() {
const {
anchor,
visible,
title,
form,
itemData,
onCancel,
messageType = [],
tenantId,
fetchLoading,
deleteLoading,
webHook: { pagination = {}, webHookData = [] },
ds,
path,
} = this.props;
const { getFieldDecorator, getFieldValue } = form;
const isEdit = !isEmpty(itemData);
const { selectedRowKeys } = this.state;
const columns = [
{
title: intl.get('hmsg.common.view.accountCode').d('账户代码'),
dataIndex: 'serverCode',
width: 100,
},
{
title: intl.get('hmsg.common.view.accountName').d('账户名称'),
dataIndex: 'serverName',
},
{
title: intl.get('hmsg.sendConfig.model.sendConfig.accountType').d('账户类型'),
dataIndex: 'serverTypeMeaning',
width: 100,
},
];
return (
<Modal
title={title}
width={520}
wrapClassName={`ant-modal-sidebar-${anchor}`}
transitionName={`move-${anchor}`}
visible={visible}
onOk={this.saveBtn}
okText={intl.get('hzero.common.button.sure').d('确定')}
onCancel={onCancel}
cancelText={intl.get('hzero.common.button.cancel').d('取消')}
zIndex={999}
destroyOnClose
>
<Form>
<Form.Item
label={intl.get('hmsg.sendConfig.model.sendConfig.templateId').d('模板代码')}
{...formLayout}
>
{getFieldDecorator('templateCode', {
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hmsg.sendConfig.model.sendConfig.templateCode').d('模板代码'),
}),
},
],
initialValue: itemData.templateCode,
})(
<Lov
code="HMSG.TEMP_SERVER.MESSAGE_TEMP"
textValue={itemData.templateCode}
disabled={!isNumber(tenantId)}
queryParams={{
tenantId,
}}
onChange={this.onChangeTemplate}
/>
)}
</Form.Item>
<FormItem
label={intl.get('hmsg.sendConfig.model.sendConfig.typeCode').d('消息类型')}
{...formLayout}
>
{getFieldDecorator('typeCode', {
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hmsg.sendConfig.model.sendConfig.typeCode').d('消息类型'),
}),
},
],
initialValue: itemData.typeCode,
})(
<Select allowClear disabled={isEdit} onChange={this.changeTypeCode}>
{messageType &&
messageType.map((item) => (
<Option value={item.value} key={item.value}>
{item.meaning}
</Option>
))}
</Select>
)}
</FormItem>
{itemData.typeCode !== 'WEB_HOOK' && (
<>
<Form.Item
label={intl.get('hmsg.common.view.accountCode').d('账户代码')}
{...formLayout}
>
{getFieldDecorator('serverCode', {
rules: [
{
required:
getFieldValue('typeCode') !== 'WEB' &&
getFieldValue('typeCode') !== 'WEB_HOOK',
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hmsg.common.view.accountCode').d('账户代码'),
}),
},
],
initialValue: itemData.serverCode,
})(
<Lov
code="HMSG.SERVER"
textValue={itemData.serverCode}
disabled={
!getFieldValue('typeCode') ||
!isNumber(tenantId) ||
getFieldValue('typeCode') === 'WEB' ||
getFieldValue('typeCode') === 'WEB_HOOK'
}
queryParams={{
typeCode: getFieldValue('typeCode'),
tenantId,
}}
onChange={this.getServerName}
/>
)}
</Form.Item>
<Form.Item
label={intl.get('hmsg.common.view.accountName').d('账户名称')}
{...formLayout}
>
{getFieldDecorator('serverName', {
rules: [
{
required: false,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hmsg.common.view.accountName').d('账户名称'),
}),
},
],
initialValue: itemData.serverName,
})(<Input disabled />)}
</Form.Item>
</>
)}
<Form.Item
{...formLayout}
label={intl.get('hmsg.sendConfig.model.sendConfig.tryTimes').d('重试次数')}
>
{getFieldDecorator('tryTimes', {
initialValue: itemData.tryTimes,
})(
<InputNumber step={1} min={0} disabled={form.getFieldValue('typeCode') !== 'EMAIL'} />
)}
</Form.Item>
<Form.Item label={intl.get('hzero.common.remark').d('备注')} {...formLayout}>
{getFieldDecorator('remark', {
rules: [
{
required: false,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hzero.common.remark').d('备注'),
}),
},
],
initialValue: itemData.remark,
})(<Input />)}
</Form.Item>
<Form.Item label={intl.get('hzero.common.status').d('状态')} {...formLayout}>
{getFieldDecorator('enabledFlag', {
initialValue: itemData.enabledFlag !== undefined ? itemData.enabledFlag : 1,
})(<Switch />)}
</Form.Item>
{isEdit && itemData.typeCode === 'WEB_HOOK' && isNumber(itemData.objectVersionNumber) && (
<>
<div style={{ textAlign: 'right', marginBottom: '12px' }}>
<ButtonPermission
permissionList={[
{
code: `${path}.button.deleteUser`,
type: 'button',
meaning: '消息发送配置-删除',
},
]}
style={{ marginRight: 8 }}
onClick={this.handleDeleteWebHook}
disabled={selectedRowKeys.length === 0 || deleteLoading}
>
{intl.get('hzero.common.button.delete').d('删除')}
</ButtonPermission>
{/* <Lov
isButton
code='HMSG.TEMP_SERVER_WEBHOOK'
onChange={this.handleCreateWebHook}
queryParams={{tenantId, tempServerLineId: itemData.tempServerLineId}}
type="primary"
>
{intl.get('hzero.common.button.create').d('新建')}
</Lov> */}
<C7nLov
name="code"
mode="button"
color="primary"
placeholder={intl.get('hzero.common.button.create').d('新建')}
dataSet={ds}
clearButton={false}
modalProps={{ zIndex: 1000 }}
className={styles['lov-button']}
/>
</div>
<Table
bordered
rowKey="tempServerWhId"
loading={fetchLoading}
columns={columns}
pagination={pagination}
dataSource={webHookData}
style={{ marginTop: 14 }}
scroll={{ x: tableScrollWidth(columns) }}
rowSelection={{
selectedRowKeys,
onChange: this.handleRowSelectionChange,
}}
onChange={this.handleTableChange}
/>
</>
)}
{/* <Form.Item>
{getFieldDecorator('serverCode', {
initialValue: itemData.serverCode,
})(<div />)}
</Form.Item> */}
</Form>
</Modal>
);
}