management_UI/src/utils/common.js
2020-10-22 18:45:05 +08:00

78 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @desc 函数防抖
* @param func 函数
* @param wait 延迟执行毫秒数
* @param immediate true 表立即执行false 表非立即执行
*/
export function debounce (func, wait, immediate) {
let timeout
return function () {
let context = this
let args = arguments
if (timeout) clearTimeout(timeout)
if (immediate) {
var callNow = !timeout
timeout = setTimeout(() => {
timeout = null
}, wait)
if (callNow) func.apply(context, args)
} else {
timeout = setTimeout(function () {
func.apply(context, args)
}, wait)
}
}
}
export function personlGetForm (arr = []) {
const params = {
list: [],
title: '',
value: ''
}
if (!arr || arr.length === 0) return params
if (!arr[0].staffId) {
arr = arr.map(i => {
i.staffId = i.id
return i
})
}
const key = 'staffId'
params.list = arr
for (let i in arr) {
if (i < 1) { params.title = params.title + (i === '0' ? '' : ',') + arr[i].name }
params.value += arr[i][key] + (i < arr.length - 1 ? ',' : '')
}
console.log('params: ', params)
return params
}
export function departGetForm (arr = []) {
const params = {
list: [],
title: '',
value: ''
}
if (!arr || arr.length === 0) return params
if (!arr[0].departmentId) {
arr = arr.map(i => {
i.departmentId = i.id
if (!i.departmentName) i.departmentName = i.name
return i
})
}
const key = 'departmentId'
const key1 = 'departmentName'
params.list = arr
for (let i in arr) {
if (i < 1) {
params.title = params.title + (i === '0' ? '' : ',') + arr[i][key1]
}
params.value += arr[i][key] + (i < arr.length - 1 ? ',' : '')
}
console.log('params: ', params)
return params
}