From 965f565060e6eb4f253e487c127e0ea6f743e2c5 Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Thu, 18 Jul 2024 00:03:41 +0800 Subject: [PATCH] uu --- common/util.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/common/util.js b/common/util.js index 3397256..098b295 100644 --- a/common/util.js +++ b/common/util.js @@ -179,6 +179,48 @@ const textDecoder = (input)=> { return decodeURIComponent(escape(String.fromCharCode(...[input]))); } +const getQueryObject = (url)=> { + var query = url.split('?')[1]; + var obj = {}; + + query = query.split('&'); + query.forEach(query => { + var item = query.split('='); + obj[item[0]] = item[1]; // 当然如果有中文/Unicode字符可以在这里用URIencode方法转码一下 + }); + return obj; +} + +export function isPlainObject(obj){ + return typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]' +} + +export function isPlainArray(obj){ + return typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Array]' +} + +export function deepAssign() { + let len = arguments.length, target = arguments[0] + if (!isPlainObject(target)) { + target = {} + } + for (let i = 1; i < len; i++) { + let source = arguments[i] + if (isPlainObject(source)) { + for (let s in source) { + if (s === '__proto__' || target === source[s]) { + continue + } + if (isPlainObject(source[s])) { + target[s] = deepAssign(target[s], source[s]) + } else { + target[s] = source[s] + } + } + } + } + return target +} export { getAddressDetail, @@ -192,4 +234,5 @@ export { throttle, textEncoder, textDecoder, + getQueryObject, }