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

vue3 + antd +ts cron 选择器使用

https://github.com/shiyzhang/shiyzhang-cron

shiyzhang-cron组件

使用方法:

  1. npm i shiyzhangcron 或 pnpm i shiyzhangcron
  2. 给ts添加类型声明文件
    • 在项目根目录下创建 types 文件夹
    • types 文件夹中创建 shiyzhangcron.d.ts 文件
    • 添加以下内容
      // types/shiyzhangcron.d.ts
      declare module 'shiyzhangcron';
  3. 使用

    <script setup lang="ts">import { EasyCronInner } from 'shiyzhangcron';import 'shiyzhangcron/dist/style.css';</script><template><divclass="fixed inset-0 z-50 flex items-center justify-center"><EasyCronInnerinput-area="true"/></div>
    </template>

    Attributes

    参数说明类型默认值
    model-value / v-model 绑定值 string -
    disabled 是否禁用 boolean false
    hideSecond 是否显示秒 boolean false
    hideYear 是否显示年(秒不显示时会显示年) boolean false
    inputArea 是否显示下面输入区 boolean false

    Events

    事件名说明类型
    change 仅当 modelValue 改变时 Function(e)
    封装弹窗组件
    <script setup lang="ts">
    import { computed, ref, watch } from 'vue';import { Button, Modal } from 'ant-design-vue';
    import { EasyCronInner } from 'shiyzhangcron';import 'shiyzhangcron/dist/style.css';interface Props {visible: boolean;value: string;title?: string;
    }const props = defineProps<Props>();
    const emit = defineEmits(['update:visible', 'confirm', 'cancel']);const innerValue = ref(props.value);watch(() => props.value,(v) => {innerValue.value = v;},
    );const isVisible = computed(() => props.visible);const onCancel = () => {emit('update:visible', false);emit('cancel');
    };const onOk = () => {emit('confirm', innerValue.value);emit('update:visible', false);
    };const onCronChange = (v: string) => {innerValue.value = v;
    };
    </script><template><Modal:open="isVisible"@update:open="(v) => emit('update:visible', v)":title="title || 'Cron 配置'"width="860px":footer="null"destroy-on-close@cancel="onCancel"><EasyCronInnerv-model:value="innerValue"input-area="true"@change="onCronChange"/><div class="mt-4 flex items-center justify-between"><div>当前选择: {{ innerValue }}</div><div class="space-x-2"><Button @click="onCancel">取消</Button><Button type="primary" @click="onOk">确定</Button></div></div></Modal>
    </template>

    使用

    <script setup lang="ts">
    import { defineAsyncComponent, ref } from 'vue';import 'shiyzhangcron/dist/style.css';const CronPickerModal = defineAsyncComponent(() => import('./CronPickerModal.vue'),
    );const easyCronInnerValue = ref('* * * * * ? *');const cronModalVisible = ref(false);const openCronModal = () => {cronModalVisible.value = true;
    };const onCronConfirm = (val: string) => {easyCronInnerValue.value = val;cronModalVisible.value = false;
    };const onCronCancel = () => {cronModalVisible.value = false;
    };
    </script><template><div class="p-4"><h1 class="mb-4 text-2xl font-bold">Test Detail Page</h1><div class="flex items-center gap-2" style="max-width: 640px"><input:value="easyCronInnerValue"type="text"placeholder="请输入 CRON 表达式"class="flex-1 rounded border border-gray-300 px-3 py-1"/><buttonclass="rounded bg-blue-600 px-3 py-1 text-white"@click="openCronModal">配置</button></div><p class="mt-4">当前cron值为: {{ easyCronInnerValue }}</p><CronPickerModalv-if="cronModalVisible"v-model:visible="cronModalVisible":value="easyCronInnerValue"@confirm="onCronConfirm"@cancel="onCronCancel"/></div>
    </template>

     

http://www.jsqmd.com/news/2974/

相关文章:

  • HarmonyOS 5 性能优化全攻略:从启动加速到内存管理
  • #字符串执行函数——eval()、exec()和compile()详解
  • HarmonyOS 5 网络编程与数据存储实战:从RESTful API到本地持久化
  • OceanBase 向量数据库使用指南
  • 【光照】[环境光ambient]以UnityURP为例
  • 浅谈当前时代下大学生的就业择业及人生规划
  • 实用指南:玳瑁的嵌入式日记---0923(ARM)
  • 个人博客搭建记录【hexo】
  • 喵喵喵
  • Ansible自动化管理 - 指南
  • flink不同环境切换 - --
  • ps-填充色
  • PythonStudio_圆的面积demo源代码
  • HarmonyOS 5分布式数据同步实战:跨设备待办事项应用
  • 深入理解HarmonyOS 5的AVSession:构建跨设备媒体播放器
  • HT-AD4PS-1+ 一分四射频功分器:1-500 MHz 小尺寸/低插损,通信、医疗全能打
  • HarmonyOS资源管理与访问:多分辨率与多语言适配
  • 面试官:为什么没有虚拟线程池?
  • 润生软件简介:以“重构与共生”引领商业未来
  • Python 并发编程
  • 安装pyautogui时与setuptool时冲突报错-module setuptools.dist has no attribute check_test_suite
  • 牛客周赛 Round 110 题解
  • 统计机器学习经典分类算法MATLAB实现
  • 从安装到中文界面,一文带你玩转 DaVinci Resolve 20(零基础也能搞定)
  • 靶场1
  • 299、已凉
  • linux手动安装阿里云Logtail采集Nginx访问日志
  • WPF的数据绑定之通知修改
  • 古代史
  • matlab运行时遇到的license问题