updated 代码优化
This commit is contained in:
parent
230b0a8d23
commit
970094a88f
4
dist/lang/relationship.zh-HK.min.js
vendored
4
dist/lang/relationship.zh-HK.min.js
vendored
File diff suppressed because one or more lines are too long
4
dist/lang/relationship.zh-HK.min.mjs
vendored
4
dist/lang/relationship.zh-HK.min.mjs
vendored
File diff suppressed because one or more lines are too long
4
dist/relationship.min.js
vendored
4
dist/relationship.min.js
vendored
File diff suppressed because one or more lines are too long
4
dist/relationship.min.mjs
vendored
4
dist/relationship.min.mjs
vendored
File diff suppressed because one or more lines are too long
@ -9,6 +9,10 @@ import {modeData} from './mode.js';
|
|||||||
|
|
||||||
// 逆转ID
|
// 逆转ID
|
||||||
export function reverseId(id,sex){
|
export function reverseId(id,sex){
|
||||||
|
if(!id){
|
||||||
|
return [''];
|
||||||
|
}
|
||||||
|
// 映射关系
|
||||||
let hash = {
|
let hash = {
|
||||||
f:['d','s'],
|
f:['d','s'],
|
||||||
m:['d','s'],
|
m:['d','s'],
|
||||||
@ -23,42 +27,35 @@ export function reverseId(id,sex){
|
|||||||
os:['ls','lb'],
|
os:['ls','lb'],
|
||||||
xs:['xs','xb']
|
xs:['xs','xb']
|
||||||
};
|
};
|
||||||
|
// 年纪判断
|
||||||
let age = '';
|
let age = '';
|
||||||
if(id.match(/&o$/)){
|
if(id.match(/&o$/)){
|
||||||
age = '&l';
|
age = '&l';
|
||||||
}else if(id.match(/&l$/)){
|
}else if(id.match(/&l$/)){
|
||||||
age = '&o';
|
age = '&o';
|
||||||
}
|
}
|
||||||
if(id){
|
id = id.replace(/&[ol\d+]/g,'');
|
||||||
id = id.replace(/&[ol\d+]/g,'');
|
// 性别判断
|
||||||
//性别判断
|
if(sex<0){
|
||||||
if(sex<0){
|
if(id.match(/^w/)){
|
||||||
if(id.match(/^w/)){
|
sex = 1;
|
||||||
sex = 1;
|
}else if(id.match(/^h/)){
|
||||||
}else if(id.match(/^h/)){
|
sex = 0;
|
||||||
sex = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let result = [];
|
|
||||||
let doing = function(sex){
|
|
||||||
let sid = (','+sex+','+id).replace(/,[fhs]|,[olx]b/g,',1').replace(/,[mwd]|,[olx]s/g,',0');
|
|
||||||
sid = sid.substring(0,sid.length-2);
|
|
||||||
let id_arr = id.split(',').reverse();
|
|
||||||
let sid_arr = sid.split(',').reverse();
|
|
||||||
let arr = id_arr.map((id,i)=>hash[id][sid_arr[i]]);
|
|
||||||
let r_id = arr.join(',');
|
|
||||||
let gen = getGenById(r_id);
|
|
||||||
return r_id +(gen?'':age);
|
|
||||||
};
|
|
||||||
if(sex<0){
|
|
||||||
result.push(doing(1));
|
|
||||||
result.push(doing(0));
|
|
||||||
}else{
|
|
||||||
result.push(doing(sex));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
return [''];
|
let doing = function(sex){
|
||||||
|
let sid = (','+sex+','+id).replace(/,[fhs]|,[olx]b/g,',1').replace(/,[mwd]|,[olx]s/g,',0');
|
||||||
|
sid = sid.substring(0,sid.length-2);
|
||||||
|
let sid_arr = sid.split(',').reverse();
|
||||||
|
let r_id = id.split(',').reverse().map((id,i)=>hash[id][sid_arr[i]]).join(',');
|
||||||
|
let gen = getGenById(r_id);
|
||||||
|
return r_id + (gen?'':age);
|
||||||
|
};
|
||||||
|
if(sex<0){
|
||||||
|
return [doing(1),doing(0)];
|
||||||
|
}else{
|
||||||
|
return [doing(sex)];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ID列表去重
|
// ID列表去重
|
||||||
@ -112,18 +109,18 @@ export function getItemsById(id){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!item){
|
if(!item){
|
||||||
item = modeData[id][0].match(/^[大小]/)?modeData[id][0].replace(/^[大小]/,zh):zh+modeData[id][0];
|
item = modeData[id][0];
|
||||||
|
item = item.match(/^[大小]/)?item.replace(/^[大小]/,zh):zh+item;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
item = modeData[id][0]
|
item = modeData[id][0]
|
||||||
}
|
}
|
||||||
items.push(item);
|
items.push(item);
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
id = id.replace(/&\d+/g,'');
|
|
||||||
}
|
}
|
||||||
// 直接匹配称呼
|
// 直接匹配称呼
|
||||||
if(!items.length){
|
if(!items.length){
|
||||||
|
id = id.replace(/&\d+/g,'');
|
||||||
items = getData(id);
|
items = getData(id);
|
||||||
}
|
}
|
||||||
// 忽略年龄条件查找
|
// 忽略年龄条件查找
|
||||||
@ -150,19 +147,19 @@ let data = Object.assign({},modeData,{
|
|||||||
'xb':['兄弟'],
|
'xb':['兄弟'],
|
||||||
'xs':['姐妹']
|
'xs':['姐妹']
|
||||||
});
|
});
|
||||||
export function getChainById(id,sex){
|
export function getChainById(id,sex=-1){
|
||||||
let item = id.split(',').map(function(sign){
|
let item = id.split(',').map(function(sign){
|
||||||
let key = sign.replace(/&[ol\d]+/,'');
|
let key = sign.replace(/&[ol\d]+/,'');
|
||||||
return data[key][0];
|
return data[key][0];
|
||||||
}).join('的');
|
}).join('的');
|
||||||
if(sex&&sex>-1&&data[sex+','+id]){
|
if(sex>-1&&data[sex+','+id]){
|
||||||
if(sex==0){
|
if(sex==0){
|
||||||
item = '(女性)'+item;
|
item = '(女性)'+item;
|
||||||
}else if(sex==1){
|
}else if(sex==1){
|
||||||
item = '(男性)'+item;
|
item = '(男性)'+item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item
|
return item;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 通过ID获取关系合称
|
// 通过ID获取关系合称
|
||||||
|
@ -9,6 +9,25 @@ import _multipie from './data/multiple.js';
|
|||||||
import {expandSelector} from './selector.js';
|
import {expandSelector} from './selector.js';
|
||||||
|
|
||||||
let _map = Object.assign({},_multipie);
|
let _map = Object.assign({},_multipie);
|
||||||
|
|
||||||
|
// 分支 - 前缀处理
|
||||||
|
let prefixMap = {};
|
||||||
|
for(let key in _prefix){
|
||||||
|
prefixMap[key] = {};
|
||||||
|
for(let selector in _prefix[key]){
|
||||||
|
expandSelector(selector).forEach(function(s){
|
||||||
|
prefixMap[key][s] = _prefix[key][selector];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 分支 - 节点处理
|
||||||
|
let branchMap = {};
|
||||||
|
for(let selector in _branch){
|
||||||
|
expandSelector(selector).forEach(function(s){
|
||||||
|
branchMap[s] = _branch[selector];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 分支 - 合并
|
||||||
let getMap = function(prefixMap,branchMap){
|
let getMap = function(prefixMap,branchMap){
|
||||||
let map = {};
|
let map = {};
|
||||||
for(let key in branchMap){
|
for(let key in branchMap){
|
||||||
@ -38,25 +57,8 @@ let getMap = function(prefixMap,branchMap){
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 分支前缀处理
|
|
||||||
let prefixMap = {};
|
|
||||||
for(let key in _prefix){
|
|
||||||
prefixMap[key] = {};
|
|
||||||
for(let selector in _prefix[key]){
|
|
||||||
expandSelector(selector).forEach(function(s){
|
|
||||||
prefixMap[key][s] = _prefix[key][selector];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 分支节点处理
|
|
||||||
let branchMap = {};
|
|
||||||
for(let selector in _branch){
|
|
||||||
expandSelector(selector).forEach(function(s){
|
|
||||||
branchMap[s] = _branch[selector];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
_map = Object.assign({},_map,getMap(prefixMap,branchMap));
|
_map = Object.assign({},_map,getMap(prefixMap,branchMap));
|
||||||
|
|
||||||
// 主要关系
|
// 主要关系
|
||||||
for(let key in _main){
|
for(let key in _main){
|
||||||
_map[key] = [].concat(_main[key],_map[key]||[]);
|
_map[key] = [].concat(_main[key],_map[key]||[]);
|
||||||
|
@ -16,8 +16,8 @@ let getOptimal = function(options){
|
|||||||
to,
|
to,
|
||||||
sex
|
sex
|
||||||
} = options;
|
} = options;
|
||||||
let from_chain = options['from'].split(',');
|
let from_chain = from.split(',');
|
||||||
let to_chain = options['to'].split(',');
|
let to_chain = to.split(',');
|
||||||
for(let i=0;i<from_chain.length&&i<to_chain.length;i++){
|
for(let i=0;i<from_chain.length&&i<to_chain.length;i++){
|
||||||
if(from_chain[i]==to_chain[i]){
|
if(from_chain[i]==to_chain[i]){
|
||||||
from = from_chain.slice(i+1).join(',');
|
from = from_chain.slice(i+1).join(',');
|
||||||
@ -31,16 +31,8 @@ let getOptimal = function(options){
|
|||||||
if(form_type!=to_type){
|
if(form_type!=to_type){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let from_match = from_chain[i].match(/&([ol\d]+)/);
|
let from_attr = from_chain[i].match(/&([ol\d]+)/)?.[1]||from_chain[i].match(/([ol])[bs]/)?.[1]||'';
|
||||||
let to_match = to_chain[i].match(/&([ol\d]+)/);
|
let to_attr = to_chain[i].match(/&([ol\d]+)/)?.[1]||to_chain[i].match(/([ol])[bs]/)?.[1]||'';
|
||||||
if(!from_match){
|
|
||||||
from_match = from_chain[i].match(/([ol])[bs]/);
|
|
||||||
}
|
|
||||||
if(!to_match){
|
|
||||||
to_match = to_chain[i].match(/([ol])[bs]/);
|
|
||||||
}
|
|
||||||
let from_attr = from_match?from_match[1]:'';
|
|
||||||
let to_attr = to_match?to_match[1]:'';
|
|
||||||
if(from_attr&&to_attr){
|
if(from_attr&&to_attr){
|
||||||
if(!isNaN(from_attr)&&!isNaN(to_attr)){
|
if(!isNaN(from_attr)&&!isNaN(to_attr)){
|
||||||
if(+from_attr>+to_attr){
|
if(+from_attr>+to_attr){
|
||||||
@ -57,10 +49,8 @@ let getOptimal = function(options){
|
|||||||
to = to_chain.slice(i+1).join(',');
|
to = to_chain.slice(i+1).join(',');
|
||||||
sex = to_chain[i].match(/^([fhs1](&[ol\d]+)?|[olx]b)(&[ol\d]+)?/)?1:0;
|
sex = to_chain[i].match(/^([fhs1](&[ol\d]+)?|[olx]b)(&[ol\d]+)?/)?1:0;
|
||||||
}else if(options['optimal']){
|
}else if(options['optimal']){
|
||||||
from_match = from_chain[i].match(/([xol])[bs]/);
|
from_attr = from_chain[i].match(/([xol])[bs]/)?.[1]||'';
|
||||||
to_match = to_chain[i].match(/([xol])[bs]/);
|
to_attr = to_chain[i].match(/([xol])[bs]/)?.[1]||'';
|
||||||
from_attr = from_match?from_match[1]:'';
|
|
||||||
to_attr = to_match?to_match[1]:'';
|
|
||||||
if(from_attr=='x'||to_attr=='x'){
|
if(from_attr=='x'||to_attr=='x'){
|
||||||
from = from_chain.slice(i+1).join(',');
|
from = from_chain.slice(i+1).join(',');
|
||||||
to = to_chain.slice(i+1).join(',');
|
to = to_chain.slice(i+1).join(',');
|
||||||
@ -73,9 +63,9 @@ let getOptimal = function(options){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
'from':from,
|
from,
|
||||||
'to':to,
|
to,
|
||||||
'sex':sex
|
sex
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user