| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import moment from 'moment';
- /**
- * @param value string[]
- * @param onChange (data: string[]) => void
- */
- export interface Props {
- value?: string[],
- onChange?: (data: string[]) => void
- }
- const [_, ...rest] = moment.weekdays();
- export const WEEK_SERIRES = [...rest, _].map((item, index) => ({
- name: item,
- key: index,
- value: index + 1,
- }));
- export const HOUR_LIST = Array.from({ length: 24 }, (v, i) => i);
- // export const TIME_PICKER = Array(24)
- // .fill(0)
- // .map((k, v) => `${v}:30`);
- const totalHour = 48;
- export const initTimerPicker = function (value: any[] = []) {
- const result: any[] = [];
- let index = 0;
- WEEK_SERIRES.forEach((week, rowNum) => {
- const weekList = [];
- let hourSpan = 0;
- while (hourSpan < totalHour) {
- const hour = Math.floor(hourSpan / 2);
- const curHour = ('00' + hour).slice(-2);
- const nextHour = ('00' + (hour + 1)).slice(-2);
- const timer = index % 2 === 0 ? `${curHour}:00-${curHour}:30` : `${curHour}:30-${nextHour}:00`;
- const selected = value[index] === '1';
- const timerBox = {
- key: `${week.value}_${timer}`,
- name: `${week.name} ${timer}`,
- value: index,
- rowNum: rowNum + 1,
- colNum: (index % totalHour) + 1,
- selected,
- };
- weekList.push(timerBox);
- if (!selected) {
- value[index] = '0';
- }
- index++;
- hourSpan++;
- }
- result.push(weekList);
- });
- value.length = 7 * 24 * 2;
- return result;
- };
- export function formatData(data: any, timeBox: any) {
- data[timeBox.value] = timeBox.selected ? '1' : '0';
- return data;
- }
- export function getInitalFormatList() {
- return new Array(7 * 24 * 2).fill('0');
- }
|