cron.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template lang="html">
  2. <div class="cron" :val="value_">
  3. <el-tabs v-model="activeName">
  4. <el-tab-pane label="秒" name="s">
  5. <second-and-minute v-model="sVal" lable="秒"></second-and-minute >
  6. </el-tab-pane>
  7. <el-tab-pane label="分" name="m">
  8. <second-and-minute v-model="mVal" lable="分"></second-and-minute >
  9. </el-tab-pane>
  10. <el-tab-pane label="时" name="h">
  11. <hour v-model="hVal" lable="时"></hour>
  12. </el-tab-pane>
  13. <el-tab-pane label="日" name="d">
  14. <day v-model="dVal" lable="日"></day>
  15. </el-tab-pane>
  16. <el-tab-pane label="月" name="month">
  17. <month v-model="monthVal" lable="月"></month>
  18. </el-tab-pane>
  19. <el-tab-pane label="周" name="week">
  20. <week v-model="weekVal" lable="周"></week>
  21. </el-tab-pane>
  22. <!-- <el-tab-pane label="年" name="year">
  23. <year v-model="yearVal" lable="年"></year>
  24. </el-tab-pane> -->
  25. </el-tabs>
  26. <!-- table -->
  27. <el-table
  28. :data="tableData"
  29. size="mini"
  30. border
  31. style="width: 100%;">
  32. <el-table-column
  33. prop="sVal"
  34. label="秒"
  35. width="70">
  36. </el-table-column>
  37. <el-table-column
  38. prop="mVal"
  39. label="分"
  40. width="70">
  41. </el-table-column>
  42. <el-table-column
  43. prop="hVal"
  44. label="时"
  45. width="70">
  46. </el-table-column>
  47. <el-table-column
  48. prop="dVal"
  49. label="日"
  50. width="70">
  51. </el-table-column>
  52. <el-table-column
  53. prop="monthVal"
  54. label="月"
  55. width="70">
  56. </el-table-column>
  57. <el-table-column
  58. prop="weekVal"
  59. label="周"
  60. width="70">
  61. </el-table-column>
  62. <!-- <el-table-column
  63. prop="yearVal"
  64. label="年">
  65. </el-table-column> -->
  66. </el-table>
  67. </div>
  68. </template>
  69. <script>
  70. import SecondAndMinute from './cron/secondAndMinute'
  71. import hour from './cron/hour'
  72. import day from './cron/day'
  73. import month from './cron/month'
  74. import week from './cron/week'
  75. // import year from './cron/year'
  76. export default {
  77. props: {
  78. value: {
  79. type: String
  80. }
  81. },
  82. data () {
  83. return {
  84. //
  85. activeName: 's',
  86. sVal: '',
  87. mVal: '',
  88. hVal: '',
  89. dVal: '',
  90. monthVal: '',
  91. weekVal: ''
  92. // yearVal: ''
  93. }
  94. },
  95. watch: {
  96. 'value' (a, b) {
  97. this.updateVal()
  98. }
  99. },
  100. computed: {
  101. tableData () {
  102. return [{
  103. sVal: this.sVal,
  104. mVal: this.mVal,
  105. hVal: this.hVal,
  106. dVal: this.dVal,
  107. monthVal: this.monthVal,
  108. weekVal: this.weekVal
  109. // yearVal: this.yearVal
  110. }]
  111. },
  112. value_ () {
  113. if (!this.dVal && !this.weekVal) {
  114. return ''
  115. }
  116. if (this.dVal === '?' && this.weekVal === '?') {
  117. this.$message.error('日期与星期不可以同时为“不指定”')
  118. }
  119. if (this.dVal !== '?' && this.weekVal !== '?') {
  120. this.$message.error('日期与星期必须有一个为“不指定”')
  121. }
  122. let v = `${this.sVal} ${this.mVal} ${this.hVal} ${this.dVal} ${this.monthVal} ${this.weekVal}`
  123. // ${this.yearVal}
  124. if (v !== this.value) {
  125. this.$emit('input', v)
  126. }
  127. return v
  128. }
  129. },
  130. methods: {
  131. updateVal () {
  132. if (!this.value) {
  133. return
  134. }
  135. let arrays = this.value.split(' ')
  136. this.sVal = arrays[0]
  137. this.mVal = arrays[1]
  138. this.hVal = arrays[2]
  139. this.dVal = arrays[3]
  140. this.monthVal = arrays[4]
  141. this.weekVal = arrays[5]
  142. // this.yearVal = arrays[6]
  143. }
  144. },
  145. created () {
  146. this.updateVal()
  147. },
  148. components: {
  149. SecondAndMinute, hour, day, month, week
  150. // , year
  151. }
  152. }
  153. </script>
  154. <style lang="css">
  155. .cron {
  156. text-align: left;
  157. padding: 10px;
  158. background: #fff;
  159. border: 1px solid #dcdfe6;
  160. box-shadow: 0 2px 4px 0 rgba(0,0,0,.12), 0 0 6px 0 rgba(0,0,0,.04);
  161. }
  162. </style>