当前位置: 首页 > news >正文

营销型网站建设有哪些平台深圳网络推广培训学校

营销型网站建设有哪些平台,深圳网络推广培训学校,企业年金的作用及意义,wordpress加速访问前言 最近在写的一个分布式调度系统#xff0c;后端同学需要让我传入cron表达式#xff0c;给调度接口传参。我去了学习了解了cron表达式的用法#xff0c;发现有3个通用的表达式刚好符合我们的需求#xff1a; 需求 每天 xx 的时间#xff1a; 0 11 20 * * ? 上面是…前言 最近在写的一个分布式调度系统后端同学需要让我传入cron表达式给调度接口传参。我去了学习了解了cron表达式的用法发现有3个通用的表达式刚好符合我们的需求 需求 每天 xx 的时间 0 11 20 * * ? 上面是每天20:11的cron表达式 每周的 xxx 星期 的 xxx 时间 0 14 20 * * WED,THU 上面是 每周星期三星期四20:14的cron表达式 每周的 xxx号 的 xxx时间 0 15 20 3,7 * ? 上面是 每月的37号20:15的cron表达式 这三个表达式刚好符合我们的需求并且每个符号表达的意思也很直观。那么话不多说直接开写 环境 react 我的版本“react”: “18.2.0”用的函数组件react hooks moment npm install moment semi-design组件库 npm install semi-design typescript 实现 数据 utils下创建cron.ts对组件所用到的数据进行统一的管理 export const dayOfTheWeekData [{ key: MON, label: 星期一 },{ key: TUE, label: 星期二 },{ key: WED, label: 星期三 },{ key: THU, label: 星期四 },{ key: FRI, label: 星期五 },{ key: SAT, label: 星期六 },{ key: SUN, label: 星期天 } ];export const dayOfTheWeekOption [{ key: 1, label: 星期一 },{ key: 2, label: 星期二 },{ key: 3, label: 星期三 },{ key: 4, label: 星期四 },{ key: 5, label: 星期五 },{ key: 6, label: 星期六 },{ key: 7, label: 星期天 } ];export const monthOption [{ key: 1, label: 一月 },{ key: 2, label: 二月 },{ key: 3, label: 三月 },{ key: 4, label: 四月 },{ key: 5, label: 五月 },{ key: 6, label: 六月 },{ key: 7, label: 七月 },{ key: 8, label: 八月 },{ key: 9, label: 九月 },{ key: 10, label: 十月 },{ key: 11, label: 十一月 },{ key: 12, label: 十二月 } ];//获取dayOfTheMonthOption的每月对象 function getDayOfTheMonthOption() {const days [];for (let i 1; i 32; i 1) {days.push({ key: i.toString(), label: i.toString().concat(号) });}return days; }export const dayOfTheMonthOption getDayOfTheMonthOption(); 组件 到了组件的具体实现个人感觉我写的注释挺全的就单挑几个核心重点讲下 时间转换函数handleTimeChange //时间选择函数const handleTimeChange (time: moment.Moment | null) {setSelectTime(time);if (!time) return;const currentCron expression ? expression.split( ) : [];const [seconds, , , dayOfMonth, month1, dayOfWeek] currentCron;const minutes moment(time).minutes().toString(); //获取分钟const hours moment(time).hours().toString(); //获取小时let result null;if (!Number.isNaN(Number(hours)) !Number.isNaN(Number(minutes))) {const minutesAndHour seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space);if (defaultTimeType everyDay) result minutesAndHour.concat(* * ?);if (defaultTimeType ! everyDay)result minutesAndHour.concat(dayOfMonth).concat(space).concat(month1).concat(space).concat(dayOfWeek);}if (result) onChange?.(result);setExpression(result);};使用moment函数将time转成数字类型 minutes moment(time).minutes().toString(); //获取分钟hours moment(time).hours().toString(); //获取小时 获取时间cron字符串minutesAndHour const minutesAndHour seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space);拼接得到完整的cron表达式 defaultTimeType ‘everyDay’ result minutesAndHour.concat(‘* * ?’); defaultTimeType ! ‘everyDay’ result minutesAndHour.concat(dayOfMonth).concat(space).concat(month1).concat(space).concat(dayOfWeek);日期转换函数handleSelectChange setSelectedValue(data); const selectValues data.join(,); const currentCron expression ? expression.split( ) : []; const [seconds, minutes, hours, dayOfMonth, month1, dayOfWeek] currentCron; let result ; if (defaultTimeType everyWeek) {result seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space).concat(dayOfMonth).concat(space).concat(month1).concat(space).concat(selectValues); } if (defaultTimeType everyMonth) {result seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space).concat(data.length ? selectValues : *).concat(space).concat(month1).concat(space).concat(dayOfWeek); } if (selectTime) onChange?.(result); setExpression(result);defaultTimeType ‘everyWeek’ result seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space).concat(dayOfMonth).concat(space).concat(month1).concat(space).concat(selectValues);defaultTimeType ‘everyMonth’ result seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space).concat(data.length ? selectValues : *).concat(space).concat(month1).concat(space).concat(dayOfWeek);组件全部代码CronInput import { ConfigProvider, TimePicker } from douyinfe/semi-ui; import { Fragment, useState } from react; import { Select } from douyinfe/semi-ui; import moment from moment; //引入数据 import { dayOfTheMonthOption, dayOfTheWeekData } from /utils/cron;const { Option } Select; const format HH:mm; const defaultCron 0 * * * * ?; const space ; //空格 //类型选择 const timeTypes [{ key: everyDay, label: 每天 },{ key: everyWeek, label: 每周 },{ key: everyMonth, label: 每月 } ];interface Props {onChange?: (cron?: string) void; } const CronInput: React.FCProps ({ onChange }) {const [defaultTimeType, setDefaultTimeType] useState(timeTypes[0].key); //选择类型const [selectedValue, setSelectedValue] useState[]([]); //日期多选数组const [selectTime, setSelectTime] useStateany(null); //时间const [expression, setExpression] useStatestring | null(defaultCron); //bzd//类型选择函数const handleTimeTypeChange (selectValue: string) {setDefaultTimeType(selectValue);setSelectTime(null);setSelectedValue([]);setExpression(defaultCron);};//时间选择函数const handleTimeChange (time: moment.Moment | null) {setSelectTime(time);if (!time) return;const currentCron expression ? expression.split( ) : [];const [seconds, , , dayOfMonth, month1, dayOfWeek] currentCron;const minutes moment(time).minutes().toString(); //获取分钟const hours moment(time).hours().toString(); //获取小时let result null;if (!Number.isNaN(Number(hours)) !Number.isNaN(Number(minutes))) {const minutesAndHour seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space);if (defaultTimeType everyDay) result minutesAndHour.concat(* * ?);if (defaultTimeType ! everyDay)result minutesAndHour.concat(dayOfMonth).concat(space).concat(month1).concat(space).concat(dayOfWeek);}if (result) onChange?.(result);setExpression(result);};const handleSelectChange (data: []) {setSelectedValue(data);const selectValues data.join(,);const currentCron expression ? expression.split( ) : [];const [seconds, minutes, hours, dayOfMonth, month1, dayOfWeek] currentCron;let result ;if (defaultTimeType everyWeek) {result seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space).concat(dayOfMonth).concat(space).concat(month1).concat(space).concat(selectValues);}if (defaultTimeType everyMonth) {result seconds.concat(space).concat(minutes).concat(space).concat(hours).concat(space).concat(data.length ? selectValues : *).concat(space).concat(month1).concat(space).concat(dayOfWeek);}if (selectTime) onChange?.(result);setExpression(result);};const RenderSelect ({placeholder,data []}: {placeholder: string;data: { key: string; label: string }[];}) {return (FragmentSelectmultipleplaceholder{placeholder}onChange{(val: any) handleSelectChange(val)}style{{ marginRight: 16px, width: auto }}value{selectedValue}{data.map((item: { key: string; label: string }) (Option key{item.key} value{item.key}{item.label}/Option))}/SelectConfigProviderTimePickervalue{selectTime moment(selectTime, format).toDate()}format{format}placeholder请选择时间onChange{(val: any) handleTimeChange(val)}//ConfigProvider/Fragment);};return (div className{cron}Select// rolecron-typestyle{{ marginRight: 16px, width: auto }}placeholder请选择类型onChange{(val: any) handleTimeTypeChange(val)}value{defaultTimeType}{timeTypes.map((item) (Option key{item.key} value{item.key}{ }{item.label}/Option))}/Select{defaultTimeType everyDay (ConfigProviderTimePickervalue{selectTime moment(selectTime, format).toDate()}format{format}placeholder请选择时间onChange{(val: any) handleTimeChange(val)}//ConfigProvider)}{defaultTimeType everyWeek (RenderSelect data{dayOfTheWeekData} placeholder请选择星期 /)}{defaultTimeType everyMonth (RenderSelect data{dayOfTheMonthOption} placeholder请选择日期 /)}/div/); };export default CronInput; 使用与效果 使用 使用方法很简单接收onChange传来的cron表达式即可 const App: FCIProps (props) {const { datas [] } props;let [value, setValue] useStatestring();return (divCronInput onChange{(cron) setValue(cron)} /div{value}/div/div); };效果 每天 每周 每月
http://www.tj-hxxt.cn/news/140405.html

相关文章:

  • 企业网站的建立如何带来询盘wordpress主题首页显示不全
  • 本地怎样上传自己做的网站如何设计大型电商网站建设
  • wordpress表情插件优化seo方案
  • 做宠物店网站的素材横岗做网站公司
  • 网站建设的环境巨久科技网站建设
  • 不收费的网站有哪些公司网站制作教程
  • 淄博做网站的公司学网站开发培训班
  • 北京网站建设优化学校哪个网站做的系统好用吗
  • 怎样注册自己网站的域名抖音推广费用标准
  • 单页网站域名提供深圳网站制作公司
  • 开一家做网站的公司wordpress检测
  • 班级网站怎么做ppt平面设计好的网站
  • ps做简洁大气网站中国建设银行安徽省分行网站
  • 公司网站建设规划wordpress4.7更新说明
  • 网站续费公司软件开发培训学校软件开发培训机构
  • 新泰做网站做网站的快捷方式代码
  • 沈阳网站开发技术公司怎么建设网站让国外看
  • 烟台网站制作策划做家旅游的视频网站好
  • 做家装的有没有网站可以找工作企业管理软件管理系统
  • seo网站建设步骤模板网站建设价格
  • 昌平区手机网站制作服务营销咨询
  • 网站关键词多少个字数 站长网国内网站空间
  • 保护动物网站建设策划书江苏五星建设网站
  • 网站的组织与风格设计怎么在阿里云建立网站
  • 怀安县网站建设怎么做ppt教程网站
  • 用织梦做的网站国家官方网站
  • 广州公司核名在哪个网站长沙移动网站建设哪家好
  • 网站性能容量的收集与分析怎么做站长综合查询工具
  • 学网站开发技术中英文网站建设费用
  • 网站正在建设中手机版wordpress tags