123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- // 序号生成方式
- export const snGenerationMethodList = [
- { value: 'recalculate', label: '重新计算' },
- { value: 'follow', label: '跟随上题' },
- ];
- // 查看方式
- export const viewMethodList = [
- { value: 'independent', label: '独立排放' },
- { value: 'list', label: '播放列表' },
- ];
- // 序号类型
- export const serialNumberTypeList = [
- { value: 'number', label: '数字' },
- { value: 'bracket_number', label: '括号数字' },
- { value: 'letter', label: '字母' },
- { value: 'capital', label: '大写字母' },
- ];
- // 序号位置
- export const serialNumberPositionList = [
- { value: 'top-start', justifyContent: 'flex-start' },
- { value: 'top', justifyContent: 'center' },
- { value: 'top-end', justifyContent: 'flex-end' },
- { value: 'left-start', justifyContent: 'flex-start' },
- { value: 'left', justifyContent: 'center' },
- { value: 'left-end', justifyContent: 'flex-end' },
- { value: 'right-start', justifyContent: 'flex-start' },
- { value: 'right', justifyContent: 'center' },
- { value: 'right-end', justifyContent: 'flex-end' },
- { value: 'bottom-start', justifyContent: 'flex-start' },
- { value: 'bottom', justifyContent: 'center' },
- { value: 'bottom-end', justifyContent: 'flex-end' },
- ];
- // 拼音位置
- export const pinyinPositionList = [
- { value: 'top', label: '上' },
- { value: 'bottom', label: '下' },
- ];
- // 排列方式
- export const arrangeTypeList = [
- { value: 'horizontal', label: '横排' },
- { value: 'vertical', label: '竖排' },
- ];
- /**
- * 判断序号类型
- * @param {string} str
- */
- export function checkString(str) {
- const number = /\d/.test(str); // 判断是否包含数字
- const letter = /[a-z]/.test(str); // 判断是否包含字母
- const capital = /[A-Z]/.test(str); // 判断是否包含大写字母
- const bracket_number = /\(\d+\)/.test(str); // 判断是否包含括号数字,例如 (123)
- const obj = { number, letter, capital, bracket_number };
- let strType = Object.keys(obj).find((key) => obj[key]);
- return strType;
- }
- // 计算选项方法
- export const computeOptionMethods = {
- [serialNumberTypeList[0].value]: (i) => `${i + 1}`,
- [serialNumberTypeList[1].value]: (i) => `(${i + 1})`,
- [serialNumberTypeList[2].value]: (i) => `${String.fromCharCode(97 + i)}`, // 小写
- [serialNumberTypeList[3].value]: (i) => `${String.fromCharCode(65 + i)}`, // 大写
- };
- // 反向计算选项方法
- export const reversedComputeOptionMethods = {
- [serialNumberTypeList[0].value]: (i) => Number(i),
- [serialNumberTypeList[1].value]: (i) => Number(i.replace('(', '').replace(')', '')),
- [serialNumberTypeList[2].value]: (i) => i.charCodeAt(0) - 97 + 1, // 小写
- [serialNumberTypeList[3].value]: (i) => i.charCodeAt(0) - 65 + 1,
- };
- /**
- * 改变选项序号
- * @param {object} property 选项属性
- */
- export function switchSerialNumber(property) {
- let relNum = 1;
- const reversedComputationMethod = reversedComputeOptionMethods[property.sn_type];
- if (reversedComputationMethod) {
- relNum = reversedComputationMethod(property.serial_number);
- }
- let index = serialNumberTypeList.findIndex((p) => p.value === property.sn_type);
- property.sn_type = serialNumberTypeList[index + 1]?.value || serialNumberTypeList[0].value;
- const computationMethod = computeOptionMethods[property.sn_type];
- if (computationMethod) {
- property.serial_number = computationMethod(relNum - 1);
- }
- }
- /**
- * 计算选项序号
- * @param {Number} i 序号
- * @param {String} sn_type 选项类型
- * @returns String 题号
- */
- export function computedSerialNumber(i, sn_type) {
- const computationMethod = computeOptionMethods[sn_type];
- if (computationMethod) {
- return computationMethod(i);
- }
- return '';
- }
|