qs#parse JavaScript Examples

The following examples show how to use qs#parse. 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: query.js    From egoshop with Apache License 2.0 6 votes vote down vote up
/**
     * todo 思考是否废弃
     * 为了列表类型的接口调用方便
     * @param delCondition
     * @returns {*}
     */
    static make(delCondition = []) {
        const QueryClass = new Query();
        return QueryClass.parse().delEmptyParams().withPageParams().delParams(delCondition).getParams();
    }
Example #2
Source File: utils.js    From prometheusPro with MIT License 6 votes vote down vote up
export function getPageQuery() {
  return parse(window.location.href.split('?')[1]);
}
Example #3
Source File: index.es.js    From the-eye-knows-the-garbage with MIT License 6 votes vote down vote up
function getParamObject(val) {
  if (isURLSearchParams(val)) {
    return parse(val.toString(), {
      strictNullHandling: true
    });
  }

  if (typeof val === 'string') {
    return [val];
  }

  return val;
}
Example #4
Source File: index.es.js    From the-eye-knows-the-garbage with MIT License 6 votes vote down vote up
/**
 * 安全的JSON.parse
 */

function safeJsonParse(data) {
  var throwErrIfParseFail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  var response = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  var request = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;

  try {
    return JSON.parse(data);
  } catch (e) {
    if (throwErrIfParseFail) {
      throw new ResponseError(response, 'JSON.parse fail', data, request, 'ParseError');
    }
  } // eslint-disable-line no-empty


  return data;
}
Example #5
Source File: index.js    From the-eye-knows-the-garbage with MIT License 6 votes vote down vote up
getParamsFromUrl = function getParamsFromUrl(settings) {
  if (!isBrowser()) {
    return defaultSettings;
  } // 第一次进入与 浏览器参数同步一下


  var params = {};

  if (window.location.search) {
    params = parse(window.location.search.replace('?', ''));
  }

  return Object.assign(Object.assign(Object.assign({}, defaultSettings), settings || {}), params);
}
Example #6
Source File: utils.js    From youdidao-unmanned-shop with MIT License 6 votes vote down vote up
export function getPageQuery() {
  return parse(window.location.href.split('?')[1]);
}
Example #7
Source File: utils.js    From camel-store-admin with Apache License 2.0 6 votes vote down vote up
export function getPageQuery() {
  return parse(window.location.href.split('?')[1]);
}
Example #8
Source File: utils.js    From acy-dex-interface with MIT License 6 votes vote down vote up
export function getPageQuery() {
  return parse(window.location.href.split('?')[1]);
}
Example #9
Source File: query.js    From juno with Apache License 2.0 6 votes vote down vote up
/**
   * todo 思考是否废弃
   * 为了列表类型的接口调用方便
   * @param delCondition
   * @returns {*}
   */
  static make(delCondition = []) {
    const QueryClass = new Query();
    return QueryClass.parse().delEmptyParams().withPageParams().delParams(delCondition).getParams();
  }
Example #10
Source File: utils.js    From online-test-platform with Apache License 2.0 6 votes vote down vote up
export function isJson(str) {
  try {
    const obj = JSON.parse(str);
    if (obj && typeof obj == "object") return true;
  } catch(e) {
  }
  return false;
}
Example #11
Source File: utils.js    From online-test-platform with Apache License 2.0 6 votes vote down vote up
export function getPageQuery() {
  return parse(window.location.href.split('?')[1]);
}
Example #12
Source File: query.js    From egoshop with Apache License 2.0 5 votes vote down vote up
parse() {
        this.params = parse(window.location.href.split("?")[1]);
        return this;
    }
Example #13
Source File: index.js    From egoshop with Apache License 2.0 5 votes vote down vote up
function getPageQuery() {
    return parse(window.location.href.split("?")[1]);
}
Example #14
Source File: query.js    From egoshop with Apache License 2.0 5 votes vote down vote up
static getQuery() {
        return parse(window.location.href.split("?")[1]);
    }
Example #15
Source File: query.js    From juno with Apache License 2.0 5 votes vote down vote up
static getQuery() {
    return parse(window.location.href.split('?')[1]);
  }
Example #16
Source File: index.js    From the-eye-knows-the-garbage with MIT License 5 votes vote down vote up
initState = function initState(settings, onSettingChange, publicPath) {
  if (!isBrowser()) {
    return;
  }

  var loadedStyle = false;

  if (window.location.search) {
    var params = parse(window.location.search.replace('?', ''));
    var replaceSetting = {};
    Object.keys(params).forEach(function (key) {
      if (defaultSettings[key] || defaultSettings[key] === undefined) {
        replaceSetting[key] = params[key];

        if (key.includes('Render')) {
          replaceSetting[key] = params[key] === 'false' ? false : undefined;
        }
      }
    });

    if (onSettingChange) {
      onSettingChange(Object.assign(Object.assign({}, settings), replaceSetting));
    } // 如果 url 中设置主题,进行一次加载。


    if (oldSetting.navTheme !== params.navTheme && params.navTheme) {
      updateTheme(settings.navTheme === 'realDark', params.primaryColor, true, publicPath);
      loadedStyle = true;
    }
  }

  if (loadedStyle) {
    return;
  } // 如果 url 中没有设置主题,并且 url 中的没有加载,进行一次加载。


  if (defaultSettings.navTheme !== settings.navTheme && settings.navTheme) {
    updateTheme(settings.navTheme === 'realDark', settings.primaryColor, true, publicPath);
  }
}
Example #17
Source File: query.js    From juno with Apache License 2.0 5 votes vote down vote up
parse() {
    this.params = parse(window.location.href.split('?')[1]);
    return this;
  }
Example #18
Source File: index.js    From juno with Apache License 2.0 5 votes vote down vote up
constructor(options) {
    // console.log("########### options",options);
    const params = parse(window.location.href.split('?')[1]);
    if (typeof options['currentPage'] !== 'undefined') {
      this.currentPage = options['currentPage'];
    } else if (typeof params['currentPage'] !== 'undefined') {
      this.currentPage = parseInt(params['currentPage']);
    }
    if (typeof options['pageSize'] !== 'undefined') {
      this.pageSize = options['pageSize'];
    } else if (typeof params['pageSize'] !== 'undefined') {
      this.pageSize = parseInt(params['pageSize']);
    }
    if (typeof options['router'] !== 'undefined') {
      this.router = options['router'];
    }
    if (typeof options['param'] !== 'undefined') {
      this.param = options['param'];
      this.defaultParam = options['param'];
    }
    if (typeof options['rule'] !== 'undefined') {
      this.rule = options['rule'];
    }
    if (typeof options['refresh'] !== 'undefined') {
      this.refresh = options['refresh'];
    }
    if (typeof options['submit'] !== 'undefined') {
      this.submit = options['submit'];
    }
    if (typeof options['reset'] !== 'undefined') {
      this.reset = options['reset'];
    }
    if (count(params) > 0) {
      let _params = {};
      Object.keys(params).forEach((key) => {
        if (typeof params[key] !== 'undefined') {
          _params[key] = params[key];
        }
      });
      this.param = Object.assign({}, options['param'], _params);
    }
  }
Example #19
Source File: index.js    From the-eye-knows-the-garbage with MIT License 4 votes vote down vote up
SettingDrawer = function SettingDrawer(props) {
  var _props$settings = props.settings,
      propsSettings = _props$settings === void 0 ? undefined : _props$settings,
      _props$hideLoading = props.hideLoading,
      hideLoading = _props$hideLoading === void 0 ? false : _props$hideLoading,
      hideColors = props.hideColors,
      hideHintAlert = props.hideHintAlert,
      hideCopyButton = props.hideCopyButton,
      getContainer = props.getContainer,
      onSettingChange = props.onSettingChange,
      _props$prefixCls = props.prefixCls,
      prefixCls = _props$prefixCls === void 0 ? 'ant-pro' : _props$prefixCls;
  var firstRender = useRef(true);

  var _useMergeValue = useMergeValue(false, {
    value: props.collapse,
    onChange: props.onCollapseChange
  }),
      _useMergeValue2 = _slicedToArray(_useMergeValue, 2),
      show = _useMergeValue2[0],
      setShow = _useMergeValue2[1];

  var _useState = useState(getLanguage()),
      _useState2 = _slicedToArray(_useState, 2),
      language = _useState2[0],
      setLanguage = _useState2[1];

  var _useMergeValue3 = useMergeValue(function () {
    return getParamsFromUrl(propsSettings);
  }, {
    value: propsSettings,
    onChange: onSettingChange
  }),
      _useMergeValue4 = _slicedToArray(_useMergeValue3, 2),
      settingState = _useMergeValue4[0],
      setSettingState = _useMergeValue4[1];

  var preStateRef = useRef(settingState);

  var _ref3 = settingState || {},
      _ref3$navTheme = _ref3.navTheme,
      navTheme = _ref3$navTheme === void 0 ? 'dark' : _ref3$navTheme,
      _ref3$primaryColor = _ref3.primaryColor,
      primaryColor = _ref3$primaryColor === void 0 ? 'daybreak' : _ref3$primaryColor,
      _ref3$layout = _ref3.layout,
      layout = _ref3$layout === void 0 ? 'sidemenu' : _ref3$layout,
      colorWeak = _ref3.colorWeak;

  useEffect(function () {
    // 语言修改,这个是和 locale 是配置起来的
    var onLanguageChange = function onLanguageChange() {
      if (language !== getLanguage()) {
        setLanguage(getLanguage());
      }
    }; // 记住默认的选择,方便做 diff,然后保存到 url 参数中


    oldSetting = Object.assign(Object.assign({}, defaultSettings), propsSettings);
    /**
     * 如果不是浏览器 都没有必要做了
     */

    if (!isBrowser()) {
      return function () {
        return null;
      };
    }

    initState(settingState, setSettingState, props.publicPath);
    window.addEventListener('languagechange', onLanguageChange, {
      passive: true
    });
    return function () {
      return window.removeEventListener('languagechange', onLanguageChange);
    };
  }, []);
  /**
   * 修改设置
   * @param key
   * @param value
   * @param hideMessageLoading
   */

  var changeSetting = function changeSetting(key, value, hideMessageLoading) {
    var nextState = Object.assign({}, preStateRef.current);
    nextState[key] = value;

    if (key === 'navTheme') {
      updateTheme(value === 'realDark', undefined, hideMessageLoading, props.publicPath);
      nextState.primaryColor = 'daybreak';
    }

    if (key === 'primaryColor') {
      updateTheme(nextState.navTheme === 'realDark', value === 'daybreak' ? '' : value, hideMessageLoading, props.publicPath);
    }

    if (key === 'layout') {
      nextState.contentWidth = value === 'top' ? 'Fixed' : 'Fluid';
    }

    if (key === 'layout' && value !== 'mix') {
      nextState.splitMenus = false;
    }

    if (key === 'layout' && value === 'mix') {
      nextState.navTheme = 'light';
    }

    if (key === 'colorWeak' && value === true) {
      var dom = document.querySelector('body div');

      if (!dom) {
        return;
      }

      dom.dataset.prosettingdrawer = dom.style.filter;
      dom.style.filter = 'invert(80%)';
    }

    if (key === 'colorWeak' && value === false) {
      var _dom = document.querySelector('body div');

      if (!_dom) {
        return;
      }

      _dom.style.filter = _dom.dataset.prosettingdrawer || 'none';
      delete _dom.dataset.prosettingdrawer;
    }

    preStateRef.current = nextState;
    setSettingState(nextState);
  };

  var formatMessage = getFormatMessage();
  var themeList = getThemeList(settingState);
  useEffect(function () {
    /**
     * 如果不是浏览器 都没有必要做了
     */
    if (!isBrowser()) {
      return;
    }

    if (firstRender.current) {
      firstRender.current = false;
      return;
    }

    var browserHistory = createBrowserHistory();
    var params = {};

    if (window.location.search) {
      params = parse(window.location.search.replace('?', ''));
    }

    var diffParams = getDifferentSetting(Object.assign(Object.assign({}, params), settingState));

    if (Object.keys(settingState).length < 1) {
      return;
    }

    browserHistory.replace({
      search: stringify(diffParams)
    });
  }, [JSON.stringify(settingState)]);
  var baseClassName = "".concat(prefixCls, "-setting");
  return React.createElement(_Drawer, {
    visible: show,
    width: 300,
    onClose: function onClose() {
      return setShow(false);
    },
    placement: "right",
    getContainer: getContainer,
    handler: React.createElement("div", {
      className: "".concat(baseClassName, "-drawer-handle"),
      onClick: function onClick() {
        return setShow(!show);
      }
    }, show ? React.createElement(CloseOutlined, {
      style: {
        color: '#fff',
        fontSize: 20
      }
    }) : React.createElement(SettingOutlined, {
      style: {
        color: '#fff',
        fontSize: 20
      }
    })),
    style: {
      zIndex: 999
    }
  }, React.createElement("div", {
    className: "".concat(baseClassName, "-drawer-content")
  }, React.createElement(Body, {
    title: formatMessage({
      id: 'app.setting.pagestyle',
      defaultMessage: 'Page style setting'
    }),
    prefixCls: baseClassName
  }, React.createElement(BlockCheckbox, {
    prefixCls: baseClassName,
    list: themeList.themeList,
    value: navTheme,
    key: "navTheme",
    onChange: function onChange(value) {
      return changeSetting('navTheme', value, hideLoading);
    }
  })), React.createElement(Body, {
    title: formatMessage({
      id: 'app.setting.themecolor',
      defaultMessage: 'Theme color'
    }),
    prefixCls: baseClassName
  }, React.createElement(ThemeColor, {
    value: primaryColor,
    colors: hideColors ? [] : themeList.colorList[navTheme === 'realDark' ? 'dark' : 'light'],
    formatMessage: formatMessage,
    onChange: function onChange(color) {
      return changeSetting('primaryColor', color, hideLoading);
    }
  })), React.createElement(_Divider, null), React.createElement(Body, {
    prefixCls: baseClassName,
    title: formatMessage({
      id: 'app.setting.navigationmode'
    })
  }, React.createElement(BlockCheckbox, {
    prefixCls: baseClassName,
    value: layout,
    key: "layout",
    list: [{
      key: 'side',
      url: 'https://gw.alipayobjects.com/zos/antfincdn/XwFOFbLkSM/LCkqqYNmvBEbokSDscrm.svg',
      title: formatMessage({
        id: 'app.setting.sidemenu'
      })
    }, {
      key: 'top',
      url: 'https://gw.alipayobjects.com/zos/antfincdn/URETY8%24STp/KDNDBbriJhLwuqMoxcAr.svg',
      title: formatMessage({
        id: 'app.setting.topmenu'
      })
    }, {
      key: 'mix',
      url: 'https://gw.alipayobjects.com/zos/antfincdn/x8Ob%26B8cy8/LCkqqYNmvBEbokSDscrm.svg',
      title: formatMessage({
        id: 'app.setting.mixmenu'
      })
    }],
    onChange: function onChange(value) {
      return changeSetting('layout', value, hideLoading);
    }
  })), React.createElement(LayoutSetting, {
    settings: settingState,
    changeSetting: changeSetting
  }), React.createElement(_Divider, null), React.createElement(Body, {
    prefixCls: baseClassName,
    title: formatMessage({
      id: 'app.setting.regionalsettings'
    })
  }, React.createElement(RegionalSetting, {
    settings: settingState,
    changeSetting: changeSetting
  })), React.createElement(_Divider, null), React.createElement(Body, {
    prefixCls: baseClassName,
    title: formatMessage({
      id: 'app.setting.othersettings'
    })
  }, React.createElement(_List, {
    split: false,
    renderItem: renderLayoutSettingItem,
    dataSource: [{
      title: formatMessage({
        id: 'app.setting.weakmode'
      }),
      action: React.createElement(_Switch, {
        size: "small",
        checked: !!colorWeak,
        onChange: function onChange(checked) {
          return changeSetting('colorWeak', checked);
        }
      })
    }]
  })), hideHintAlert && hideCopyButton ? null : React.createElement(_Divider, null), hideHintAlert ? null : React.createElement(_Alert, {
    type: "warning",
    message: formatMessage({
      id: 'app.setting.production.hint'
    }),
    icon: React.createElement(NotificationOutlined, null),
    showIcon: true,
    style: {
      marginBottom: 16
    }
  }), hideCopyButton ? null : React.createElement(CopyToClipboard, {
    text: genCopySettingJson(settingState),
    onCopy: function onCopy() {
      return _message.success(formatMessage({
        id: 'app.setting.copyinfo'
      }));
    }
  }, React.createElement(_Button, {
    block: true
  }, React.createElement(CopyOutlined, null), " ", formatMessage({
    id: 'app.setting.copy'
  })))));
}