lodash#split JavaScript Examples

The following examples show how to use lodash#split. 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: menuTab.js    From hzero-front with Apache License 2.0 6 votes vote down vote up
/**
 * 获取真正的 pathname 和 search
 * 有些 监听 到的 url 可能被 search 污染了, 需要把 search 剥离出去
 * 注意 有些 search 可能还是在 location 中,而不是在url, 所以 search 可能为空
 * @param {!String} pathname - url 地址
 */
function getLocation(pathname) {
  const [realPathname, search] = split(pathname, '?');
  return { pathname: realPathname, search };
}
Example #2
Source File: menuTab.js    From hzero-front with Apache License 2.0 5 votes vote down vote up
/**
 * 从pathname中获取 tabKey
 * @param {!String} pathname - 切换的pathname
 */
function getTabKey(pathname) {
  return slice(split(pathname, '/'), 1);
}
Example #3
Source File: index.js    From hzero-front with Apache License 2.0 4 votes vote down vote up
getColumnsAndScrollX() {
    const { context, fields } = this.props;
    let columnsWidth = 0;
    let hasAutoWidth = false;
    const columns = map(fields, field => {
      const dealFieldProps = dealObjectProps(field, context);
      const componentProps = preProcessComponentProps({ field, context });
      const isAutoWidth = +dealFieldProps.width === 0; // autoWidth field
      const columnWidth =
        +dealFieldProps.width || getWidthFromWord({ word: field[fieldLabelProp] });
      const column = {
        dataIndex: field[fieldNameProp],
        title: field[fieldLabelProp],
        align: dealFieldProps.align,
        render: (_, record) => getDisplayValue({ field, dataSource: record, componentProps }),
      };
      if (isAutoWidth) {
        hasAutoWidth = true;
        columnsWidth += 120;
      } else {
        column.width = columnWidth;
        columnsWidth += columnWidth;
      }
      switch (field.componentType) {
        case 'LinkButton':
          column.render = (_, record) => {
            const btns = {};
            forEach(componentProps, (prop, propKey) => {
              set(btns, propKey, prop);
            });
            // todo 按钮按钮的顺序
            const linkBtns = [];
            forEach(btns, btnProps => {
              const { btnKey } = btnProps;
              const modalProps = {};
              let onBtnClick;
              switch (btnProps.action) {
                case actionCode.page:
                  // 打开 Modal 或 页面
                  switch (btnProps.openType) {
                    case openTypeCode.inner:
                      // 跳转
                      break;
                    case openTypeCode.modal:
                      // 打开 Modal
                      modalProps.type = openTypeCode.modal;
                      modalProps.bodyStyle =
                        openPageModalBodyStyle[btnProps.openPageTypeModal].bodyStyle;
                      modalProps.width = openPageModalBodyStyle[btnProps.openPageTypeModal].width;
                      modalProps.modalBtns = btnProps.modalBtns; // modal 按钮
                      // 订阅事件
                      if (btnProps.subEvents) {
                        forEach(btnProps.subEvents, subEvent => {
                          const [subEventListenStr, subEventActionStr] = split(
                            subEvent,
                            subEventSep
                          );
                          const subEventAction = getContextValue(context, subEventActionStr);
                          if (isFunction(subEventAction)) {
                            modalProps[subEventListenStr] = subEventAction;
                          }
                        });
                      }
                      break;
                    case openTypeCode.drawer:
                      // 打开 侧滑Modal
                      modalProps.type = openTypeCode.drawer;
                      modalProps.width = btnProps.openPageTypeDrawer;
                      modalProps.modalBtns = btnProps.modalBtns; // modal 按钮
                      // 订阅事件
                      if (btnProps.subEvents) {
                        forEach(btnProps.subEvents, subEvent => {
                          const [subEventListenStr, subEventActionStr] = split(
                            subEvent,
                            subEventSep
                          );
                          const subEventAction = getContextValue(context, subEventActionStr);
                          if (isFunction(subEventAction)) {
                            modalProps[subEventListenStr] = subEventAction;
                          }
                        });
                      }
                      break;
                    default:
                      break;
                  }
                  onBtnClick = e => {
                    e.preventDefault();
                    const params = {};
                    const {
                      history: { search },
                    } = this.props;
                    const urlParams = querystring.parse(search);
                    const paramStream = (btnProps.params || '').split(',');
                    for (let i = 1; i <= paramStream.length; i++) {
                      if (i % 3 === 0) {
                        switch (paramStream[i - 2]) {
                          case paramTypeCode.fixParam:
                            params[paramStream[i - 3]] = paramStream[i - 1];
                            break;
                          case paramTypeCode.urlParam:
                            params[paramStream[i - 1]] = urlParams[paramStream[i - 3]];
                            break;
                          case paramTypeCode.columnParam:
                            params[paramStream[i - 1]] = record[paramStream[i - 3]];
                            break;
                          default:
                            break;
                        }
                      }
                    }
                    this.setState({
                      pageModalProps: {
                        pageCode: btnProps.pageCode,
                        ...modalProps,
                      },
                    });
                    if (this.pageModalRef) {
                      this.pageModalRef.init(params);
                      this.pageModalRef.show();
                    }
                  };
                  break;
                case actionCode.action:
                  // 自定义动作
                  onBtnClick = () => {
                    if (btnProps.actionEvent === internalFuncsInfo.lineRemove.code) {
                      this.handleLineRemove(record).catch((/* e */) => {
                        // console.error(e);
                      });
                    }
                  };
                  // Table 的动作, 删除行 ...
                  // 其他事件
                  break;
                default:
                  break;
              }
              linkBtns[btnProps.orderSeq] = {
                key: btnKey,
                ele: (
                  <a onClick={onBtnClick} style={linkButtonStyle}>
                    {btnProps.title}
                  </a>
                ),
                len: (btnProps.title && btnProps.title.length) || 4,
                title: btnProps.title || null,
              };
            });
            return operatorRender(linkBtns.filter(Boolean));
          };
          break;
        default:
          break;
      }
      return column;
    });
    if (hasAutoWidth) {
      return { columns };
    }
    return {
      scroll: { x: columnsWidth },
      columns,
    };
  }
Example #4
Source File: index.js    From hzero-front with Apache License 2.0 4 votes vote down vote up
renderToolbarFields({ fields = [], context }) {
    return map(fields, field => {
      // 获取组件不依赖 Context 的属性
      // 获取对应的组件
      const ComponentType = getBtnType({ field });
      const { componentProps, btn: btnProps = {} } = dealButtonProps({ field, context });
      const buttonProps = {};
      switch (btnProps.action) {
        case ACTION_CODE.action:
          buttonProps.onClick = () => {
            const { actionEvent } = btnProps;
            const func = getContextValue(context, actionEvent);
            if (isFunction(func)) {
              func().catch((/* e */) => {
                // todo 失败不需要做事情?
                // console.error(e);
              });
            }
          };
          break;
        case ACTION_CODE.page:
          buttonProps.onClick = () => {
            const modalProps = {};
            const params = {};
            const {
              history: { search },
            } = this.props;
            const urlParams = querystring.parse(search);
            const paramStream = (btnProps.params || '').split(',');
            for (let i = 1; i <= paramStream.length; i++) {
              if (i % 3 === 0) {
                switch (paramStream[i - 2]) {
                  case PAGE_PARAM.fixParam:
                    params[paramStream[i - 3]] = paramStream[i - 1];
                    break;
                  case PAGE_PARAM.urlParam:
                    params[paramStream[i - 1]] = urlParams[paramStream[i - 3]];
                    break;
                  default:
                    break;
                }
              }
            }
            // 打开 Modal 或 页面
            switch (btnProps.openType) {
              case openTypeCode.inner:
                // 跳转
                break;
              case openTypeCode.modal:
                // 打开 Modal
                modalProps.type = openTypeCode.modal;
                modalProps.bodyStyle = openPageModalBodyStyle[btnProps.openPageTypeModal].bodyStyle;
                modalProps.width = openPageModalBodyStyle[btnProps.openPageTypeModal].width;
                modalProps.modalBtns = btnProps.modalBtns; // modal 按钮
                // 订阅事件
                if (btnProps.subEvents) {
                  forEach(btnProps.subEvents, subEvent => {
                    const [subEventListenStr, subEventActionStr] = split(subEvent, subEventSep);
                    const subEventAction = getContextValue(context, subEventActionStr);
                    if (isFunction(subEventAction)) {
                      modalProps[subEventListenStr] = subEventAction;
                    }
                  });
                }
                break;
              case openTypeCode.drawer:
                // 打开 侧滑Modal
                modalProps.type = openTypeCode.drawer;
                modalProps.width = btnProps.openPageTypeDrawer;
                modalProps.modalBtns = btnProps.modalBtns; // modal 按钮
                // 订阅事件
                if (btnProps.subEvents) {
                  forEach(btnProps.subEvents, subEvent => {
                    const [subEventListenStr, subEventActionStr] = split(subEvent, subEventSep);
                    const subEventAction = getContextValue(context, subEventActionStr);
                    if (isFunction(subEventAction)) {
                      modalProps[subEventListenStr] = subEventAction;
                    }
                  });
                }
                break;
              default:
                break;
            }
            this.setState({
              pageModalProps: {
                pageCode: btnProps.pageCode,
                ...modalProps,
              },
            });
            if (this.pageModalRef) {
              this.pageModalRef.init(params);
              this.pageModalRef.show();
            }
          };
          break;
        default:
          break;
      }
      // TODO Button 的显示属性 最后看在哪里处理
      if (!componentProps.children && componentProps.text) {
        componentProps.children = componentProps.text;
      } else {
        // use [fieldLabelProp] as Button's text
        componentProps.children = field[fieldLabelProp];
      }
      return (
        <React.Fragment key={field[fieldNameProp]}>
          {React.createElement(ComponentType, { ...componentProps, ...buttonProps })}
        </React.Fragment>
      );
    });
  }