/*
function: 根据给定参数生成url地址
var dic = {name: 'genreal', age: 24}
var url = 'https://www.baidu.com?age=22';
_buildUrl(dic, url);
将得到"https://www.baidu.com?age=24&name=genreal"
哦, 忽略先后顺序吧...

补充: 可以参考浏览器URLSearchParams对象, 更加方便和强大.
考虑到兼容性, 暂时不使用这个工具.
function _buildUrl(dict) {
      var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.search;

      for (var _iterator = function (target) {
        return Object.keys(target).map(function (key) {
          return [key, target[key]];
        });
      }(dict), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
        var _ref;

        if (_isArray) {
          if (_i >= _iterator.length) break;
          _ref = _iterator[_i++];
        } else {
          _i = _iterator.next();
          if (_i.done) break;
          _ref = _i.value;
        }

        var _ref2 = _ref,
            _ref3 = _slicedToArray(_ref2, 2),
            key = _ref3[0],
            val = _ref3[1];

        // 搜索name=general这种形式的字符串(&是分隔符)
        var pattern = key + '=([^&]*)';
        var targetStr = key + '=' + val;

        /*
         * 如果目标url中包含了key键, 我们需要将它替换成我们自己的val
         * 不然就直接添加好了.
         */
        if (url.match(pattern)) {
          var tmp = new RegExp('(' + key + '=)([^&]*)', 'gi');
          url = url.replace(tmp, targetStr);
        } else {
          var seperator = url.match('[?]') ? '&' : '?';
          url = url + seperator + targetStr;
        }
      }
      if (location.hash) {
        url += location.hash;
      }
      return url;
    }