Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function name2value(name: any[], list: any[]): any {
let rs = map(name, (one, index) => {
let parent: any = ''
if (index === 2) {
// 可能存在区名一样的情况,比如南山区
parent = find(list, item => {
return item.name === name[1]
}) || { value: '__' }
if (specialMap[name[0]]) {
parent = {
value: specialMap[name[0]]
}
}
return find(list, item => {
return item.name === one && item.parent === parent.value
})
} else {
function stringifyParams (obj) {
return obj ? arrayMap(objectKeys(obj).sort(), function (key) {
var val = obj[key]
if (angular.isArray(val)) {
return arrayMap(val.sort(), function (val2) {
return encodeURIComponent(key) + '=' + encodeURIComponent(val2)
}).join('&')
}
return encodeURIComponent(key) + '=' + encodeURIComponent(val)
}).join('&') : ''
}
export function value2name (value: any, list: any, delimiter?: any): any {
if (value && !list.length) {
return ''
}
if (!delimiter) {
delimiter = ' '
}
let rs = map(value, (one, index) => {
if (list.length && Object.prototype.toString.call(list[0]) === '[object Array]') {
return find(list[index], item => {
return item.value === one
})
} else {
return find(list, item => {
return item.value === one
})
}
})
rs = rs.filter(one => {
return typeof one !== 'undefined'
})
return map(rs, one => {
return one.name
}).join(delimiter).replace('--', '')
return find(list, item => {
return item.name === one && item.parent === parent.value
})
} else {
if (index === 1 && specialMap[name[0]]) {
return {
value: specialMap[name[0]]
}
}
return find(list, item => {
return item.name === one
})
}
})
return map(rs, one => {
return one ? one.value : '__'
}).join(' ')
}
return obj ? arrayMap(objectKeys(obj).sort(), function (key) {
var val = obj[key]
if (angular.isArray(val)) {
return arrayMap(val.sort(), function (val2) {
return encodeURIComponent(key) + '=' + encodeURIComponent(val2)
}).join('&')
}
return encodeURIComponent(key) + '=' + encodeURIComponent(val)
}).join('&') : ''
}
return find(list, item => {
return item.name === one && item.parent === parent.value
})
} else {
if (index === 1 && specialMap[name[0]]) {
return {
value: specialMap[name[0]]
}
}
return find(list, item => {
return item.name === one
})
}
})
return map(rs, one => {
return one ? one.value : '__'
}).join(' ')
}
export function value2name (value: any, list?: any[], delimiter?: string): any {
if (value && !list.length) {
return ''
}
if (!delimiter) {
delimiter = ' '
}
let rs = map(value, (one, index) => {
if (list.length && Object.prototype.toString.call(list[0]) === '[object Array]') {
return find(list[index], item => {
return item.value === one
})
} else {
return find(list, item => {
return item.value === one
})
}
})
rs = rs.filter(one => {
return typeof one !== 'undefined'
})
return map(rs, one => {
return one.name
}).join(delimiter).replace('--', '')
let rs = map(value, (one, index) => {
if (list.length && Object.prototype.toString.call(list[0]) === '[object Array]') {
return find(list[index], item => {
return item.value === one
})
} else {
return find(list, item => {
return item.value === one
})
}
})
rs = rs.filter(one => {
return typeof one !== 'undefined'
})
return map(rs, one => {
return one.name
}).join(delimiter).replace('--', '')
}
let rs = map(value, (one, index) => {
if (list.length && Object.prototype.toString.call(list[0]) === '[object Array]') {
return find(list[index], item => {
return item.value === one
})
} else {
return find(list, item => {
return item.value === one
})
}
})
rs = rs.filter(one => {
return typeof one !== 'undefined'
})
return map(rs, one => {
return one.name
}).join(delimiter).replace('--', '')
}