InputCron.vue 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
<template>
  <div class="input-cron">
    <a-input :placeholder="placeholder" v-model="editCronValue" :disabled="disabled">
      <a slot="addonAfter" @click="showConfigDlg" class="config-btn" :disabled="disabled">
        <a-icon type="setting"></a-icon>
        选择
      </a>
    </a-input>
    <j-modal :visible.sync="show" title="Cron表达式" width="800px">
      <easy-cron
        v-model="editCronValue"
        :exeStartTime="exeStartTime"
        :hideYear="hideYear"
        :remote="remote"
        :hideSecond="hideSecond"
        style="width: 100%"
      ></easy-cron>
    </j-modal>
  </div>
</template>

<script>
import EasyCron from './EasyCron.vue'

export default {
  name: 'input-cron',
  components: {EasyCron},
  model: {
    prop: 'cronValue',
    event: 'change'
  },
  props: {
    cronValue: {
      type: String,
      default: ''
    },
    width: {
      type: String,
      default: '800px'
    },
    placeholder: {
      type: String,
      default: '请输入cron表达式'
    },
    disabled: {
      type: Boolean,
      default: false
    },
    exeStartTime: {
      type: [Number, String, Object],
      default: 0
    },
    hideSecond: {
      type: Boolean,
      default: false
    },
    hideYear: {
      type: Boolean,
      default: false
    },
    remote: {
      type: Function,
      default: null
    }
  },
  data() {
    return {
      editCronValue: this.cronValue,
      show: false,
    }
  },
  watch: {
    cronValue(newVal, oldVal) {
      if (newVal === this.editCronValue) {
        return
      }
      this.editCronValue = newVal
    },
    editCronValue(newVal, oldVal) {
      this.$emit('change', newVal)
    }
  },
  methods: {
    showConfigDlg() {
      if (!this.disabled) {
        this.show = true
      }
    }
  }
}
</script>

<style scoped>

  .config-btn {
    cursor: pointer;
  }

</style>