helpers.wxs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var relationMap = {
  2. '1': '父',
  3. '2': '母',
  4. '3': '祖父',
  5. '4': '祖母'
  6. };
  7. var maritalStatusMap = {
  8. '0': '未知',
  9. '1': '未婚',
  10. '2': '已婚',
  11. '3': '离异/丧偶'
  12. };
  13. var ancestorLabels = ['父/母', '祖父/祖母', '曾祖父', '高祖父', '天祖父', '烈祖父'];
  14. var childOrderNums = ['', '长', '次', '三', '四', '五', '六', '七', '八', '九', '十'];
  15. function getRelationText(relation) {
  16. return relationMap['' + relation] || '';
  17. }
  18. function getSiblingType(relation) {
  19. var r = '' + relation;
  20. if (r === '11') return '兄';
  21. if (r === '12') return '姐';
  22. return '弟/妹';
  23. }
  24. function getMaritalStatusText(status) {
  25. return maritalStatusMap['' + status] || '未知';
  26. }
  27. function getAncestorLabel(depth) {
  28. var d = depth < 0 ? 0 : depth;
  29. if (d < ancestorLabels.length) return ancestorLabels[d];
  30. return '第' + (d + 1) + '代祖先';
  31. }
  32. function getChildOrderText(order) {
  33. if (!order || order < 1) return '子';
  34. if (order < childOrderNums.length) return childOrderNums[order] + '子';
  35. return order + '子';
  36. }
  37. function shortName(name, simplified) {
  38. if (simplified && simplified !== name) {
  39. return name + '\n(' + simplified + ')';
  40. }
  41. return name;
  42. }
  43. module.exports = {
  44. getRelationText: getRelationText,
  45. getSiblingType: getSiblingType,
  46. getMaritalStatusText: getMaritalStatusText,
  47. getAncestorLabel: getAncestorLabel,
  48. getChildOrderText: getChildOrderText,
  49. shortName: shortName
  50. };