loulijun2021
2022-07-11 9b825939b7f0a7439d704b379812362dd95697fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { NewEncodingRules } from '@/api/xtsz'
 
// 全局主要颜色
export function getGlobalColor() {
  return { globalColor: `#42b983` }
}
 
// 处理表头单元格样式
export function headerCellStyle() {
  const option = {
    background: '#eee', padding: '0'
  }
  return option
}
 
// 处理表格单元格样式
export function cellStyle() {
  const option = {
    padding: '5px 0'
  }
  return option
}
 
// 时间处理函数
export function handleDatetime(value) {
  const data = new Date(value)
  const month = data.getMonth() < 9 ? '0' + (data.getMonth() + 1) : data.getMonth() + 1
  const date = data.getDate() <= 9 ? '0' + data.getDate() : data.getDate()
  return data.getFullYear() + '-' + month + '-' + date
}
 
// 获取规则生成的编码
export async function getNewEncodingRules(encode) {
  const res = await NewEncodingRules({ rightcode: encode })
  if (res.code === '200') {
    return { RightCode: res.data[0], numvalue: res.data[1] }
  }
}
 
// 递归清除数组每个元素下的children为空的数组
const clearAllChildren = (items, childrenName = 'children') => {
  for (let i = 0; i < items.length; i++) {
    const item = items[i]
    // 当前对象存在children
    if (item && item[childrenName]) {
      // children为空数组时删除
      if (item[childrenName].length === 0) {
        delete item[childrenName]
      } else {
        // 递归当前children数组
        clearAllChildren(item[childrenName], childrenName)
      }
    }
  }
  return items
}
 
export default clearAllChildren