year.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <el-form size="small">
  3. <el-form-item>
  4. <el-radio :label="1" v-model='radioValue'>
  5. 不填,允许的通配符[, - * /]
  6. </el-radio>
  7. </el-form-item>
  8. <el-form-item>
  9. <el-radio :label="2" v-model='radioValue'>
  10. 每年
  11. </el-radio>
  12. </el-form-item>
  13. <el-form-item>
  14. <el-radio :label="3" v-model='radioValue'>
  15. 周期从
  16. <el-input-number v-model='cycle01' :min='fullYear' :max="2098" /> -
  17. <el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : fullYear + 1" :max="2099" />
  18. </el-radio>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-radio :label="4" v-model='radioValue'>
  22. <el-input-number v-model='average01' :min='fullYear' :max="2098"/> 年开始,每
  23. <el-input-number v-model='average02' :min="1" :max="2099 - average01 || fullYear" /> 年执行一次
  24. </el-radio>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-radio :label="5" v-model='radioValue'>
  28. 指定
  29. <el-select clearable v-model="checkboxList" placeholder="可多选" multiple>
  30. <el-option v-for="item in 9" :key="item" :value="item - 1 + fullYear" :label="item -1 + fullYear" />
  31. </el-select>
  32. </el-radio>
  33. </el-form-item>
  34. </el-form>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. fullYear: 0,
  41. radioValue: 1,
  42. cycle01: 0,
  43. cycle02: 0,
  44. average01: 0,
  45. average02: 1,
  46. checkboxList: [],
  47. checkNum: this.$options.propsData.check
  48. }
  49. },
  50. name: 'crontab-year',
  51. props: ['check', 'month', 'cron'],
  52. methods: {
  53. // 单选按钮值变化时
  54. radioChange() {
  55. switch (this.radioValue) {
  56. case 1:
  57. this.$emit('update', 'year', '');
  58. break;
  59. case 2:
  60. this.$emit('update', 'year', '*');
  61. break;
  62. case 3:
  63. this.$emit('update', 'year', this.cycleTotal);
  64. break;
  65. case 4:
  66. this.$emit('update', 'year', this.averageTotal);
  67. break;
  68. case 5:
  69. this.$emit('update', 'year', this.checkboxString);
  70. break;
  71. }
  72. },
  73. // 周期两个值变化时
  74. cycleChange() {
  75. if (this.radioValue == '3') {
  76. this.$emit('update', 'year', this.cycleTotal);
  77. }
  78. },
  79. // 平均两个值变化时
  80. averageChange() {
  81. if (this.radioValue == '4') {
  82. this.$emit('update', 'year', this.averageTotal);
  83. }
  84. },
  85. // checkbox值变化时
  86. checkboxChange() {
  87. if (this.radioValue == '5') {
  88. this.$emit('update', 'year', this.checkboxString);
  89. }
  90. }
  91. },
  92. watch: {
  93. 'radioValue': 'radioChange',
  94. 'cycleTotal': 'cycleChange',
  95. 'averageTotal': 'averageChange',
  96. 'checkboxString': 'checkboxChange'
  97. },
  98. computed: {
  99. // 计算两个周期值
  100. cycleTotal: function () {
  101. const cycle01 = this.checkNum(this.cycle01, this.fullYear, 2098)
  102. const cycle02 = this.checkNum(this.cycle02, cycle01 ? cycle01 + 1 : this.fullYear + 1, 2099)
  103. return cycle01 + '-' + cycle02;
  104. },
  105. // 计算平均用到的值
  106. averageTotal: function () {
  107. const average01 = this.checkNum(this.average01, this.fullYear, 2098)
  108. const average02 = this.checkNum(this.average02, 1, 2099 - average01 || this.fullYear)
  109. return average01 + '/' + average02;
  110. },
  111. // 计算勾选的checkbox值合集
  112. checkboxString: function () {
  113. let str = this.checkboxList.join();
  114. return str;
  115. }
  116. },
  117. mounted: function () {
  118. // 仅获取当前年份
  119. this.fullYear = Number(new Date().getFullYear());
  120. this.cycle01 = this.fullYear
  121. this.average01 = this.fullYear
  122. }
  123. }
  124. </script>