mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
commit
694e048146
@ -22,11 +22,11 @@ Object.keys(_ENUMS).forEach(key => {
|
|||||||
function get(name, key, opt = { dir: 'value', extend: []}) {
|
function get(name, key, opt = { dir: 'value', extend: []}) {
|
||||||
if (Object.prototype.toString.call(key) === '[object Object]') {
|
if (Object.prototype.toString.call(key) === '[object Object]') {
|
||||||
opt = key
|
opt = key
|
||||||
key = ''
|
key = null
|
||||||
}
|
}
|
||||||
let list = ENUMS[name] || []
|
let list = ENUMS[name] || []
|
||||||
let value
|
let value
|
||||||
if (key) {
|
if (key !== undefined && key !== null) {
|
||||||
let res = list.filter(item => item.key === key)[0]
|
let res = list.filter(item => item.key === key)[0]
|
||||||
if (!res) return key
|
if (!res) return key
|
||||||
value = parseValueDir(res.value, opt.dir) || key
|
value = parseValueDir(res.value, opt.dir) || key
|
||||||
@ -81,7 +81,7 @@ function concat(name, _enum, opt = { keyName: '', valueName: '', before: false,
|
|||||||
} else {
|
} else {
|
||||||
list = list.concat(partList)
|
list = list.concat(partList)
|
||||||
}
|
}
|
||||||
return readonly(format(list, extend))
|
return readonly(format(list, opt.extend))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +111,7 @@ function format(_enum = [], extend = []) {
|
|||||||
* @param dir
|
* @param dir
|
||||||
*/
|
*/
|
||||||
function parseValueDir(value, dir='value') {
|
function parseValueDir(value, dir='value') {
|
||||||
if (!['object', 'function'].includes(typeof value) || !value || !dir) return value
|
if (!['object', 'function'].includes(typeof value) || !value || !dir || dir === 'value') return value
|
||||||
if (dir.startsWith('[')) {
|
if (dir.startsWith('[')) {
|
||||||
let key = dir.slice(1, dir.indexOf(']'))
|
let key = dir.slice(1, dir.indexOf(']'))
|
||||||
return parseValueDir(value[key], dir.slice(dir.indexOf(']') + 1))
|
return parseValueDir(value[key], dir.slice(dir.indexOf(']') + 1))
|
||||||
|
@ -62,8 +62,11 @@ export default {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
console.log(roles);
|
console.log('enums roles=>', roles);
|
||||||
console.log(enums.get('status', {
|
console.log('enums roles[1]=>', enums.get('roles', '1'));
|
||||||
|
console.log('enums status[0]=> ', enums.get('status', 0));
|
||||||
|
console.log('enums status concat', enums.concat('status', [['3', '普通的']], { extend: [{ key: 'name', dir: 'value' }] }));
|
||||||
|
console.log('enums status get extend=>', enums.get('status', {
|
||||||
extend: [
|
extend: [
|
||||||
{
|
{
|
||||||
key: 'name',
|
key: 'name',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user