This commit is contained in:
xiaozhiyong
2024-03-14 08:37:41 +08:00
parent 338cbe6990
commit fb74b5bb1d
7 changed files with 173 additions and 99 deletions

View File

@@ -212,7 +212,15 @@ export function param2Obj(url) {
if (!search) {
return {}
}
return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"').replace(/\+/g, ' ') + '"}')
return JSON.parse(
'{"' +
decodeURIComponent(search)
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')
.replace(/\+/g, ' ') +
'"}'
)
}
/**
@@ -288,7 +296,7 @@ export function getTime(type) {
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result
const later = function () {
const later = function() {
// 据上一次触发时间间隔
const last = +new Date() - timestamp
@@ -305,7 +313,7 @@ export function debounce(func, wait, immediate) {
}
}
return function (...args) {
return function(...args) {
context = this
timestamp = +new Date()
const callNow = immediate && !timeout
@@ -420,9 +428,9 @@ export function fileAdd(file, resolve, reject) {
const reader = new FileReader()
const image = new Image()
reader.readAsDataURL(file)
reader.onload = function () {
reader.onload = function() {
file.src = this.result
image.onload = function () {
image.onload = function() {
const width = image.width
const height = image.height
file.width = width
@@ -444,7 +452,7 @@ export function startImgCompress(path, obj, resolve, reject) {
// path是指上传的图片obj是压缩的品质越低越模糊
var img = new Image()
img.src = path.src
img.onload = function () {
img.onload = function() {
var that = this // 这里的this 是把img的对象指向改变为that
// 默认按比例压缩
var w = that.width
@@ -501,7 +509,7 @@ export function formatXML(xml, tab) {
var formatted = ''
var indent = ''
tab = tab || ' '
xml.split(/>\s*</).forEach(function (node) {
xml.split(/>\s*</).forEach(function(node) {
if (node.match(/^\/\w/)) indent = indent.substring(tab.length)
formatted += indent + '<' + node + '>\r\n'
if (node.match(/^<?\w[^>]*[^\/]$/)) indent += tab
@@ -660,7 +668,7 @@ export const exportDefault = 'export default '
// 类型判断
export function typeJudgment(object) {
try {
let res = {}.__proto__.toString.call(object);
let res = {}.__proto__.toString.call(object)
// let type = /(?<= ).+(?=\])/.exec(res);
let type = res.replace(/[\[\]]/g, '').split(' ')
return type.length ? type[1] : ''
@@ -668,3 +676,21 @@ export function typeJudgment(object) {
return ''
}
}
// url取参
export function urlParamsHandle(url) {
const search = url.split('?')[1]
if (!search) {
return {}
}
const result = {}
const searchArr = search.split('&')
searchArr.forEach(v => {
const index = v.indexOf('=')
if (index !== -1) {
const name = v.substring(0, index)
const val = v.substring(index + 1, v.length)
result[name] = val
}
})
return result
}