lodash#toInteger JavaScript Examples

The following examples show how to use lodash#toInteger. 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: utils.js    From hzero-front with Apache License 2.0 7 votes vote down vote up
function getDisplayValue({ field, dataSource = {}, componentProps = {} }) {
  let format;
  let dateStr;
  let value;
  switch (field.componentType) {
    case 'ValueList':
    case 'Lov':
      value =
        dataSource[componentProps.displayField] ||
        dataSource[`${field.fieldCode}Meaning`] ||
        dataSource[field.fieldCode];
      return value;
    case 'DatePicker':
      format = getDatePickerFormat(field, getDateFormat());
      dateStr = dataSource[componentProps.displayField] || dataSource[field.fieldCode];
      return dateStr && moment(dateStr, DEFAULT_DATE_FORMAT).format(format);
    case 'TimePicker':
      format = getDatePickerFormat(field, DEFAULT_TIME_FORMAT);
      dateStr = dataSource[componentProps.displayField] || dataSource[field.fieldCode];
      return dateStr && moment(dateStr, DEFAULT_TIME_FORMAT).format(format);
    case 'Checkbox':
    case 'Switch':
      value = dataSource[componentProps.displayField] || dataSource[field.fieldCode];
      if (isNil(value)) {
        return;
      }
      return toInteger(value) === 1
        ? intl.get('hzero.common.status.yes')
        : intl.get('hzero.common.status.no');
    default:
      return dataSource[componentProps.displayField] || dataSource[field.fieldCode];
  }
}
Example #2
Source File: utils.js    From hzero-front with Apache License 2.0 7 votes vote down vote up
/**
 *
 * @param {{field: object, dataSource: object, componentProps: object}}
 * @param {object} field - 字段
 * @param {object} [dataSource={}] - 数据
 * @param {object} componentProps - 属性
 */
export function getDisplayValue({ field, dataSource = {}, componentProps }) {
  const displayFieldName = componentProps.displayField;
  let format;
  let dateStr;
  switch (field.componentType) {
    case 'ValueList':
    case 'Lov':
      return (
        dataSource[displayFieldName] ||
        dataSource[`${field.fieldName}Meaning`] ||
        dataSource[field.fieldName]
      );
    case 'DatePicker':
      format = getDateFormat();
      dateStr = dataSource[displayFieldName] || dataSource[field.fieldName];
      return dateStr && moment(dateStr, DEFAULT_DATE_FORMAT).format(format);
    case 'TimePicker':
      format = getTimeFormat();
      dateStr = dataSource[displayFieldName] || dataSource[field.fieldName];
      return dateStr && moment(dateStr, DEFAULT_DATE_FORMAT).format(format);
    case 'Checkbox':
    case 'Switch':
      return toInteger(dataSource[displayFieldName] || dataSource[field.fieldName]) === 1
        ? intl.get('hzero.common.status.yes')
        : intl.get('hzero.common.status.no');
    default:
      return dataSource[displayFieldName] || dataSource[field.fieldName];
  }
}
Example #3
Source File: index.js    From puente-reactnative-collect with MIT License 5 votes vote down vote up
checkAppVersionAndSendPush = async (token) => {
  await getData('appVersion').then(async (appVersion) => {
    const [majorCurrent, minorCurrent, patchCurrent] = appVersion.split('.');
    const majorCurrentInt = toInteger(majorCurrent);
    const minorCurrentInt = toInteger(minorCurrent);
    const patchCurrentInt = toInteger(patchCurrent);
    if (Platform.OS === 'android') {
      await axios.get(`${selectedENV.awsFlaskApi}android`)
        .then((latestVersion) => {
          const [majorLatest, minorLatest, patchLatest] = latestVersion.data.version.version_number.split('.');
          const majorLatestInt = toInteger(majorLatest);
          const minorLatestInt = toInteger(minorLatest);
          const patchLatestInt = toInteger(patchLatest);
          if (!((majorCurrentInt > majorLatestInt)
          || (majorCurrentInt === majorLatestInt && minorCurrentInt > minorLatestInt)
          || (majorCurrentInt === majorLatestInt && minorCurrentInt === minorLatestInt
            && patchCurrentInt > patchLatestInt)
          || (majorCurrentInt === majorLatestInt && minorCurrentInt === minorLatestInt
            && patchCurrentInt === patchLatestInt)
          )) {
            axios.post(selectedENV.expoPushTokenUrl,
              [
                {
                  to: token,
                  sound: 'default',
                  body: I18n.t('pushNotifications.updateApp')
                }
              ]).then((response) => {
              console.log(response) //eslint-disable-line
            }, (error) => {
              console.log(error) //eslint-disable-line
            });
          }
        })
        .catch((error) => console.log("push notification", error)); //eslint-disable-line
    } else if (Platform.OS === 'ios') {
      await axios.get(`${selectedENV.awsFlaskApi}ios`).then((latestVersion) => {
        const [majorLatest, minorLatest, patchLatest] = latestVersion.data.version.version_number.split('.');
        const majorLatestInt = toInteger(majorLatest);
        const minorLatestInt = toInteger(minorLatest);
        const patchLatestInt = toInteger(patchLatest);
        if (!((majorCurrentInt > majorLatestInt)
          || (majorCurrentInt === majorLatestInt && minorCurrentInt > minorLatestInt)
          || (majorCurrentInt === majorLatestInt && minorCurrentInt === minorLatestInt
            && patchCurrentInt > patchLatestInt)
          || (majorCurrentInt === majorLatestInt && minorCurrentInt === minorLatestInt
            && patchCurrentInt === patchLatestInt)
        )) {
          axios.post(selectedENV.expoPushTokenUrl,
            [
              {
                to: token,
                sound: 'default',
                body: I18n.t('pushNotifications.updateApp')
              }
            ]).then((response) => {
              console.log(response) //eslint-disable-line
          }, (error) => {
              console.log("push notification", error) //eslint-disable-line
          });
        }
      })
        .catch((error) => console.log("push notification", error)); //eslint-disable-line
    }
  });
}
Example #4
Source File: index.js    From hzero-front with Apache License 2.0 4 votes vote down vote up
/**
   * 渲染最终的字段
   * @param {Object} field - 字段
   */
  renderComposeFormField({ field }) {
    const { disableStyle, fieldLabelWidth, col, editable, organizationId, context } = this.props;
    const formItemProps = {
      labelCol: {
        style: { width: fieldLabelWidth, minWidth: fieldLabelWidth, maxWidth: fieldLabelWidth },
      },
      wrapperCol: { style: { flex: 'auto' } },
    };
    const colProps = getColLayout(col);
    const fieldColProps = getColLayout(col, field.colspan);
    const leftEmptyCols = [];
    const rightEmptyCols = [];
    if (inRange(field.leftOffset, 1, col)) {
      for (let i = 0; i < field.leftOffset; i++) {
        leftEmptyCols.push(<Col {...colProps} key={`${field.fieldCode}#left-offset-${i}`} />);
      }
    }
    if (inRange(field.rightOffset, 1, col)) {
      for (let i = 0; i < field.rightOffset; i++) {
        rightEmptyCols.push(<Col {...colProps} key={`${field.fieldCode}#right-offset-${i}`} />);
      }
    }
    const ComponentType = getComponentType(field);
    const componentProps = getComponentProps({
      field,
      componentType: field.componentType,
      context,
    });

    const otherFormItemOptions = {};
    let isViewOnly = false; // 附件是否为只读
    const getValueFromEvent = getGetValueFromEventFunc(field.componentType);
    const getValueProps = getGetValuePropFunc(field);
    if (field.componentType === 'Upload') {
      otherFormItemOptions.valuePropName = 'attachmentUUID';
      if (field.props) {
        const propsIndex = findIndex(field.props, ['attributeName', 'viewOnly']);
        if (propsIndex >= 0) {
          isViewOnly = field.props[propsIndex].attributeValue;
        }
      }
    }
    if (getValueFromEvent) {
      otherFormItemOptions.getValueFromEvent = getValueFromEvent;
    }
    if (getValueProps) {
      // 不影响存的值, 只影响传递给组件的值
      otherFormItemOptions.getValueProps = getValueProps;
    }
    const composeFormItem = (
      <Col {...fieldColProps} key={field.fieldCode}>
        <ComposeFormContext.Consumer>
          {({ form, dataSource }) => {
            const otherComponentProps = {}; // 为 lov 和 valueList 准备的属性
            switch (field.componentType) {
              case 'Lov':
              case 'ValueList':
                otherComponentProps.textValue = getDisplayValue(field, dataSource);
                break;
              default:
                break;
            }
            return editable ? (
              <FormItem
                label={field.fieldDescription}
                {...formItemProps}
                required={
                  field.componentType !== 'Checkbox' &&
                  toInteger(field.requiredFlag) !== 0 &&
                  !isViewOnly
                } // 当附件只读时,不必输
              >
                {(field.fieldCode === 'mail'
                  ? form.getFieldDecorator(`mail`, {
                      ...otherFormItemOptions,
                      initialValue: getInitialValue({ field, dataSource }),
                      rules: [
                        {
                          required: true,
                          message: intl.get('hzero.common.validation.notNull', {
                            name: intl.get('hzero.common.email').d('邮箱'),
                          }),
                        },
                        {
                          pattern: EMAIL,
                          message: intl.get('hzero.common.validation.email').d('邮箱格式不正确'),
                        },
                        {
                          max: 60,
                          message: intl.get('hzero.common.validation.max', {
                            max: 60,
                          }),
                        },
                      ],
                    })
                  : form.getFieldDecorator(field.fieldCode, {
                      ...otherFormItemOptions,
                      initialValue: getInitialValue({ field, dataSource }),
                      rules: [
                        {
                          required: toInteger(field.requiredFlag) !== 0 && !isViewOnly,
                          message: intl.get('hzero.common.validation.notNull', {
                            name: field.fieldDescription,
                          }),
                        },
                      ],
                    }))(
                  React.createElement(
                    ComponentType,
                    { ...componentProps, ...otherComponentProps } // otherComponentProps 比 componentProps 优先级高
                  )
                )}
              </FormItem>
            ) : (
              <FormItem label={field.fieldDescription} {...formItemProps}>
                {renderDisabledField({
                  field,
                  dataSource,
                  formItemProps,
                  organizationId,
                  disableStyle,
                  componentProps: { ...componentProps, ...otherComponentProps },
                })}
              </FormItem>
            );
          }}
        </ComposeFormContext.Consumer>
      </Col>
    );
    if (isEmpty(leftEmptyCols) && isEmpty(rightEmptyCols)) {
      return composeFormItem;
    }
    return (
      <React.Fragment key={field.fieldCode}>
        {leftEmptyCols}
        {composeFormItem}
        {rightEmptyCols}
      </React.Fragment>
    );
  }