index.js
3.39 KB
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
function debounce(func, wait = 200) {
let timeout
return function(event) {
clearTimeout(timeout)
timeout = setTimeout(() => {
func.call(this, event)
}, wait)
}
}
function dateFormat(dateTime, format = 'YYYY-MM-DD HH:mm') {
const date = new Date(dateTime)
const config = {
YYYY: date.getFullYear(),
MM: date.getMonth() + 1, //getMonth() 方法根据本地时间返回指定日期的月份(从 0 到 11)
DD: date.getDate(),
HH: date.getHours(),
mm: date.getMinutes(),
ss: date.getSeconds()
}
for (const key in config) {
format = format.replace(key, config[key])
}
return format
}
/**
* 校验手机号码格式
*/
function checkPhone(mobile) {
const myreg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/
return myreg.test(mobile)
}
/**
* 用于glsx-combi-form的select写入options
* formName String FormData的属性名
* hasAll Boolean 是否需要添加“全部”属性
* refreshSigle String 更新特定的属性的options
*/
function getOptionsList(that, formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
var item = that[formName].find(k => k.name == refreshSigle)
var index = that[formName].findIndex(k => k.name == refreshSigle)
that.$set(that[formName][index], 'optionList', that.$common.utils.deepClone(that.baseData[item.optionsName]))
if (hasAll && that.baseData[item.optionsName].length && that.baseData[item.optionsName][0][that[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[that[formName][index].optionId] = ''
temp[that[formName][index].optionLabel] = '全部'
that[formName][index].optionList.unshift(temp)
}
} else {
that[formName].forEach((item, index) => {
if (item.type === 'select' && that.baseData[item.optionsName]?.length) {
that.$set(that[formName][index], 'optionList', that.$common.utils.deepClone(that.baseData[item.optionsName]))
if (hasAll && that.baseData[item.optionsName].length && that.baseData[item.optionsName][0][that[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[that[formName][index].optionId] = ''
temp[that[formName][index].optionLabel] = '全部'
that[formName][index].optionList.unshift(temp)
}
}
})
}
}
/** 二次确认封装 */
function secondConfirm(that, title, txt, apiModule, apiName, apiParams, type = 'warning', fn) {
that.$confirm(txt, title, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type,
callback: action => {
if (action == 'confirm') {
that.$apis[apiModule][apiName](apiParams).then(res => {
that.$message({
message: res.code == '0' ? '操作成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
if (res.code == '0') {
fn && fn()
that.handleSearch()
}
})
}
}
})
}
function aToExport(url) {
var a = document.createElement('a')
a.setAttribute('id', 'exportToExport')
a.setAttribute('href', url)
a.setAttribute('target', '_blank')
document.body.appendChild(a)
a.click()
}
function getArrayIsSubset (arr2, arr1) {
if(arr2.length ==0) return false
return arr2.every(item => {
return arr1.includes(item)
})
}
export default {
debounce,
dateFormat,
checkPhone,
getOptionsList,
secondConfirm,
aToExport,
getArrayIsSubset
}