You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tanghe-report/report-ui/src/mixins/common.js

130 lines
2.9 KiB
JavaScript

3 years ago
export default {
3 years ago
data () {
3 years ago
return {
}
},
computed: {
},
3 years ago
created () {
3 years ago
},
3 years ago
mounted () {
3 years ago
},
3 years ago
destroyed () {
3 years ago
},
methods: {
3 years ago
goBack () {
3 years ago
this.$router.go(-1)
},
3 years ago
refresh () {
3 years ago
this.$router.go(0)
},
3 years ago
parseString (object) {
3 years ago
if (typeof object === 'undefined' || object == null) {
return ''
}
if (typeof object === 'number') {
return object.toString()
}
if (typeof object === 'boolean') {
return object.toString()
}
if (typeof object === 'object') {
return JSON.stringify(object)
}
return ''
},
3 years ago
isBlank (val) {
3 years ago
if (typeof val === 'undefined') {
return true
}
if (val == null || val === '') {
return true
}
return false
},
3 years ago
// 封装定制删除数组中的值
contains (a, obj) {
var i = a.length
while (i--) {
if (a[i] === obj) {
return i
}
}
return false
},
//获取url后边参数
getUrlKey: function (name) {
return (
decodeURIComponent(
(new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(
/\+/g,
'%20'
)
) || null
)
3 years ago
},
/**
*
*/
3 years ago
resetForm (data) {
3 years ago
let formKeys = Object.keys(data)
for (let k of formKeys) {
data[k] = null
}
},
3 years ago
sortArray (propertyName) {
return function (object1, object2) {
3 years ago
var value1 = object1[propertyName];
var value2 = object2[propertyName];
3 years ago
if (value1 < value2) {
3 years ago
return -1;
3 years ago
} else if (value1 > value2) {
3 years ago
return 1;
3 years ago
} else {
3 years ago
return 0;
}
}
3 years ago
},
objToOne (obj) {
var tmpData = {}
for (var index in obj) {
if (typeof obj[index] == 'object') {
var resObj = this.objToOne(obj[index])
Object.assign(tmpData, resObj) // 这里使用对象合并
} else {
tmpData[index] = obj[index]
}
}
return tmpData
},
isNotNull (val) {
return !this.isNull(val)
},
isNull (val) {
// 特殊判断
if (val && parseInt(val) === 0) return false
const list = ['$parent']
if (val instanceof Date || typeof val === 'boolean' || typeof val === 'number') return false
if (val instanceof Array) {
if (val.length === 0) return true
} else if (val instanceof Object) {
val = this.deepClone(val)
list.forEach((ele) => {
delete val[ele]
})
for (var o in val) {
return false
}
return true
} else {
if (val === 'null' || val == null || val === 'undefined' || val === undefined || val === '') {
return true
}
return false
}
return false
},
3 years ago
}
}