// 防抖函數
function debounce (fn, wait) {
let t
return () => {json
let context = this let args = arguments if (t) clearTimeout(t) t = setTimeout(() => { fn.apply(context, args) }, wait)
}
}
function flatten (arr) { // 數組扁平化
return arr.reduce((result, item) => {數組
return result.concat(Array.isArray(item) ? flatten(item) : item)
}, [])
}
function handleMulitePerson (sPerson) {
console.log(44, sPerson.split(','))
if (typeof sPerson == 'string') {session
let personArr = [] sPerson.split(',').forEach(item => { let obj = { userCode: item.split('/')[0], userName: item.split('/')[1] } personArr.push(obj) }) return personArr
}
}app
function uniqueArray (array, key) { // json數組根據key去重
var result = [array[0]]
for (var i = 1; i < array.length; i++) {函數
var item = array[i] var repeat = false for (var j = 0; j < result.length; j++) { if (item[key] == result[j][key]) { repeat = true break } } if (!repeat) { result.push(item) }
}
return result
}
function setSessionStorage (key, val) {
if (typeof (val) == 'object') {this
sessionStorage.setItem(key, JSON.stringify(val))
} else {url
sessionStorage.setItem(key, val)
}
}
function getSessionStorage (key) {
return sessionStorage.getItem(key)
}
function removeStorage (key) {
sessionStorage.removeItem(key)
}code
function urlParams () { // 獲取連接參數
var str = location.search.length > 0 ? location.search.substring(1) : ''
var items = str.length ? str.split('&') : []
var args = {}
var item = null
var name = null
var value = null
for (let i = 0, len = items.length; i < len; i++) {rem
item = items[i].split('=') name = decodeURIComponent(item[0]) value = decodeURIComponent(item[1]) if (name.length) { args[name] = value }
};
return args
}get
function urlAfterParams () {
var str = window.location.hash.length > 0 ? window.location.hash.substring(window.location.hash.indexOf('?') + 1) : ''
var items = str.indexOf('&') > 0 ? str.split('&') : str.split('?')
var args = {}
var item = null
var name = null
var value = null
for (let i = 0, len = items.length; i < len; i++) {
item = items[i].split('=') name = decodeURIComponent(item[0]) value = decodeURIComponent(item[1]) if (name.length) { args[name] = value }
};
return args
}
function parseParams (url) {
url = decodeURIComponent(url)
var params = {}
var idx = url.indexOf('?')
if (idx > 0) {
var queryStr = url.substring(idx + 1) if (queryStr.length > 0) { var arr = queryStr.split('&') for (let i = 0; i < arr.length; i++) { var pair = arr[i].split('=') if (pair.length == 2 && pair[0].length > 0) { params[pair[0]] = pair[1] } } }
}
return params
}
/**
*/
function getSelectUserName (userName, userCode) {
return userName + '(' + userCode + ')'
}
function getSelectLoginUser () {
var userInfo = getLoginUserInfo()
return getSelectUserName(userInfo.userName, userInfo.userId)
}
function getUserNameBySelectUserName (userName) {
let i = userName.indexOf('(')
return userName.substring(0, i)
}
/**
*/
function getLoginUserInfo () {
return JSON.parse(localStorage.getItem('userInfo'))
}
function getLoginUserCode () {
return JSON.parse(localStorage.getItem('userInfo')).userId
}
export default { getNyr, getYDate, setSessionStorage, urlParams, urlAfterParams, parseParams, debounce, handleMulitePerson, uniqueArray, flatten, getSessionStorage, removeStorage, getSelectUserName, getSelectLoginUser, getLoginUserInfo, getLoginUserCode, getUserNameBySelectUserName}