sh-view 2.8.0 → 2.8.2
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.
- package/.eslintrc.js +25 -20
- package/other.js +8 -8
- package/package.json +9 -6
- package/packages/components/index.js +91 -91
- package/packages/components/sh-alert/alert.ts +30 -0
- package/packages/components/sh-alert/index.vue +143 -168
- package/packages/components/sh-badge/index.vue +242 -242
- package/packages/components/sh-calendar/index.vue +650 -650
- package/packages/components/sh-card/index.vue +148 -148
- package/packages/components/sh-code-editor/index.vue +19 -19
- package/packages/components/sh-col/index.vue +92 -92
- package/packages/components/sh-corner/index.vue +230 -230
- package/packages/components/sh-count-to/index.vue +131 -131
- package/packages/components/sh-date/index.vue +301 -301
- package/packages/components/sh-drawer/index.vue +579 -579
- package/packages/components/sh-drawer/scrollbar.js +78 -78
- package/packages/components/sh-empty/index.vue +42 -42
- package/packages/components/sh-form/js/props.js +76 -76
- package/packages/components/sh-form/js/useForm.js +229 -229
- package/packages/components/sh-header/index.vue +261 -260
- package/packages/components/sh-icon/css/default/ionicons.svg +869 -869
- package/packages/components/sh-icon/css/font/iconfont.json +247 -247
- package/packages/components/sh-icon/index.vue +41 -41
- package/packages/components/sh-image/index.vue +133 -133
- package/packages/components/sh-list/index.vue +146 -146
- package/packages/components/sh-loading/index.vue +53 -53
- package/packages/components/sh-modal/index.vue +188 -188
- package/packages/components/sh-noticebar/index.vue +215 -215
- package/packages/components/sh-poptip/index.vue +597 -597
- package/packages/components/sh-progress/index.vue +276 -276
- package/packages/components/sh-pull-refresh/index.vue +289 -289
- package/packages/components/sh-result/index.vue +114 -114
- package/packages/components/sh-row/index.vue +66 -66
- package/packages/components/sh-split/components/trigger.vue +33 -33
- package/packages/components/sh-split/index.vue +342 -342
- package/packages/components/sh-table/components/importModal.vue +363 -363
- package/packages/components/sh-table/components/sh-column.vue +68 -68
- package/packages/components/sh-table/js/excel_to_json.js +313 -313
- package/packages/components/sh-table/js/props.js +305 -305
- package/packages/components/sh-table/js/tableMethods.js +167 -167
- package/packages/components/sh-table/js/useTable.js +636 -636
- package/packages/components/sh-table/table.vue +217 -217
- package/packages/components/sh-tabs/index.vue +426 -426
- package/packages/components/sh-tag/index.vue +168 -168
- package/packages/components/sh-toolbar/index.vue +182 -182
- package/packages/components/sh-tree/components/table-tree.vue +289 -289
- package/packages/components/sh-tree/mixin/treeProps.js +122 -122
- package/packages/components/sh-upload/index.vue +535 -535
- package/packages/components/sh-water-fall/index.vue +80 -80
- package/packages/components/sh-water-mark/index.vue +96 -96
- package/packages/css/index.js +4 -4
- package/packages/directive/index.js +19 -19
- package/packages/directive/module/click-out.js +14 -14
- package/packages/directive/module/draggable.js +42 -42
- package/packages/directive/module/line-clamp.js +22 -22
- package/packages/directive/module/prevent-click.js +18 -18
- package/packages/directive/module/resize.js +14 -14
- package/packages/directive/module/ripple.js +166 -166
- package/packages/index.js +39 -39
- package/packages/mixin/index.js +86 -86
- package/packages/other/sh-cron-modal/components/cron-content.vue +294 -294
- package/packages/other/sh-cron-modal/index.vue +81 -81
- package/packages/other/sh-cron-modal/mixin/cron-emits.js +1 -1
- package/packages/other/sh-cron-modal/mixin/cron-props.js +9 -9
- package/packages/other/sh-cron-modal/tabs/cron-week-box.vue +126 -126
- package/packages/other/sh-menu/index.vue +326 -326
- package/packages/other/sh-menu/menu-group-content.vue +136 -136
- package/packages/other/sh-menu/menu-item-content.vue +71 -71
- package/packages/other/sh-menu-card/index.vue +250 -250
- package/packages/other/sh-menu-card/menu-box.vue +87 -87
- package/packages/other/sh-preview/components/sh-excel.vue +163 -163
- package/packages/other/sh-preview/js/data-hook.js +41 -41
- package/packages/other/sh-preview/js/data-props.js +15 -15
- package/packages/other/sh-system-tip/index.vue +115 -115
- package/packages/utils/resize.js +69 -70
- package/packages/utils/transfer-queue.js +12 -12
- package/packages/vxeTable/index.js +193 -184
- package/packages/vxeTable/plugins/export.js +450 -450
- package/packages/vxeTable/render/cell/vxe-render-img.vue +27 -27
- package/packages/vxeTable/render/cell/vxe-render-table.vue +51 -51
- package/packages/vxeTable/render/cell/vxe-render-time.vue +44 -44
- package/packages/vxeTable/render/cell/vxe-render-tree.vue +70 -70
- package/packages/vxeTable/render/filters/vxe-filter-input.vue +26 -26
- package/packages/vxeTable/render/filters/vxe-filter-time.vue +26 -26
- package/packages/vxeTable/render/globalRenders.jsx +514 -514
- package/packages/vxeTable/render/mixin/cell-hooks.js +198 -198
- package/packages/vxeTable/render/mixin/cell-props.js +23 -23
- package/packages/vxeTable/render/mixin/filter-hooks.js +46 -46
- package/tsconfig.json +25 -0
- package/types/component.d.ts +1 -0
- package/types/index.ts +0 -0
|
@@ -1,294 +1,294 @@
|
|
|
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 { defineComponent, computed, getCurrentInstance, ref, reactive, watch, onBeforeMount } from 'vue'
|
|
44
|
-
import cronSecondBox from '../tabs/cron-second-box.vue'
|
|
45
|
-
import cronMinuteBox from '../tabs/cron-minute-box.vue'
|
|
46
|
-
import cronHourBox from '../tabs/cron-hour-box.vue'
|
|
47
|
-
import cronDayBox from '../tabs/cron-day-box.vue'
|
|
48
|
-
import cronMonthBox from '../tabs/cron-month-box.vue'
|
|
49
|
-
import cronWeekBox from '../tabs/cron-week-box.vue'
|
|
50
|
-
import cronYearBox from '../tabs/cron-year-box.vue'
|
|
51
|
-
import cronUtils from '../utils'
|
|
52
|
-
export default defineComponent({
|
|
53
|
-
name: 'CronContent',
|
|
54
|
-
components: {
|
|
55
|
-
cronSecondBox,
|
|
56
|
-
cronMinuteBox,
|
|
57
|
-
cronHourBox,
|
|
58
|
-
cronDayBox,
|
|
59
|
-
cronMonthBox,
|
|
60
|
-
cronWeekBox,
|
|
61
|
-
cronYearBox
|
|
62
|
-
},
|
|
63
|
-
props: {
|
|
64
|
-
modelValue: {
|
|
65
|
-
type: String,
|
|
66
|
-
default: ''
|
|
67
|
-
},
|
|
68
|
-
disabled: {
|
|
69
|
-
type: Boolean
|
|
70
|
-
},
|
|
71
|
-
hideSecond: {
|
|
72
|
-
type: Boolean
|
|
73
|
-
},
|
|
74
|
-
hideYear: {
|
|
75
|
-
type: Boolean
|
|
76
|
-
},
|
|
77
|
-
remote: {
|
|
78
|
-
type: Function
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
emits: ['update:modelValue', 'change'],
|
|
82
|
-
setup(props, context) {
|
|
83
|
-
const { proxy } = getCurrentInstance()
|
|
84
|
-
const { $vUtils } = proxy
|
|
85
|
-
const { emit, slots } = context
|
|
86
|
-
|
|
87
|
-
const activeKey = ref(props.hideSecond ? 'minute' : 'second')
|
|
88
|
-
const second = ref('*')
|
|
89
|
-
const minute = ref('*')
|
|
90
|
-
const hour = ref('*')
|
|
91
|
-
const day = ref('*')
|
|
92
|
-
const month = ref('*')
|
|
93
|
-
const week = ref('*')
|
|
94
|
-
const year = ref('*')
|
|
95
|
-
const tableConfig = reactive({
|
|
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: !props.disabled
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
const preTimeList = ref('执行预览,会忽略年份参数。')
|
|
112
|
-
const errMessage = ref('')
|
|
113
|
-
|
|
114
|
-
const cronTabList = computed(() => {
|
|
115
|
-
let list = [
|
|
116
|
-
{ value: 'second', label: '秒' },
|
|
117
|
-
{ value: 'minute', label: '分' },
|
|
118
|
-
{ value: 'hour', label: '时' },
|
|
119
|
-
{ value: 'day', label: '日' },
|
|
120
|
-
{ value: 'month', label: '月' },
|
|
121
|
-
{ value: 'week', label: '周' },
|
|
122
|
-
{ value: 'year', label: '年' }
|
|
123
|
-
]
|
|
124
|
-
if (props.hideSecond) {
|
|
125
|
-
list = list.filter(item => !['second', 'year'].includes(item.value))
|
|
126
|
-
} else if (props.hideYear) {
|
|
127
|
-
list = list.filter(item => !['year'].includes(item.value))
|
|
128
|
-
}
|
|
129
|
-
return list
|
|
130
|
-
})
|
|
131
|
-
const cronValueInner = computed(() => {
|
|
132
|
-
let result = []
|
|
133
|
-
if (!props.hideSecond) {
|
|
134
|
-
result.push(second.value || '*')
|
|
135
|
-
}
|
|
136
|
-
result.push(minute.value || '*')
|
|
137
|
-
result.push(hour.value || '*')
|
|
138
|
-
result.push(day.value || '*')
|
|
139
|
-
result.push(month.value || '*')
|
|
140
|
-
result.push(week.value || '?')
|
|
141
|
-
if (!props.hideYear && !props.hideSecond) result.push(year.value || '*')
|
|
142
|
-
return result.join(' ')
|
|
143
|
-
})
|
|
144
|
-
const cronValueNoYear = computed(() => {
|
|
145
|
-
const v = cronValueInner.value
|
|
146
|
-
if (props.hideYear || props.hideSecond) return v
|
|
147
|
-
const vs = v.split(' ')
|
|
148
|
-
if (vs.length >= 6) {
|
|
149
|
-
// 转成 Quartz 的规则
|
|
150
|
-
vs[5] = convertWeekToQuartz(vs[5])
|
|
151
|
-
}
|
|
152
|
-
return vs.slice(0, vs.length - 1).join(' ')
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
const formatValue = () => {
|
|
156
|
-
let { modelValue, hideSecond } = props
|
|
157
|
-
if (!modelValue) return
|
|
158
|
-
const values = modelValue.split(' ').filter(item => !!item)
|
|
159
|
-
if (!values || values.length <= 0) return
|
|
160
|
-
let i = 0
|
|
161
|
-
if (!hideSecond) second.value = values[i++]
|
|
162
|
-
if (values.length > i) minute.value = values[i++]
|
|
163
|
-
if (values.length > i) hour.value = values[i++]
|
|
164
|
-
if (values.length > i) day.value = values[i++]
|
|
165
|
-
if (values.length > i) month.value = values[i++]
|
|
166
|
-
if (values.length > i) week.value = values[i++]
|
|
167
|
-
if (values.length > i) year.value = values[i]
|
|
168
|
-
assignTable()
|
|
169
|
-
}
|
|
170
|
-
const assignTable = () => {
|
|
171
|
-
tableConfig.data = [{ second: second.value, minute: minute.value, hour: hour.value, day: day.value, month: month.value, week: week.value, year: year.value }]
|
|
172
|
-
}
|
|
173
|
-
const calTriggerListInner = () => {
|
|
174
|
-
errMessage.value = ''
|
|
175
|
-
// 设置了回调函数
|
|
176
|
-
if (props.remote) {
|
|
177
|
-
props.remote(cronValueInner.value, +new Date(), v => {
|
|
178
|
-
preTimeList.value = v
|
|
179
|
-
})
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
try {
|
|
183
|
-
const format = 'yyyy-MM-dd hh:mm:ss'
|
|
184
|
-
const options = {
|
|
185
|
-
currentDate: $vUtils.toDateString(new Date(), format)
|
|
186
|
-
}
|
|
187
|
-
const iter = cronUtils.parse(cronValueNoYear.value, options)
|
|
188
|
-
const result = []
|
|
189
|
-
for (let i = 1; i <= 10; i++) {
|
|
190
|
-
result.push($vUtils.toDateString(new Date(iter.next()), format))
|
|
191
|
-
}
|
|
192
|
-
preTimeList.value = result.length > 0 ? result.join('\n') : '无执行时间'
|
|
193
|
-
} catch (e) {
|
|
194
|
-
errMessage.value = e
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
// Quartz 的规则:
|
|
198
|
-
// 1 = 周日,2 = 周一,3 = 周二,4 = 周三,5 = 周四,6 = 周五,7 = 周六
|
|
199
|
-
const convertWeekToQuartz = week => {
|
|
200
|
-
let convert = v => {
|
|
201
|
-
if (v === '0') {
|
|
202
|
-
return '1'
|
|
203
|
-
}
|
|
204
|
-
if (v === '1') {
|
|
205
|
-
return '0'
|
|
206
|
-
}
|
|
207
|
-
return (Number.parseInt(v) - 1).toString()
|
|
208
|
-
}
|
|
209
|
-
// 匹配示例 1-7 or 1/7
|
|
210
|
-
let patten1 = /^([0-7])([-/])([0-7])$/
|
|
211
|
-
// 匹配示例 1,4,7
|
|
212
|
-
let patten2 = /^([0-7])(,[0-7])+$/
|
|
213
|
-
if (/^[0-7]$/.test(week)) {
|
|
214
|
-
return convert(week)
|
|
215
|
-
} else if (patten1.test(week)) {
|
|
216
|
-
return week.replace(patten1, ($0, before, separator, after) => {
|
|
217
|
-
if (separator === '/') {
|
|
218
|
-
return convert(before) + separator + after
|
|
219
|
-
} else {
|
|
220
|
-
return convert(before) + separator + convert(after)
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
} else if (patten2.test(week)) {
|
|
224
|
-
return week
|
|
225
|
-
.split(',')
|
|
226
|
-
.map(v => convert(v))
|
|
227
|
-
.join(',')
|
|
228
|
-
}
|
|
229
|
-
return week
|
|
230
|
-
}
|
|
231
|
-
const onTableHeaderClick = ({ column }) => {
|
|
232
|
-
activeKey.value = column.property
|
|
233
|
-
}
|
|
234
|
-
const onTableEditClosed = ({ row, column }) => {
|
|
235
|
-
second.value = row.second
|
|
236
|
-
minute.value = row.minute
|
|
237
|
-
hour.value = row.hour
|
|
238
|
-
day.value = row.day
|
|
239
|
-
month.value = row.month
|
|
240
|
-
week.value = row.week
|
|
241
|
-
year.value = row.year
|
|
242
|
-
}
|
|
243
|
-
const emitValue = value => {
|
|
244
|
-
emit('change', value)
|
|
245
|
-
emit('update:modelValue', value)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const calTriggerList = $vUtils.debounce(calTriggerListInner, 500)
|
|
249
|
-
|
|
250
|
-
watch(
|
|
251
|
-
() => props.modelValue,
|
|
252
|
-
nv => {
|
|
253
|
-
if (nv === cronValueInner.value) {
|
|
254
|
-
return
|
|
255
|
-
}
|
|
256
|
-
formatValue()
|
|
257
|
-
}
|
|
258
|
-
)
|
|
259
|
-
watch(
|
|
260
|
-
() => cronValueInner.value,
|
|
261
|
-
nv => {
|
|
262
|
-
calTriggerList()
|
|
263
|
-
emitValue(nv)
|
|
264
|
-
assignTable()
|
|
265
|
-
}
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
onBeforeMount(() => {
|
|
269
|
-
assignTable()
|
|
270
|
-
formatValue()
|
|
271
|
-
calTriggerListInner()
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
return {
|
|
275
|
-
activeKey,
|
|
276
|
-
cronTabList,
|
|
277
|
-
second,
|
|
278
|
-
minute,
|
|
279
|
-
hour,
|
|
280
|
-
day,
|
|
281
|
-
month,
|
|
282
|
-
week,
|
|
283
|
-
year,
|
|
284
|
-
tableConfig,
|
|
285
|
-
errMessage,
|
|
286
|
-
preTimeList,
|
|
287
|
-
onTableEditClosed,
|
|
288
|
-
onTableHeaderClick
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
})
|
|
292
|
-
</script>
|
|
293
|
-
|
|
294
|
-
<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 { defineComponent, computed, getCurrentInstance, ref, reactive, watch, onBeforeMount } from 'vue'
|
|
44
|
+
import cronSecondBox from '../tabs/cron-second-box.vue'
|
|
45
|
+
import cronMinuteBox from '../tabs/cron-minute-box.vue'
|
|
46
|
+
import cronHourBox from '../tabs/cron-hour-box.vue'
|
|
47
|
+
import cronDayBox from '../tabs/cron-day-box.vue'
|
|
48
|
+
import cronMonthBox from '../tabs/cron-month-box.vue'
|
|
49
|
+
import cronWeekBox from '../tabs/cron-week-box.vue'
|
|
50
|
+
import cronYearBox from '../tabs/cron-year-box.vue'
|
|
51
|
+
import cronUtils from '../utils'
|
|
52
|
+
export default defineComponent({
|
|
53
|
+
name: 'CronContent',
|
|
54
|
+
components: {
|
|
55
|
+
cronSecondBox,
|
|
56
|
+
cronMinuteBox,
|
|
57
|
+
cronHourBox,
|
|
58
|
+
cronDayBox,
|
|
59
|
+
cronMonthBox,
|
|
60
|
+
cronWeekBox,
|
|
61
|
+
cronYearBox
|
|
62
|
+
},
|
|
63
|
+
props: {
|
|
64
|
+
modelValue: {
|
|
65
|
+
type: String,
|
|
66
|
+
default: ''
|
|
67
|
+
},
|
|
68
|
+
disabled: {
|
|
69
|
+
type: Boolean
|
|
70
|
+
},
|
|
71
|
+
hideSecond: {
|
|
72
|
+
type: Boolean
|
|
73
|
+
},
|
|
74
|
+
hideYear: {
|
|
75
|
+
type: Boolean
|
|
76
|
+
},
|
|
77
|
+
remote: {
|
|
78
|
+
type: Function
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
emits: ['update:modelValue', 'change'],
|
|
82
|
+
setup(props, context) {
|
|
83
|
+
const { proxy } = getCurrentInstance()
|
|
84
|
+
const { $vUtils } = proxy
|
|
85
|
+
const { emit, slots } = context
|
|
86
|
+
|
|
87
|
+
const activeKey = ref(props.hideSecond ? 'minute' : 'second')
|
|
88
|
+
const second = ref('*')
|
|
89
|
+
const minute = ref('*')
|
|
90
|
+
const hour = ref('*')
|
|
91
|
+
const day = ref('*')
|
|
92
|
+
const month = ref('*')
|
|
93
|
+
const week = ref('*')
|
|
94
|
+
const year = ref('*')
|
|
95
|
+
const tableConfig = reactive({
|
|
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: !props.disabled
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
const preTimeList = ref('执行预览,会忽略年份参数。')
|
|
112
|
+
const errMessage = ref('')
|
|
113
|
+
|
|
114
|
+
const cronTabList = computed(() => {
|
|
115
|
+
let list = [
|
|
116
|
+
{ value: 'second', label: '秒' },
|
|
117
|
+
{ value: 'minute', label: '分' },
|
|
118
|
+
{ value: 'hour', label: '时' },
|
|
119
|
+
{ value: 'day', label: '日' },
|
|
120
|
+
{ value: 'month', label: '月' },
|
|
121
|
+
{ value: 'week', label: '周' },
|
|
122
|
+
{ value: 'year', label: '年' }
|
|
123
|
+
]
|
|
124
|
+
if (props.hideSecond) {
|
|
125
|
+
list = list.filter(item => !['second', 'year'].includes(item.value))
|
|
126
|
+
} else if (props.hideYear) {
|
|
127
|
+
list = list.filter(item => !['year'].includes(item.value))
|
|
128
|
+
}
|
|
129
|
+
return list
|
|
130
|
+
})
|
|
131
|
+
const cronValueInner = computed(() => {
|
|
132
|
+
let result = []
|
|
133
|
+
if (!props.hideSecond) {
|
|
134
|
+
result.push(second.value || '*')
|
|
135
|
+
}
|
|
136
|
+
result.push(minute.value || '*')
|
|
137
|
+
result.push(hour.value || '*')
|
|
138
|
+
result.push(day.value || '*')
|
|
139
|
+
result.push(month.value || '*')
|
|
140
|
+
result.push(week.value || '?')
|
|
141
|
+
if (!props.hideYear && !props.hideSecond) result.push(year.value || '*')
|
|
142
|
+
return result.join(' ')
|
|
143
|
+
})
|
|
144
|
+
const cronValueNoYear = computed(() => {
|
|
145
|
+
const v = cronValueInner.value
|
|
146
|
+
if (props.hideYear || props.hideSecond) return v
|
|
147
|
+
const vs = v.split(' ')
|
|
148
|
+
if (vs.length >= 6) {
|
|
149
|
+
// 转成 Quartz 的规则
|
|
150
|
+
vs[5] = convertWeekToQuartz(vs[5])
|
|
151
|
+
}
|
|
152
|
+
return vs.slice(0, vs.length - 1).join(' ')
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
const formatValue = () => {
|
|
156
|
+
let { modelValue, hideSecond } = props
|
|
157
|
+
if (!modelValue) return
|
|
158
|
+
const values = modelValue.split(' ').filter(item => !!item)
|
|
159
|
+
if (!values || values.length <= 0) return
|
|
160
|
+
let i = 0
|
|
161
|
+
if (!hideSecond) second.value = values[i++]
|
|
162
|
+
if (values.length > i) minute.value = values[i++]
|
|
163
|
+
if (values.length > i) hour.value = values[i++]
|
|
164
|
+
if (values.length > i) day.value = values[i++]
|
|
165
|
+
if (values.length > i) month.value = values[i++]
|
|
166
|
+
if (values.length > i) week.value = values[i++]
|
|
167
|
+
if (values.length > i) year.value = values[i]
|
|
168
|
+
assignTable()
|
|
169
|
+
}
|
|
170
|
+
const assignTable = () => {
|
|
171
|
+
tableConfig.data = [{ second: second.value, minute: minute.value, hour: hour.value, day: day.value, month: month.value, week: week.value, year: year.value }]
|
|
172
|
+
}
|
|
173
|
+
const calTriggerListInner = () => {
|
|
174
|
+
errMessage.value = ''
|
|
175
|
+
// 设置了回调函数
|
|
176
|
+
if (props.remote) {
|
|
177
|
+
props.remote(cronValueInner.value, +new Date(), v => {
|
|
178
|
+
preTimeList.value = v
|
|
179
|
+
})
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const format = 'yyyy-MM-dd hh:mm:ss'
|
|
184
|
+
const options = {
|
|
185
|
+
currentDate: $vUtils.toDateString(new Date(), format)
|
|
186
|
+
}
|
|
187
|
+
const iter = cronUtils.parse(cronValueNoYear.value, options)
|
|
188
|
+
const result = []
|
|
189
|
+
for (let i = 1; i <= 10; i++) {
|
|
190
|
+
result.push($vUtils.toDateString(new Date(iter.next()), format))
|
|
191
|
+
}
|
|
192
|
+
preTimeList.value = result.length > 0 ? result.join('\n') : '无执行时间'
|
|
193
|
+
} catch (e) {
|
|
194
|
+
errMessage.value = e
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Quartz 的规则:
|
|
198
|
+
// 1 = 周日,2 = 周一,3 = 周二,4 = 周三,5 = 周四,6 = 周五,7 = 周六
|
|
199
|
+
const convertWeekToQuartz = week => {
|
|
200
|
+
let convert = v => {
|
|
201
|
+
if (v === '0') {
|
|
202
|
+
return '1'
|
|
203
|
+
}
|
|
204
|
+
if (v === '1') {
|
|
205
|
+
return '0'
|
|
206
|
+
}
|
|
207
|
+
return (Number.parseInt(v) - 1).toString()
|
|
208
|
+
}
|
|
209
|
+
// 匹配示例 1-7 or 1/7
|
|
210
|
+
let patten1 = /^([0-7])([-/])([0-7])$/
|
|
211
|
+
// 匹配示例 1,4,7
|
|
212
|
+
let patten2 = /^([0-7])(,[0-7])+$/
|
|
213
|
+
if (/^[0-7]$/.test(week)) {
|
|
214
|
+
return convert(week)
|
|
215
|
+
} else if (patten1.test(week)) {
|
|
216
|
+
return week.replace(patten1, ($0, before, separator, after) => {
|
|
217
|
+
if (separator === '/') {
|
|
218
|
+
return convert(before) + separator + after
|
|
219
|
+
} else {
|
|
220
|
+
return convert(before) + separator + convert(after)
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
} else if (patten2.test(week)) {
|
|
224
|
+
return week
|
|
225
|
+
.split(',')
|
|
226
|
+
.map(v => convert(v))
|
|
227
|
+
.join(',')
|
|
228
|
+
}
|
|
229
|
+
return week
|
|
230
|
+
}
|
|
231
|
+
const onTableHeaderClick = ({ column }) => {
|
|
232
|
+
activeKey.value = column.property
|
|
233
|
+
}
|
|
234
|
+
const onTableEditClosed = ({ row, column }) => {
|
|
235
|
+
second.value = row.second
|
|
236
|
+
minute.value = row.minute
|
|
237
|
+
hour.value = row.hour
|
|
238
|
+
day.value = row.day
|
|
239
|
+
month.value = row.month
|
|
240
|
+
week.value = row.week
|
|
241
|
+
year.value = row.year
|
|
242
|
+
}
|
|
243
|
+
const emitValue = value => {
|
|
244
|
+
emit('change', value)
|
|
245
|
+
emit('update:modelValue', value)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const calTriggerList = $vUtils.debounce(calTriggerListInner, 500)
|
|
249
|
+
|
|
250
|
+
watch(
|
|
251
|
+
() => props.modelValue,
|
|
252
|
+
nv => {
|
|
253
|
+
if (nv === cronValueInner.value) {
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
formatValue()
|
|
257
|
+
}
|
|
258
|
+
)
|
|
259
|
+
watch(
|
|
260
|
+
() => cronValueInner.value,
|
|
261
|
+
nv => {
|
|
262
|
+
calTriggerList()
|
|
263
|
+
emitValue(nv)
|
|
264
|
+
assignTable()
|
|
265
|
+
}
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
onBeforeMount(() => {
|
|
269
|
+
assignTable()
|
|
270
|
+
formatValue()
|
|
271
|
+
calTriggerListInner()
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
activeKey,
|
|
276
|
+
cronTabList,
|
|
277
|
+
second,
|
|
278
|
+
minute,
|
|
279
|
+
hour,
|
|
280
|
+
day,
|
|
281
|
+
month,
|
|
282
|
+
week,
|
|
283
|
+
year,
|
|
284
|
+
tableConfig,
|
|
285
|
+
errMessage,
|
|
286
|
+
preTimeList,
|
|
287
|
+
onTableEditClosed,
|
|
288
|
+
onTableHeaderClick
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
</script>
|
|
293
|
+
|
|
294
|
+
<style scoped></style>
|