小小儁爺
20 小时以前 c4d59de5b8132c70ae4dc64e4309fc6d761b111d
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import axios from 'axios'
import Vue from 'vue'
import { AppTicketSelect } from '@/api/WorkOrder'
 
// 全局主要颜色
export function getGlobalColor() {
  return { globalColor: `#42b983` }
}
 
// 处理表头单元格样式
export function headerCellStyle() {
  const option = {
    // background: '#a7a7a7', padding: '0'
    background: '#f8f8fa', padding: '0', color: '#000', fontWeight: 500
  }
  return option
}
 
// 处理表格单元格样式
export function cellStyle() {
  const option = {
    // padding: '5px 0'
    padding: '5px 0'
 
  }
  return option
}
 
// 时间处理函数  年月
export function handleDatetime4(value) {
  const data = new Date(value)
  const month = data.getMonth() < 9 ? '0' + (data.getMonth() + 1) : data.getMonth() + 1
  return data.getFullYear() + '-' + month
}
 
// 时间处理函数  年月日
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 function handleDatetime2(value) {
  const dt = new Date(value)
  const wk = dt.getDay()
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
 
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  const weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  const week = weeks[wk]
 
  // return `${y}-${m}-${d}  ${hh}:${mm}:${ss}   ${week}`
  return `${y}-${m}-${d}  ${hh}:${mm}:${ss}`
}
 
// 时间处理函数   返回 时分
export function handleDatetime3(value) {
  const dt = new Date(value)
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  return `${hh}:${mm}`
}
 
// 递归清除数组每个元素下的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
 
// 正则表达式  编码不能含有中文或特殊字符
const SER_HZ = /^[a-zA-Z0-9_\-;,.<>() ]{0,}$/
export const validateCode = (rule, value, callback) => {
  if (!value) {
    return callback(new Error('请输入编码'))
  } else {
    if (!SER_HZ.test(value)) {
      return callback(new Error('编码不能含有中文或特殊字符'))
    } else {
      callback()
    }
  }
}
 
// 获取token 用于请求畅捷通接口
export async function getTPlusToken() {
  const r1 = await AppTicketSelect()
  const r2 = r1.data[0]
  Vue.prototype.$AppKey = r2.appKey
  Vue.prototype.$AppSecret = r2.appSecret
  const data = {
    appTicket: r2.AppTicket,
    certificate: r2.certificate
  }
  const r3 = await axios.post(Vue.prototype.$chanjetBaseUrl + '/v1/common/auth/selfBuiltApp/generateToken',
    data, {
      headers: {
        'appKey': Vue.prototype.$AppKey,
        'appSecret': Vue.prototype.$AppSecret,
        'Content-Type': 'application/json'
      }
    })
  return r3.data.value.accessToken
}