sh-view 2.0.8 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,287 +1,283 @@
1
- <template>
2
- <div class="sh-cron-content">
3
- <Tabs v-model="activeKey" :size="`small`">
4
- <template v-for="tab in cronTabList" :key="tab.name">
5
- <TabPane v-bind="tab"></TabPane>
6
- </template>
7
- </Tabs>
8
- <template v-if="activeKey === 'second'">
9
- <cronSecondBox v-model="second" :disabled="disabled" />
10
- </template>
11
- <template v-else-if="activeKey === 'minute'">
12
- <cronMinuteBox v-model="minute" :disabled="disabled" />
13
- </template>
14
- <template v-else-if="activeKey === 'hour'">
15
- <cronHourBox v-model="hour" :disabled="disabled" />
16
- </template>
17
- <template v-else-if="activeKey === 'day'">
18
- <cronDayBox v-model="day" :week="week" :disabled="disabled" />
19
- </template>
20
- <template v-else-if="activeKey === 'month'">
21
- <cronMonthBox v-model="month" :disabled="disabled" />
22
- </template>
23
- <template v-else-if="activeKey === 'week'">
24
- <cronWeekBox v-model="week" :day="day" :disabled="disabled" />
25
- </template>
26
- <template v-else-if="activeKey === 'year'">
27
- <cronYearBox v-model="year" :disabled="disabled" />
28
- </template>
29
- <!-- 执行时间预览 -->
30
- <vxe-grid v-bind="tableConfig" @edit-closed="onTableEditClosed" @header-cell-click="onTableHeaderClick">
31
- <template #bottom>
32
- <!-- cron错误提示 -->
33
- <Alert v-if="errMessage" type="error" show-icon>
34
- <span>表达式错误,请检查</span>
35
- <template #desc>{{ errMessage }}</template>
36
- </Alert>
37
- <template v-else>
38
- <div class="cron-title">近十次执行时间(不含年)</div>
39
- <vxe-textarea v-model="preTimeList" :rows="5" disabled />
40
- </template>
41
- </template>
42
- </vxe-grid>
43
- </div>
44
- </template>
45
-
46
- <script>
47
- import cronSecondBox from '../tabs/cron-second-box.vue'
48
- import cronMinuteBox from '../tabs/cron-minute-box.vue'
49
- import cronHourBox from '../tabs/cron-hour-box.vue'
50
- import cronDayBox from '../tabs/cron-day-box.vue'
51
- import cronMonthBox from '../tabs/cron-month-box.vue'
52
- import cronWeekBox from '../tabs/cron-week-box.vue'
53
- import cronYearBox from '../tabs/cron-year-box.vue'
54
- import cronUtils from '../utils'
55
- export default {
56
- name: 'CronContent',
57
- components: {
58
- cronSecondBox,
59
- cronMinuteBox,
60
- cronHourBox,
61
- cronDayBox,
62
- cronMonthBox,
63
- cronWeekBox,
64
- cronYearBox
65
- },
66
- props: {
67
- modelValue: {
68
- type: String,
69
- default: ''
70
- },
71
- disabled: {
72
- type: Boolean
73
- },
74
- hideSecond: {
75
- type: Boolean
76
- },
77
- hideYear: {
78
- type: Boolean
79
- },
80
- remote: {
81
- type: Function
82
- }
83
- },
84
- emits: ['update:modelValue', 'change'],
85
- data() {
86
- return {
87
- activeKey: this.hideSecond ? 'minute' : 'second',
88
- second: '*',
89
- minute: '*',
90
- hour: '*',
91
- day: '*',
92
- month: '*',
93
- week: '?',
94
- year: '*',
95
- tableConfig: {
96
- align: 'center',
97
- columns: [
98
- { title: '', field: 'second', editRender: { name: '$input' } },
99
- { title: '', field: 'minute', editRender: { name: '$input' } },
100
- { title: '', field: 'hour', editRender: { name: '$input' } },
101
- { title: '日', field: 'day', editRender: { name: '$input' } },
102
- { title: '月', field: 'month', editRender: { name: '$input' } },
103
- { title: '周', field: 'week', editRender: { name: '$input' } },
104
- { title: '年', field: 'year', editRender: { name: '$input' } }
105
- ],
106
- data: [],
107
- editConfig: {
108
- enable: !this.disabled
109
- }
110
- },
111
- preTimeList: '执行预览,会忽略年份参数。',
112
- errMessage: '',
113
- calTriggerList: this.$vUtils.debounce(this.calTriggerListInner, 500)
114
- }
115
- },
116
- computed: {
117
- cronTabList() {
118
- let list = [
119
- { name: 'second', label: '' },
120
- { name: 'minute', label: '' },
121
- { name: 'hour', label: '' },
122
- { name: 'day', label: '日' },
123
- { name: 'month', label: '月' },
124
- { name: 'week', label: '' },
125
- { name: 'year', label: '年' }
126
- ]
127
- if (this.hideSecond) {
128
- list = list.filter(item => !['second', 'year'].includes(item.name))
129
- } else if (this.hideYear) {
130
- list = list.filter(item => !['year'].includes(item.name))
131
- }
132
- return list
133
- },
134
- cronValueInner() {
135
- let { hideSecond, hideYear, second, minute, hour, day, month, week, year } = this
136
- let result = []
137
- if (!hideSecond) {
138
- result.push(second ? second : '*')
139
- }
140
- result.push(minute ? minute : '*')
141
- result.push(hour ? hour : '*')
142
- result.push(day ? day : '*')
143
- result.push(month ? month : '*')
144
- result.push(week ? week : '?')
145
- if (!hideYear && !hideSecond) result.push(year ? year : '*')
146
- return result.join(' ')
147
- },
148
- cronValueNoYear() {
149
- const v = this.cronValueInner
150
- if (this.hideYear || this.hideSecond) return v
151
- const vs = v.split(' ')
152
- if (vs.length >= 6) {
153
- // 转成 Quartz 的规则
154
- vs[5] = this.convertWeekToQuartz(vs[5])
155
- }
156
- return vs.slice(0, vs.length - 1).join(' ')
157
- }
158
- },
159
- watch: {
160
- modelValue(nv) {
161
- if (nv === this.cronValueInner) {
162
- return
163
- }
164
- this.formatValue()
165
- },
166
- cronValueInner(nv) {
167
- this.calTriggerList()
168
- this.emitValue(nv)
169
- this.assignTable()
170
- }
171
- },
172
- created() {
173
- this.assignTable()
174
- this.formatValue()
175
- this.calTriggerListInner()
176
- },
177
- methods: {
178
- formatValue() {
179
- let { modelValue, hideSecond } = this
180
- if (!modelValue) return
181
- const values = modelValue.split(' ').filter(item => !!item)
182
- if (!values || values.length <= 0) return
183
- let i = 0
184
- if (!hideSecond) this.second = values[i++]
185
- if (values.length > i) this.minute = values[i++]
186
- if (values.length > i) this.hour = values[i++]
187
- if (values.length > i) this.day = values[i++]
188
- if (values.length > i) this.month = values[i++]
189
- if (values.length > i) this.week = values[i++]
190
- if (values.length > i) this.year = values[i]
191
- this.assignTable()
192
- },
193
- assignTable() {
194
- this.tableConfig.data = [
195
- {
196
- second: this.second,
197
- minute: this.minute,
198
- hour: this.hour,
199
- day: this.day,
200
- month: this.month,
201
- week: this.week,
202
- year: this.year
203
- }
204
- ]
205
- },
206
- calTriggerListInner() {
207
- this.errMessage = ''
208
- // 设置了回调函数
209
- if (this.remote) {
210
- this.remote(this.cronValueInner, +new Date(), v => {
211
- this.preTimeList = v
212
- })
213
- return
214
- }
215
- try {
216
- const format = 'yyyy-MM-dd hh:mm:ss'
217
- const options = {
218
- currentDate: this.$vUtils.toDateString(new Date(), format)
219
- }
220
- const iter = cronUtils.parse(this.cronValueNoYear, options)
221
- const result = []
222
- for (let i = 1; i <= 10; i++) {
223
- result.push(this.$vUtils.toDateString(new Date(iter.next()), format))
224
- }
225
- this.preTimeList = result.length > 0 ? result.join('\n') : '无执行时间'
226
- } catch (e) {
227
- this.errMessage = e
228
- }
229
- },
230
- // Quartz 的规则:
231
- // 1 = 周日,2 = 周一,3 = 周二,4 = 周三,5 = 周四,6 = 周五,7 = 周六
232
- convertWeekToQuartz(week) {
233
- let convert = v => {
234
- if (v === '0') {
235
- return '1'
236
- }
237
- if (v === '1') {
238
- return '0'
239
- }
240
- return (Number.parseInt(v) - 1).toString()
241
- }
242
- // 匹配示例 1-7 or 1/7
243
- let patten1 = /^([0-7])([-/])([0-7])$/
244
- // 匹配示例 1,4,7
245
- let patten2 = /^([0-7])(,[0-7])+$/
246
- if (/^[0-7]$/.test(week)) {
247
- return convert(week)
248
- } else if (patten1.test(week)) {
249
- return week.replace(patten1, ($0, before, separator, after) => {
250
- if (separator === '/') {
251
- return convert(before) + separator + after
252
- } else {
253
- return convert(before) + separator + convert(after)
254
- }
255
- })
256
- } else if (patten2.test(week)) {
257
- return week
258
- .split(',')
259
- .map(v => convert(v))
260
- .join(',')
261
- }
262
- return week
263
- },
264
- onTableHeaderClick({ column }) {
265
- this.activeKey = column.property
266
- },
267
- onTableEditClosed({ row, column }) {
268
- this.second = row.second
269
- this.minute = row.minute
270
- this.hour = row.hour
271
- this.day = row.day
272
- this.month = row.month
273
- this.week = row.week
274
- this.year = row.year
275
- },
276
- onInputCronBlur(event) {
277
- this.emitValue(event.target.value)
278
- },
279
- emitValue(value) {
280
- this.$emit('change', value)
281
- this.$emit('update:modelValue', value)
282
- }
283
- }
284
- }
285
- </script>
286
-
287
- <style scoped></style>
1
+ <template>
2
+ <div class="sh-cron-content">
3
+ <sh-tabs v-model="activeKey" size="small" :options="cronTabList" :is-content="false"></sh-tabs>
4
+ <template v-if="activeKey === 'second'">
5
+ <cronSecondBox v-model="second" :disabled="disabled" />
6
+ </template>
7
+ <template v-else-if="activeKey === 'minute'">
8
+ <cronMinuteBox v-model="minute" :disabled="disabled" />
9
+ </template>
10
+ <template v-else-if="activeKey === 'hour'">
11
+ <cronHourBox v-model="hour" :disabled="disabled" />
12
+ </template>
13
+ <template v-else-if="activeKey === 'day'">
14
+ <cronDayBox v-model="day" :week="week" :disabled="disabled" />
15
+ </template>
16
+ <template v-else-if="activeKey === 'month'">
17
+ <cronMonthBox v-model="month" :disabled="disabled" />
18
+ </template>
19
+ <template v-else-if="activeKey === 'week'">
20
+ <cronWeekBox v-model="week" :day="day" :disabled="disabled" />
21
+ </template>
22
+ <template v-else-if="activeKey === 'year'">
23
+ <cronYearBox v-model="year" :disabled="disabled" />
24
+ </template>
25
+ <!-- 执行时间预览 -->
26
+ <vxe-grid v-bind="tableConfig" @edit-closed="onTableEditClosed" @header-cell-click="onTableHeaderClick">
27
+ <template #bottom>
28
+ <!-- cron错误提示 -->
29
+ <sh-alert v-if="errMessage" type="error" show-icon>
30
+ <span>表达式错误,请检查</span>
31
+ <template #desc>{{ errMessage }}</template>
32
+ </sh-alert>
33
+ <template v-else>
34
+ <div class="cron-title">近十次执行时间(不含年)</div>
35
+ <vxe-textarea v-model="preTimeList" :rows="5" disabled />
36
+ </template>
37
+ </template>
38
+ </vxe-grid>
39
+ </div>
40
+ </template>
41
+
42
+ <script>
43
+ import cronSecondBox from '../tabs/cron-second-box.vue'
44
+ import cronMinuteBox from '../tabs/cron-minute-box.vue'
45
+ import cronHourBox from '../tabs/cron-hour-box.vue'
46
+ import cronDayBox from '../tabs/cron-day-box.vue'
47
+ import cronMonthBox from '../tabs/cron-month-box.vue'
48
+ import cronWeekBox from '../tabs/cron-week-box.vue'
49
+ import cronYearBox from '../tabs/cron-year-box.vue'
50
+ import cronUtils from '../utils'
51
+ export default {
52
+ name: 'CronContent',
53
+ components: {
54
+ cronSecondBox,
55
+ cronMinuteBox,
56
+ cronHourBox,
57
+ cronDayBox,
58
+ cronMonthBox,
59
+ cronWeekBox,
60
+ cronYearBox
61
+ },
62
+ props: {
63
+ modelValue: {
64
+ type: String,
65
+ default: ''
66
+ },
67
+ disabled: {
68
+ type: Boolean
69
+ },
70
+ hideSecond: {
71
+ type: Boolean
72
+ },
73
+ hideYear: {
74
+ type: Boolean
75
+ },
76
+ remote: {
77
+ type: Function
78
+ }
79
+ },
80
+ emits: ['update:modelValue', 'change'],
81
+ data() {
82
+ return {
83
+ activeKey: this.hideSecond ? 'minute' : 'second',
84
+ second: '*',
85
+ minute: '*',
86
+ hour: '*',
87
+ day: '*',
88
+ month: '*',
89
+ week: '?',
90
+ year: '*',
91
+ tableConfig: {
92
+ align: 'center',
93
+ columns: [
94
+ { title: '', field: 'second', editRender: { name: '$input' } },
95
+ { title: '分', field: 'minute', editRender: { name: '$input' } },
96
+ { title: '', field: 'hour', editRender: { name: '$input' } },
97
+ { title: '日', field: 'day', editRender: { name: '$input' } },
98
+ { title: '', field: 'month', editRender: { name: '$input' } },
99
+ { title: '', field: 'week', editRender: { name: '$input' } },
100
+ { title: '', field: 'year', editRender: { name: '$input' } }
101
+ ],
102
+ data: [],
103
+ editConfig: {
104
+ enable: !this.disabled
105
+ }
106
+ },
107
+ preTimeList: '执行预览,会忽略年份参数。',
108
+ errMessage: '',
109
+ calTriggerList: this.$vUtils.debounce(this.calTriggerListInner, 500)
110
+ }
111
+ },
112
+ computed: {
113
+ cronTabList() {
114
+ let list = [
115
+ { value: 'second', label: '秒' },
116
+ { value: 'minute', label: '分' },
117
+ { value: 'hour', label: '时' },
118
+ { value: 'day', label: '日' },
119
+ { value: 'month', label: '' },
120
+ { value: 'week', label: '' },
121
+ { value: 'year', label: '' }
122
+ ]
123
+ if (this.hideSecond) {
124
+ list = list.filter(item => !['second', 'year'].includes(item.value))
125
+ } else if (this.hideYear) {
126
+ list = list.filter(item => !['year'].includes(item.value))
127
+ }
128
+ return list
129
+ },
130
+ cronValueInner() {
131
+ let { hideSecond, hideYear, second, minute, hour, day, month, week, year } = this
132
+ let result = []
133
+ if (!hideSecond) {
134
+ result.push(second ? second : '*')
135
+ }
136
+ result.push(minute ? minute : '*')
137
+ result.push(hour ? hour : '*')
138
+ result.push(day ? day : '*')
139
+ result.push(month ? month : '*')
140
+ result.push(week ? week : '?')
141
+ if (!hideYear && !hideSecond) result.push(year ? year : '*')
142
+ return result.join(' ')
143
+ },
144
+ cronValueNoYear() {
145
+ const v = this.cronValueInner
146
+ if (this.hideYear || this.hideSecond) return v
147
+ const vs = v.split(' ')
148
+ if (vs.length >= 6) {
149
+ // 转成 Quartz 的规则
150
+ vs[5] = this.convertWeekToQuartz(vs[5])
151
+ }
152
+ return vs.slice(0, vs.length - 1).join(' ')
153
+ }
154
+ },
155
+ watch: {
156
+ modelValue(nv) {
157
+ if (nv === this.cronValueInner) {
158
+ return
159
+ }
160
+ this.formatValue()
161
+ },
162
+ cronValueInner(nv) {
163
+ this.calTriggerList()
164
+ this.emitValue(nv)
165
+ this.assignTable()
166
+ }
167
+ },
168
+ created() {
169
+ this.assignTable()
170
+ this.formatValue()
171
+ this.calTriggerListInner()
172
+ },
173
+ methods: {
174
+ formatValue() {
175
+ let { modelValue, hideSecond } = this
176
+ if (!modelValue) return
177
+ const values = modelValue.split(' ').filter(item => !!item)
178
+ if (!values || values.length <= 0) return
179
+ let i = 0
180
+ if (!hideSecond) this.second = values[i++]
181
+ if (values.length > i) this.minute = values[i++]
182
+ if (values.length > i) this.hour = values[i++]
183
+ if (values.length > i) this.day = values[i++]
184
+ if (values.length > i) this.month = values[i++]
185
+ if (values.length > i) this.week = values[i++]
186
+ if (values.length > i) this.year = values[i]
187
+ this.assignTable()
188
+ },
189
+ assignTable() {
190
+ this.tableConfig.data = [
191
+ {
192
+ second: this.second,
193
+ minute: this.minute,
194
+ hour: this.hour,
195
+ day: this.day,
196
+ month: this.month,
197
+ week: this.week,
198
+ year: this.year
199
+ }
200
+ ]
201
+ },
202
+ calTriggerListInner() {
203
+ this.errMessage = ''
204
+ // 设置了回调函数
205
+ if (this.remote) {
206
+ this.remote(this.cronValueInner, +new Date(), v => {
207
+ this.preTimeList = v
208
+ })
209
+ return
210
+ }
211
+ try {
212
+ const format = 'yyyy-MM-dd hh:mm:ss'
213
+ const options = {
214
+ currentDate: this.$vUtils.toDateString(new Date(), format)
215
+ }
216
+ const iter = cronUtils.parse(this.cronValueNoYear, options)
217
+ const result = []
218
+ for (let i = 1; i <= 10; i++) {
219
+ result.push(this.$vUtils.toDateString(new Date(iter.next()), format))
220
+ }
221
+ this.preTimeList = result.length > 0 ? result.join('\n') : '无执行时间'
222
+ } catch (e) {
223
+ this.errMessage = e
224
+ }
225
+ },
226
+ // Quartz 的规则:
227
+ // 1 = 周日,2 = 周一,3 = 周二,4 = 周三,5 = 周四,6 = 周五,7 = 周六
228
+ convertWeekToQuartz(week) {
229
+ let convert = v => {
230
+ if (v === '0') {
231
+ return '1'
232
+ }
233
+ if (v === '1') {
234
+ return '0'
235
+ }
236
+ return (Number.parseInt(v) - 1).toString()
237
+ }
238
+ // 匹配示例 1-7 or 1/7
239
+ let patten1 = /^([0-7])([-/])([0-7])$/
240
+ // 匹配示例 1,4,7
241
+ let patten2 = /^([0-7])(,[0-7])+$/
242
+ if (/^[0-7]$/.test(week)) {
243
+ return convert(week)
244
+ } else if (patten1.test(week)) {
245
+ return week.replace(patten1, ($0, before, separator, after) => {
246
+ if (separator === '/') {
247
+ return convert(before) + separator + after
248
+ } else {
249
+ return convert(before) + separator + convert(after)
250
+ }
251
+ })
252
+ } else if (patten2.test(week)) {
253
+ return week
254
+ .split(',')
255
+ .map(v => convert(v))
256
+ .join(',')
257
+ }
258
+ return week
259
+ },
260
+ onTableHeaderClick({ column }) {
261
+ this.activeKey = column.property
262
+ },
263
+ onTableEditClosed({ row, column }) {
264
+ this.second = row.second
265
+ this.minute = row.minute
266
+ this.hour = row.hour
267
+ this.day = row.day
268
+ this.month = row.month
269
+ this.week = row.week
270
+ this.year = row.year
271
+ },
272
+ onInputCronBlur(event) {
273
+ this.emitValue(event.target.value)
274
+ },
275
+ emitValue(value) {
276
+ this.$emit('change', value)
277
+ this.$emit('update:modelValue', value)
278
+ }
279
+ }
280
+ }
281
+ </script>
282
+
283
+ <style scoped></style>
@@ -295,6 +295,8 @@ $expandDkBgColor: var(--vxe-primary-darken-color);
295
295
  .sh-menu-item-title {
296
296
  flex: 1;
297
297
  white-space: nowrap;
298
+ overflow: hidden;
299
+ text-overflow: ellipsis;
298
300
  }
299
301
  .sh-menu-item-arrow {
300
302
  margin-left: 5px;