1.实列图片

image.png
image.png

2.代码部分

  1. <!--
  2. * @description: InputCron cron 表达式输入框
  3. * @author: wanghao
  4. * @Date: 2022-03-22 15:49:07
  5. * @Modified By: wanghao
  6. * @version: 1.0.0
  7. -->
  8. <template>
  9. <div class="Ami-input-cron">
  10. <div class="ami-input-cron">
  11. <ami-input class="ami-input-cron" style="width: auto" v-model="editCronValue" :placeholder="placeholder" :disabled="disabled" :clearable="clearable" :size="size">
  12. <template slot="append" :disabled="disabled">
  13. <ami-button slot="append" :icon="icon" @click="showConfigDlg">
  14. <!-- 文字 -->
  15. <span>{{ configure }}</span>
  16. </ami-button>
  17. </template>
  18. </ami-input>
  19. <!-- 弹窗 -->
  20. <ami-dialog :title="title" :visible.sync="dialogVisible" width="1280px" :before-close="handleClose">
  21. <!-- 内容区域-->
  22. <easy-cron ref="child" v-model="editCronValue" :exeStartTime="exeStartTime" :hideYear="hideYear" :remote="remote" :hideSecond="hideSecond"></easy-cron>
  23. <span slot="footer" class="dialog-footer">
  24. <ami-button @click="dialogVisible = false">取 消</ami-button>
  25. <ami-button type="primary" @click="submit">确 定</ami-button>
  26. </span>
  27. </ami-dialog>
  28. <!-- 数据预览 -->
  29. <ami-input
  30. v-if="preview===true"
  31. class="ami-input-cron-text"
  32. type="textarea"
  33. :value="previewlist"
  34. :rows="6"
  35. readonly>
  36. </ami-input>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import EasyCron from './easy-cron';
  42. export default {
  43. name: 'ami-input-cron',
  44. model: {
  45. prop: 'cronValue',
  46. event: 'change'
  47. },
  48. /**
  49. * 绑定事件
  50. * @access:change
  51. */
  52. props: {
  53. // v-model监听值
  54. cronValue: {
  55. type: String,
  56. default: ''
  57. },
  58. // 输入框展位文本
  59. placeholder: {
  60. type: String,
  61. default: '请输入cron表达式'
  62. },
  63. // 执行时间
  64. exeStartTime: {
  65. type: [Number, String, Object],
  66. default: 0
  67. },
  68. // 预览
  69. preview: {
  70. type: Boolean,
  71. default: false
  72. },
  73. // 隐藏选择--秒,年
  74. hideSecond: {
  75. type: Boolean,
  76. default: false
  77. },
  78. // 隐藏选择--年
  79. hideYear: {
  80. type: Boolean,
  81. default: false
  82. },
  83. // 回调函数,在创建和值改变时回调
  84. remote: {
  85. type: Function,
  86. default: null
  87. },
  88. // 输入框是否清空
  89. clearable: {
  90. type: Boolean,
  91. default: false
  92. },
  93. // 禁用
  94. disabled: {
  95. type: Boolean,
  96. default: false
  97. },
  98. // (输入框)尺寸大小 large、small 和 mini 三种尺寸
  99. size: {
  100. type: String,
  101. default: ''
  102. },
  103. // 输入框按钮文字
  104. configure: {
  105. type: String,
  106. default: '配置'
  107. },
  108. // 输入框图标
  109. icon: {
  110. type: String,
  111. default: 'ami-icon-date'
  112. },
  113. // 弹窗标题
  114. title: {
  115. type: String,
  116. default: '配置Cron表达式'
  117. }
  118. },
  119. data() {
  120. return {
  121. editCronValue: this.cronValue,
  122. dialogVisible: false, // 弹窗
  123. // 预览子组件数据
  124. previewlist: ''
  125. };
  126. },
  127. watch: {
  128. /**
  129. * 监听v-model 绑定的值
  130. */
  131. cronValue(newVal, oldVal) {
  132. if (newVal === this.editCronValue) {
  133. return;
  134. }
  135. this.editCronValue = newVal;
  136. },
  137. /**
  138. * 编辑 cronValue
  139. */
  140. editCronValue(newVal, oldVal) {
  141. this.$emit('change', newVal);
  142. }
  143. },
  144. methods: {
  145. /**
  146. * @default:通知父组件促发change事件
  147. * 提交数据
  148. */
  149. submit(newVal) {
  150. this.$emit('click', newVal);
  151. // 调用子组件数据
  152. this.previewlist = this.$refs.child.preTimeList;
  153. // 触发父组件click事件,关闭弹窗
  154. this.dialogVisible = false;
  155. },
  156. /**
  157. * 打开弹出层(弹窗)
  158. */
  159. showConfigDlg() {
  160. if (!this.disabled) {
  161. this.dialogVisible = true;
  162. }
  163. },
  164. /**
  165. * 关闭弹出层(弹窗)
  166. */
  167. handleClose() {
  168. this.dialogVisible = false;
  169. }
  170. },
  171. components: {
  172. EasyCron
  173. }
  174. };
  175. </script>

代码附件:附件地址

3.说明文档

InputCron cron 表达式输入框

基础用法

:::demo v-model的值为当前被选中的ami-input-cron的 value 属性值

  1. <ami-input-cron v-model="formData.cronValue" clearable></ami-input-cron>
  2. <script>
  3. export default {
  4. data() {
  5. return {
  6. exeStartTime:String(new Date()),
  7. formData:{
  8. cronValue:"",
  9. }
  10. };
  11. },
  12. }
  13. </script>

:::

配置完展示预览效果的

:::demo preview 配置完是否展示预览数据

  1. <ami-input-cron v-model="formData.cronValue" preview></ami-input-cron>
  2. <script>
  3. export default {
  4. data() {
  5. return {
  6. exeStartTime:String(new Date()),
  7. formData:{
  8. cronValue:'',
  9. }
  10. };
  11. },
  12. }
  13. </script>

:::

创建和值改变时回调

:::demo remote 回调函数,在创建和值改变时回调

  1. <ami-input-cron v-model="formData.cronValue" :remote="remote"></ami-input-cron>
  2. <script>
  3. export default {
  4. data() {
  5. return {
  6. exeStartTime:'2015-09-02 12:23:10',
  7. formData:{
  8. cronValue:"11 9 2 * 4 ? *",
  9. }
  10. };
  11. },
  12. methods:{
  13. remote (val, time, cb) {
  14. const msg = `remote called: ${val} ${time}`
  15. console.info(msg)
  16. setTimeout(() => {
  17. // get result for e via http...
  18. const result = msg
  19. // ...
  20. // callback
  21. cb(result)
  22. }, 200)
  23. }
  24. }
  25. }
  26. </script>

:::

基础用法-促发事件

:::demo @click 促发事件,弹窗内确定按钮触发事件

  1. <ami-input-cron v-model="formData.cronValue" @click="sublist" clearable></ami-input-cron>
  2. <script>
  3. export default {
  4. data() {
  5. return {
  6. exeStartTime:String(new Date()),
  7. formData:{
  8. cronValue:"",
  9. }
  10. };
  11. },
  12. methods:{
  13. /*
  14. * 点击事件
  15. */
  16. sublist(){
  17. alert('触发点击');
  18. }
  19. }
  20. }
  21. </script>

:::

Attributes

参数 说明 类型 可选值 默认值
v-model 双向绑定 String
disabled 禁用(是否禁止编辑) Boolean true / false false
placeholder 输入框占位文本 String
clearable 是否显示清除按钮 Boolean true / false false
configure 输入框按钮文字 String —— ——
exeStartTime 执行时间 Number / String / Object
hideSecond 隐藏选择—秒,年 Boolean true / false false
hideYear 隐藏选择—年 Boolean true / false false
size 尺寸 String 默认/large/small/mini 默认
icon 图标(ami-icon-date)可更换 String —— ——
title Dialog 标题区的内容 String —— ——
remote 回调函数,在创建和值改变时回调 Function null
preview 配置完是否展示预览数据 Boolean true / false false

Input Events

事件说明 说明 回调参数
clear 在点击由 clearable 属性生成的清空按钮时触发 ——
click 在值改变点击确定后触发 ——