common.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // 序号生成方式
  2. export const snGenerationMethodList = [
  3. { value: 'recalculate', label: '重新计算' },
  4. { value: 'follow', label: '跟随上题' },
  5. ];
  6. // 查看方式
  7. export const viewMethodList = [
  8. { value: 'independent', label: '独立排放' },
  9. { value: 'list', label: '播放列表' },
  10. ];
  11. // 序号类型
  12. export const serialNumberTypeList = [
  13. { value: 'number', label: '数字' },
  14. { value: 'bracket_number', label: '括号数字' },
  15. { value: 'letter', label: '字母' },
  16. { value: 'capital', label: '大写字母' },
  17. ];
  18. // 序号位置
  19. export const serialNumberPositionList = [
  20. { value: 'top-start', justifyContent: 'flex-start' },
  21. { value: 'top', justifyContent: 'center' },
  22. { value: 'top-end', justifyContent: 'flex-end' },
  23. { value: 'left-start', justifyContent: 'flex-start' },
  24. { value: 'left', justifyContent: 'center' },
  25. { value: 'left-end', justifyContent: 'flex-end' },
  26. { value: 'right-start', justifyContent: 'flex-start' },
  27. { value: 'right', justifyContent: 'center' },
  28. { value: 'right-end', justifyContent: 'flex-end' },
  29. { value: 'bottom-start', justifyContent: 'flex-start' },
  30. { value: 'bottom', justifyContent: 'center' },
  31. { value: 'bottom-end', justifyContent: 'flex-end' },
  32. ];
  33. // 拼音位置
  34. export const pinyinPositionList = [
  35. { value: 'top', label: '上' },
  36. { value: 'bottom', label: '下' },
  37. ];
  38. // 排列方式
  39. export const arrangeTypeList = [
  40. { value: 'horizontal', label: '横排' },
  41. { value: 'vertical', label: '竖排' },
  42. ];
  43. /**
  44. * 判断序号类型
  45. * @param {string} str
  46. */
  47. export function checkString(str) {
  48. const number = /\d/.test(str); // 判断是否包含数字
  49. const letter = /[a-z]/.test(str); // 判断是否包含字母
  50. const capital = /[A-Z]/.test(str); // 判断是否包含大写字母
  51. const bracket_number = /\(\d+\)/.test(str); // 判断是否包含括号数字,例如 (123)
  52. const obj = { number, letter, capital, bracket_number };
  53. let strType = Object.keys(obj).find((key) => obj[key]);
  54. return strType;
  55. }
  56. // 计算选项方法
  57. export const computeOptionMethods = {
  58. [serialNumberTypeList[0].value]: (i) => `${i + 1}`,
  59. [serialNumberTypeList[1].value]: (i) => `(${i + 1})`,
  60. [serialNumberTypeList[2].value]: (i) => `${String.fromCharCode(97 + i)}`, // 小写
  61. [serialNumberTypeList[3].value]: (i) => `${String.fromCharCode(65 + i)}`, // 大写
  62. };
  63. // 反向计算选项方法
  64. export const reversedComputeOptionMethods = {
  65. [serialNumberTypeList[0].value]: (i) => Number(i),
  66. [serialNumberTypeList[1].value]: (i) => Number(i.replace('(', '').replace(')', '')),
  67. [serialNumberTypeList[2].value]: (i) => i.charCodeAt(0) - 97 + 1, // 小写
  68. [serialNumberTypeList[3].value]: (i) => i.charCodeAt(0) - 65 + 1,
  69. };
  70. /**
  71. * 改变选项序号
  72. * @param {object} property 选项属性
  73. */
  74. export function switchSerialNumber(property) {
  75. let relNum = 1;
  76. const reversedComputationMethod = reversedComputeOptionMethods[property.sn_type];
  77. if (reversedComputationMethod) {
  78. relNum = reversedComputationMethod(property.serial_number);
  79. }
  80. let index = serialNumberTypeList.findIndex((p) => p.value === property.sn_type);
  81. property.sn_type = serialNumberTypeList[index + 1]?.value || serialNumberTypeList[0].value;
  82. const computationMethod = computeOptionMethods[property.sn_type];
  83. if (computationMethod) {
  84. property.serial_number = computationMethod(relNum - 1);
  85. }
  86. }
  87. /**
  88. * 计算选项序号
  89. * @param {Number} i 序号
  90. * @param {String} sn_type 选项类型
  91. * @returns String 题号
  92. */
  93. export function computedSerialNumber(i, sn_type) {
  94. const computationMethod = computeOptionMethods[sn_type];
  95. if (computationMethod) {
  96. return computationMethod(i);
  97. }
  98. return '';
  99. }