前端显示动态时间(定时器)

/*
 * @Author: yangzihua
 * @Date: 2022-10-25 09:20:43
 * @LastEditors: yangzihua
 * @LastEditTime: 2022-11-02 10:53:15
 * @Description:工作日历
 */
import React, { PureComponent } from 'react';
import { Form } from '@ant-design/compatible';
import { Calendar, Input } from 'antd';
import { connect } from 'dva';
import {
  AppstoreOutlined,
  CalendarOutlined,
  PlusCircleOutlined,
} from '@ant-design/icons';
import LForm from '@/components/ModalButton/LForm';
import styles from '../WorkHome.less';

const { TextArea } = Input;
@connect()
@Form.create({})
export default class WorkCalendar extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      localYear: '', // 年份
      localDate: '', // 月日
      localDay: '', // 星期
      localTime: '', // 时间
    };
  }

  componentDidMount() {
    this.timer = setInterval(() => {
      this.refreshQuery();
    }, 1000);
  }

  componentWillUnmount() {
    clearInterval(this.timer);
  }

  refreshQuery = () => {
    let time = new Date();
    this.setState({
      localYear: time.getFullYear(),
    });
    switch (time.getDay()) {
      case 0:
        this.setState({
          localDay: '星期日',
        });
        break;
      case 1:
        this.setState({
          localDay: '星期一',
        });
        break;
      case 2:
        this.setState({
          localDay: '星期二',
        });
        break;
      case 3:
        this.setState({
          localDay: '星期三',
        });
        break;
      case 4:
        this.setState({
          localDay: '星期四',
        });
        break;
      case 5:
        this.setState({
          localDay: '星期五',
        });
        break;
      case 6:
        this.setState({
          localDay: '星期六',
        });
        break;
      default:
        break;
    }
    this.setState({
      localTime: time.toLocaleTimeString(),
    });

    this.setState({
      localDate: `${time.getMonth() + 1}月${time.getDate()}日`,
    });

    time = null;
  };

  // 获取系统时间
  getLocalTime = () => {
    setInterval(this.refreshQuery, 0);
  };

  handleOpen = () => {
    this.props.dispatch({
      type: 'dialog/open',
      payload: '添加日程',
    });
  };

  render() {
    const { form } = this.props;
    return (
      <>
        <LForm
          form={form}
          type="modal"
          disableLayout
          maskClosable={false}
          width={500}
          title="添加日程"
          operation
          // footer={this.searchFooter()}
          // onCancel="advancedSearch/resetSearchList"
        >
          <TextArea
            rows={4}
            placeholder="请输入日程"
            allowClear
            style={{ width: '100%' }}
          />
        </LForm>
        <div className={styles.divCalendar}>
          <div className={styles.divTitle}>
            <AppstoreOutlined className={styles.iconTitle} />
            <div className={styles.textTitle}>我的工作日历</div>
          </div>
          <div className={styles.divCalendarArea}>
            <div className={styles.divCalendarContext}>
              <Calendar fullscreen={false} />
            </div>
            <div className={styles.divScheduleInfo}>
              <div className={styles.divScheduleIconAndDate}>
                <div className={styles.divCalendarTime}>
                  {/* {`${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`} */}
                  {this.state.localTime}
                </div>
                <CalendarOutlined className={styles.iconCalendar} />
              </div>

              <div className={styles.divCalendarTimeTwo}>
                {`${this.state.localDate}  ${this.state.localDay}`}
              </div>
              <div className={styles.divCalendarTimeTwo}>
                {`${this.state.localYear}年`}
              </div>
              <div className={styles.divDivider} />
              <div className={styles.textSchedule}>
                添加日程 <PlusCircleOutlined onClick={this.handleOpen} />
              </div>
            </div>
          </div>
        </div>
      </>
    );
  }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值