|
|
@@ -327,25 +327,23 @@ export const mixEnum = <T, K>(enum1: T, enum2: K): T | K => {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
-// 字符串转params对象
|
|
|
-export const strToParams = (str: string) => {
|
|
|
- if (!str) return {};
|
|
|
- if (str?.[0] === "?") {
|
|
|
- str = str.substr(1);
|
|
|
- }
|
|
|
-
|
|
|
- const result: { [key: string]: string } = {};
|
|
|
- const splitRG = /([^=&]+)(?:=([^&]*))?&?/;
|
|
|
-
|
|
|
- let rgRet;
|
|
|
- while ((rgRet = str.match(splitRG))) {
|
|
|
- result[rgRet[1]] = rgRet[2] === undefined ? "" : rgRet[2];
|
|
|
- str = str.substr(rgRet[0].length);
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-};
|
|
|
-
|
|
|
+/**
|
|
|
+ * 解析 URL 中的所有参数,返回对象
|
|
|
+ * @param {string} url 可选,不传默认取当前页面 url
|
|
|
+ * @returns {object} 参数对象
|
|
|
+ */
|
|
|
+export const strToParams = (url = window.location.href) => {
|
|
|
+ // 取出 ? 后面的参数部分
|
|
|
+ const queryStr = url.split('?')[1] || ''
|
|
|
+ if (!queryStr) return {}
|
|
|
+
|
|
|
+ // 解析成键值对
|
|
|
+ const params = {}
|
|
|
+ new URLSearchParams(queryStr).forEach((val, key) => {
|
|
|
+ params[key] = val
|
|
|
+ })
|
|
|
+ return params
|
|
|
+}
|
|
|
export const getDomMatrix = (dom: HTMLElement) => {
|
|
|
const str = getComputedStyle(dom, null).getPropertyValue("transform");
|
|
|
const matrix2d = str
|