utils.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. export function defaultFormat(value, options) {
  2. if (options) {
  3. return options.map(function (v) { return v.label; }).join('');
  4. }
  5. return '';
  6. }
  7. export function getterColumns(value, options) {
  8. if (options === void 0) { options = []; }
  9. var getColumns = function (options, value, columns) {
  10. var _a;
  11. if (columns === void 0) { columns = []; }
  12. columns.push(options.map(function (v) { return ({ value: v.value, label: v.label }); }));
  13. var currentOption = options.find(function (v) { return v.value === (value === null || value === void 0 ? void 0 : value[columns.length - 1]); }) ||
  14. options[0];
  15. if (((_a = currentOption === null || currentOption === void 0 ? void 0 : currentOption.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
  16. return getColumns(currentOption.children, value, columns);
  17. }
  18. return columns;
  19. };
  20. return getColumns(options, value);
  21. }
  22. export function getValidValue(value, columns) {
  23. var result = [];
  24. var _loop_1 = function (i) {
  25. if (!columns[i].some(function (v) { return v.value === (value === null || value === void 0 ? void 0 : value[i]); })) {
  26. result.push.apply(result, columns.slice(i).map(function (v) { var _a; return (_a = v[0]) === null || _a === void 0 ? void 0 : _a.value; }));
  27. return "break";
  28. }
  29. else {
  30. result[i] = value[i];
  31. }
  32. };
  33. for (var i = 0; i < columns.length; i++) {
  34. var state_1 = _loop_1(i);
  35. if (state_1 === "break")
  36. break;
  37. }
  38. return result;
  39. }