代码整理

qianlishi 2 years ago
parent ee83bad2e9
commit 4117fce4df

@ -1,40 +1,40 @@
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import { getStorageItem } from '@/utils/storage' import { getStorageItem } from '@/utils/storage'
export default { export default {
data () { data() {
return { return {
} }
}, },
computed: { computed: {
// 网页高度 // 网页高度
bodyWidth () { bodyWidth() {
return document.body.clientWidth return document.body.clientWidth
}, },
// 网页宽度 // 网页宽度
bodyHeight () { bodyHeight() {
return document.body.clientHeight return document.body.clientHeight
}, },
}, },
created () { created() {
}, },
mounted () { mounted() {
}, },
destroyed () { destroyed() {
}, },
methods: { methods: {
setCookies (key, val, option) { setCookies(key, val, option) {
if (option == null) { if (option == null) {
option = { expires: 15 } option = { expires: 15 }
} }
Cookies.set(key, val, option) Cookies.set(key, val, option)
}, },
goBack () { goBack() {
this.$router.go(-1) this.$router.go(-1)
}, },
refresh () { refresh() {
this.$router.go(0) this.$router.go(0)
}, },
parseString (object) { parseString(object) {
if (typeof object === 'undefined' || object == null) { if (typeof object === 'undefined' || object == null) {
return '' return ''
} }
@ -49,7 +49,7 @@ export default {
} }
return '' return ''
}, },
isBlank (val) { isBlank(val) {
if (typeof val === 'undefined') { if (typeof val === 'undefined') {
return true return true
} }
@ -59,7 +59,7 @@ export default {
return false return false
}, },
// 封装定制删除数组中的值 // 封装定制删除数组中的值
contains (a, obj) { contains(a, obj) {
let i = a.length let i = a.length
while (i--) { while (i--) {
if (a[i] === obj) { if (a[i] === obj) {
@ -82,13 +82,13 @@ export default {
/** /**
* *
*/ */
resetForm (data) { resetForm(data) {
let formKeys = Object.keys(data) let formKeys = Object.keys(data)
for (let k of formKeys) { for (let k of formKeys) {
data[k] = null data[k] = null
} }
}, },
sortArray (propertyName) { sortArray(propertyName) {
return function (object1, object2) { return function (object1, object2) {
let value1 = object1[propertyName]; let value1 = object1[propertyName];
let value2 = object2[propertyName]; let value2 = object2[propertyName];
@ -103,7 +103,7 @@ export default {
} }
}, },
// 获取对象类型 // 获取对象类型
getObjectType (obj) { getObjectType(obj) {
let toString = Object.prototype.toString let toString = Object.prototype.toString
let map = { let map = {
'[object Boolean]': 'boolean', '[object Boolean]': 'boolean',
@ -122,23 +122,22 @@ export default {
} }
return map[toString.call(obj)] return map[toString.call(obj)]
}, },
isNumber (obj) { isNumber(obj) {
return this.getObjectType(obj) == 'number' return this.getObjectType(obj) == 'number'
}, },
isString (obj) { isString(obj) {
return this.getObjectType(obj) == 'string' return this.getObjectType(obj) == 'string'
}, },
isArray (obj) { isArray(obj) {
return this.getObjectType(obj) == 'array' return this.getObjectType(obj) == 'array'
}, },
hasOwn (obj, key) { hasOwn(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key) return Object.prototype.hasOwnProperty.call(obj, key)
}, },
isNotBlank(val) {
isNotBlank (val) {
return !this.isBlank(val) return !this.isBlank(val)
}, },
isBlank (val) { isBlank(val) {
if (this.isNull(val)) { if (this.isNull(val)) {
return true return true
} }
@ -153,10 +152,10 @@ export default {
} }
return false return false
}, },
isNotNull (val) { isNotNull(val) {
return !this.isNull(val) return !this.isNull(val)
}, },
isNull (val) { isNull(val) {
// 特殊判断 // 特殊判断
if (val && parseInt(val) === 0) return false if (val && parseInt(val) === 0) return false
const list = ['$parent'] const list = ['$parent']
@ -182,7 +181,7 @@ export default {
}, },
// 对象深拷贝 // 对象深拷贝
deepClone (data) { deepClone(data) {
let type = this.getObjectType(data) let type = this.getObjectType(data)
let obj let obj
if (type === 'array') { if (type === 'array') {
@ -218,7 +217,7 @@ export default {
}, },
// 合并json // 合并json
mergeObject () { mergeObject() {
let target = arguments[0] || {} let target = arguments[0] || {}
let deep = false let deep = false
let arr = Array.prototype.slice.call(arguments) let arr = Array.prototype.slice.call(arguments)
@ -261,7 +260,7 @@ export default {
}, },
// 获取dom在屏幕中的top和left // 获取dom在屏幕中的top和left
getDomTopLeftById (id) { getDomTopLeftById(id) {
let dom = document.getElementById(id) let dom = document.getElementById(id)
let top = 0 let top = 0
let left = 0 let left = 0
@ -271,7 +270,7 @@ export default {
} }
return { top: top, left: left } return { top: top, left: left }
}, },
objToOne (obj) { objToOne(obj) {
console.log(obj) console.log(obj)
let tmpData = {} let tmpData = {}
for (let index in obj) { for (let index in obj) {
@ -291,13 +290,16 @@ export default {
return Object.prototype.toString.call(value) === "[object Array]"; return Object.prototype.toString.call(value) === "[object Array]";
} }
}, },
urlEncode (val) { isObjectFn(value) {
return Object.prototype.toString.call(value) === "[object Array]";
},
urlEncode(val) {
return encodeURIComponent(val) return encodeURIComponent(val)
}, },
urlDecode (val) { urlDecode(val) {
return decodeURIComponent(val) return decodeURIComponent(val)
}, },
urlEncodeObject (obj, ingoreFields) { urlEncodeObject(obj, ingoreFields) {
if (toString.call(obj) != '[object Object]') { if (toString.call(obj) != '[object Object]') {
return obj return obj
} }
@ -316,7 +318,7 @@ export default {
}, },
// 根据数据字典查询指定字典dict指定值code的返回整个dictItem{id, text, extend} // 根据数据字典查询指定字典dict指定值code的返回整个dictItem{id, text, extend}
getDictItemByCode (dict, code) { getDictItemByCode(dict, code) {
let dicts = getStorageItem('AJReportDict') let dicts = getStorageItem('AJReportDict')
if (!dicts.hasOwnProperty(dict)) { if (!dicts.hasOwnProperty(dict)) {
return null return null
@ -334,7 +336,7 @@ export default {
return null return null
}, },
// 根据数据字典查询指定字典dict指定值code的dictItem.text // 根据数据字典查询指定字典dict指定值code的dictItem.text
getDictLabelByCode (dict, code) { getDictLabelByCode(dict, code) {
let dictItem = this.getDictItemByCode(dict, code) let dictItem = this.getDictItemByCode(dict, code)
if (dictItem != null) { if (dictItem != null) {
return dictItem['text'] return dictItem['text']
@ -343,7 +345,7 @@ export default {
} }
}, },
// 根据数据字典查询指定字典dict指定值code的dictItem.extend // 根据数据字典查询指定字典dict指定值code的dictItem.extend
getDictExtendByCode (dict, code) { getDictExtendByCode(dict, code) {
let dictItem = this.getDictItemByCode(dict, code) let dictItem = this.getDictItemByCode(dict, code)
if (dictItem == null) { if (dictItem == null) {
return null return null

@ -570,11 +570,11 @@ export default {
for (const key in data.setup) { for (const key in data.setup) {
for (let i = 0; i < option.setup.length; i++) { for (let i = 0; i < option.setup.length; i++) {
let item = option.setup[i]; let item = option.setup[i];
if (Object.prototype.toString.call(item) == "[object Object]") { if (this.isObjectFn(item)) {
if (key == option.setup[i].name) { if (key == option.setup[i].name) {
option.setup[i].value = data.setup[key]; option.setup[i].value = data.setup[key];
} }
} else if (Object.prototype.toString.call(item) == "[object Array]") { } else if (this.isArrayFn(item)) {
for (let j = 0; j < item.length; j++) { for (let j = 0; j < item.length; j++) {
const list = item[j].list; const list = item[j].list;
list.forEach((el) => { list.forEach((el) => {
@ -696,17 +696,16 @@ export default {
}, },
// //
handleDefaultValue(widgetJson) { handleDefaultValue(widgetJson) {
console.log(widgetJson);
for (const key in widgetJson) { for (const key in widgetJson) {
if (key == "options") { if (key == "options") {
// collapsedatapositionsetup // collapsedatapositionsetup
// setup // setup
for (let i = 0; i < widgetJson.options.setup.length; i++) { for (let i = 0; i < widgetJson.options.setup.length; i++) {
const item = widgetJson.options.setup[i]; const item = widgetJson.options.setup[i];
if (Object.prototype.toString.call(item) == "[object Object]") { if (this.isObjectFn(item)) {
widgetJson.value.setup[item.name] = item.value; widgetJson.value.setup[item.name] = item.value;
} else if ( } else if (this.isArrayFn(item)) {
Object.prototype.toString.call(item) == "[object Array]"
) {
for (let j = 0; j < item.length; j++) { for (let j = 0; j < item.length; j++) {
const list = item[j].list; const list = item[j].list;
list.forEach((el) => { list.forEach((el) => {
@ -827,15 +826,13 @@ export default {
}, },
setDefaultValue(options, val) { setDefaultValue(options, val) {
for (let i = 0; i < options.length; i++) { for (let i = 0; i < options.length; i++) {
if (Object.prototype.toString.call(options[i]) == "[object Object]") { if (this.isObjectFn(options[i])) {
for (const k in val) { for (const k in val) {
if (options[i].name == k) { if (options[i].name == k) {
options[i].value = val[k]; options[i].value = val[k];
} }
} }
} else if ( } else if (this.isArrayFn(options[i])) {
Object.prototype.toString.call(options[i]) == "[object Array]"
) {
for (let j = 0; j < options[i].length; j++) { for (let j = 0; j < options[i].length; j++) {
const list = options[i][j].list; const list = options[i][j].list;
for (let z = 0; z < list.length; z++) { for (let z = 0; z < list.length; z++) {

Loading…
Cancel
Save