const.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import moment from 'moment';
  2. /**
  3. * @param value string[]
  4. * @param onChange (data: string[]) => void
  5. */
  6. export interface Props {
  7. value?: string[],
  8. onChange?: (data: string[]) => void
  9. }
  10. const [_, ...rest] = moment.weekdays();
  11. export const WEEK_SERIRES = [...rest, _].map((item, index) => ({
  12. name: item,
  13. key: index,
  14. value: index + 1,
  15. }));
  16. export const HOUR_LIST = Array.from({ length: 24 }, (v, i) => i);
  17. // export const TIME_PICKER = Array(24)
  18. // .fill(0)
  19. // .map((k, v) => `${v}:30`);
  20. const totalHour = 48;
  21. export const initTimerPicker = function (value: any[] = []) {
  22. const result: any[] = [];
  23. let index = 0;
  24. WEEK_SERIRES.forEach((week, rowNum) => {
  25. const weekList = [];
  26. let hourSpan = 0;
  27. while (hourSpan < totalHour) {
  28. const hour = Math.floor(hourSpan / 2);
  29. const curHour = ('00' + hour).slice(-2);
  30. const nextHour = ('00' + (hour + 1)).slice(-2);
  31. const timer = index % 2 === 0 ? `${curHour}:00-${curHour}:30` : `${curHour}:30-${nextHour}:00`;
  32. const selected = value[index] === '1';
  33. const timerBox = {
  34. key: `${week.value}_${timer}`,
  35. name: `${week.name} ${timer}`,
  36. value: index,
  37. rowNum: rowNum + 1,
  38. colNum: (index % totalHour) + 1,
  39. selected,
  40. };
  41. weekList.push(timerBox);
  42. if (!selected) {
  43. value[index] = '0';
  44. }
  45. index++;
  46. hourSpan++;
  47. }
  48. result.push(weekList);
  49. });
  50. value.length = 7 * 24 * 2;
  51. return result;
  52. };
  53. export function formatData(data: any, timeBox: any) {
  54. data[timeBox.value] = timeBox.selected ? '1' : '0';
  55. return data;
  56. }
  57. export function getInitalFormatList() {
  58. return new Array(7 * 24 * 2).fill('0');
  59. }