lodash#indexOf JavaScript Examples

The following examples show how to use lodash#indexOf. 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: AvatarUploadModal.js    From hzero-front with Apache License 2.0 5 votes vote down vote up
/**
   * 校验上传参数
   * 使用时: 如果Boolean(返回的数据), 则不做限制
   */
  validateUploadParams() {
    const { file, limitData } = this.state;
    const { fileFormat, storageSize, storageUnit } = limitData;
    if (!fileFormat && !storageSize) {
      // 如果没有查询到桶配置, 那么就不做限制;
      return;
    }

    let flag = true;
    let message;
    if (fileFormat) {
      const fileType = fileFormat.split(',').map(item => `image/${item}`);
      if (fileType.indexOf('image/jpg') > -1) {
        fileType.push('image/jpeg');
      }
      flag = indexOf(fileType, file.type) > -1;
      message = flag
        ? ''
        : intl.get('hiam.userInfo.view.message.fileTypeError').d('文件类型不支持');
    }

    if (storageSize && flag) {
      // 表示文件大小上限,单位:KB
      const fileSize = STORAGE_UNIT[storageUnit] * storageSize;
      flag = fileSize > file.size;
      message = flag
        ? ''
        : intl
            .get('hzero.common.upload.error.size.custom', {
              fileSize: `${storageSize}${storageUnit}`,
            })
            .d(`上传文件大小不能超过: ${storageSize}${storageUnit}`);
    }

    return message;
  }
Example #2
Source File: List.js    From hzero-front with Apache License 2.0 5 votes vote down vote up
/**
   * modal确定的时候,需要把最新的当前数据更新到currentRecord中,以防下一次打开获取到的是旧的数据
   * @param {*} data
   */
  @Bind()
  handleModalOk(data = {}) {
    const { modalData = [], currentRecord = {}, dataIndex } = this.state;
    // 获取当前语言
    const currentLanguage = getCurrentLanguage();
    const { _tls = {} } = currentRecord;
    const keys = Object.keys(data);
    const values = Object.values(data);
    const index = indexOf(keys, currentLanguage);
    const newData = [];
    // 获取到modal里的新数据
    keys.forEach((key, ki) => {
      modalData.forEach((m) => {
        if (m.lang === key) {
          newData.push({
            ...m,
            value: values[ki],
          });
        }
      });
    });
    // 给外层的Input赋值,并且需要根据当前语言,渲染不同的值
    currentRecord.$form.setFieldsValue({
      [dataIndex]: values[index],
    });
    // 转换为后端需要的格式
    const newTls = {
      ..._tls,
      [dataIndex]: {
        ..._tls[dataIndex],
        ...data,
      },
    };
    const newCurrentRecord = {
      ...currentRecord,
      [dataIndex]: values[0],
      _tls: newTls,
    };
    this.setState({
      modalData: newData,
      visible: false,
      currentRecord: newCurrentRecord,
    });
  }
Example #3
Source File: index.js    From hzero-front with Apache License 2.0 5 votes vote down vote up
@Bind()
  onCheckboxChange(params) {
    const { receiveCode, type, flag } = params;
    const { checkedList } = this.state;
    const index = findIndex(checkedList, (v) => v.receiveCode === receiveCode);
    const checkItem = checkedList[index];

    const addOrRemove = (item) => {
      // flag为true,代表当前已经被勾选,需要去除勾选
      if (flag) {
        remove(item && item.receiveTypeList, (v) => v === type);
      } else if (
        indexOf(item && item.receiveTypeList, type) < 0 &&
        indexOf(item.defaultReceiveTypeList, type) > -1
      ) {
        (item.receiveTypeList || []).push(type);
      }
    };
    addOrRemove(checkItem);

    /**
     * 根据父节点,选择所有的子节点
     *
     * @param {*} parentId
     */
    const iterator = (parentId) => {
      const subList = [];
      forEach(checkedList, (v) => {
        if (v.parentId === parentId) {
          addOrRemove(v);
          subList.push(v);
        }
      });
      if (subList && subList.length > 0) {
        forEach(subList, (v) => iterator(v.receiveCode));
      }
    };
    iterator(checkItem.receiveCode);

    /**
     * 反向勾选,即根据子节点反向勾选父节点
     *
     * @param {*} parentId 父节点的receiveCode
     */
    const reverseCheck = (parentId) => {
      if (!parentId) {
        return;
      }
      const sameParents = checkedList.filter((v) => v.parentId === parentId) || [];
      const temp = sameParents.filter((v) => {
        if (indexOf(v.defaultReceiveTypeList, type) < 0) {
          return true;
        }
        const idx = indexOf(v && v.receiveTypeList, type);
        return flag ? idx < 0 : idx > -1;
      });
      if (sameParents.length === temp.length || (sameParents.length !== temp.length && flag)) {
        const parentIndex = findIndex(checkedList, (v) => v.receiveCode === parentId);
        const parent = checkedList[parentIndex];
        addOrRemove(parent);

        reverseCheck(parent.parentId);
      }
    };

    reverseCheck(checkItem.parentId);

    this.setState({ checkedList });
  }
Example #4
Source File: index.js    From hzero-front with Apache License 2.0 4 votes vote down vote up
/**
   * render
   * @returns React.element
   */
  render() {
    const { userReceiveConfig, searchLoading, saveLoading } = this.props;
    const { configList = [], messageTypeList = [] } = userReceiveConfig;
    const { expandedRowKeys = [], checkedList } = this.state;
    let newList = messageTypeList;
    if (configList[0]) {
      const { defaultReceiveTypeList = [] } = configList[0];
      newList = messageTypeList.filter((item) => defaultReceiveTypeList.includes(item.value));
    }
    const columns = [
      {
        title: intl.get('hiam.userReceiveConfig.model.userReceiveConfig.type').d('消息类型'),
        dataIndex: 'receiveName',
      },
    ];

    forEach(newList, (item) => {
      columns.push({
        title: intl
          .get('hiam.userReceiveConfig.model.userReceiveConfig', {
            typeName: item.meaning,
          })
          .d(`${item.meaning}`),
        dataIndex: item.value,
        width: 150,
        render: (val, record) => {
          let checkboxElement = '';
          const { receiveCode } = record;
          if (isArray(checkedList) && !isEmpty(checkedList)) {
            const index = findIndex(checkedList, (v) => v.receiveCode === record.receiveCode);
            const flagParam = checkedList[index] || {};
            const { receiveTypeList = [] } = flagParam;
            const flag = indexOf(receiveTypeList, item.value) > -1;
            if (indexOf(record.defaultReceiveTypeList, item.value) > -1) {
              checkboxElement = (
                <Checkbox
                  indeterminate={
                    !flag && isReceiveTypeIsIndeterminate(item.value, receiveCode, checkedList)
                  }
                  checked={flag}
                  onChange={() => this.onCheckboxChange({ receiveCode, flag, type: item.value })}
                >
                  {intl.get('hzero.common.status.enable').d('启用')}
                </Checkbox>
              );
            }
          }
          return checkboxElement;
        },
      });
    });

    const editTableProps = {
      expandedRowKeys,
      columns,
      scroll: { x: tableScrollWidth(columns) },
      rowKey: 'receiveCode',
      pagination: false,
      bordered: true,
      dataSource: configList,
      loading: searchLoading,
      onExpand: this.onExpand,
    };

    return (
      <div className={styles.receive}>
        <Main
          title={intl.get('hiam.userReceiveConfig.view.title.subMain.config').d('用户消息接收设置')}
        >
          <Table {...editTableProps} />
          <div className={styles['operation-btn']}>
            <Button type="primary" onClick={this.handleSave} loading={saveLoading}>
              {intl.get('hzero.common.button.save').d('保存')}
            </Button>
            <Button style={btnStyle} onClick={this.handleCancel}>
              {intl.get('hzero.common.button.cancel').d('取消')}
            </Button>
            <Button style={btnStyle} onClick={this.handleSearch}>
              {intl.get('hzero.common.button.refresh').d('刷新')}
            </Button>
          </div>
        </Main>
      </div>
    );
  }