功能: - 网站收藏管理(添加/编辑/删除/收藏) - 分类管理(支持自定义图标和颜色) - 搜索功能 - 点击统计 - 现代暗色主题 UI 技术栈: - 后端: Python Flask + MySQL - 前端: React + Vite + Tailwind CSS - 数据库: MySQL (192.168.8.160) - 端口: 后端 5003, 前端 5173
67 lines
1.6 KiB
JavaScript
67 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
import utils from '../utils.js';
|
|
import AxiosURLSearchParams from '../helpers/AxiosURLSearchParams.js';
|
|
|
|
/**
|
|
* It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
|
|
* their plain counterparts (`:`, `$`, `,`, `+`).
|
|
*
|
|
* @param {string} val The value to be encoded.
|
|
*
|
|
* @returns {string} The encoded value.
|
|
*/
|
|
function encode(val) {
|
|
return encodeURIComponent(val)
|
|
.replace(/%3A/gi, ':')
|
|
.replace(/%24/g, '$')
|
|
.replace(/%2C/gi, ',')
|
|
.replace(/%20/g, '+');
|
|
}
|
|
|
|
/**
|
|
* Build a URL by appending params to the end
|
|
*
|
|
* @param {string} url The base of the url (e.g., http://www.google.com)
|
|
* @param {object} [params] The params to be appended
|
|
* @param {?(object|Function)} options
|
|
*
|
|
* @returns {string} The formatted url
|
|
*/
|
|
export default function buildURL(url, params, options) {
|
|
if (!params) {
|
|
return url;
|
|
}
|
|
|
|
const _encode = (options && options.encode) || encode;
|
|
|
|
const _options = utils.isFunction(options)
|
|
? {
|
|
serialize: options,
|
|
}
|
|
: options;
|
|
|
|
const serializeFn = _options && _options.serialize;
|
|
|
|
let serializedParams;
|
|
|
|
if (serializeFn) {
|
|
serializedParams = serializeFn(params, _options);
|
|
} else {
|
|
serializedParams = utils.isURLSearchParams(params)
|
|
? params.toString()
|
|
: new AxiosURLSearchParams(params, _options).toString(_encode);
|
|
}
|
|
|
|
if (serializedParams) {
|
|
const hashmarkIndex = url.indexOf('#');
|
|
|
|
if (hashmarkIndex !== -1) {
|
|
url = url.slice(0, hashmarkIndex);
|
|
}
|
|
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
|
}
|
|
|
|
return url;
|
|
}
|